@surfaces-ui/components 0.2.0 → 0.4.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 (53) hide show
  1. package/README.md +3 -0
  2. package/dist/chart/BulletGraph.js +2 -1
  3. package/dist/chart/BulletGraph.js.map +1 -1
  4. package/dist/chart/Chart.d.ts +2 -1
  5. package/dist/chart/Chart.js +9 -3
  6. package/dist/chart/Chart.js.map +1 -1
  7. package/dist/chart/Sparkline.js +2 -1
  8. package/dist/chart/Sparkline.js.map +1 -1
  9. package/dist/chart/advice.d.ts +5 -1
  10. package/dist/chart/advice.js +9 -0
  11. package/dist/chart/advice.js.map +1 -1
  12. package/dist/chart/wheel.d.ts +12 -0
  13. package/dist/chart/wheel.js +21 -0
  14. package/dist/chart/wheel.js.map +1 -0
  15. package/dist/data/DataNotes.d.ts +13 -0
  16. package/dist/data/DataNotes.js +18 -0
  17. package/dist/data/DataNotes.js.map +1 -0
  18. package/dist/discovery/AskData.js +2 -1
  19. package/dist/discovery/AskData.js.map +1 -1
  20. package/dist/explore/SemanticRows.js +5 -1
  21. package/dist/explore/SemanticRows.js.map +1 -1
  22. package/dist/graph/NodeGraph.js +3 -0
  23. package/dist/graph/NodeGraph.js.map +1 -1
  24. package/dist/grid/DataGrid.js +2 -1
  25. package/dist/grid/DataGrid.js.map +1 -1
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +1 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/metric/Metric.js +3 -2
  30. package/dist/metric/Metric.js.map +1 -1
  31. package/dist/metric/useMeasure.d.ts +2 -0
  32. package/dist/metric/useMeasure.js +2 -1
  33. package/dist/metric/useMeasure.js.map +1 -1
  34. package/dist/model/ModelDiagram.js +2 -1
  35. package/dist/model/ModelDiagram.js.map +1 -1
  36. package/dist/pivot/PivotTable.js +8 -3
  37. package/dist/pivot/PivotTable.js.map +1 -1
  38. package/dist/result/QueryResult.js +2 -1
  39. package/dist/result/QueryResult.js.map +1 -1
  40. package/dist/rows/RowList.js +3 -2
  41. package/dist/rows/RowList.js.map +1 -1
  42. package/dist/styles.css +113 -26
  43. package/dist/styles.layer.css +113 -26
  44. package/dist/theme/ThemePicker.d.ts +2 -2
  45. package/dist/theme/ThemePicker.js +3 -2
  46. package/dist/theme/ThemePicker.js.map +1 -1
  47. package/dist/theme/ThemeProvider.d.ts +10 -1
  48. package/dist/theme/ThemeProvider.js +31 -16
  49. package/dist/theme/ThemeProvider.js.map +1 -1
  50. package/dist/workspace/Workspace.d.ts +3 -0
  51. package/dist/workspace/Workspace.js +1 -1
  52. package/dist/workspace/Workspace.js.map +1 -1
  53. package/package.json +6 -6
package/README.md CHANGED
@@ -41,6 +41,9 @@ To restyle, start with a theme. `@surfaces-ui/components/styles.layer.css` is th
41
41
 
42
42
  Surfaces UI is a UI library for data and analytics: exploring schemas, querying, charting, tables at scale, chat, and pages an agent can build.
43
43
 
44
+ Every Surfaces UI package is released at the same version; install them all at that one version, since mixing releases is not supported.
45
+
46
+ - [The guides on surfaces-ui.com](https://surfaces-ui.com/#docs)
44
47
  - [Getting started](https://github.com/teradata-labs/surfaces-ui/blob/main/docs/getting-started.md)
45
48
  - [Building with an agent](https://github.com/teradata-labs/surfaces-ui/blob/main/docs/agent-integration.md)
46
49
  - [Styling](https://github.com/teradata-labs/surfaces-ui/blob/main/docs/styling.md)
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useDataSource } from "../data/DataSourceProvider.js";
3
+ import { DataNotes } from "../data/DataNotes.js";
3
4
  import { label as text } from "../locale/locale.js";
4
5
  import { formatMetric } from "../metric/Metric.js";
5
6
  import { useMeasure } from "../metric/useMeasure.js";
@@ -35,6 +36,6 @@ export function BulletGraph(props) {
35
36
  band: band ? `, ${band.label.toLowerCase()}` : "",
36
37
  target: target !== undefined ? text(value >= target ? "bullet.targetMet" : "bullet.targetNotMet", { target: write(target) }) : "",
37
38
  });
38
- return (_jsxs("div", { className: ["sf-bullet", props.className].filter(Boolean).join(" "), "aria-busy": state.loading, children: [_jsxs("div", { className: "sf-bullet-head", children: [_jsx("span", { className: "sf-bullet-label", children: label }), state.error ? (_jsx("span", { className: "sf-metric-error", role: "alert", "data-error": state.error, children: props.errorMessage ?? state.error })) : (_jsxs("span", { className: "sf-bullet-value", children: [value == null ? (state.loading ? text("metric.loading") : (props.emptyMessage ?? text("metric.none"))) : write(value), band && _jsxs("span", { className: "sf-bullet-band", children: [" ", band.label] })] }))] }), _jsxs("div", { className: "sf-bullet-track", role: "img", "aria-label": reading, children: [ranges.map((range, i) => (_jsx("span", { className: "sf-bullet-range", "data-band": i + 1, style: { left: pct(ranges[i - 1]?.to ?? 0), right: `calc(100% - ${pct(range.to)})` } }, range.to))), value != null && _jsx("span", { className: "sf-bullet-bar", style: { width: pct(value) } }), target !== undefined && _jsx("span", { className: "sf-bullet-target", style: { left: pct(target) } })] }), _jsxs("div", { className: "sf-bullet-scale", "aria-hidden": "true", children: [_jsx("span", { children: write(0) }), target !== undefined && _jsx("span", { children: text("bullet.target", { target: write(target) }) }), _jsx("span", { children: write(end) })] })] }));
39
+ return (_jsxs("div", { className: ["sf-bullet", props.className].filter(Boolean).join(" "), "aria-busy": state.loading, children: [_jsxs("div", { className: "sf-bullet-head", children: [_jsx("span", { className: "sf-bullet-label", children: label }), state.error ? (_jsx("span", { className: "sf-metric-error", role: "alert", "data-error": state.error, children: props.errorMessage ?? state.error })) : (_jsxs("span", { className: "sf-bullet-value", children: [value == null ? (state.loading ? text("metric.loading") : (props.emptyMessage ?? text("metric.none"))) : write(value), band && _jsxs("span", { className: "sf-bullet-band", children: [" ", band.label] })] }))] }), _jsxs("div", { className: "sf-bullet-track", role: "img", "aria-label": reading, children: [ranges.map((range, i) => (_jsx("span", { className: "sf-bullet-range", "data-band": i + 1, style: { left: pct(ranges[i - 1]?.to ?? 0), right: `calc(100% - ${pct(range.to)})` } }, range.to))), value != null && _jsx("span", { className: "sf-bullet-bar", style: { width: pct(value) } }), target !== undefined && _jsx("span", { className: "sf-bullet-target", style: { left: pct(target) } })] }), _jsxs("div", { className: "sf-bullet-scale", "aria-hidden": "true", children: [_jsx("span", { children: write(0) }), target !== undefined && _jsx("span", { children: text("bullet.target", { target: write(target) }) }), _jsx("span", { children: write(end) })] }), _jsx(DataNotes, { notes: state.notes })] }));
39
40
  }
40
41
  //# sourceMappingURL=BulletGraph.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BulletGraph.js","sourceRoot":"","sources":["../../src/chart/BulletGraph.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAG9D,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAoB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAyBrD,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,MAAuC;IAC/E,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAuB;IACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACxG,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAA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AG,IAAI,CAAC,KAAK,IAAQ,IACzD,CACR,IACG,EACN,eAAK,SAAS,EAAC,iBAAiB,EAAC,IAAI,EAAC,KAAK,gBAAa,OAAO,aAC5D,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CACxB,eAAqB,SAAS,EAAC,iBAAiB,eAAY,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,IAA5I,KAAK,CAAC,EAAE,CAAwI,CAC5J,CAAC,EACD,KAAK,IAAI,IAAI,IAAI,eAAM,SAAS,EAAC,eAAe,EAAC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,GAAI,EACjF,MAAM,KAAK,SAAS,IAAI,eAAM,SAAS,EAAC,kBAAkB,EAAC,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,GAAI,IACxF,EACN,eAAK,SAAS,EAAC,iBAAiB,iBAAa,MAAM,aACjD,yBAAO,KAAK,CAAC,CAAC,CAAC,GAAQ,EACtB,MAAM,KAAK,SAAS,IAAI,yBAAO,IAAI,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,GAAQ,EACxF,yBAAO,KAAK,CAAC,GAAG,CAAC,GAAQ,IACrB,IACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { DataSource } from \"@surfaces-ui/data\";\nimport { useDataSource } from \"../data/DataSourceProvider.js\";\nimport type { DataMessages } from \"../data/messages.js\";\nimport type { FilterInit } from \"../data/useRowWindow.js\";\nimport { label as text } from \"../locale/locale.js\";\nimport { type MetricProps, formatMetric } from \"../metric/Metric.js\";\nimport { useMeasure } from \"../metric/useMeasure.js\";\nimport type { ChartAggregate } from \"./Chart.js\";\n\nexport interface BulletGraphProps extends DataMessages {\n sourceId: string;\n sql: string;\n column?: string;\n aggregate: ChartAggregate;\n label: string;\n /** The value to compare against, drawn as a tick across the bar. */\n target?: number;\n /**\n * Where the qualitative bands end, lowest first, with a name for each:\n * `[{ to: 50, label: \"Poor\" }, { to: 80, label: \"Fair\" }, { to: 100, label: \"Good\" }]`.\n * The last band's end is the end of the scale. Up to five.\n */\n ranges: { to: number; label: string }[];\n format?: MetricProps[\"format\"];\n currency?: string;\n filters?: FilterInit[];\n notBefore?: string;\n dataSource?: DataSource;\n className?: string;\n}\n\n/** The band a value falls in, or the last one when it is past the end. */\nexport function bulletBand(value: number, ranges: { to: number; label: string }[]): { to: number; label: string } | undefined {\n return ranges.find((r) => value <= r.to) ?? ranges.at(-1);\n}\n\n/**\n * Stephen Few's bullet graph: one measure as a bar from zero, a tick for the\n * target, and shaded bands that say whether the value is poor, fair or good.\n * It replaces a gauge in a fraction of the space. The bands differ in\n * lightness only, and the reading is also written out in words.\n */\nexport function BulletGraph(props: BulletGraphProps) {\n const { sourceId, sql, column, aggregate, label, target, format, currency, filters, notBefore } = props;\n const ranges = [...props.ranges].sort((a, b) => a.to - b.to).slice(0, 5);\n const dataSource = useDataSource(props.dataSource);\n const state = useMeasure(dataSource, { sourceId, sql, column, aggregate, filters, notBefore });\n const value = state.values?.[0] ?? undefined;\n const write = (n: number) => formatMetric(n, format, currency);\n const end = Math.max(ranges.at(-1)?.to ?? 0, target ?? 0, value ?? 0) || 1;\n const pct = (n: number) => `${Math.max(0, Math.min(100, (n / end) * 100))}%`;\n const band = value == null ? undefined : bulletBand(value, ranges);\n const reading =\n value == null\n ? state.loading\n ? text(\"bullet.loading\", { label })\n : props.emptyMessage\n ? `${label}: ${props.emptyMessage}`\n : text(\"bullet.empty\", { label })\n : text(\"bullet.reading\", {\n label,\n value: write(value),\n band: band ? `, ${band.label.toLowerCase()}` : \"\",\n target: target !== undefined ? text(value >= target ? \"bullet.targetMet\" : \"bullet.targetNotMet\", { target: write(target) }) : \"\",\n });\n\n return (\n <div className={[\"sf-bullet\", props.className].filter(Boolean).join(\" \")} aria-busy={state.loading}>\n <div className=\"sf-bullet-head\">\n <span className=\"sf-bullet-label\">{label}</span>\n {state.error ? (\n <span className=\"sf-metric-error\" role=\"alert\" data-error={state.error}>\n {props.errorMessage ?? state.error}\n </span>\n ) : (\n <span className=\"sf-bullet-value\">\n {value == null ? (state.loading ? text(\"metric.loading\") : (props.emptyMessage ?? text(\"metric.none\"))) : write(value)}\n {band && <span className=\"sf-bullet-band\"> {band.label}</span>}\n </span>\n )}\n </div>\n <div className=\"sf-bullet-track\" role=\"img\" aria-label={reading}>\n {ranges.map((range, i) => (\n <span key={range.to} className=\"sf-bullet-range\" data-band={i + 1} style={{ left: pct(ranges[i - 1]?.to ?? 0), right: `calc(100% - ${pct(range.to)})` }} />\n ))}\n {value != null && <span className=\"sf-bullet-bar\" style={{ width: pct(value) }} />}\n {target !== undefined && <span className=\"sf-bullet-target\" style={{ left: pct(target) }} />}\n </div>\n <div className=\"sf-bullet-scale\" aria-hidden=\"true\">\n <span>{write(0)}</span>\n {target !== undefined && <span>{text(\"bullet.target\", { target: write(target) })}</span>}\n <span>{write(end)}</span>\n </div>\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"BulletGraph.js","sourceRoot":"","sources":["../../src/chart/BulletGraph.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAoB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAyBrD,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,K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,SAAS,EAAC,kBAAkB,EAAC,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,GAAI,IACxF,EACN,eAAK,SAAS,EAAC,iBAAiB,iBAAa,MAAM,aACjD,yBAAO,KAAK,CAAC,CAAC,CAAC,GAAQ,EACtB,MAAM,KAAK,SAAS,IAAI,yBAAO,IAAI,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,GAAQ,EACxF,yBAAO,KAAK,CAAC,GAAG,CAAC,GAAQ,IACrB,EACN,KAAC,SAAS,IAAC,KAAK,EAAE,KAAK,CAAC,KAAK,GAAI,IAC7B,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { DataSource } from \"@surfaces-ui/data\";\nimport { useDataSource } from \"../data/DataSourceProvider.js\";\nimport { DataNotes } from \"../data/DataNotes.js\";\nimport type { DataMessages } from \"../data/messages.js\";\nimport type { FilterInit } from \"../data/useRowWindow.js\";\nimport { label as text } from \"../locale/locale.js\";\nimport { type MetricProps, formatMetric } from \"../metric/Metric.js\";\nimport { useMeasure } from \"../metric/useMeasure.js\";\nimport type { ChartAggregate } from \"./Chart.js\";\n\nexport interface BulletGraphProps extends DataMessages {\n sourceId: string;\n sql: string;\n column?: string;\n aggregate: ChartAggregate;\n label: string;\n /** The value to compare against, drawn as a tick across the bar. */\n target?: number;\n /**\n * Where the qualitative bands end, lowest first, with a name for each:\n * `[{ to: 50, label: \"Poor\" }, { to: 80, label: \"Fair\" }, { to: 100, label: \"Good\" }]`.\n * The last band's end is the end of the scale. Up to five.\n */\n ranges: { to: number; label: string }[];\n format?: MetricProps[\"format\"];\n currency?: string;\n filters?: FilterInit[];\n notBefore?: string;\n dataSource?: DataSource;\n className?: string;\n}\n\n/** The band a value falls in, or the last one when it is past the end. */\nexport function bulletBand(value: number, ranges: { to: number; label: string }[]): { to: number; label: string } | undefined {\n return ranges.find((r) => value <= r.to) ?? ranges.at(-1);\n}\n\n/**\n * Stephen Few's bullet graph: one measure as a bar from zero, a tick for the\n * target, and shaded bands that say whether the value is poor, fair or good.\n * It replaces a gauge in a fraction of the space. The bands differ in\n * lightness only, and the reading is also written out in words.\n */\nexport function BulletGraph(props: BulletGraphProps) {\n const { sourceId, sql, column, aggregate, label, target, format, currency, filters, notBefore } = props;\n const ranges = [...props.ranges].sort((a, b) => a.to - b.to).slice(0, 5);\n const dataSource = useDataSource(props.dataSource);\n const state = useMeasure(dataSource, { sourceId, sql, column, aggregate, filters, notBefore });\n const value = state.values?.[0] ?? undefined;\n const write = (n: number) => formatMetric(n, format, currency);\n const end = Math.max(ranges.at(-1)?.to ?? 0, target ?? 0, value ?? 0) || 1;\n const pct = (n: number) => `${Math.max(0, Math.min(100, (n / end) * 100))}%`;\n const band = value == null ? undefined : bulletBand(value, ranges);\n const reading =\n value == null\n ? state.loading\n ? text(\"bullet.loading\", { label })\n : props.emptyMessage\n ? `${label}: ${props.emptyMessage}`\n : text(\"bullet.empty\", { label })\n : text(\"bullet.reading\", {\n label,\n value: write(value),\n band: band ? `, ${band.label.toLowerCase()}` : \"\",\n target: target !== undefined ? text(value >= target ? \"bullet.targetMet\" : \"bullet.targetNotMet\", { target: write(target) }) : \"\",\n });\n\n return (\n <div className={[\"sf-bullet\", props.className].filter(Boolean).join(\" \")} aria-busy={state.loading}>\n <div className=\"sf-bullet-head\">\n <span className=\"sf-bullet-label\">{label}</span>\n {state.error ? (\n <span className=\"sf-metric-error\" role=\"alert\" data-error={state.error}>\n {props.errorMessage ?? state.error}\n </span>\n ) : (\n <span className=\"sf-bullet-value\">\n {value == null ? (state.loading ? text(\"metric.loading\") : (props.emptyMessage ?? text(\"metric.none\"))) : write(value)}\n {band && <span className=\"sf-bullet-band\"> {band.label}</span>}\n </span>\n )}\n </div>\n <div className=\"sf-bullet-track\" role=\"img\" aria-label={reading}>\n {ranges.map((range, i) => (\n <span key={range.to} className=\"sf-bullet-range\" data-band={i + 1} style={{ left: pct(ranges[i - 1]?.to ?? 0), right: `calc(100% - ${pct(range.to)})` }} />\n ))}\n {value != null && <span className=\"sf-bullet-bar\" style={{ width: pct(value) }} />}\n {target !== undefined && <span className=\"sf-bullet-target\" style={{ left: pct(target) }} />}\n </div>\n <div className=\"sf-bullet-scale\" aria-hidden=\"true\">\n <span>{write(0)}</span>\n {target !== undefined && <span>{text(\"bullet.target\", { target: write(target) })}</span>}\n <span>{write(end)}</span>\n </div>\n <DataNotes notes={state.notes} />\n </div>\n );\n}\n"]}
@@ -135,9 +135,10 @@ export type ChartQueryInput = Pick<ChartProps, "sql" | "type" | "x" | "xGrain" |
135
135
  limit: number;
136
136
  };
137
137
  /** The shape of a loaded chart, in the terms `chartAdvice` checks. Nothing drawn gives no advice. */
138
- export declare function drawnShape(input: Pick<ChartProps, "type" | "x" | "y" | "stacked"> & Pick<ChartOptionInput, "fields" | "rows"> & {
138
+ export declare function drawnShape(input: Pick<ChartProps, "type" | "x" | "y" | "stacked" | "legend"> & Pick<ChartOptionInput, "fields" | "rows"> & {
139
139
  seriesCount: number;
140
140
  binned: boolean;
141
+ histogram?: boolean;
141
142
  }): ChartShape;
142
143
  /** How a chart's categories are ordered when not told: bars by size, everything else along x. */
143
144
  export declare function chartSort(input: Pick<ChartQueryInput, "type" | "xGrain" | "binWidth" | "sort" | "y">): "value" | "x";
@@ -8,11 +8,13 @@ import * as echarts from "echarts/core";
8
8
  import { CanvasRenderer } from "echarts/renderers";
9
9
  import { useEffect, useMemo, useRef, useState } from "react";
10
10
  import { useDataSource } from "../data/DataSourceProvider.js";
11
+ import { dataNotes } from "../data/DataNotes.js";
11
12
  import { chartValue, numericValue } from "../data/format.js";
12
13
  import { label as text, numberFormat } from "../locale/locale.js";
13
14
  import { messageOf } from "../data/useRowWindow.js";
14
15
  import { useOptionalTheme } from "../theme/ThemeProvider.js";
15
16
  import { chartAdvice } from "./advice.js";
17
+ import { wheelScrollsThePage } from "./wheel.js";
16
18
  import { buildChartOption, isOrdered, niceBinWidth, rowsWithoutX } from "./option.js";
17
19
  echarts.use([
18
20
  BarChart,
@@ -86,6 +88,8 @@ export function drawnShape(input) {
86
88
  stacked: input.stacked,
87
89
  rightAxis: input.y.some((m) => m.axis === "right"),
88
90
  orderedX: input.binned || isOrdered(input.fields.find((f) => f.name === input.x)),
91
+ ...(input.histogram ? { binned: true } : {}),
92
+ ...(input.legend ? { legend: input.legend } : {}),
89
93
  };
90
94
  }
91
95
  /** How a chart's categories are ordered when not told: bars by size, everything else along x. */
@@ -197,7 +201,7 @@ export function Chart(props) {
197
201
  const fields = result.table.schema.fields;
198
202
  const columns = fields.map((_, i) => result.table.getChildAt(i));
199
203
  const rows = Array.from({ length: result.table.numRows }, (_, r) => Object.fromEntries(fields.map((f, c) => [f.name, chartValue(columns[c].get(r), f.type)])));
200
- return { fields, rows, sort, cut: rows.length < limit ? undefined : aggregated ? "first" : "sample" };
204
+ return { fields, rows, sort, cut: rows.length < limit ? undefined : aggregated ? "first" : "sample", notes: dataNotes(result.header.notices) };
201
205
  };
202
206
  load()
203
207
  .then((loaded) => {
@@ -258,13 +262,15 @@ export function Chart(props) {
258
262
  });
259
263
  const observer = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(() => chart.resize());
260
264
  observer?.observe(element.current);
265
+ const unwheel = wheelScrollsThePage(element.current);
261
266
  return () => {
267
+ unwheel();
262
268
  observer?.disconnect();
263
269
  chart.dispose();
264
270
  };
265
271
  }, [option, themeDocument, mode]);
266
272
  // Advice is worked out from what was actually drawn, so it follows filters and the data.
267
- const advice = props.advice === false || !state.loaded ? [] : chartAdvice(drawnShape({ type, x, y, stacked, seriesCount, binned: Boolean(xGrain || xBinWidth || xBins), fields: state.loaded.fields, rows: state.loaded.rows }));
273
+ const advice = props.advice === false || !state.loaded ? [] : chartAdvice(drawnShape({ type, x, y, stacked, legend, seriesCount, binned: Boolean(xGrain || xBinWidth || xBins), histogram: Boolean(xBinWidth || xBins), fields: state.loaded.fields, rows: state.loaded.rows }));
268
274
  // Rows a time or number axis cannot place are left out, and the chart says so with what they hold.
269
275
  const unplaced = state.loaded ? rowsWithoutX({ type, x, series: outputs.map((o) => ({ column: o.column, label: o.label, type: o.measure.type })), fields: state.loaded.fields, rows: state.loaded.rows }) : [];
270
276
  const unplacedDetail = unplaced.length === 1
@@ -272,7 +278,7 @@ export function Chart(props) {
272
278
  : "";
273
279
  const nothingDrawn = !!state.loaded && state.loaded.rows.length === unplaced.length;
274
280
  const description = props.label ?? text("chart.description", { type, measures: outputs.map((o) => o.label).join(", "), x });
275
- return (_jsxs("figure", { className: ["sf-chart", props.className].filter(Boolean).join(" "), "aria-busy": state.loading, children: [state.error ? (_jsx("p", { className: "sf-chart-message", role: "alert", "data-error": state.error, style: { minHeight: height }, children: props.errorMessage ?? state.error })) : nothingDrawn ? (_jsx("p", { className: "sf-chart-message", style: { minHeight: height }, children: props.emptyMessage ?? text("chart.empty") })) : (_jsx("div", { ref: element, className: "sf-chart-canvas", role: "img", "aria-label": description, style: { height } })), unplaced.length > 0 && _jsx("figcaption", { className: "sf-chart-note", children: text("chart.missingX", { x, detail: unplacedDetail }) }), seriesCount > palette.length && (_jsx("figcaption", { className: "sf-chart-note", children: text("chart.coloursRepeat", { count: seriesCount, colours: palette.length }) })), advice.map((item) => (_jsx("figcaption", { className: "sf-chart-note sf-chart-advice", role: "note", children: text("chart.advice", { message: item.message, instead: item.instead }) }, item.rule))), state.loaded?.cut && (_jsx("figcaption", { className: "sf-chart-note", children: state.loaded.cut === "sample"
281
+ return (_jsxs("figure", { className: ["sf-chart", props.className].filter(Boolean).join(" "), "aria-busy": state.loading, children: [state.error ? (_jsx("p", { className: "sf-chart-message", role: "alert", "data-error": state.error, style: { minHeight: height }, children: props.errorMessage ?? state.error })) : nothingDrawn ? (_jsx("p", { className: "sf-chart-message", style: { minHeight: height }, children: props.emptyMessage ?? text("chart.empty") })) : (_jsx("div", { ref: element, className: "sf-chart-canvas", role: "img", "aria-label": description, style: { height } })), unplaced.length > 0 && _jsx("figcaption", { className: "sf-chart-note", children: text("chart.missingX", { x, detail: unplacedDetail }) }), seriesCount > palette.length && (_jsx("figcaption", { className: "sf-chart-note", children: text("chart.coloursRepeat", { count: seriesCount, colours: palette.length }) })), advice.map((item) => (_jsx("figcaption", { className: "sf-chart-note sf-chart-advice", role: "note", children: text("chart.advice", { message: item.message, instead: item.instead }) }, item.rule))), state.loaded && state.loaded.notes.length > 0 && (_jsx("figcaption", { className: "sf-chart-note", role: "note", children: state.loaded.notes.join(" ") })), state.loaded?.cut && (_jsx("figcaption", { className: "sf-chart-note", children: state.loaded.cut === "sample"
276
282
  ? text("chart.sampleNote", { count: numberFormat().format(limit) })
277
283
  : text(state.loaded.sort === "value" ? "chart.largestNote" : "chart.firstNote", { count: numberFormat().format(limit) }) }))] }));
278
284
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Chart.js","sourceRoot":"","sources":["../../src/chart/Chart.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAmB,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGnG,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,EAAwB,MAAM,oBAAoB,CAAC;AACvG,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,+BA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ACA,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACpB,qBAA4B,SAAS,EAAC,+BAA+B,EAAC,IAAI,EAAC,MAAM,YAC9E,IAAI,CAAC,cAAc,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,IADxD,IAAI,CAAC,IAAI,CAEb,CACd,CAAC,EACD,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CACpB,qBAAY,SAAS,EAAC,eAAe,YAClC,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,QAAQ;oBAC5B,CAAC,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;oBACnE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,GAC/G,CACd,IACM,CACV,CAAC;AACJ,CAAC","sourcesContent":["import { type DataSource, collect, parseMeasureExpression, writeMeasure } from \"@surfaces-ui/data\";\nimport type { MessageInitShape } from \"@bufbuild/protobuf\";\nimport type { DataType } from \"apache-arrow\";\nimport { AggregateFunction, SortDirection, TimeGrain, type ViewQuerySchema } from \"@surfaces-ui/proto\";\nimport { defaultTheme, echartsTheme, resolveColors } from \"@surfaces-ui/tokens\";\nimport { BarChart, LineChart, PieChart, ScatterChart } from \"echarts/charts\";\nimport {\n AriaComponent,\n DataZoomComponent,\n DatasetComponent,\n GridComponent,\n LegendComponent,\n TooltipComponent,\n} from \"echarts/components\";\nimport * as echarts from \"echarts/core\";\nimport { CanvasRenderer } from \"echarts/renderers\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { useDataSource } from \"../data/DataSourceProvider.js\";\nimport type { DataMessages } from \"../data/messages.js\";\nimport { chartValue, numericValue } from \"../data/format.js\";\nimport { label as text, numberFormat } from \"../locale/locale.js\";\nimport { type FilterInit, type TimeTravelInit, type ValueInit, messageOf } from \"../data/useRowWindow.js\";\nimport { useOptionalTheme } from \"../theme/ThemeProvider.js\";\nimport { type ChartShape, chartAdvice } from \"./advice.js\";\nimport { type AxisFormat, type ChartOptionInput, type ChartType, type LegendPlacement, type SeriesType, buildChartOption, isOrdered, niceBinWidth, rowsWithoutX } from \"./option.js\";\n\necharts.use([\n BarChart,\n LineChart,\n PieChart,\n ScatterChart,\n AriaComponent,\n DataZoomComponent,\n DatasetComponent,\n GridComponent,\n LegendComponent,\n TooltipComponent,\n CanvasRenderer,\n]);\n\nexport type ChartAggregate =\n | \"sum\"\n | \"avg\"\n | \"count\"\n | \"count_distinct\"\n | \"min\"\n | \"max\"\n | \"median\"\n | \"stddev\"\n | \"variance\"\n | \"percentile\";\n\nexport type ChartGrain = \"minute\" | \"hour\" | \"day\" | \"week\" | \"month\" | \"quarter\" | \"year\";\n\nexport interface ChartMeasure {\n /** Column to plot. Optional only for `count`, which then counts rows. */\n column?: string;\n /**\n * Summarise the column per x value in the engine. Without it the chart\n * plots raw rows: all of them when the result is small, otherwise a random\n * sample.\n */\n aggregate?: ChartAggregate;\n /** For `percentile`: a fraction from 0 to 1. Defaults to 0.9. */\n percentile?: number;\n /**\n * A calculation instead of a column: arithmetic over the measures named in\n * `terms`, such as `refunded / revenue`. The engine works it out after\n * summarising, so it is right for any number of rows and can be sorted by.\n */\n expression?: string;\n /** The measures an `expression` names, by the name it uses for them. */\n terms?: Record<string, { column?: string; aggregate: ChartAggregate; percentile?: number }>;\n /** Name for the legend. Defaults to e.g. \"sum of amount\". */\n label?: string;\n /** Draw this series differently from the chart's `type`, e.g. a line over bars. */\n type?: SeriesType;\n /** The y axis this series is measured on. Use \"right\" for a measure on another scale. Defaults to \"left\". */\n axis?: \"left\" | \"right\";\n /** Series with the same stack name are stacked on each other. */\n stack?: string;\n /**\n * Which of the theme's series colours to use, counting from 1. Give a\n * measure the same slot wherever it appears and it keeps its colour across\n * charts. Without it, series take the theme's colours in order.\n */\n slot?: number;\n}\n\nexport interface ChartProps extends DataMessages {\n sourceId: string;\n /** The base SQL. Grouping and aggregation are applied around it by the backend. */\n sql: string;\n /** How series are drawn unless a measure sets its own `type`. */\n type: ChartType;\n /** Column for the x axis, or the slices of a pie. */\n x: string;\n /** Group a date or time x column into buckets of this size, so a time series has one point per bucket. */\n xGrain?: ChartGrain;\n /** Group a numeric x column into bins of this width (a histogram). */\n xBinWidth?: number;\n /** Group a numeric x column into about this many bins; the width is chosen from the column's range. */\n xBins?: number;\n /** One entry per series. */\n y: ChartMeasure[];\n /** Split each measure into one series per distinct value of this column. */\n splitBy?: string;\n /**\n * The theme colour slot for particular values of `splitBy`, by value, e.g.\n * `{ Europe: 1, \"Asia Pacific\": 2 }`. A value then keeps its colour when a\n * filter removes other values.\n */\n splitSlots?: Record<string, number>;\n /** Stack the series. */\n stacked?: boolean;\n /**\n * The order of bars. \"value\" (the default for a bar chart over categories)\n * puts the largest first, and with a row limit keeps the largest. \"x\" keeps\n * the order of the x column. Dates, bins and numbers always keep their own order.\n */\n sort?: \"value\" | \"x\";\n /** Show advice when the chart's shape is one that misleads or cannot be read. Defaults to true. */\n advice?: boolean;\n /** Where the legend goes. Defaults to \"top\" when there is more than one series. */\n legend?: LegendPlacement;\n /** Axis titles. */\n xTitle?: string;\n yTitle?: string;\n yRightTitle?: string;\n /**\n * Turn the bars on their side: categories down the left, largest at the\n * top, values along the bottom. Easier to read with long category names or\n * many of them. Only for bars on one scale; ignored otherwise.\n */\n horizontal?: boolean;\n /** How the left axis writes its numbers: \"percent\" for a rate (6%, not 0.06), \"currency\" for money. Labels only; the values are untouched. */\n yFormat?: AxisFormat;\n filters?: FilterInit[];\n parameters?: ValueInit[];\n timeTravel?: TimeTravelInit;\n /** ISO 8601 time of the run this chart belongs to; see `RowWindowQuery.notBefore`. */\n notBefore?: string;\n /** Most points fetched. Defaults to 5,000; the chart says when it was cut off or sampled. */\n limit?: number;\n /** Height in px. Defaults to 320. */\n height?: number;\n /**\n * Called when a point, bar or slice is clicked, with its x value and\n * series name. Use it to filter other views (cross-filtering).\n */\n onPointClick?(point: { x: string | number | null; series: string; value: number | null }): void;\n /** Adjust the generated ECharts option before it is applied. */\n option?(option: Record<string, unknown>): Record<string, unknown>;\n /** Accessible description of what the chart shows. */\n label?: string;\n dataSource?: DataSource;\n className?: string;\n}\n\n/** The contract's function for each aggregate name. */\nexport const AGGREGATE_FUNCTIONS: Record<ChartAggregate, AggregateFunction> = {\n sum: AggregateFunction.SUM,\n avg: AggregateFunction.AVG,\n count: AggregateFunction.COUNT,\n count_distinct: AggregateFunction.COUNT_DISTINCT,\n min: AggregateFunction.MIN,\n max: AggregateFunction.MAX,\n median: AggregateFunction.MEDIAN,\n stddev: AggregateFunction.STDDEV,\n variance: AggregateFunction.VARIANCE,\n percentile: AggregateFunction.PERCENTILE,\n};\n\n/** The contract's grain for each grain name. */\nexport const TIME_GRAINS: Record<ChartGrain, TimeGrain> = {\n minute: TimeGrain.MINUTE,\n hour: TimeGrain.HOUR,\n day: TimeGrain.DAY,\n week: TimeGrain.WEEK,\n month: TimeGrain.MONTH,\n quarter: TimeGrain.QUARTER,\n year: TimeGrain.YEAR,\n};\n\ninterface Loaded extends Pick<ChartOptionInput, \"fields\" | \"rows\"> {\n /** \"first\": more points existed than the limit. \"sample\": the rows are a random sample. */\n cut: \"first\" | \"sample\" | undefined;\n /** How the categories were ordered, so the drawing and the notes agree with the query. */\n sort: \"value\" | \"x\";\n}\n\n/** Output column and label for each measure. */\nexport function measureOutputs(y: ChartMeasure[]): { column: string; label: string; measure: ChartMeasure }[] {\n return y.map((measure, i) => {\n if (measure.expression) return { column: `calc_${i}`, label: measure.label ?? measure.expression, measure };\n if (!measure.aggregate) return { column: measure.column ?? \"\", label: measure.label ?? measure.column ?? \"\", measure };\n const subject = measure.column ?? \"rows\";\n const name =\n measure.aggregate === \"percentile\" ? `p${Math.round((measure.percentile ?? 0.9) * 100)}` : measure.aggregate.replace(\"_\", \" \");\n return {\n column: `${measure.aggregate}_${measure.column ?? \"rows\"}_${i}`.replace(/\\W+/g, \"_\"),\n label: measure.label ?? (measure.aggregate === \"count\" && !measure.column ? \"count\" : `${name} of ${subject}`),\n measure,\n };\n });\n}\n\n/** A calculation with each name given a prefix, so its terms are its own. One that cannot be read is sent as it is, and the engine says why. */\nfunction termExpression(expression: string, prefix: string): string {\n try {\n return writeMeasure(parseMeasureExpression(expression), { name: (name) => `${prefix}_${name}`, divide: (left, right) => `(${left} / ${right})` });\n } catch {\n return expression;\n }\n}\n\nexport type ChartQueryInput = Pick<ChartProps, \"sql\" | \"type\" | \"x\" | \"xGrain\" | \"y\" | \"splitBy\" | \"filters\" | \"parameters\" | \"sort\"> & {\n /** Bin width for a numeric x, already resolved from `xBinWidth` or `xBins`. */\n binWidth?: number;\n limit: number;\n};\n\n/** The shape of a loaded chart, in the terms `chartAdvice` checks. Nothing drawn gives no advice. */\nexport function drawnShape(input: Pick<ChartProps, \"type\" | \"x\" | \"y\" | \"stacked\"> & Pick<ChartOptionInput, \"fields\" | \"rows\"> & { seriesCount: number; binned: boolean }): ChartShape {\n if (input.rows.length === 0) return { type: input.type, categories: 0, series: 0 };\n return {\n type: input.type,\n categories: new Set(input.rows.map((row) => row[input.x])).size,\n series: input.type === \"pie\" ? 1 : input.seriesCount,\n stacked: input.stacked,\n rightAxis: input.y.some((m) => m.axis === \"right\"),\n orderedX: input.binned || isOrdered(input.fields.find((f) => f.name === input.x)),\n };\n}\n\n/** How a chart's categories are ordered when not told: bars by size, everything else along x. */\nexport function chartSort(input: Pick<ChartQueryInput, \"type\" | \"xGrain\" | \"binWidth\" | \"sort\" | \"y\">): \"value\" | \"x\" {\n if (input.xGrain || input.binWidth) return \"x\";\n return input.sort ?? (input.type === \"bar\" && input.y.every((m) => (m.type ?? \"bar\") === \"bar\") ? \"value\" : \"x\");\n}\n\n/**\n * The query a chart sends. With aggregated measures the engine groups by x\n * (bucketed by time grain or bin width when asked) and by the split column;\n * otherwise it returns a random sample of raw rows.\n */\nexport function buildChartQuery(input: ChartQueryInput): MessageInitShape<typeof ViewQuerySchema> {\n const { sql, type, x, y, splitBy, filters, parameters, limit } = input;\n const outputs = measureOutputs(y);\n const aggregated = outputs.filter((o) => o.measure.aggregate || o.measure.expression);\n if (aggregated.length === 0) {\n const columns = [...new Set([x, ...(splitBy ? [splitBy] : []), ...outputs.map((o) => o.column)])];\n return { baseSql: sql, filters, parameters, columns, sample: { rows: limit } };\n }\n const bucket = input.xGrain\n ? { column: x, by: { case: \"grain\" as const, value: TIME_GRAINS[input.xGrain] } }\n : input.binWidth\n ? { column: x, by: { case: \"binWidth\" as const, value: input.binWidth } }\n : undefined;\n return {\n baseSql: sql,\n filters,\n parameters,\n groupBy: [...(bucket ? [] : [x]), ...(splitBy ? [splitBy] : [])],\n buckets: bucket ? [bucket] : [],\n aggregates: aggregated.flatMap((o) =>\n o.measure.expression\n ? // A calculation's terms are aggregates of their own, named after the calculation so two calculations cannot collide.\n Object.entries(o.measure.terms ?? {}).map(([name, term]) => ({\n function: AGGREGATE_FUNCTIONS[term.aggregate],\n column: term.column ?? \"\",\n alias: `${o.column}_${name}`,\n percentile: term.aggregate === \"percentile\" ? (term.percentile ?? 0.9) : 0,\n }))\n : [\n {\n function: AGGREGATE_FUNCTIONS[o.measure.aggregate!],\n column: o.measure.column ?? \"\",\n alias: o.column,\n percentile: o.measure.aggregate === \"percentile\" ? (o.measure.percentile ?? 0.9) : 0,\n },\n ],\n ),\n derived: aggregated.filter((o) => o.measure.expression).map((o) => ({ alias: o.column, expression: termExpression(o.measure.expression!, o.column) })),\n // By size, the engine keeps the largest when the limit cuts the result; a split chart is put in order from its totals afterwards.\n sorts:\n type === \"pie\" || (chartSort(input) === \"value\" && !splitBy)\n ? [{ column: aggregated[0]!.column, direction: SortDirection.DESC }]\n : [{ column: x, direction: SortDirection.ASC }],\n page: { limit },\n };\n}\n\n/**\n * An ECharts chart bound to a query. With aggregated measures the engine\n * groups the data, so the chart receives one row per point however large the\n * table is. Each measure is a series and can have its own type and y axis,\n * which makes compound charts (bars with a line, two scales). Colours, fonts\n * and radius follow the theme.\n */\n/** The columns a range query returns, as Arrow gives them: each column's values and its type. */\ninterface RangeTable {\n schema: { fields: { name: string; type: DataType }[] };\n getChild(name: string): { get(index: number): unknown } | null;\n}\n\n/**\n * The bin width for `bins` bins over the lowest and highest values the engine\n * found (`lo` and `hi`). Read with the column's type: a DECIMAL arrives as its\n * digits without the point, and read as a plain number it widens the range a\n * hundredfold or more, putting every value in one bin.\n */\nexport function rangeBinWidth(table: RangeTable, bins: number): number {\n const read = (name: string) => {\n const field = table.schema.fields.find((f) => f.name === name);\n const value = table.getChild(name)?.get(0);\n return field ? numericValue(value, field.type) : null;\n };\n const lo = read(\"lo\");\n const hi = read(\"hi\");\n return lo === null || hi === null ? 1 : niceBinWidth(lo, hi, bins);\n}\n\nexport function Chart(props: ChartProps) {\n const { sourceId, sql, type, x, xGrain, xBinWidth, xBins, y, splitBy, filters, parameters, timeTravel, notBefore, limit = 5000, height = 320 } = props;\n const dataSource = useDataSource(props.dataSource);\n const theme = useOptionalTheme();\n const element = useRef<HTMLDivElement>(null);\n const [state, setState] = useState<{ loaded?: Loaded; error?: string; loading: boolean }>({ loading: true });\n\n const outputs = useMemo(() => measureOutputs(y), [JSON.stringify(y)]); // eslint-disable-line react-hooks/exhaustive-deps\n const key = JSON.stringify([sourceId, sql, type, x, xGrain, xBinWidth, xBins, y, splitBy, filters, parameters, timeTravel, notBefore, limit, props.sort], (_, v) =>\n typeof v === \"bigint\" ? `${v}n` : v,\n );\n\n useEffect(() => {\n const controller = new AbortController();\n const call = { signal: controller.signal };\n setState((previous) => ({ ...previous, loading: true, error: undefined }));\n const aggregated = outputs.some((o) => o.measure.aggregate || o.measure.expression);\n const load = async (): Promise<Loaded> => {\n let binWidth = xGrain ? undefined : xBinWidth;\n if (aggregated && !xGrain && !binWidth && xBins) {\n // The bin width comes from the column's range, which the engine works out.\n const range = await collect(\n dataSource.execute(\n {\n sourceId,\n timeTravel,\n notBefore,\n query: {\n baseSql: sql,\n filters,\n parameters,\n aggregates: [\n { function: AggregateFunction.MIN, column: x, alias: \"lo\" },\n { function: AggregateFunction.MAX, column: x, alias: \"hi\" },\n ],\n },\n },\n call,\n ),\n );\n binWidth = rangeBinWidth(range.table, xBins);\n }\n const sort = chartSort({ type, xGrain, binWidth, sort: props.sort, y });\n const query = buildChartQuery({ sql, type, x, xGrain, binWidth, y, splitBy, filters, parameters, limit, sort });\n const result = await collect(dataSource.execute({ sourceId, timeTravel, notBefore, query }, call));\n const fields = result.table.schema.fields;\n const columns = fields.map((_, i) => result.table.getChildAt(i)!);\n const rows = Array.from({ length: result.table.numRows }, (_, r) =>\n Object.fromEntries(fields.map((f, c) => [f.name, chartValue(columns[c]!.get(r), f.type)])),\n );\n return { fields, rows, sort, cut: rows.length < limit ? undefined : aggregated ? \"first\" : \"sample\" };\n };\n load()\n .then((loaded) => {\n if (!controller.signal.aborted) setState({ loaded, loading: false });\n })\n .catch((error: unknown) => {\n if (!controller.signal.aborted) setState({ error: messageOf(error), loading: false });\n });\n return () => controller.abort();\n }, [dataSource, key]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const onPointClick = useRef(props.onPointClick);\n onPointClick.current = props.onPointClick;\n const mode = theme?.resolvedMode ?? \"light\";\n const themeDocument = theme?.theme ?? defaultTheme;\n const { stacked, legend, xTitle, yTitle, yRightTitle, yFormat, splitSlots, horizontal } = props;\n const palette = useMemo(() => resolveColors(themeDocument[mode], themeDocument.charts?.[mode]).series, [themeDocument, mode]);\n const slotsKey = JSON.stringify(splitSlots ?? null);\n const option = useMemo(() => {\n if (!state.loaded) return undefined;\n const slotColor = (slot: number | undefined) => (slot === undefined ? undefined : palette[slot - 1]);\n const base = buildChartOption({\n type,\n x,\n splitBy,\n series: outputs.map((o) => ({ column: o.column, label: o.label, type: o.measure.type, axis: o.measure.axis, stack: o.measure.stack, color: slotColor(o.measure.slot) })),\n splitColors: splitSlots ? Object.fromEntries(Object.entries(splitSlots).map(([value, slot]) => [value, slotColor(slot) ?? \"\"]).filter(([, color]) => color !== \"\")) : undefined,\n fields: state.loaded.fields,\n rows: state.loaded.rows,\n sort: state.loaded.sort,\n stacked,\n legend,\n xTitle,\n yTitle,\n yRightTitle,\n yFormat,\n horizontal,\n });\n // People who ask for less motion get none: the chart appears in place.\n const still = typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n const withAria = { aria: { enabled: true }, ...(still ? { animation: false } : {}), ...base };\n return props.option ? props.option(withAria) : withAria;\n }, [state.loaded, type, x, splitBy, outputs, props.option, stacked, legend, xTitle, yTitle, yRightTitle, yFormat, horizontal, palette, slotsKey]); // eslint-disable-line react-hooks/exhaustive-deps\n const seriesCount = type !== \"pie\" && Array.isArray((option as { series?: unknown[] } | undefined)?.series) ? (option as { series: unknown[] }).series.length : 0;\n\n useEffect(() => {\n if (!element.current || !option) return;\n const chart = echarts.init(element.current, echartsTheme(themeDocument, mode));\n chart.setOption(option);\n chart.on(\"click\", (event: { seriesName?: string; name?: string; data?: unknown; value?: unknown }) => {\n const row = event.data !== null && typeof event.data === \"object\" ? (event.data as Record<string, string | number | null>) : undefined;\n // Pie slices carry a name; other series carry the dataset row.\n const at = row && x in row ? row[x]! : (event.name ?? null);\n const amount = row && typeof row.value === \"number\" ? row.value : typeof event.value === \"number\" ? event.value : null;\n onPointClick.current?.({ x: at, series: event.seriesName ?? \"\", value: amount });\n });\n const observer = typeof ResizeObserver === \"undefined\" ? undefined : new ResizeObserver(() => chart.resize());\n observer?.observe(element.current);\n return () => {\n observer?.disconnect();\n chart.dispose();\n };\n }, [option, themeDocument, mode]);\n\n // Advice is worked out from what was actually drawn, so it follows filters and the data.\n const advice = props.advice === false || !state.loaded ? [] : chartAdvice(drawnShape({ type, x, y, stacked, seriesCount, binned: Boolean(xGrain || xBinWidth || xBins), fields: state.loaded.fields, rows: state.loaded.rows }));\n\n // Rows a time or number axis cannot place are left out, and the chart says so with what they hold.\n const unplaced = state.loaded ? rowsWithoutX({ type, x, series: outputs.map((o) => ({ column: o.column, label: o.label, type: o.measure.type })), fields: state.loaded.fields, rows: state.loaded.rows }) : [];\n const unplacedDetail =\n unplaced.length === 1\n ? ` (${outputs.map((o) => `${o.label}: ${typeof unplaced[0]![o.column] === \"number\" ? numberFormat().format(unplaced[0]![o.column] as number) : String(unplaced[0]![o.column] ?? \"–\")}`).join(\", \")})`\n : \"\";\n const nothingDrawn = !!state.loaded && state.loaded.rows.length === unplaced.length;\n\n const description = props.label ?? text(\"chart.description\", { type, measures: outputs.map((o) => o.label).join(\", \"), x });\n return (\n <figure className={[\"sf-chart\", props.className].filter(Boolean).join(\" \")} aria-busy={state.loading}>\n {state.error ? (\n <p className=\"sf-chart-message\" role=\"alert\" data-error={state.error} style={{ minHeight: height }}>\n {props.errorMessage ?? state.error}\n </p>\n ) : nothingDrawn ? (\n <p className=\"sf-chart-message\" style={{ minHeight: height }}>\n {props.emptyMessage ?? text(\"chart.empty\")}\n </p>\n ) : (\n <div ref={element} className=\"sf-chart-canvas\" role=\"img\" aria-label={description} style={{ height }} />\n )}\n {unplaced.length > 0 && <figcaption className=\"sf-chart-note\">{text(\"chart.missingX\", { x, detail: unplacedDetail })}</figcaption>}\n {seriesCount > palette.length && (\n <figcaption className=\"sf-chart-note\">\n {text(\"chart.coloursRepeat\", { count: seriesCount, colours: palette.length })}\n </figcaption>\n )}\n {advice.map((item) => (\n <figcaption key={item.rule} className=\"sf-chart-note sf-chart-advice\" role=\"note\">\n {text(\"chart.advice\", { message: item.message, instead: item.instead })}\n </figcaption>\n ))}\n {state.loaded?.cut && (\n <figcaption className=\"sf-chart-note\">\n {state.loaded.cut === \"sample\"\n ? text(\"chart.sampleNote\", { count: numberFormat().format(limit) })\n : text(state.loaded.sort === \"value\" ? \"chart.largestNote\" : \"chart.firstNote\", { count: numberFormat().format(limit) })}\n </figcaption>\n )}\n </figure>\n );\n}\n"]}
1
+ {"version":3,"file":"Chart.js","sourceRoot":"","sources":["../../src/chart/Chart.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAmB,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGnG,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,EAAwB,MAAM,oBAAoB,CAAC;AACvG,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAwD,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC1G,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAA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,OAAO,CAAC,MAAM,IAAI,CAC/B,qBAAY,SAAS,EAAC,eAAe,YAClC,IAAI,CAAC,qBAAqB,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,GAClE,CACd,EACA,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACpB,qBAA4B,SAAS,EAAC,+BAA+B,EAAC,IAAI,EAAC,MAAM,YAC9E,IAAI,CAAC,cAAc,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,IADxD,IAAI,CAAC,IAAI,CAEb,CACd,CAAC,EACD,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAChD,qBAAY,SAAS,EAAC,eAAe,EAAC,IAAI,EAAC,MAAM,YAC9C,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAClB,CACd,EACA,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CACpB,qBAAY,SAAS,EAAC,eAAe,YAClC,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,QAAQ;oBAC5B,CAAC,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;oBACnE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,GAC/G,CACd,IACM,CACV,CAAC;AACJ,CAAC","sourcesContent":["import { type DataSource, collect, parseMeasureExpression, writeMeasure } from \"@surfaces-ui/data\";\nimport type { MessageInitShape } from \"@bufbuild/protobuf\";\nimport type { DataType } from \"apache-arrow\";\nimport { AggregateFunction, SortDirection, TimeGrain, type ViewQuerySchema } from \"@surfaces-ui/proto\";\nimport { defaultTheme, echartsTheme, resolveColors } from \"@surfaces-ui/tokens\";\nimport { BarChart, LineChart, PieChart, ScatterChart } from \"echarts/charts\";\nimport {\n AriaComponent,\n DataZoomComponent,\n DatasetComponent,\n GridComponent,\n LegendComponent,\n TooltipComponent,\n} from \"echarts/components\";\nimport * as echarts from \"echarts/core\";\nimport { CanvasRenderer } from \"echarts/renderers\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { useDataSource } from \"../data/DataSourceProvider.js\";\nimport { dataNotes } from \"../data/DataNotes.js\";\nimport type { DataMessages } from \"../data/messages.js\";\nimport { chartValue, numericValue } from \"../data/format.js\";\nimport { label as text, numberFormat } from \"../locale/locale.js\";\nimport { type FilterInit, type TimeTravelInit, type ValueInit, messageOf } from \"../data/useRowWindow.js\";\nimport { useOptionalTheme } from \"../theme/ThemeProvider.js\";\nimport { type ChartShape, chartAdvice } from \"./advice.js\";\nimport { wheelScrollsThePage } from \"./wheel.js\";\nimport { type AxisFormat, type ChartOptionInput, type ChartType, type LegendPlacement, type SeriesType, buildChartOption, isOrdered, niceBinWidth, rowsWithoutX } from \"./option.js\";\n\necharts.use([\n BarChart,\n LineChart,\n PieChart,\n ScatterChart,\n AriaComponent,\n DataZoomComponent,\n DatasetComponent,\n GridComponent,\n LegendComponent,\n TooltipComponent,\n CanvasRenderer,\n]);\n\nexport type ChartAggregate =\n | \"sum\"\n | \"avg\"\n | \"count\"\n | \"count_distinct\"\n | \"min\"\n | \"max\"\n | \"median\"\n | \"stddev\"\n | \"variance\"\n | \"percentile\";\n\nexport type ChartGrain = \"minute\" | \"hour\" | \"day\" | \"week\" | \"month\" | \"quarter\" | \"year\";\n\nexport interface ChartMeasure {\n /** Column to plot. Optional only for `count`, which then counts rows. */\n column?: string;\n /**\n * Summarise the column per x value in the engine. Without it the chart\n * plots raw rows: all of them when the result is small, otherwise a random\n * sample.\n */\n aggregate?: ChartAggregate;\n /** For `percentile`: a fraction from 0 to 1. Defaults to 0.9. */\n percentile?: number;\n /**\n * A calculation instead of a column: arithmetic over the measures named in\n * `terms`, such as `refunded / revenue`. The engine works it out after\n * summarising, so it is right for any number of rows and can be sorted by.\n */\n expression?: string;\n /** The measures an `expression` names, by the name it uses for them. */\n terms?: Record<string, { column?: string; aggregate: ChartAggregate; percentile?: number }>;\n /** Name for the legend. Defaults to e.g. \"sum of amount\". */\n label?: string;\n /** Draw this series differently from the chart's `type`, e.g. a line over bars. */\n type?: SeriesType;\n /** The y axis this series is measured on. Use \"right\" for a measure on another scale. Defaults to \"left\". */\n axis?: \"left\" | \"right\";\n /** Series with the same stack name are stacked on each other. */\n stack?: string;\n /**\n * Which of the theme's series colours to use, counting from 1. Give a\n * measure the same slot wherever it appears and it keeps its colour across\n * charts. Without it, series take the theme's colours in order.\n */\n slot?: number;\n}\n\nexport interface ChartProps extends DataMessages {\n sourceId: string;\n /** The base SQL. Grouping and aggregation are applied around it by the backend. */\n sql: string;\n /** How series are drawn unless a measure sets its own `type`. */\n type: ChartType;\n /** Column for the x axis, or the slices of a pie. */\n x: string;\n /** Group a date or time x column into buckets of this size, so a time series has one point per bucket. */\n xGrain?: ChartGrain;\n /** Group a numeric x column into bins of this width (a histogram). */\n xBinWidth?: number;\n /** Group a numeric x column into about this many bins; the width is chosen from the column's range. */\n xBins?: number;\n /** One entry per series. */\n y: ChartMeasure[];\n /** Split each measure into one series per distinct value of this column. */\n splitBy?: string;\n /**\n * The theme colour slot for particular values of `splitBy`, by value, e.g.\n * `{ Europe: 1, \"Asia Pacific\": 2 }`. A value then keeps its colour when a\n * filter removes other values.\n */\n splitSlots?: Record<string, number>;\n /** Stack the series. */\n stacked?: boolean;\n /**\n * The order of bars. \"value\" (the default for a bar chart over categories)\n * puts the largest first, and with a row limit keeps the largest. \"x\" keeps\n * the order of the x column. Dates, bins and numbers always keep their own order.\n */\n sort?: \"value\" | \"x\";\n /** Show advice when the chart's shape is one that misleads or cannot be read. Defaults to true. */\n advice?: boolean;\n /** Where the legend goes. Defaults to \"top\" when there is more than one series. */\n legend?: LegendPlacement;\n /** Axis titles. */\n xTitle?: string;\n yTitle?: string;\n yRightTitle?: string;\n /**\n * Turn the bars on their side: categories down the left, largest at the\n * top, values along the bottom. Easier to read with long category names or\n * many of them. Only for bars on one scale; ignored otherwise.\n */\n horizontal?: boolean;\n /** How the left axis writes its numbers: \"percent\" for a rate (6%, not 0.06), \"currency\" for money. Labels only; the values are untouched. */\n yFormat?: AxisFormat;\n filters?: FilterInit[];\n parameters?: ValueInit[];\n timeTravel?: TimeTravelInit;\n /** ISO 8601 time of the run this chart belongs to; see `RowWindowQuery.notBefore`. */\n notBefore?: string;\n /** Most points fetched. Defaults to 5,000; the chart says when it was cut off or sampled. */\n limit?: number;\n /** Height in px. Defaults to 320. */\n height?: number;\n /**\n * Called when a point, bar or slice is clicked, with its x value and\n * series name. Use it to filter other views (cross-filtering).\n */\n onPointClick?(point: { x: string | number | null; series: string; value: number | null }): void;\n /** Adjust the generated ECharts option before it is applied. */\n option?(option: Record<string, unknown>): Record<string, unknown>;\n /** Accessible description of what the chart shows. */\n label?: string;\n dataSource?: DataSource;\n className?: string;\n}\n\n/** The contract's function for each aggregate name. */\nexport const AGGREGATE_FUNCTIONS: Record<ChartAggregate, AggregateFunction> = {\n sum: AggregateFunction.SUM,\n avg: AggregateFunction.AVG,\n count: AggregateFunction.COUNT,\n count_distinct: AggregateFunction.COUNT_DISTINCT,\n min: AggregateFunction.MIN,\n max: AggregateFunction.MAX,\n median: AggregateFunction.MEDIAN,\n stddev: AggregateFunction.STDDEV,\n variance: AggregateFunction.VARIANCE,\n percentile: AggregateFunction.PERCENTILE,\n};\n\n/** The contract's grain for each grain name. */\nexport const TIME_GRAINS: Record<ChartGrain, TimeGrain> = {\n minute: TimeGrain.MINUTE,\n hour: TimeGrain.HOUR,\n day: TimeGrain.DAY,\n week: TimeGrain.WEEK,\n month: TimeGrain.MONTH,\n quarter: TimeGrain.QUARTER,\n year: TimeGrain.YEAR,\n};\n\ninterface Loaded extends Pick<ChartOptionInput, \"fields\" | \"rows\"> {\n /** \"first\": more points existed than the limit. \"sample\": the rows are a random sample. */\n cut: \"first\" | \"sample\" | undefined;\n /** How the categories were ordered, so the drawing and the notes agree with the query. */\n sort: \"value\" | \"x\";\n /** What the chart was not filtered by, for its readers (see `DataNotes`). */\n notes: string[];\n}\n\n/** Output column and label for each measure. */\nexport function measureOutputs(y: ChartMeasure[]): { column: string; label: string; measure: ChartMeasure }[] {\n return y.map((measure, i) => {\n if (measure.expression) return { column: `calc_${i}`, label: measure.label ?? measure.expression, measure };\n if (!measure.aggregate) return { column: measure.column ?? \"\", label: measure.label ?? measure.column ?? \"\", measure };\n const subject = measure.column ?? \"rows\";\n const name =\n measure.aggregate === \"percentile\" ? `p${Math.round((measure.percentile ?? 0.9) * 100)}` : measure.aggregate.replace(\"_\", \" \");\n return {\n column: `${measure.aggregate}_${measure.column ?? \"rows\"}_${i}`.replace(/\\W+/g, \"_\"),\n label: measure.label ?? (measure.aggregate === \"count\" && !measure.column ? \"count\" : `${name} of ${subject}`),\n measure,\n };\n });\n}\n\n/** A calculation with each name given a prefix, so its terms are its own. One that cannot be read is sent as it is, and the engine says why. */\nfunction termExpression(expression: string, prefix: string): string {\n try {\n return writeMeasure(parseMeasureExpression(expression), { name: (name) => `${prefix}_${name}`, divide: (left, right) => `(${left} / ${right})` });\n } catch {\n return expression;\n }\n}\n\nexport type ChartQueryInput = Pick<ChartProps, \"sql\" | \"type\" | \"x\" | \"xGrain\" | \"y\" | \"splitBy\" | \"filters\" | \"parameters\" | \"sort\"> & {\n /** Bin width for a numeric x, already resolved from `xBinWidth` or `xBins`. */\n binWidth?: number;\n limit: number;\n};\n\n/** The shape of a loaded chart, in the terms `chartAdvice` checks. Nothing drawn gives no advice. */\nexport function drawnShape(input: Pick<ChartProps, \"type\" | \"x\" | \"y\" | \"stacked\" | \"legend\"> & Pick<ChartOptionInput, \"fields\" | \"rows\"> & { seriesCount: number; binned: boolean; histogram?: boolean }): ChartShape {\n if (input.rows.length === 0) return { type: input.type, categories: 0, series: 0 };\n return {\n type: input.type,\n categories: new Set(input.rows.map((row) => row[input.x])).size,\n series: input.type === \"pie\" ? 1 : input.seriesCount,\n stacked: input.stacked,\n rightAxis: input.y.some((m) => m.axis === \"right\"),\n orderedX: input.binned || isOrdered(input.fields.find((f) => f.name === input.x)),\n ...(input.histogram ? { binned: true } : {}),\n ...(input.legend ? { legend: input.legend } : {}),\n };\n}\n\n/** How a chart's categories are ordered when not told: bars by size, everything else along x. */\nexport function chartSort(input: Pick<ChartQueryInput, \"type\" | \"xGrain\" | \"binWidth\" | \"sort\" | \"y\">): \"value\" | \"x\" {\n if (input.xGrain || input.binWidth) return \"x\";\n return input.sort ?? (input.type === \"bar\" && input.y.every((m) => (m.type ?? \"bar\") === \"bar\") ? \"value\" : \"x\");\n}\n\n/**\n * The query a chart sends. With aggregated measures the engine groups by x\n * (bucketed by time grain or bin width when asked) and by the split column;\n * otherwise it returns a random sample of raw rows.\n */\nexport function buildChartQuery(input: ChartQueryInput): MessageInitShape<typeof ViewQuerySchema> {\n const { sql, type, x, y, splitBy, filters, parameters, limit } = input;\n const outputs = measureOutputs(y);\n const aggregated = outputs.filter((o) => o.measure.aggregate || o.measure.expression);\n if (aggregated.length === 0) {\n const columns = [...new Set([x, ...(splitBy ? [splitBy] : []), ...outputs.map((o) => o.column)])];\n return { baseSql: sql, filters, parameters, columns, sample: { rows: limit } };\n }\n const bucket = input.xGrain\n ? { column: x, by: { case: \"grain\" as const, value: TIME_GRAINS[input.xGrain] } }\n : input.binWidth\n ? { column: x, by: { case: \"binWidth\" as const, value: input.binWidth } }\n : undefined;\n return {\n baseSql: sql,\n filters,\n parameters,\n groupBy: [...(bucket ? [] : [x]), ...(splitBy ? [splitBy] : [])],\n buckets: bucket ? [bucket] : [],\n aggregates: aggregated.flatMap((o) =>\n o.measure.expression\n ? // A calculation's terms are aggregates of their own, named after the calculation so two calculations cannot collide.\n Object.entries(o.measure.terms ?? {}).map(([name, term]) => ({\n function: AGGREGATE_FUNCTIONS[term.aggregate],\n column: term.column ?? \"\",\n alias: `${o.column}_${name}`,\n percentile: term.aggregate === \"percentile\" ? (term.percentile ?? 0.9) : 0,\n }))\n : [\n {\n function: AGGREGATE_FUNCTIONS[o.measure.aggregate!],\n column: o.measure.column ?? \"\",\n alias: o.column,\n percentile: o.measure.aggregate === \"percentile\" ? (o.measure.percentile ?? 0.9) : 0,\n },\n ],\n ),\n derived: aggregated.filter((o) => o.measure.expression).map((o) => ({ alias: o.column, expression: termExpression(o.measure.expression!, o.column) })),\n // By size, the engine keeps the largest when the limit cuts the result; a split chart is put in order from its totals afterwards.\n sorts:\n type === \"pie\" || (chartSort(input) === \"value\" && !splitBy)\n ? [{ column: aggregated[0]!.column, direction: SortDirection.DESC }]\n : [{ column: x, direction: SortDirection.ASC }],\n page: { limit },\n };\n}\n\n/**\n * An ECharts chart bound to a query. With aggregated measures the engine\n * groups the data, so the chart receives one row per point however large the\n * table is. Each measure is a series and can have its own type and y axis,\n * which makes compound charts (bars with a line, two scales). Colours, fonts\n * and radius follow the theme.\n */\n/** The columns a range query returns, as Arrow gives them: each column's values and its type. */\ninterface RangeTable {\n schema: { fields: { name: string; type: DataType }[] };\n getChild(name: string): { get(index: number): unknown } | null;\n}\n\n/**\n * The bin width for `bins` bins over the lowest and highest values the engine\n * found (`lo` and `hi`). Read with the column's type: a DECIMAL arrives as its\n * digits without the point, and read as a plain number it widens the range a\n * hundredfold or more, putting every value in one bin.\n */\nexport function rangeBinWidth(table: RangeTable, bins: number): number {\n const read = (name: string) => {\n const field = table.schema.fields.find((f) => f.name === name);\n const value = table.getChild(name)?.get(0);\n return field ? numericValue(value, field.type) : null;\n };\n const lo = read(\"lo\");\n const hi = read(\"hi\");\n return lo === null || hi === null ? 1 : niceBinWidth(lo, hi, bins);\n}\n\nexport function Chart(props: ChartProps) {\n const { sourceId, sql, type, x, xGrain, xBinWidth, xBins, y, splitBy, filters, parameters, timeTravel, notBefore, limit = 5000, height = 320 } = props;\n const dataSource = useDataSource(props.dataSource);\n const theme = useOptionalTheme();\n const element = useRef<HTMLDivElement>(null);\n const [state, setState] = useState<{ loaded?: Loaded; error?: string; loading: boolean }>({ loading: true });\n\n const outputs = useMemo(() => measureOutputs(y), [JSON.stringify(y)]); // eslint-disable-line react-hooks/exhaustive-deps\n const key = JSON.stringify([sourceId, sql, type, x, xGrain, xBinWidth, xBins, y, splitBy, filters, parameters, timeTravel, notBefore, limit, props.sort], (_, v) =>\n typeof v === \"bigint\" ? `${v}n` : v,\n );\n\n useEffect(() => {\n const controller = new AbortController();\n const call = { signal: controller.signal };\n setState((previous) => ({ ...previous, loading: true, error: undefined }));\n const aggregated = outputs.some((o) => o.measure.aggregate || o.measure.expression);\n const load = async (): Promise<Loaded> => {\n let binWidth = xGrain ? undefined : xBinWidth;\n if (aggregated && !xGrain && !binWidth && xBins) {\n // The bin width comes from the column's range, which the engine works out.\n const range = await collect(\n dataSource.execute(\n {\n sourceId,\n timeTravel,\n notBefore,\n query: {\n baseSql: sql,\n filters,\n parameters,\n aggregates: [\n { function: AggregateFunction.MIN, column: x, alias: \"lo\" },\n { function: AggregateFunction.MAX, column: x, alias: \"hi\" },\n ],\n },\n },\n call,\n ),\n );\n binWidth = rangeBinWidth(range.table, xBins);\n }\n const sort = chartSort({ type, xGrain, binWidth, sort: props.sort, y });\n const query = buildChartQuery({ sql, type, x, xGrain, binWidth, y, splitBy, filters, parameters, limit, sort });\n const result = await collect(dataSource.execute({ sourceId, timeTravel, notBefore, query }, call));\n const fields = result.table.schema.fields;\n const columns = fields.map((_, i) => result.table.getChildAt(i)!);\n const rows = Array.from({ length: result.table.numRows }, (_, r) =>\n Object.fromEntries(fields.map((f, c) => [f.name, chartValue(columns[c]!.get(r), f.type)])),\n );\n return { fields, rows, sort, cut: rows.length < limit ? undefined : aggregated ? \"first\" : \"sample\", notes: dataNotes(result.header.notices) };\n };\n load()\n .then((loaded) => {\n if (!controller.signal.aborted) setState({ loaded, loading: false });\n })\n .catch((error: unknown) => {\n if (!controller.signal.aborted) setState({ error: messageOf(error), loading: false });\n });\n return () => controller.abort();\n }, [dataSource, key]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const onPointClick = useRef(props.onPointClick);\n onPointClick.current = props.onPointClick;\n const mode = theme?.resolvedMode ?? \"light\";\n const themeDocument = theme?.theme ?? defaultTheme;\n const { stacked, legend, xTitle, yTitle, yRightTitle, yFormat, splitSlots, horizontal } = props;\n const palette = useMemo(() => resolveColors(themeDocument[mode], themeDocument.charts?.[mode]).series, [themeDocument, mode]);\n const slotsKey = JSON.stringify(splitSlots ?? null);\n const option = useMemo(() => {\n if (!state.loaded) return undefined;\n const slotColor = (slot: number | undefined) => (slot === undefined ? undefined : palette[slot - 1]);\n const base = buildChartOption({\n type,\n x,\n splitBy,\n series: outputs.map((o) => ({ column: o.column, label: o.label, type: o.measure.type, axis: o.measure.axis, stack: o.measure.stack, color: slotColor(o.measure.slot) })),\n splitColors: splitSlots ? Object.fromEntries(Object.entries(splitSlots).map(([value, slot]) => [value, slotColor(slot) ?? \"\"]).filter(([, color]) => color !== \"\")) : undefined,\n fields: state.loaded.fields,\n rows: state.loaded.rows,\n sort: state.loaded.sort,\n stacked,\n legend,\n xTitle,\n yTitle,\n yRightTitle,\n yFormat,\n horizontal,\n });\n // People who ask for less motion get none: the chart appears in place.\n const still = typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n const withAria = { aria: { enabled: true }, ...(still ? { animation: false } : {}), ...base };\n return props.option ? props.option(withAria) : withAria;\n }, [state.loaded, type, x, splitBy, outputs, props.option, stacked, legend, xTitle, yTitle, yRightTitle, yFormat, horizontal, palette, slotsKey]); // eslint-disable-line react-hooks/exhaustive-deps\n const seriesCount = type !== \"pie\" && Array.isArray((option as { series?: unknown[] } | undefined)?.series) ? (option as { series: unknown[] }).series.length : 0;\n\n useEffect(() => {\n if (!element.current || !option) return;\n const chart = echarts.init(element.current, echartsTheme(themeDocument, mode));\n chart.setOption(option);\n chart.on(\"click\", (event: { seriesName?: string; name?: string; data?: unknown; value?: unknown }) => {\n const row = event.data !== null && typeof event.data === \"object\" ? (event.data as Record<string, string | number | null>) : undefined;\n // Pie slices carry a name; other series carry the dataset row.\n const at = row && x in row ? row[x]! : (event.name ?? null);\n const amount = row && typeof row.value === \"number\" ? row.value : typeof event.value === \"number\" ? event.value : null;\n onPointClick.current?.({ x: at, series: event.seriesName ?? \"\", value: amount });\n });\n const observer = typeof ResizeObserver === \"undefined\" ? undefined : new ResizeObserver(() => chart.resize());\n observer?.observe(element.current);\n const unwheel = wheelScrollsThePage(element.current);\n return () => {\n unwheel();\n observer?.disconnect();\n chart.dispose();\n };\n }, [option, themeDocument, mode]);\n\n // Advice is worked out from what was actually drawn, so it follows filters and the data.\n const advice = props.advice === false || !state.loaded ? [] : chartAdvice(drawnShape({ type, x, y, stacked, legend, seriesCount, binned: Boolean(xGrain || xBinWidth || xBins), histogram: Boolean(xBinWidth || xBins), fields: state.loaded.fields, rows: state.loaded.rows }));\n\n // Rows a time or number axis cannot place are left out, and the chart says so with what they hold.\n const unplaced = state.loaded ? rowsWithoutX({ type, x, series: outputs.map((o) => ({ column: o.column, label: o.label, type: o.measure.type })), fields: state.loaded.fields, rows: state.loaded.rows }) : [];\n const unplacedDetail =\n unplaced.length === 1\n ? ` (${outputs.map((o) => `${o.label}: ${typeof unplaced[0]![o.column] === \"number\" ? numberFormat().format(unplaced[0]![o.column] as number) : String(unplaced[0]![o.column] ?? \"–\")}`).join(\", \")})`\n : \"\";\n const nothingDrawn = !!state.loaded && state.loaded.rows.length === unplaced.length;\n\n const description = props.label ?? text(\"chart.description\", { type, measures: outputs.map((o) => o.label).join(\", \"), x });\n return (\n <figure className={[\"sf-chart\", props.className].filter(Boolean).join(\" \")} aria-busy={state.loading}>\n {state.error ? (\n <p className=\"sf-chart-message\" role=\"alert\" data-error={state.error} style={{ minHeight: height }}>\n {props.errorMessage ?? state.error}\n </p>\n ) : nothingDrawn ? (\n <p className=\"sf-chart-message\" style={{ minHeight: height }}>\n {props.emptyMessage ?? text(\"chart.empty\")}\n </p>\n ) : (\n <div ref={element} className=\"sf-chart-canvas\" role=\"img\" aria-label={description} style={{ height }} />\n )}\n {unplaced.length > 0 && <figcaption className=\"sf-chart-note\">{text(\"chart.missingX\", { x, detail: unplacedDetail })}</figcaption>}\n {seriesCount > palette.length && (\n <figcaption className=\"sf-chart-note\">\n {text(\"chart.coloursRepeat\", { count: seriesCount, colours: palette.length })}\n </figcaption>\n )}\n {advice.map((item) => (\n <figcaption key={item.rule} className=\"sf-chart-note sf-chart-advice\" role=\"note\">\n {text(\"chart.advice\", { message: item.message, instead: item.instead })}\n </figcaption>\n ))}\n {state.loaded && state.loaded.notes.length > 0 && (\n <figcaption className=\"sf-chart-note\" role=\"note\">\n {state.loaded.notes.join(\" \")}\n </figcaption>\n )}\n {state.loaded?.cut && (\n <figcaption className=\"sf-chart-note\">\n {state.loaded.cut === \"sample\"\n ? text(\"chart.sampleNote\", { count: numberFormat().format(limit) })\n : text(state.loaded.sort === \"value\" ? \"chart.largestNote\" : \"chart.firstNote\", { count: numberFormat().format(limit) })}\n </figcaption>\n )}\n </figure>\n );\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useDataSource } from "../data/DataSourceProvider.js";
3
+ import { DataNotes } from "../data/DataNotes.js";
3
4
  import { label as text } from "../locale/locale.js";
4
5
  import { formatMetric } from "../metric/Metric.js";
5
6
  import { useMeasure } from "../metric/useMeasure.js";
@@ -32,6 +33,6 @@ export function Sparkline(props) {
32
33
  const low = line.reduce((a, p) => (!a || p.value < a.value ? p : a), undefined);
33
34
  const high = line.reduce((a, p) => (!a || p.value > a.value ? p : a), undefined);
34
35
  const summary = last && low && high && line[0] ? text("sparkline.summary", { label, now: write(last.value), first: write(line[0].value), low: write(low.value), high: write(high.value), count: line.length, grain }) : props.emptyMessage ? `${label}: ${props.emptyMessage}` : text("sparkline.empty", { label });
35
- return (_jsxs("span", { className: ["sf-spark", props.className].filter(Boolean).join(" "), "aria-busy": state.loading, children: [_jsx("span", { className: "sf-spark-label", children: label }), state.error ? (_jsx("span", { className: "sf-metric-error", role: "alert", "data-error": state.error, children: props.errorMessage ?? state.error })) : (_jsxs(_Fragment, { children: [_jsxs("svg", { className: "sf-spark-line", viewBox: `0 0 ${WIDTH} ${HEIGHT}`, width: WIDTH, height: HEIGHT, role: "img", "aria-label": summary, children: [line.length > 1 && _jsx("polyline", { points: line.map((p) => `${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(" ") }), low && high && low !== high && (_jsxs(_Fragment, { children: [_jsx("circle", { className: "sf-spark-extreme", cx: low.x, cy: low.y, r: 1.8 }), _jsx("circle", { className: "sf-spark-extreme", cx: high.x, cy: high.y, r: 1.8 })] })), last && _jsx("circle", { className: "sf-spark-last", cx: last.x, cy: last.y, r: 2.4 })] }), _jsx("span", { className: "sf-spark-value", children: last ? write(last.value) : state.loading ? text("metric.loading") : (props.emptyMessage ?? text("metric.none")) })] }))] }));
36
+ return (_jsxs("span", { className: ["sf-spark", props.className].filter(Boolean).join(" "), "aria-busy": state.loading, children: [_jsx("span", { className: "sf-spark-label", children: label }), state.error ? (_jsx("span", { className: "sf-metric-error", role: "alert", "data-error": state.error, children: props.errorMessage ?? state.error })) : (_jsxs(_Fragment, { children: [_jsxs("svg", { className: "sf-spark-line", viewBox: `0 0 ${WIDTH} ${HEIGHT}`, width: WIDTH, height: HEIGHT, role: "img", "aria-label": summary, children: [line.length > 1 && _jsx("polyline", { points: line.map((p) => `${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(" ") }), low && high && low !== high && (_jsxs(_Fragment, { children: [_jsx("circle", { className: "sf-spark-extreme", cx: low.x, cy: low.y, r: 1.8 }), _jsx("circle", { className: "sf-spark-extreme", cx: high.x, cy: high.y, r: 1.8 })] })), last && _jsx("circle", { className: "sf-spark-last", cx: last.x, cy: last.y, r: 2.4 })] }), _jsx("span", { className: "sf-spark-value", children: last ? write(last.value) : state.loading ? text("metric.loading") : (props.emptyMessage ?? text("metric.none")) })] })), _jsx(DataNotes, { notes: state.notes })] }));
36
37
  }
37
38
  //# sourceMappingURL=Sparkline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Sparkline.js","sourceRoot":"","sources":["../../src/chart/Sparkline.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAG9D,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAoB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAsBrD,MAAM,KAAK,GAAG,GAAG,CAAC;AAClB,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,GAAG,GAAG,CAAC,CAAC;AAEd,uFAAuF;AACvF,MAAM,UAAU,eAAe,CAAC,MAAyB,EAAE,KAAK,GAAG,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG;IAClG,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IAC5D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,GAAG,GAAG,IAAI,CAAC,CAAC;IAC7B,MAAM,IAA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,iBAAQ,SAAS,EAAC,eAAe,EAAC,EAAE,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,GAAI,IACzE,EACN,eAAM,SAAS,EAAC,gBAAgB,YAAE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,GAAQ,IACxJ,CACJ,IACI,CACR,CAAC;AACJ,CAAC","sourcesContent":["import type { DataSource } from \"@surfaces-ui/data\";\nimport { useDataSource } from \"../data/DataSourceProvider.js\";\nimport type { DataMessages } from \"../data/messages.js\";\nimport type { FilterInit } from \"../data/useRowWindow.js\";\nimport { label as text } from \"../locale/locale.js\";\nimport { type MetricProps, formatMetric } from \"../metric/Metric.js\";\nimport { useMeasure } from \"../metric/useMeasure.js\";\nimport type { ChartAggregate, ChartGrain } from \"./Chart.js\";\n\nexport interface SparklineProps extends DataMessages {\n sourceId: string;\n sql: string;\n /** The date or time column the line runs along. */\n x: string;\n grain: ChartGrain;\n column?: string;\n aggregate: ChartAggregate;\n label: string;\n format?: MetricProps[\"format\"];\n currency?: string;\n /** Most recent buckets to draw. Defaults to 30. */\n points?: number;\n filters?: FilterInit[];\n notBefore?: string;\n dataSource?: DataSource;\n className?: string;\n}\n\nconst WIDTH = 120;\nconst HEIGHT = 28;\nconst PAD = 3;\n\n/** Points for a line through `values` in a box, with gaps where a value is missing. */\nexport function sparklinePoints(values: (number | null)[], width = WIDTH, height = HEIGHT, pad = PAD): { x: number; y: number; value: number }[] {\n const known = values.filter((v): v is number => v !== null);\n if (known.length === 0) return [];\n const low = Math.min(...known);\n const high = Math.max(...known);\n const span = high - low || 1;\n const step = values.length > 1 ? (width - pad * 2) / (values.length - 1) : 0;\n return values.flatMap((value, i) => (value === null ? [] : [{ x: pad + i * step, y: high === low ? height / 2 : pad + (1 - (value - low) / span) * (height - pad * 2), value }]));\n}\n\n/**\n * A word-sized line next to its latest value: the trend without axes, grid\n * or legend. The low and high points are marked, and the same facts are\n * given in words for people who cannot see the line.\n */\nexport function Sparkline(props: SparklineProps) {\n const { sourceId, sql, x, grain, column, aggregate, label, format, currency, points = 30, filters, notBefore } = props;\n const dataSource = useDataSource(props.dataSource);\n const state = useMeasure(dataSource, { sourceId, sql, column, aggregate, filters, notBefore, x, grain, points });\n const line = sparklinePoints(state.values ?? []);\n const write = (value: number) => formatMetric(value, format, currency);\n const last = line.at(-1);\n const low = line.reduce<(typeof line)[number] | undefined>((a, p) => (!a || p.value < a.value ? p : a), undefined);\n const high = line.reduce<(typeof line)[number] | undefined>((a, p) => (!a || p.value > a.value ? p : a), undefined);\n const summary = last && low && high && line[0] ? text(\"sparkline.summary\", { label, now: write(last.value), first: write(line[0].value), low: write(low.value), high: write(high.value), count: line.length, grain }) : props.emptyMessage ? `${label}: ${props.emptyMessage}` : text(\"sparkline.empty\", { label });\n\n return (\n <span className={[\"sf-spark\", props.className].filter(Boolean).join(\" \")} aria-busy={state.loading}>\n <span className=\"sf-spark-label\">{label}</span>\n {state.error ? (\n <span className=\"sf-metric-error\" role=\"alert\" data-error={state.error}>\n {props.errorMessage ?? state.error}\n </span>\n ) : (\n <>\n <svg className=\"sf-spark-line\" viewBox={`0 0 ${WIDTH} ${HEIGHT}`} width={WIDTH} height={HEIGHT} role=\"img\" aria-label={summary}>\n {line.length > 1 && <polyline points={line.map((p) => `${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(\" \")} />}\n {low && high && low !== high && (\n <>\n <circle className=\"sf-spark-extreme\" cx={low.x} cy={low.y} r={1.8} />\n <circle className=\"sf-spark-extreme\" cx={high.x} cy={high.y} r={1.8} />\n </>\n )}\n {last && <circle className=\"sf-spark-last\" cx={last.x} cy={last.y} r={2.4} />}\n </svg>\n <span className=\"sf-spark-value\">{last ? write(last.value) : state.loading ? text(\"metric.loading\") : (props.emptyMessage ?? text(\"metric.none\"))}</span>\n </>\n )}\n </span>\n );\n}\n"]}
1
+ {"version":3,"file":"Sparkline.js","sourceRoot":"","sources":["../../src/chart/Sparkline.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAoB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAsBrD,MAAM,KAAK,GAAG,GAAG,CAAC;AAClB,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,GAAG,GAAG,CAAC,CAAC;AAEd,uFAAuF;AACvF,MAAM,UAAU,eAAe,CAAC,MAAyB,EAAE,KAAK,GAAG,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG;IAClG,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IAC5D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,GAAG,GAAG,IAAI,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAA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AI,IACzE,EACN,eAAM,SAAS,EAAC,gBAAgB,YAAE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,GAAQ,IACxJ,CACJ,EACD,KAAC,SAAS,IAAC,KAAK,EAAE,KAAK,CAAC,KAAK,GAAI,IAC5B,CACR,CAAC;AACJ,CAAC","sourcesContent":["import type { DataSource } from \"@surfaces-ui/data\";\nimport { useDataSource } from \"../data/DataSourceProvider.js\";\nimport { DataNotes } from \"../data/DataNotes.js\";\nimport type { DataMessages } from \"../data/messages.js\";\nimport type { FilterInit } from \"../data/useRowWindow.js\";\nimport { label as text } from \"../locale/locale.js\";\nimport { type MetricProps, formatMetric } from \"../metric/Metric.js\";\nimport { useMeasure } from \"../metric/useMeasure.js\";\nimport type { ChartAggregate, ChartGrain } from \"./Chart.js\";\n\nexport interface SparklineProps extends DataMessages {\n sourceId: string;\n sql: string;\n /** The date or time column the line runs along. */\n x: string;\n grain: ChartGrain;\n column?: string;\n aggregate: ChartAggregate;\n label: string;\n format?: MetricProps[\"format\"];\n currency?: string;\n /** Most recent buckets to draw. Defaults to 30. */\n points?: number;\n filters?: FilterInit[];\n notBefore?: string;\n dataSource?: DataSource;\n className?: string;\n}\n\nconst WIDTH = 120;\nconst HEIGHT = 28;\nconst PAD = 3;\n\n/** Points for a line through `values` in a box, with gaps where a value is missing. */\nexport function sparklinePoints(values: (number | null)[], width = WIDTH, height = HEIGHT, pad = PAD): { x: number; y: number; value: number }[] {\n const known = values.filter((v): v is number => v !== null);\n if (known.length === 0) return [];\n const low = Math.min(...known);\n const high = Math.max(...known);\n const span = high - low || 1;\n const step = values.length > 1 ? (width - pad * 2) / (values.length - 1) : 0;\n return values.flatMap((value, i) => (value === null ? [] : [{ x: pad + i * step, y: high === low ? height / 2 : pad + (1 - (value - low) / span) * (height - pad * 2), value }]));\n}\n\n/**\n * A word-sized line next to its latest value: the trend without axes, grid\n * or legend. The low and high points are marked, and the same facts are\n * given in words for people who cannot see the line.\n */\nexport function Sparkline(props: SparklineProps) {\n const { sourceId, sql, x, grain, column, aggregate, label, format, currency, points = 30, filters, notBefore } = props;\n const dataSource = useDataSource(props.dataSource);\n const state = useMeasure(dataSource, { sourceId, sql, column, aggregate, filters, notBefore, x, grain, points });\n const line = sparklinePoints(state.values ?? []);\n const write = (value: number) => formatMetric(value, format, currency);\n const last = line.at(-1);\n const low = line.reduce<(typeof line)[number] | undefined>((a, p) => (!a || p.value < a.value ? p : a), undefined);\n const high = line.reduce<(typeof line)[number] | undefined>((a, p) => (!a || p.value > a.value ? p : a), undefined);\n const summary = last && low && high && line[0] ? text(\"sparkline.summary\", { label, now: write(last.value), first: write(line[0].value), low: write(low.value), high: write(high.value), count: line.length, grain }) : props.emptyMessage ? `${label}: ${props.emptyMessage}` : text(\"sparkline.empty\", { label });\n\n return (\n <span className={[\"sf-spark\", props.className].filter(Boolean).join(\" \")} aria-busy={state.loading}>\n <span className=\"sf-spark-label\">{label}</span>\n {state.error ? (\n <span className=\"sf-metric-error\" role=\"alert\" data-error={state.error}>\n {props.errorMessage ?? state.error}\n </span>\n ) : (\n <>\n <svg className=\"sf-spark-line\" viewBox={`0 0 ${WIDTH} ${HEIGHT}`} width={WIDTH} height={HEIGHT} role=\"img\" aria-label={summary}>\n {line.length > 1 && <polyline points={line.map((p) => `${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(\" \")} />}\n {low && high && low !== high && (\n <>\n <circle className=\"sf-spark-extreme\" cx={low.x} cy={low.y} r={1.8} />\n <circle className=\"sf-spark-extreme\" cx={high.x} cy={high.y} r={1.8} />\n </>\n )}\n {last && <circle className=\"sf-spark-last\" cx={last.x} cy={last.y} r={2.4} />}\n </svg>\n <span className=\"sf-spark-value\">{last ? write(last.value) : state.loading ? text(\"metric.loading\") : (props.emptyMessage ?? text(\"metric.none\"))}</span>\n </>\n )}\n <DataNotes notes={state.notes} />\n </span>\n );\n}\n"]}
@@ -13,9 +13,13 @@ export interface ChartShape {
13
13
  orderedX?: boolean;
14
14
  /** True when the value axis has been told to start somewhere other than zero. */
15
15
  truncatedAxis?: boolean;
16
+ /** True when x is a numeric column grouped into bins (a histogram). */
17
+ binned?: boolean;
18
+ /** Where the legend was asked for, when it was; left out, the chart chooses. */
19
+ legend?: "top" | "bottom" | "right" | "none";
16
20
  }
17
21
  export interface ChartAdvice {
18
- rule: "pie-slices" | "two-scales" | "bar-baseline" | "line-order" | "too-many-lines" | "stack-depth" | "bar-crowding" | "overlapping-areas";
22
+ rule: "pie-slices" | "two-scales" | "bar-baseline" | "line-order" | "too-many-lines" | "stack-depth" | "bar-crowding" | "overlapping-areas" | "bars-over-time" | "pie-in-order" | "one-series-legend";
19
23
  message: string;
20
24
  /** What to draw instead. */
21
25
  instead: string;
@@ -34,6 +34,15 @@ export function chartAdvice(shape) {
34
34
  if (type === "area" && !shape.stacked && series > 1) {
35
35
  advice.push({ rule: "overlapping-areas", message: "Unstacked areas hide each other.", instead: "Lines, or a stacked area if the total matters." });
36
36
  }
37
+ if (type === "bar" && shape.orderedX && !shape.binned && categories > 24) {
38
+ advice.push({ rule: "bars-over-time", message: `${categories} bars in a row hide the trend they make.`, instead: "A line, with a time grain coarse enough for the decision." });
39
+ }
40
+ if (type === "pie" && shape.orderedX) {
41
+ advice.push({ rule: "pie-in-order", message: "A pie puts its slices round a circle, so the order of these values is lost.", instead: "A line or bars, in the order of x." });
42
+ }
43
+ if (type !== "pie" && series === 1 && shape.legend && shape.legend !== "none") {
44
+ advice.push({ rule: "one-series-legend", message: "A legend for one series repeats what the title says.", instead: "Leave the legend out and name the measure in the title." });
45
+ }
37
46
  return advice;
38
47
  }
39
48
  //# sourceMappingURL=advice.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"advice.js","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mCAAmC,EAAE,OAAO,EAAE,+EAA+E,EAAE,CAAC,CAAC;IAC3L,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,sBAAsB,MAAM,gDAAgD,EAAE,OAAO,EAAE,6EAA6E,EAAE,CAAC,CAAC;IACtN,CAAC;IACD,IAAI,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,UAAU,GAAG,MAAM,GAAG,EAAE,EAAE,CAAC;QACjE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,qCAAqC,EAAE,OAAO,EAAE,4CAA4C,EAAE,CAAC,CAAC;IAC/I,CAAC;IACD,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACpD,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,kCAAkC,EAAE,OAAO,EAAE,gDAAgD,EAAE,CAAC,CAAC;IACrJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { ChartType } from \"./option.js\";\n\n/** What a chart is about to draw, in the terms the advice needs. */\nexport interface ChartShape {\n type: ChartType;\n /** Distinct values on the x axis (or slices of a pie). */\n categories?: number;\n /** Series drawn, after any split. */\n series?: number;\n stacked?: boolean;\n /** True when a measure is on a second y scale. */\n rightAxis?: boolean;\n /** True when x is a date, time or number, so its order means something. */\n orderedX?: boolean;\n /** True when the value axis has been told to start somewhere other than zero. */\n truncatedAxis?: boolean;\n}\n\nexport interface ChartAdvice {\n rule: \"pie-slices\" | \"two-scales\" | \"bar-baseline\" | \"line-order\" | \"too-many-lines\" | \"stack-depth\" | \"bar-crowding\" | \"overlapping-areas\";\n message: string;\n /** What to draw instead. */\n instead: string;\n}\n\n/**\n * Checks a chart against the working rules of Edward Tufte and Stephen Few:\n * show the data honestly, compare like with like, and spend ink only on\n * data. It returns advice, not errors; a person or an agent decides.\n */\nexport function chartAdvice(shape: ChartShape): ChartAdvice[] {\n const advice: ChartAdvice[] = [];\n const { type, categories = 0, series = 1 } = shape;\n if (type === \"pie\" && categories > 5) {\n advice.push({ rule: \"pie-slices\", message: `${categories} slices are too many to compare by angle.`, instead: \"A bar chart sorted by value.\" });\n }\n if (shape.rightAxis) {\n advice.push({\n rule: \"two-scales\",\n message: \"Two y scales make heights look comparable when they are not.\",\n instead: \"Two charts stacked on the same x axis, or both measures indexed to a common start.\",\n });\n }\n if (type === \"bar\" && shape.truncatedAxis) {\n advice.push({ rule: \"bar-baseline\", message: \"A bar's length is its value, so the axis must start at zero.\", instead: \"Start at zero, or use a dot or line chart if the differences are small.\" });\n }\n if ((type === \"line\" || type === \"area\") && shape.orderedX === false) {\n advice.push({ rule: \"line-order\", message: \"A line implies order between its points; these categories have none.\", instead: \"A bar chart.\" });\n }\n if (type === \"line\" && series > 5) {\n advice.push({ rule: \"too-many-lines\", message: `${series} lines cross too often to follow.`, instead: \"Small multiples on one shared scale, or highlight one line and grey the rest.\" });\n }\n if (shape.stacked && series > 5) {\n advice.push({ rule: \"stack-depth\", message: `Only the bottom of ${series} stacked segments can be compared across bars.`, instead: \"Keep the largest four and fold the rest into Other, or use small multiples.\" });\n }\n if (type === \"bar\" && !shape.stacked && categories * series > 40) {\n advice.push({ rule: \"bar-crowding\", message: \"Too many bars to read individually.\", instead: \"The top values sorted by size, or a table.\" });\n }\n if (type === \"area\" && !shape.stacked && series > 1) {\n advice.push({ rule: \"overlapping-areas\", message: \"Unstacked areas hide each other.\", instead: \"Lines, or a stacked area if the total matters.\" });\n }\n return advice;\n}\n"]}
1
+ {"version":3,"file":"advice.js","sourceRoot":"","sources":["../../src/chart/advice.ts"],"names":[],"mappings":"AA6BA;;;;GAIG;AACH,MAAM,UAA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C,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC9E,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,sDAAsD,EAAE,OAAO,EAAE,yDAAyD,EAAE,CAAC,CAAC;IAClL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { ChartType } from \"./option.js\";\n\n/** What a chart is about to draw, in the terms the advice needs. */\nexport interface ChartShape {\n type: ChartType;\n /** Distinct values on the x axis (or slices of a pie). */\n categories?: number;\n /** Series drawn, after any split. */\n series?: number;\n stacked?: boolean;\n /** True when a measure is on a second y scale. */\n rightAxis?: boolean;\n /** True when x is a date, time or number, so its order means something. */\n orderedX?: boolean;\n /** True when the value axis has been told to start somewhere other than zero. */\n truncatedAxis?: boolean;\n /** True when x is a numeric column grouped into bins (a histogram). */\n binned?: boolean;\n /** Where the legend was asked for, when it was; left out, the chart chooses. */\n legend?: \"top\" | \"bottom\" | \"right\" | \"none\";\n}\n\nexport interface ChartAdvice {\n rule: \"pie-slices\" | \"two-scales\" | \"bar-baseline\" | \"line-order\" | \"too-many-lines\" | \"stack-depth\" | \"bar-crowding\" | \"overlapping-areas\" | \"bars-over-time\" | \"pie-in-order\" | \"one-series-legend\";\n message: string;\n /** What to draw instead. */\n instead: string;\n}\n\n/**\n * Checks a chart against the working rules of Edward Tufte and Stephen Few:\n * show the data honestly, compare like with like, and spend ink only on\n * data. It returns advice, not errors; a person or an agent decides.\n */\nexport function chartAdvice(shape: ChartShape): ChartAdvice[] {\n const advice: ChartAdvice[] = [];\n const { type, categories = 0, series = 1 } = shape;\n if (type === \"pie\" && categories > 5) {\n advice.push({ rule: \"pie-slices\", message: `${categories} slices are too many to compare by angle.`, instead: \"A bar chart sorted by value.\" });\n }\n if (shape.rightAxis) {\n advice.push({\n rule: \"two-scales\",\n message: \"Two y scales make heights look comparable when they are not.\",\n instead: \"Two charts stacked on the same x axis, or both measures indexed to a common start.\",\n });\n }\n if (type === \"bar\" && shape.truncatedAxis) {\n advice.push({ rule: \"bar-baseline\", message: \"A bar's length is its value, so the axis must start at zero.\", instead: \"Start at zero, or use a dot or line chart if the differences are small.\" });\n }\n if ((type === \"line\" || type === \"area\") && shape.orderedX === false) {\n advice.push({ rule: \"line-order\", message: \"A line implies order between its points; these categories have none.\", instead: \"A bar chart.\" });\n }\n if (type === \"line\" && series > 5) {\n advice.push({ rule: \"too-many-lines\", message: `${series} lines cross too often to follow.`, instead: \"Small multiples on one shared scale, or highlight one line and grey the rest.\" });\n }\n if (shape.stacked && series > 5) {\n advice.push({ rule: \"stack-depth\", message: `Only the bottom of ${series} stacked segments can be compared across bars.`, instead: \"Keep the largest four and fold the rest into Other, or use small multiples.\" });\n }\n if (type === \"bar\" && !shape.stacked && categories * series > 40) {\n advice.push({ rule: \"bar-crowding\", message: \"Too many bars to read individually.\", instead: \"The top values sorted by size, or a table.\" });\n }\n if (type === \"area\" && !shape.stacked && series > 1) {\n advice.push({ rule: \"overlapping-areas\", message: \"Unstacked areas hide each other.\", instead: \"Lines, or a stacked area if the total matters.\" });\n }\n if (type === \"bar\" && shape.orderedX && !shape.binned && categories > 24) {\n advice.push({ rule: \"bars-over-time\", message: `${categories} bars in a row hide the trend they make.`, instead: \"A line, with a time grain coarse enough for the decision.\" });\n }\n if (type === \"pie\" && shape.orderedX) {\n advice.push({ rule: \"pie-in-order\", message: \"A pie puts its slices round a circle, so the order of these values is lost.\", instead: \"A line or bars, in the order of x.\" });\n }\n if (type !== \"pie\" && series === 1 && shape.legend && shape.legend !== \"none\") {\n advice.push({ rule: \"one-series-legend\", message: \"A legend for one series repeats what the title says.\", instead: \"Leave the legend out and name the measure in the title.\" });\n }\n return advice;\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Lets the wheel scroll the page over a chart or graph drawn with ECharts,
3
+ * whose own zoom would otherwise take every wheel event and trap the page.
4
+ *
5
+ * The rule is the one pan-zoom diagrams follow: Ctrl/⌘ + wheel, or a pinch
6
+ * (which the browser reports as Ctrl + wheel), zooms; a plain wheel scrolls
7
+ * the page. A plain wheel event is stopped on its way down, before ECharts
8
+ * sees it, and its default (the page scrolling) is left alone.
9
+ *
10
+ * Returns the function that takes the rule away.
11
+ */
12
+ export declare function wheelScrollsThePage(element: HTMLElement): () => void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Lets the wheel scroll the page over a chart or graph drawn with ECharts,
3
+ * whose own zoom would otherwise take every wheel event and trap the page.
4
+ *
5
+ * The rule is the one pan-zoom diagrams follow: Ctrl/⌘ + wheel, or a pinch
6
+ * (which the browser reports as Ctrl + wheel), zooms; a plain wheel scrolls
7
+ * the page. A plain wheel event is stopped on its way down, before ECharts
8
+ * sees it, and its default (the page scrolling) is left alone.
9
+ *
10
+ * Returns the function that takes the rule away.
11
+ */
12
+ export function wheelScrollsThePage(element) {
13
+ const onWheel = (event) => {
14
+ if (event.ctrlKey || event.metaKey)
15
+ return;
16
+ event.stopPropagation();
17
+ };
18
+ element.addEventListener("wheel", onWheel, { capture: true });
19
+ return () => element.removeEventListener("wheel", onWheel, { capture: true });
20
+ }
21
+ //# sourceMappingURL=wheel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wheel.js","sourceRoot":"","sources":["../../src/chart/wheel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAoB;IACtD,MAAM,OAAO,GAAG,CAAC,KAAiB,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO;YAAE,OAAO;QAC3C,KAAK,CAAC,eAAe,EAAE,CAAC;IAC1B,CAAC,CAAC;IACF,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9D,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAChF,CAAC","sourcesContent":["/**\n * Lets the wheel scroll the page over a chart or graph drawn with ECharts,\n * whose own zoom would otherwise take every wheel event and trap the page.\n *\n * The rule is the one pan-zoom diagrams follow: Ctrl/⌘ + wheel, or a pinch\n * (which the browser reports as Ctrl + wheel), zooms; a plain wheel scrolls\n * the page. A plain wheel event is stopped on its way down, before ECharts\n * sees it, and its default (the page scrolling) is left alone.\n *\n * Returns the function that takes the rule away.\n */\nexport function wheelScrollsThePage(element: HTMLElement): () => void {\n const onWheel = (event: WheelEvent) => {\n if (event.ctrlKey || event.metaKey) return;\n event.stopPropagation();\n };\n element.addEventListener(\"wheel\", onWheel, { capture: true });\n return () => element.removeEventListener(\"wheel\", onWheel, { capture: true });\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /** The notice messages from a result header that are for the people reading the view. */
2
+ export declare function dataNotes(notices: readonly {
3
+ code: string;
4
+ message: string;
5
+ }[] | undefined): string[];
6
+ /**
7
+ * Says under a view what it was not filtered by, in words: a page-wide filter
8
+ * on a column the view's rows lack is left out by the engine, and the view is
9
+ * drawn without it rather than failing.
10
+ */
11
+ export declare function DataNotes({ notes }: {
12
+ notes: readonly string[] | undefined;
13
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /** Notices a view's readers should see: a filter it could not take, because its rows lack the column. */
3
+ const SHOWN = new Set(["FILTER_COLUMN_MISSING"]);
4
+ /** The notice messages from a result header that are for the people reading the view. */
5
+ export function dataNotes(notices) {
6
+ return [...new Set((notices ?? []).filter((n) => SHOWN.has(n.code)).map((n) => n.message))];
7
+ }
8
+ /**
9
+ * Says under a view what it was not filtered by, in words: a page-wide filter
10
+ * on a column the view's rows lack is left out by the engine, and the view is
11
+ * drawn without it rather than failing.
12
+ */
13
+ export function DataNotes({ notes }) {
14
+ if (!notes || notes.length === 0)
15
+ return null;
16
+ return (_jsx("span", { className: "sf-data-note", role: "note", children: notes.join(" ") }));
17
+ }
18
+ //# sourceMappingURL=DataNotes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataNotes.js","sourceRoot":"","sources":["../../src/data/DataNotes.tsx"],"names":[],"mappings":";AAAA,yGAAyG;AACzG,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC;AAEjD,yFAAyF;AACzF,MAAM,UAAU,SAAS,CAAC,OAAiE;IACzF,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC9F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,EAAE,KAAK,EAA4C;IAC3E,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9C,OAAO,CACL,eAAM,SAAS,EAAC,cAAc,EAAC,IAAI,EAAC,MAAM,YACvC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GACX,CACR,CAAC;AACJ,CAAC","sourcesContent":["/** Notices a view's readers should see: a filter it could not take, because its rows lack the column. */\nconst SHOWN = new Set([\"FILTER_COLUMN_MISSING\"]);\n\n/** The notice messages from a result header that are for the people reading the view. */\nexport function dataNotes(notices: readonly { code: string; message: string }[] | undefined): string[] {\n return [...new Set((notices ?? []).filter((n) => SHOWN.has(n.code)).map((n) => n.message))];\n}\n\n/**\n * Says under a view what it was not filtered by, in words: a page-wide filter\n * on a column the view's rows lack is left out by the engine, and the view is\n * drawn without it rather than failing.\n */\nexport function DataNotes({ notes }: { notes: readonly string[] | undefined }) {\n if (!notes || notes.length === 0) return null;\n return (\n <span className=\"sf-data-note\" role=\"note\">\n {notes.join(\" \")}\n </span>\n );\n}\n"]}