@altertable/data-app 0.69.0 → 0.71.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 (289) hide show
  1. package/AGENTS.md +11 -1
  2. package/CONTRIBUTING.md +59 -26
  3. package/README.md +22 -26
  4. package/REFERENCE.md +1900 -0
  5. package/dist/chunks/index-5a27erdg.js +54 -0
  6. package/dist/chunks/index-5a27erdg.js.map +10 -0
  7. package/dist/chunks/{index-2sbp9h2b.js → index-9yxr7nmm.js} +330 -21
  8. package/dist/chunks/index-9yxr7nmm.js.map +17 -0
  9. package/dist/chunks/{index-r7b1ftwy.js → index-j5q5n3ra.js} +8 -6
  10. package/dist/chunks/index-j5q5n3ra.js.map +10 -0
  11. package/dist/chunks/{index-22d576sn.js → index-q75zm3a7.js} +3 -3
  12. package/dist/chunks/{index-22d576sn.js.map → index-q75zm3a7.js.map} +3 -3
  13. package/dist/chunks/{index-kwnqycjt.js → index-vhaec7m5.js} +8 -6
  14. package/dist/chunks/index-vhaec7m5.js.map +10 -0
  15. package/dist/chunks/index-zp78caex.js +1047 -0
  16. package/dist/chunks/index-zp78caex.js.map +19 -0
  17. package/dist/client/index.js +284 -16
  18. package/dist/client/index.js.map +7 -3
  19. package/dist/core/appearance.js +181 -11
  20. package/dist/core/appearance.js.map +4 -3
  21. package/dist/core/config.js +3 -3
  22. package/dist/core/contract.js +13 -15
  23. package/dist/core/contract.js.map +1 -1
  24. package/dist/core/format.js +1 -1
  25. package/dist/index.js +4 -4
  26. package/dist/index.js.map +1 -1
  27. package/dist/internal.js +418 -0
  28. package/dist/internal.js.map +15 -0
  29. package/dist/server/index.js +102 -0
  30. package/dist/server/index.js.map +10 -0
  31. package/dist/types/client/annotations.d.ts +1 -1
  32. package/dist/types/client/data-client.d.ts +21 -10
  33. package/dist/types/client/iframe.d.ts +6 -6
  34. package/dist/types/client/index.d.ts +3 -4
  35. package/dist/types/client/location.d.ts +2 -2
  36. package/dist/types/client/logger.d.ts +1 -1
  37. package/dist/types/client/navigation.d.ts +1 -1
  38. package/dist/types/client/transport.d.ts +1 -1
  39. package/dist/types/core/bridge.d.ts +1 -1
  40. package/dist/types/core/config.d.ts +20 -17
  41. package/dist/types/core/contract.d.ts +23 -13
  42. package/dist/types/core/dimension-source.d.ts +64 -0
  43. package/dist/types/core/dimension.d.ts +31 -23
  44. package/dist/types/core/facets.d.ts +13 -0
  45. package/dist/types/core/filters.d.ts +1 -1
  46. package/dist/types/core/format.d.ts +1 -2
  47. package/dist/types/core/keys.d.ts +2 -0
  48. package/dist/types/core/messages.d.ts +3 -3
  49. package/dist/types/core/operation-types.d.ts +7 -6
  50. package/dist/types/core/presentation.d.ts +1 -1
  51. package/dist/types/core/queries.d.ts +75 -7
  52. package/dist/types/core/reading.d.ts +1 -1
  53. package/dist/types/core/variables.d.ts +38 -12
  54. package/dist/types/index.d.ts +1 -1
  55. package/dist/types/internal.d.ts +22 -0
  56. package/dist/types/server/index.d.ts +1 -2
  57. package/docs/app-authoring.md +12 -4
  58. package/docs/client.md +5 -6
  59. package/docs/composition.md +84 -0
  60. package/docs/contract.md +41 -21
  61. package/docs/data-context.md +5 -3
  62. package/docs/embed.md +4 -4
  63. package/docs/formatting-and-appearance.md +1 -1
  64. package/docs/hosted-apps.md +4 -0
  65. package/docs/react-embed.md +7 -6
  66. package/docs/react.md +5 -5
  67. package/docs/server-bun.md +5 -5
  68. package/docs/server.md +1 -1
  69. package/docs/stories-and-export.md +3 -3
  70. package/docs/styling.md +6 -2
  71. package/docs/ui.md +18 -7
  72. package/docs/variables.md +83 -11
  73. package/docs/views.md +57 -3
  74. package/docs/widgets.md +97 -4
  75. package/docs/worker.md +4 -4
  76. package/examples/starter-data-app/index.tsx +11 -23
  77. package/examples/starter-local-data-app/AGENTS.md +1 -1
  78. package/examples/starter-local-data-app/README.md +12 -10
  79. package/examples/starter-local-data-app/app.ts +7 -1
  80. package/examples/starter-local-data-app/package.json +3 -1
  81. package/examples/starter-local-data-app/src/App.tsx +1 -1
  82. package/examples/starter-local-data-app/src/data-context.ts +1 -1
  83. package/examples/starter-local-data-app/src/main.tsx +1 -1
  84. package/examples/starter-local-data-app/src/server.ts +1 -1
  85. package/examples/starter-local-data-app/tsconfig.json +7 -1
  86. package/package.json +16 -92
  87. package/THIRD_PARTY_NOTICES +0 -18
  88. package/dist/chunks/index-2sbp9h2b.js.map +0 -13
  89. package/dist/chunks/index-ap60vggk.js +0 -80
  90. package/dist/chunks/index-ap60vggk.js.map +0 -10
  91. package/dist/chunks/index-cv36cyna.js +0 -180
  92. package/dist/chunks/index-cv36cyna.js.map +0 -10
  93. package/dist/chunks/index-k766wwwr.js +0 -643
  94. package/dist/chunks/index-k766wwwr.js.map +0 -13
  95. package/dist/chunks/index-kwnqycjt.js.map +0 -10
  96. package/dist/chunks/index-m0gbxtgp.js +0 -355
  97. package/dist/chunks/index-m0gbxtgp.js.map +0 -13
  98. package/dist/chunks/index-qhzdzca2.js +0 -15869
  99. package/dist/chunks/index-qhzdzca2.js.map +0 -118
  100. package/dist/chunks/index-r7b1ftwy.js.map +0 -10
  101. package/dist/chunks/index-sx488hvs.js +0 -221
  102. package/dist/chunks/index-sx488hvs.js.map +0 -12
  103. package/dist/chunks/index-wss3gd3h.js +0 -319
  104. package/dist/chunks/index-wss3gd3h.js.map +0 -13
  105. package/dist/chunks/index-zcqxfwdq.js +0 -197
  106. package/dist/chunks/index-zcqxfwdq.js.map +0 -13
  107. package/dist/embed/index.js +0 -138
  108. package/dist/embed/index.js.map +0 -12
  109. package/dist/local.js +0 -432
  110. package/dist/local.js.map +0 -14
  111. package/dist/preview.js +0 -1456
  112. package/dist/preview.js.map +0 -17
  113. package/dist/react/embed/index.js +0 -117
  114. package/dist/react/embed/index.js.map +0 -10
  115. package/dist/react/index.js +0 -2948
  116. package/dist/react/index.js.map +0 -26
  117. package/dist/react/ui/index.js +0 -3142
  118. package/dist/react/ui/index.js.map +0 -35
  119. package/dist/server.js +0 -301
  120. package/dist/server.js.map +0 -13
  121. package/dist/types/core/time-interval.d.ts +0 -96
  122. package/dist/types/embed/bootstrap.d.ts +0 -5
  123. package/dist/types/embed/bridge.d.ts +0 -12
  124. package/dist/types/embed/host.d.ts +0 -36
  125. package/dist/types/embed/index.d.ts +0 -14
  126. package/dist/types/embed/navigation.d.ts +0 -6
  127. package/dist/types/embed/runtime-html.d.ts +0 -2
  128. package/dist/types/embed/source.d.ts +0 -16
  129. package/dist/types/embed/sql.d.ts +0 -4
  130. package/dist/types/react/annotations/AnnotationBar.d.ts +0 -30
  131. package/dist/types/react/annotations/AnnotationControls.d.ts +0 -10
  132. package/dist/types/react/annotations/AnnotationEditor.d.ts +0 -16
  133. package/dist/types/react/annotations/AnnotationMarkers.d.ts +0 -19
  134. package/dist/types/react/annotations/AnnotationSelectionLayer.d.ts +0 -12
  135. package/dist/types/react/annotations/AnnotationTarget.d.ts +0 -9
  136. package/dist/types/react/annotations/AnnotationTooltip.d.ts +0 -9
  137. package/dist/types/react/annotations/AnnotationTrigger.d.ts +0 -10
  138. package/dist/types/react/annotations/annotation-editor-state.d.ts +0 -58
  139. package/dist/types/react/annotations/annotation-screenshot.d.ts +0 -4
  140. package/dist/types/react/annotations/annotation-targets.d.ts +0 -34
  141. package/dist/types/react/annotations/getAnnotationProps.d.ts +0 -17
  142. package/dist/types/react/annotations/styles.d.ts +0 -3
  143. package/dist/types/react/annotations/useAnnotationGeometry.d.ts +0 -22
  144. package/dist/types/react/annotations/useDataAppAnnotations.d.ts +0 -22
  145. package/dist/types/react/app-context.d.ts +0 -3
  146. package/dist/types/react/bindings.d.ts +0 -133
  147. package/dist/types/react/content.d.ts +0 -36
  148. package/dist/types/react/date-formatting.d.ts +0 -12
  149. package/dist/types/react/embed/bridge.d.ts +0 -21
  150. package/dist/types/react/embed/index.d.ts +0 -7
  151. package/dist/types/react/hooks.d.ts +0 -75
  152. package/dist/types/react/index.d.ts +0 -75
  153. package/dist/types/react/injectStyles.d.ts +0 -7
  154. package/dist/types/react/mount.d.ts +0 -13
  155. package/dist/types/react/search-suggestions.d.ts +0 -8
  156. package/dist/types/react/source-owner.d.ts +0 -2
  157. package/dist/types/react/style-contract.d.ts +0 -88
  158. package/dist/types/react/style-validation.d.ts +0 -2
  159. package/dist/types/react/styles.d.ts +0 -8
  160. package/dist/types/react/ui/AboutData.d.ts +0 -68
  161. package/dist/types/react/ui/AltertableLogo.d.ts +0 -3
  162. package/dist/types/react/ui/AppFooter.d.ts +0 -6
  163. package/dist/types/react/ui/AppHeader.d.ts +0 -10
  164. package/dist/types/react/ui/AppLayout.d.ts +0 -10
  165. package/dist/types/react/ui/AppScope.d.ts +0 -7
  166. package/dist/types/react/ui/AppToolbar.d.ts +0 -30
  167. package/dist/types/react/ui/AreaChart.d.ts +0 -7
  168. package/dist/types/react/ui/BarChart.d.ts +0 -6
  169. package/dist/types/react/ui/Breakdown.d.ts +0 -13
  170. package/dist/types/react/ui/Button.d.ts +0 -11
  171. package/dist/types/react/ui/ChartLegend.d.ts +0 -32
  172. package/dist/types/react/ui/Checkbox.d.ts +0 -21
  173. package/dist/types/react/ui/CheckboxGroup.d.ts +0 -7
  174. package/dist/types/react/ui/ChoicePicker.d.ts +0 -39
  175. package/dist/types/react/ui/Comparison.d.ts +0 -14
  176. package/dist/types/react/ui/ComposedChart.d.ts +0 -41
  177. package/dist/types/react/ui/ComposedChartLegend.d.ts +0 -8
  178. package/dist/types/react/ui/ContentSkeleton.d.ts +0 -7
  179. package/dist/types/react/ui/DataApp.d.ts +0 -21
  180. package/dist/types/react/ui/DataAppFrame.d.ts +0 -52
  181. package/dist/types/react/ui/DataBoundary.d.ts +0 -14
  182. package/dist/types/react/ui/DataSection.d.ts +0 -14
  183. package/dist/types/react/ui/DataSectionBoundary.d.ts +0 -30
  184. package/dist/types/react/ui/DataTable.d.ts +0 -29
  185. package/dist/types/react/ui/DataValue.d.ts +0 -9
  186. package/dist/types/react/ui/DataViewToast.d.ts +0 -11
  187. package/dist/types/react/ui/DataWidget.d.ts +0 -34
  188. package/dist/types/react/ui/DateDisplay.d.ts +0 -9
  189. package/dist/types/react/ui/DateRangePicker.d.ts +0 -30
  190. package/dist/types/react/ui/DateTimeTooltip.d.ts +0 -10
  191. package/dist/types/react/ui/DimensionPicker.d.ts +0 -13
  192. package/dist/types/react/ui/EmptyState.d.ts +0 -6
  193. package/dist/types/react/ui/ExportControl.d.ts +0 -4
  194. package/dist/types/react/ui/FilterActions.d.ts +0 -10
  195. package/dist/types/react/ui/FilterBar.d.ts +0 -3
  196. package/dist/types/react/ui/FunnelChart.d.ts +0 -20
  197. package/dist/types/react/ui/GettingStarted.d.ts +0 -6
  198. package/dist/types/react/ui/GlossaryDefinition.d.ts +0 -7
  199. package/dist/types/react/ui/GlossaryExplanation.d.ts +0 -16
  200. package/dist/types/react/ui/GradientScroll.d.ts +0 -23
  201. package/dist/types/react/ui/Grid.d.ts +0 -12
  202. package/dist/types/react/ui/GridItem.d.ts +0 -7
  203. package/dist/types/react/ui/HelpPopover.d.ts +0 -21
  204. package/dist/types/react/ui/IconButton.d.ts +0 -19
  205. package/dist/types/react/ui/InspectionContext.d.ts +0 -12
  206. package/dist/types/react/ui/InspectionProvider.d.ts +0 -29
  207. package/dist/types/react/ui/JourneyChart.d.ts +0 -10
  208. package/dist/types/react/ui/Kbd.d.ts +0 -7
  209. package/dist/types/react/ui/LineChart.d.ts +0 -7
  210. package/dist/types/react/ui/LiveControl.d.ts +0 -10
  211. package/dist/types/react/ui/Menu.d.ts +0 -12
  212. package/dist/types/react/ui/MetricWidget.d.ts +0 -49
  213. package/dist/types/react/ui/NumberField.d.ts +0 -27
  214. package/dist/types/react/ui/NumberFilterPicker.d.ts +0 -11
  215. package/dist/types/react/ui/PeriodSummary.d.ts +0 -17
  216. package/dist/types/react/ui/PickerField.d.ts +0 -15
  217. package/dist/types/react/ui/PieChart.d.ts +0 -11
  218. package/dist/types/react/ui/PopoverSurface.d.ts +0 -5
  219. package/dist/types/react/ui/PresentStory.d.ts +0 -30
  220. package/dist/types/react/ui/QueryList.d.ts +0 -14
  221. package/dist/types/react/ui/RadioGroup.d.ts +0 -18
  222. package/dist/types/react/ui/Ranking.d.ts +0 -13
  223. package/dist/types/react/ui/RefreshControl.d.ts +0 -9
  224. package/dist/types/react/ui/RequestHint.d.ts +0 -20
  225. package/dist/types/react/ui/RetentionChart.d.ts +0 -27
  226. package/dist/types/react/ui/ScatterChart.d.ts +0 -17
  227. package/dist/types/react/ui/SearchField.d.ts +0 -23
  228. package/dist/types/react/ui/SearchInput.d.ts +0 -10
  229. package/dist/types/react/ui/SearchMatch.d.ts +0 -6
  230. package/dist/types/react/ui/SearchTypeahead.d.ts +0 -15
  231. package/dist/types/react/ui/SectionHeading.d.ts +0 -8
  232. package/dist/types/react/ui/Select.d.ts +0 -18
  233. package/dist/types/react/ui/SelectionMark.d.ts +0 -5
  234. package/dist/types/react/ui/Sheet.d.ts +0 -21
  235. package/dist/types/react/ui/Skeleton.d.ts +0 -8
  236. package/dist/types/react/ui/Stack.d.ts +0 -7
  237. package/dist/types/react/ui/StaticDataApp.d.ts +0 -4
  238. package/dist/types/react/ui/StatusPanel.d.ts +0 -10
  239. package/dist/types/react/ui/TableWidget.d.ts +0 -67
  240. package/dist/types/react/ui/Tabs.d.ts +0 -10
  241. package/dist/types/react/ui/TextContent.d.ts +0 -4
  242. package/dist/types/react/ui/TextWidget.d.ts +0 -20
  243. package/dist/types/react/ui/ThemeSelector.d.ts +0 -12
  244. package/dist/types/react/ui/Toast.d.ts +0 -8
  245. package/dist/types/react/ui/Tooltip.d.ts +0 -23
  246. package/dist/types/react/ui/TooltipSurface.d.ts +0 -3
  247. package/dist/types/react/ui/TrendChart.d.ts +0 -5
  248. package/dist/types/react/ui/UpdatedAt.d.ts +0 -9
  249. package/dist/types/react/ui/VariableBar.d.ts +0 -6
  250. package/dist/types/react/ui/VisualizationWidget.d.ts +0 -43
  251. package/dist/types/react/ui/WidgetDisclosure.d.ts +0 -6
  252. package/dist/types/react/ui/WidgetEvidence.d.ts +0 -12
  253. package/dist/types/react/ui/WidgetViewTabs.d.ts +0 -16
  254. package/dist/types/react/ui/chart-data.d.ts +0 -34
  255. package/dist/types/react/ui/chart-date-axis.d.ts +0 -15
  256. package/dist/types/react/ui/chart-interaction.d.ts +0 -21
  257. package/dist/types/react/ui/chart-primitives.d.ts +0 -22
  258. package/dist/types/react/ui/chart-time.d.ts +0 -16
  259. package/dist/types/react/ui/chartColor.d.ts +0 -2
  260. package/dist/types/react/ui/classNames.d.ts +0 -1
  261. package/dist/types/react/ui/csv-export.d.ts +0 -19
  262. package/dist/types/react/ui/data-context.d.ts +0 -76
  263. package/dist/types/react/ui/data-identifiers.d.ts +0 -32
  264. package/dist/types/react/ui/icons.d.ts +0 -47
  265. package/dist/types/react/ui/index.d.ts +0 -109
  266. package/dist/types/react/ui/journey-flow.d.ts +0 -49
  267. package/dist/types/react/ui/keyboard.d.ts +0 -6
  268. package/dist/types/react/ui/metric-comparison.d.ts +0 -30
  269. package/dist/types/react/ui/metric.d.ts +0 -11
  270. package/dist/types/react/ui/presentation.d.ts +0 -25
  271. package/dist/types/react/ui/search.d.ts +0 -6
  272. package/dist/types/react/ui/searchItems.d.ts +0 -36
  273. package/dist/types/react/ui/shortcuts.d.ts +0 -45
  274. package/dist/types/react/ui/story.d.ts +0 -20
  275. package/dist/types/react/ui/useAppAppearance.d.ts +0 -3
  276. package/dist/types/react/ui/useDataAppPresentation.d.ts +0 -3
  277. package/dist/types/react/ui/useSvgId.d.ts +0 -2
  278. package/dist/types/react/ui/variables.d.ts +0 -38
  279. package/dist/types/react/ui/widget-views.d.ts +0 -3
  280. package/dist/types/react/view-control-bar.d.ts +0 -16
  281. package/dist/types/react/view-controls.d.ts +0 -20
  282. package/dist/types/react/view-runtime.d.ts +0 -31
  283. package/dist/types/react/view.d.ts +0 -78
  284. package/dist/types/react/widgets.d.ts +0 -79
  285. package/dist/types/server/local.d.ts +0 -19
  286. package/dist/types/server/preview/host.d.ts +0 -1
  287. package/dist/types/server/preview/index.d.ts +0 -16
  288. package/dist/types/server/reload-channel.d.ts +0 -6
  289. package/dist/worker.js +0 -106
@@ -1,3142 +0,0 @@
1
- import {
2
- injectDataAppStyles2,
3
- useDateFormatting2,
4
- AppIcon2,
5
- classNames,
6
- Button2,
7
- PressButton,
8
- TooltipSurface,
9
- TooltipProvider2,
10
- Tooltip2,
11
- GradientScroll2,
12
- Sheet2,
13
- TabPanels2,
14
- TabList2,
15
- Tab2,
16
- TabPanel2,
17
- Tabs2,
18
- useViewTab2,
19
- AboutData2,
20
- DataAppProvider2,
21
- useDeclaredResult,
22
- HelpPopover2,
23
- DateDisplay2,
24
- validateChoiceOptions,
25
- useAppVariables2,
26
- SearchField2,
27
- SearchMatch2,
28
- matchSearchText2,
29
- searchItems2,
30
- SearchTypeahead2,
31
- Select2,
32
- FilterActions2,
33
- VariableBar2,
34
- NumberField2,
35
- NumberRangeField2,
36
- NumberFilterPicker2,
37
- ChoicePicker2,
38
- CheckboxGroupContext,
39
- Checkbox2,
40
- DateRangePicker2,
41
- FilterBar2,
42
- DimensionPicker2,
43
- createDataHooks2,
44
- isPlainKeyEvent2,
45
- MenuTrigger2,
46
- MenuSection2,
47
- MenuPopover2,
48
- Menu2,
49
- MenuItem2,
50
- MenuSeparator2,
51
- LiveControl2,
52
- PresentStory2,
53
- DataAppFrame,
54
- DataWidget2,
55
- VisualizationWidget2,
56
- MetricWidget2,
57
- DataTable2,
58
- DataTableShare2,
59
- DataTableEmptyRow2,
60
- DataTableTimestamp2,
61
- TableWidget2,
62
- TextWidget2,
63
- DataValue2,
64
- chartBarFill,
65
- createDataContext2,
66
- SectionHeading2
67
- } from "../../chunks/index-qhzdzca2.js";
68
- import {
69
- formatDate2,
70
- parseDateTime2,
71
- formatDateTime2,
72
- formatNumber2,
73
- formatPercent2
74
- } from "../../chunks/index-22d576sn.js";
75
- import"../../chunks/index-k766wwwr.js";
76
- import"../../chunks/index-kwnqycjt.js";
77
- import"../../chunks/index-cv36cyna.js";
78
- import {
79
- createDataClient2
80
- } from "../../chunks/index-ap60vggk.js";
81
- import"../../chunks/index-r7b1ftwy.js";
82
- import"../../chunks/index-sx488hvs.js";
83
- import {
84
- invariant
85
- } from "../../chunks/index-zcqxfwdq.js";
86
- // src/react/ui/StaticDataApp.tsx
87
- import { jsx } from "react/jsx-runtime";
88
- function DataApp(props) {
89
- return /* @__PURE__ */ jsx(DataAppFrame, {
90
- ...props
91
- });
92
- }
93
-
94
- // src/react/ui/GettingStarted.tsx
95
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
96
- var connectionContext = createDataContext2({})({
97
- description: "Connection setup",
98
- glossary: {}
99
- });
100
- var client = /* @__PURE__ */ createDataClient2();
101
- var { defineDataView } = /* @__PURE__ */ createDataHooks2(client);
102
- var connectionView = defineDataView({
103
- dataContext: connectionContext,
104
- operation: "connection",
105
- describeInput: () => "the connection",
106
- isEmpty: () => false,
107
- emptyFallback: { title: "No connection" }
108
- });
109
- function GettingStarted({ dataContext }) {
110
- const connection = useDeclaredResult(connectionView);
111
- const state = connection.view.kind === "error" || connection.view.kind === "stale-error" ? "error" : connection.refreshing || !connection.snapshot ? "checking" : "connected";
112
- return /* @__PURE__ */ jsxs(DataApp, {
113
- dataContext,
114
- description: "Check your lakehouse connection, then build a view around a real question.",
115
- queries: connection.queries,
116
- toolbarActions: /* @__PURE__ */ jsx2(Button2, {
117
- disabled: connection.refreshing,
118
- onClick: () => connection.refetch(),
119
- children: "Check connection"
120
- }),
121
- children: [
122
- /* @__PURE__ */ jsxs("section", {
123
- className: "starter-connection",
124
- "data-state": state,
125
- role: state === "error" ? "alert" : "status",
126
- children: [
127
- /* @__PURE__ */ jsx2("div", {
128
- className: "starter-connection-icon",
129
- children: /* @__PURE__ */ jsx2(AppIcon2, {
130
- name: state === "connected" ? "check" : state === "error" ? "error" : "loading",
131
- size: 24
132
- })
133
- }),
134
- /* @__PURE__ */ jsxs("div", {
135
- className: "starter-connection-copy",
136
- children: [
137
- /* @__PURE__ */ jsx2("span", {
138
- className: "starter-eyebrow",
139
- children: "Lakehouse connection"
140
- }),
141
- /* @__PURE__ */ jsx2("h2", {
142
- children: state === "connected" ? "Connected" : state === "error" ? "Connection not verified" : "Checking connection…"
143
- }),
144
- /* @__PURE__ */ jsx2("p", {
145
- children: state === "connected" ? "A query completed successfully using this app’s current profile. You’re ready to build your first view." : state === "error" ? connection.snapshot ? "An earlier query succeeded, but the latest check failed. Check the profile and try again." : "The query could not complete. Check the profile and lakehouse access, then try again." : "Running a lightweight query with this app’s current profile."
146
- }),
147
- state === "connected" && /* @__PURE__ */ jsx2("small", {
148
- children: "This check does not verify access to every dataset."
149
- })
150
- ]
151
- }),
152
- state === "error" && /* @__PURE__ */ jsx2(Button2, {
153
- onClick: () => connection.refetch(),
154
- children: "Try again"
155
- })
156
- ]
157
- }),
158
- /* @__PURE__ */ jsxs("section", {
159
- className: "starter-next",
160
- "aria-labelledby": "starter-next-title",
161
- children: [
162
- /* @__PURE__ */ jsxs("div", {
163
- className: "starter-next-heading",
164
- children: [
165
- /* @__PURE__ */ jsx2("span", {
166
- className: "starter-eyebrow",
167
- children: "Next steps"
168
- }),
169
- /* @__PURE__ */ jsx2("h2", {
170
- id: "starter-next-title",
171
- children: "Turn this starter into a useful app"
172
- }),
173
- /* @__PURE__ */ jsx2("p", {
174
- children: "Start with one question your readers need answered."
175
- })
176
- ]
177
- }),
178
- /* @__PURE__ */ jsxs("ol", {
179
- className: "starter-steps",
180
- children: [
181
- /* @__PURE__ */ jsxs("li", {
182
- children: [
183
- /* @__PURE__ */ jsx2("strong", {
184
- children: "Choose a question"
185
- }),
186
- /* @__PURE__ */ jsx2("p", {
187
- children: "Decide what someone should learn or do after opening this app."
188
- })
189
- ]
190
- }),
191
- /* @__PURE__ */ jsxs("li", {
192
- children: [
193
- /* @__PURE__ */ jsx2("strong", {
194
- children: "Find the right data"
195
- }),
196
- /* @__PURE__ */ jsx2("p", {
197
- children: "Inspect the relevant catalogs, tables, and columns before writing the query."
198
- })
199
- ]
200
- }),
201
- /* @__PURE__ */ jsxs("li", {
202
- children: [
203
- /* @__PURE__ */ jsx2("strong", {
204
- children: "Build the first view"
205
- }),
206
- /* @__PURE__ */ jsxs("p", {
207
- children: [
208
- "Replace the connection check in ",
209
- /* @__PURE__ */ jsx2("code", {
210
- children: "src/operations.ts"
211
- }),
212
- ", then render its result in ",
213
- /* @__PURE__ */ jsx2("code", {
214
- children: "src/App.tsx"
215
- }),
216
- "."
217
- ]
218
- })
219
- ]
220
- })
221
- ]
222
- })
223
- ]
224
- })
225
- ]
226
- });
227
- }
228
- // src/react/ui/GlossaryExplanation.tsx
229
- import { jsx as jsx3 } from "react/jsx-runtime";
230
- function GlossaryExplanation({
231
- entry,
232
- empty,
233
- title,
234
- description,
235
- visual,
236
- queries,
237
- dataContext,
238
- className,
239
- ...props
240
- }) {
241
- return /* @__PURE__ */ jsx3(AboutData2, {
242
- ...props,
243
- shortcut: false,
244
- iconOnly: true,
245
- variant: "ghost",
246
- title: title ?? entry.term,
247
- description,
248
- visual,
249
- references: { kind: "entries", entries: [entry] },
250
- empty,
251
- dataContext,
252
- queries,
253
- className: className ?? "altertable-inspect-trigger",
254
- tooltip: "Explore this term",
255
- "aria-label": props["aria-label"] ?? `Explore ${entry.term}`,
256
- children: /* @__PURE__ */ jsx3(AppIcon2, {
257
- name: "openDetails"
258
- })
259
- });
260
- }
261
- // src/react/ui/GlossaryDefinition.tsx
262
- import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
263
- function GlossaryDefinition({
264
- entry,
265
- children
266
- }) {
267
- return /* @__PURE__ */ jsxs2(HelpPopover2, {
268
- trigger: children ?? entry.term,
269
- triggerLabel: `Explain ${entry.term}`,
270
- label: entry.term,
271
- triggerProps: {
272
- className: "altertable-glossary-definition-trigger",
273
- "data-atbl-control": "help"
274
- },
275
- panelProps: { className: "altertable-glossary-definition-popover" },
276
- children: [
277
- /* @__PURE__ */ jsx4("strong", {
278
- children: entry.term
279
- }),
280
- /* @__PURE__ */ jsx4("div", {
281
- children: entry.definition
282
- })
283
- ]
284
- });
285
- }
286
- // src/react/ui/TrendChart.tsx
287
- import { useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState3 } from "react";
288
- import {
289
- AreaChart as RechartsAreaChart,
290
- LineChart as RechartsLineChart,
291
- ReferenceLine
292
- } from "recharts";
293
-
294
- // src/react/ui/chart-date-axis.tsx
295
- import {
296
- createContext,
297
- useCallback,
298
- useContext,
299
- useEffect,
300
- useMemo,
301
- useState
302
- } from "react";
303
- import { XAxis, usePlotArea } from "recharts";
304
-
305
- // src/core/time-interval.ts
306
- /*!
307
- * TypeScript port of d3-time 3.1.0 (ISC), https://github.com/d3/d3-time/tree/v3.1.0
308
- * Numeric tick-step helpers adapted from d3-array 3.2.4 (ISC).
309
- *
310
- * Copyright 2010-2022 Mike Bostock (d3-time)
311
- * Copyright 2010-2023 Mike Bostock (d3-array tick-step helpers)
312
- *
313
- * Permission to use, copy, modify, and/or distribute this software for any purpose
314
- * with or without fee is hereby granted, provided that the above copyright notice
315
- * and this permission notice appear in all copies.
316
- *
317
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
318
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
319
- * FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
320
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
321
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
322
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
323
- * THIS SOFTWARE.
324
- */
325
- function timeInterval(floor, offset, count, field) {
326
- function interval(value) {
327
- const date = arguments.length === 0 ? new Date : new Date(+value);
328
- floor(date);
329
- return date;
330
- }
331
- interval.floor = (value) => {
332
- const date = new Date(+value);
333
- floor(date);
334
- return date;
335
- };
336
- interval.ceil = (value) => {
337
- const date = new Date(+value - 1);
338
- floor(date);
339
- offset(date, 1);
340
- floor(date);
341
- return date;
342
- };
343
- interval.round = (value) => {
344
- const before = interval(value);
345
- const after = interval.ceil(value);
346
- return +value - +before < +after - +value ? before : after;
347
- };
348
- interval.offset = (value, step) => {
349
- const date = new Date(+value);
350
- offset(date, step == null ? 1 : Math.floor(step));
351
- return date;
352
- };
353
- interval.range = (start, stop, step) => {
354
- const range = [];
355
- const date = interval.ceil(start);
356
- const stride = step == null ? 1 : Math.floor(step);
357
- if (!(+date < +stop) || !(stride > 0))
358
- return range;
359
- let previous;
360
- do {
361
- previous = new Date(+date);
362
- range.push(previous);
363
- offset(date, stride);
364
- floor(date);
365
- } while (+previous < +date && +date < +stop);
366
- return range;
367
- };
368
- interval.filter = (test) => timeInterval((date) => {
369
- if (!Number.isNaN(+date)) {
370
- floor(date);
371
- while (!test(date)) {
372
- date.setTime(+date - 1);
373
- floor(date);
374
- }
375
- }
376
- }, (date, step) => {
377
- if (!Number.isNaN(+date)) {
378
- const direction = step < 0 ? -1 : 1;
379
- for (let remaining = Math.abs(step);remaining > 0; --remaining) {
380
- do {
381
- offset(date, direction);
382
- } while (!test(date));
383
- }
384
- }
385
- });
386
- if (count) {
387
- interval.count = (start, end) => {
388
- countStart.setTime(+start);
389
- countEnd.setTime(+end);
390
- floor(countStart);
391
- floor(countEnd);
392
- return Math.floor(count(countStart, countEnd));
393
- };
394
- interval.every = (step) => {
395
- step = Math.floor(step);
396
- if (!Number.isFinite(step) || !(step > 0))
397
- return null;
398
- if (step === 1)
399
- return interval;
400
- return interval.filter(field ? (date) => field(date) % step === 0 : (date) => interval.count(0, date) % step === 0);
401
- };
402
- }
403
- return interval;
404
- }
405
- var countStart = new Date;
406
- var countEnd = new Date;
407
- var durationSecond = 1000;
408
- var durationMinute = durationSecond * 60;
409
- var durationHour = durationMinute * 60;
410
- var durationDay = durationHour * 24;
411
- var durationWeek = durationDay * 7;
412
- var durationMonth = durationDay * 30;
413
- var durationYear = durationDay * 365;
414
- var millisecond = timeInterval(() => {}, (date, step) => {
415
- date.setTime(+date + step);
416
- }, (start, end) => {
417
- return +end - +start;
418
- });
419
- millisecond.every = (k) => {
420
- k = Math.floor(k);
421
- if (!isFinite(k) || !(k > 0))
422
- return null;
423
- if (!(k > 1))
424
- return millisecond;
425
- return timeInterval((date) => {
426
- date.setTime(Math.floor(+date / k) * k);
427
- }, (date, step) => {
428
- date.setTime(+date + step * k);
429
- }, (start, end) => {
430
- return (+end - +start) / k;
431
- });
432
- };
433
- var milliseconds = millisecond.range;
434
- var second = timeInterval((date) => {
435
- date.setTime(+date - date.getMilliseconds());
436
- }, (date, step) => {
437
- date.setTime(+date + step * durationSecond);
438
- }, (start, end) => {
439
- return (+end - +start) / durationSecond;
440
- }, (date) => {
441
- return date.getUTCSeconds();
442
- });
443
- var seconds = second.range;
444
- var timeMinute = timeInterval((date) => {
445
- date.setTime(+date - date.getMilliseconds() - date.getSeconds() * durationSecond);
446
- }, (date, step) => {
447
- date.setTime(+date + step * durationMinute);
448
- }, (start, end) => {
449
- return (+end - +start) / durationMinute;
450
- }, (date) => {
451
- return date.getMinutes();
452
- });
453
- var timeMinutes = timeMinute.range;
454
- var utcMinute = timeInterval((date) => {
455
- date.setUTCSeconds(0, 0);
456
- }, (date, step) => {
457
- date.setTime(+date + step * durationMinute);
458
- }, (start, end) => {
459
- return (+end - +start) / durationMinute;
460
- }, (date) => {
461
- return date.getUTCMinutes();
462
- });
463
- var utcMinutes = utcMinute.range;
464
- var timeHour = timeInterval((date) => {
465
- date.setTime(+date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
466
- }, (date, step) => {
467
- date.setTime(+date + step * durationHour);
468
- }, (start, end) => {
469
- return (+end - +start) / durationHour;
470
- }, (date) => {
471
- return date.getHours();
472
- });
473
- var timeHours = timeHour.range;
474
- var utcHour = timeInterval((date) => {
475
- date.setUTCMinutes(0, 0, 0);
476
- }, (date, step) => {
477
- date.setTime(+date + step * durationHour);
478
- }, (start, end) => {
479
- return (+end - +start) / durationHour;
480
- }, (date) => {
481
- return date.getUTCHours();
482
- });
483
- var utcHours = utcHour.range;
484
- var timeDay = timeInterval((date) => date.setHours(0, 0, 0, 0), (date, step) => date.setDate(date.getDate() + step), (start, end) => (+end - +start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay, (date) => date.getDate() - 1);
485
- var timeDays = timeDay.range;
486
- var utcDay = timeInterval((date) => {
487
- date.setUTCHours(0, 0, 0, 0);
488
- }, (date, step) => {
489
- date.setUTCDate(date.getUTCDate() + step);
490
- }, (start, end) => {
491
- return (+end - +start) / durationDay;
492
- }, (date) => {
493
- return date.getUTCDate() - 1;
494
- });
495
- var utcDays = utcDay.range;
496
- var unixDay = timeInterval((date) => {
497
- date.setUTCHours(0, 0, 0, 0);
498
- }, (date, step) => {
499
- date.setUTCDate(date.getUTCDate() + step);
500
- }, (start, end) => {
501
- return (+end - +start) / durationDay;
502
- }, (date) => {
503
- return Math.floor(+date / durationDay);
504
- });
505
- var unixDays = unixDay.range;
506
- function timeWeekday(i) {
507
- return timeInterval((date) => {
508
- date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
509
- date.setHours(0, 0, 0, 0);
510
- }, (date, step) => {
511
- date.setDate(date.getDate() + step * 7);
512
- }, (start, end) => {
513
- return (+end - +start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
514
- });
515
- }
516
- var timeSunday = timeWeekday(0);
517
- var timeMonday = timeWeekday(1);
518
- var timeTuesday = timeWeekday(2);
519
- var timeWednesday = timeWeekday(3);
520
- var timeThursday = timeWeekday(4);
521
- var timeFriday = timeWeekday(5);
522
- var timeSaturday = timeWeekday(6);
523
- var timeSundays = timeSunday.range;
524
- var timeMondays = timeMonday.range;
525
- var timeTuesdays = timeTuesday.range;
526
- var timeWednesdays = timeWednesday.range;
527
- var timeThursdays = timeThursday.range;
528
- var timeFridays = timeFriday.range;
529
- var timeSaturdays = timeSaturday.range;
530
- function utcWeekday(i) {
531
- return timeInterval((date) => {
532
- date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
533
- date.setUTCHours(0, 0, 0, 0);
534
- }, (date, step) => {
535
- date.setUTCDate(date.getUTCDate() + step * 7);
536
- }, (start, end) => {
537
- return (+end - +start) / durationWeek;
538
- });
539
- }
540
- var utcSunday = utcWeekday(0);
541
- var utcMonday = utcWeekday(1);
542
- var utcTuesday = utcWeekday(2);
543
- var utcWednesday = utcWeekday(3);
544
- var utcThursday = utcWeekday(4);
545
- var utcFriday = utcWeekday(5);
546
- var utcSaturday = utcWeekday(6);
547
- var utcSundays = utcSunday.range;
548
- var utcMondays = utcMonday.range;
549
- var utcTuesdays = utcTuesday.range;
550
- var utcWednesdays = utcWednesday.range;
551
- var utcThursdays = utcThursday.range;
552
- var utcFridays = utcFriday.range;
553
- var utcSaturdays = utcSaturday.range;
554
- var timeMonth = timeInterval((date) => {
555
- date.setDate(1);
556
- date.setHours(0, 0, 0, 0);
557
- }, (date, step) => {
558
- date.setMonth(date.getMonth() + step);
559
- }, (start, end) => {
560
- return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
561
- }, (date) => {
562
- return date.getMonth();
563
- });
564
- var timeMonths = timeMonth.range;
565
- var utcMonth = timeInterval((date) => {
566
- date.setUTCDate(1);
567
- date.setUTCHours(0, 0, 0, 0);
568
- }, (date, step) => {
569
- date.setUTCMonth(date.getUTCMonth() + step);
570
- }, (start, end) => {
571
- return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
572
- }, (date) => {
573
- return date.getUTCMonth();
574
- });
575
- var utcMonths = utcMonth.range;
576
- var timeYear = timeInterval((date) => {
577
- date.setMonth(0, 1);
578
- date.setHours(0, 0, 0, 0);
579
- }, (date, step) => {
580
- date.setFullYear(date.getFullYear() + step);
581
- }, (start, end) => {
582
- return end.getFullYear() - start.getFullYear();
583
- }, (date) => {
584
- return date.getFullYear();
585
- });
586
- timeYear.every = (k) => {
587
- return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
588
- date.setFullYear(Math.floor(date.getFullYear() / k) * k);
589
- date.setMonth(0, 1);
590
- date.setHours(0, 0, 0, 0);
591
- }, (date, step) => {
592
- date.setFullYear(date.getFullYear() + step * k);
593
- });
594
- };
595
- var timeYears = timeYear.range;
596
- var utcYear = timeInterval((date) => {
597
- date.setUTCMonth(0, 1);
598
- date.setUTCHours(0, 0, 0, 0);
599
- }, (date, step) => {
600
- date.setUTCFullYear(date.getUTCFullYear() + step);
601
- }, (start, end) => {
602
- return end.getUTCFullYear() - start.getUTCFullYear();
603
- }, (date) => {
604
- return date.getUTCFullYear();
605
- });
606
- utcYear.every = (k) => {
607
- return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
608
- date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
609
- date.setUTCMonth(0, 1);
610
- date.setUTCHours(0, 0, 0, 0);
611
- }, (date, step) => {
612
- date.setUTCFullYear(date.getUTCFullYear() + step * k);
613
- });
614
- };
615
- var utcYears = utcYear.range;
616
- var e10 = Math.sqrt(50);
617
- var e5 = Math.sqrt(10);
618
- var e2 = Math.sqrt(2);
619
- function tickSpec(start, stop, count) {
620
- const step = (stop - start) / Math.max(0, count), power = Math.floor(Math.log10(step)), error = step / Math.pow(10, power), factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
621
- let i1, i2, inc;
622
- if (power < 0) {
623
- inc = Math.pow(10, -power) / factor;
624
- i1 = Math.round(start * inc);
625
- i2 = Math.round(stop * inc);
626
- if (i1 / inc < start)
627
- ++i1;
628
- if (i2 / inc > stop)
629
- --i2;
630
- inc = -inc;
631
- } else {
632
- inc = Math.pow(10, power) * factor;
633
- i1 = Math.round(start / inc);
634
- i2 = Math.round(stop / inc);
635
- if (i1 * inc < start)
636
- ++i1;
637
- if (i2 * inc > stop)
638
- --i2;
639
- }
640
- if (i2 < i1 && 0.5 <= count && count < 2)
641
- return tickSpec(start, stop, count * 2);
642
- return [i1, i2, inc];
643
- }
644
- function tickIncrement(start, stop, count) {
645
- return tickSpec(start, stop, count)[2];
646
- }
647
- function tickStep(start, stop, count) {
648
- const reverse = stop < start, inc = reverse ? tickIncrement(stop, start, count) : tickIncrement(start, stop, count);
649
- return (reverse ? -1 : 1) * (inc < 0 ? 1 / -inc : inc);
650
- }
651
- function ticker(year, month, week, day, hour, minute) {
652
- const tickIntervals = [
653
- [second, 1, durationSecond],
654
- [second, 5, 5 * durationSecond],
655
- [second, 15, 15 * durationSecond],
656
- [second, 30, 30 * durationSecond],
657
- [minute, 1, durationMinute],
658
- [minute, 5, 5 * durationMinute],
659
- [minute, 15, 15 * durationMinute],
660
- [minute, 30, 30 * durationMinute],
661
- [hour, 1, durationHour],
662
- [hour, 3, 3 * durationHour],
663
- [hour, 6, 6 * durationHour],
664
- [hour, 12, 12 * durationHour],
665
- [day, 1, durationDay],
666
- [day, 2, 2 * durationDay],
667
- [week, 1, durationWeek],
668
- [month, 1, durationMonth],
669
- [month, 3, 3 * durationMonth],
670
- [year, 1, durationYear]
671
- ];
672
- function ticks(start, stop, count) {
673
- const reverse = +stop < +start;
674
- if (reverse)
675
- [start, stop] = [stop, start];
676
- const interval = typeof count !== "number" ? count : tickInterval(start, stop, count);
677
- const ticks = interval ? interval.range(start, +stop + 1) : [];
678
- return reverse ? ticks.reverse() : ticks;
679
- }
680
- function tickInterval(start, stop, count) {
681
- const target = Math.abs(+stop - +start) / count;
682
- let low = 0;
683
- let high = tickIntervals.length;
684
- if (Number.isNaN(target))
685
- low = high;
686
- while (low < high) {
687
- const middle = low + high >>> 1;
688
- if (tickIntervals[middle][2] <= target)
689
- low = middle + 1;
690
- else
691
- high = middle;
692
- }
693
- const i = low;
694
- if (i === tickIntervals.length)
695
- return year.every(tickStep(+start / durationYear, +stop / durationYear, count));
696
- if (i === 0)
697
- return millisecond.every(Math.max(tickStep(+start, +stop, count), 1));
698
- const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
699
- return t.every(step);
700
- }
701
- return [ticks, tickInterval];
702
- }
703
- var [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute);
704
- var [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute);
705
-
706
- // src/react/ui/chart-time.ts
707
- var day = 86400000;
708
- function chartTimestamp(value, numeric = false) {
709
- if (typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value)) {
710
- return parseDateTime2(`${value}T00:00:00Z`)?.getTime() ?? null;
711
- }
712
- if (value instanceof Date || typeof value === "string" || numeric && typeof value === "number") {
713
- return parseDateTime2(value)?.getTime() ?? null;
714
- }
715
- return null;
716
- }
717
- function timeModel(values, numeric = false) {
718
- if (!values.length)
719
- return null;
720
- const parsed = values.map((value) => chartTimestamp(value, numeric));
721
- if (parsed.some((value) => value == null))
722
- return null;
723
- const times = [...new Set(parsed)].sort((a, b) => a - b);
724
- const start = times[0];
725
- const end = times.at(-1);
726
- const gaps = times.slice(1).map((value, index) => value - times[index]);
727
- const precision = gaps.reduce((minimum, gap) => Math.min(minimum, gap), day);
728
- const dateOnly = values.every((value) => typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value));
729
- const seconds = times.some((value) => value % 60000 !== 0) || precision < 60000;
730
- const milliseconds = times.some((value) => value % 1000 !== 0) || precision < 1000;
731
- function tooltip(value) {
732
- const time = chartTimestamp(value, true);
733
- if (time == null)
734
- return typeof value === "string" || typeof value === "number" ? String(value) : "";
735
- if (dateOnly)
736
- return formatDate2(new Date(time).toISOString().slice(0, 10));
737
- if (milliseconds) {
738
- return new Intl.DateTimeFormat("en-US", {
739
- timeZone: "UTC",
740
- year: "numeric",
741
- month: "short",
742
- day: "numeric",
743
- hour: "2-digit",
744
- minute: "2-digit",
745
- second: "2-digit",
746
- fractionalSecondDigits: 3,
747
- hourCycle: "h23"
748
- }).format(time);
749
- }
750
- return formatDateTime2(time, {
751
- precision: seconds ? "second" : "minute",
752
- timeZone: "UTC"
753
- });
754
- }
755
- return {
756
- start,
757
- end,
758
- times,
759
- precision: gaps.length ? gaps.reduce((minimum, gap) => Math.min(minimum, gap), Infinity) : day,
760
- tooltip
761
- };
762
- }
763
- function datePart(value, options) {
764
- return new Intl.DateTimeFormat("en-US", {
765
- ...options,
766
- timeZone: "UTC"
767
- }).format(value);
768
- }
769
- function timeTicks2(model, width) {
770
- const { start, end } = model;
771
- const firstDate = new Date(start);
772
- const lastDate = new Date(end);
773
- const spansYears = firstDate.getUTCFullYear() !== lastDate.getUTCFullYear();
774
- const spansDates = firstDate.toISOString().slice(0, 10) !== lastDate.toISOString().slice(0, 10);
775
- const count = Math.max(2, Math.min(12, Math.floor(width / 80), model.times.length));
776
- let ticks = start === end ? [start] : utcTicks(new Date(start), new Date(end), Math.min(count, (end - start) / model.precision)).map(Number);
777
- const step = ticks.length > 1 ? ticks[1] - ticks[0] : Math.max(end - start, model.precision);
778
- const candidates = [...new Set([start, ...ticks, end])].sort((a, b) => a - b);
779
- ticks = [start];
780
- const gap = step < 1000 ? 110 : 80;
781
- for (const value of candidates.slice(1)) {
782
- if ((value - ticks.at(-1)) / (end - start) * width >= gap)
783
- ticks.push(value);
784
- }
785
- if (end !== start && ticks.at(-1) !== end) {
786
- if (ticks.length > 1 && (end - ticks.at(-1)) / (end - start) * width < gap)
787
- ticks.pop();
788
- ticks.push(end);
789
- }
790
- function label(value, index) {
791
- const previous = index > 0 ? new Date(ticks[index - 1]) : undefined;
792
- const date = new Date(value);
793
- const yearChanged = !previous || previous.getUTCFullYear() !== date.getUTCFullYear();
794
- const dateChanged = !previous || previous.toISOString().slice(0, 10) !== date.toISOString().slice(0, 10);
795
- if (step >= 300 * day)
796
- return { main: String(date.getUTCFullYear()), context: "" };
797
- if (step >= 28 * day && (model.precision >= 28 * day || end - start >= 180 * day))
798
- return {
799
- main: datePart(value, { month: "short" }),
800
- context: spansYears && yearChanged ? String(date.getUTCFullYear()) : ""
801
- };
802
- if (step >= day && !(model.precision < day && end - start <= 3 * day))
803
- return {
804
- main: datePart(value, { month: "short", day: "numeric" }),
805
- context: spansYears && yearChanged ? String(date.getUTCFullYear()) : ""
806
- };
807
- return {
808
- main: datePart(value, {
809
- hour: "2-digit",
810
- minute: "2-digit",
811
- ...step < 60000 ? { second: "2-digit" } : {},
812
- ...step < 1000 ? { fractionalSecondDigits: 3 } : {},
813
- hourCycle: "h23"
814
- }),
815
- context: spansDates && dateChanged ? datePart(value, {
816
- month: "short",
817
- day: "numeric",
818
- ...spansYears && yearChanged ? { year: "numeric" } : {}
819
- }) : ""
820
- };
821
- }
822
- return { ticks, label };
823
- }
824
-
825
- // src/react/ui/chart-date-axis.tsx
826
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
827
- var DateAxes = createContext(null);
828
- function ChartDateAxes({
829
- data,
830
- children
831
- }) {
832
- const [formatters, setFormatters] = useState(() => new Map);
833
- const register = useCallback((id, formatter) => {
834
- setFormatters((current) => new Map(current).set(id, formatter));
835
- return () => setFormatters((current) => {
836
- const next = new Map(current);
837
- next.delete(id);
838
- return next;
839
- });
840
- }, []);
841
- return /* @__PURE__ */ jsx5(DateAxes.Provider, {
842
- value: { data, formatters, register },
843
- children
844
- });
845
- }
846
- function useDateAxisLabel(id = 0) {
847
- return useContext(DateAxes)?.formatters.get(id);
848
- }
849
- function field(row, key) {
850
- if (row == null || typeof row !== "object")
851
- return;
852
- if (key in row)
853
- return row[key];
854
- return String(key).replace(/\[(\d+)\]/g, ".$1").split(".").reduce((value, part) => value != null && typeof value === "object" ? value[part] : undefined, row);
855
- }
856
- function ChartXAxis(props) {
857
- const context = useContext(DateAxes);
858
- const plot = usePlotArea();
859
- const data = context?.data;
860
- const dataKey = props.dataKey;
861
- const numeric = props.scale === "utc";
862
- const enabled = numeric || props.type == null && props.scale == null && props.tickFormatter == null && props.ticks == null;
863
- const model = useMemo(() => {
864
- if (!enabled || !data?.length || dataKey == null)
865
- return null;
866
- return timeModel(data.map((row) => typeof dataKey === "function" ? dataKey(row) : field(row, dataKey)), numeric);
867
- }, [data, dataKey, enabled, numeric]);
868
- const register = context?.register;
869
- const id = props.xAxisId ?? 0;
870
- useEffect(() => model ? register?.(id, model.tooltip) : undefined, [register, id, model]);
871
- const axis = model ? timeTicks2(model, plot?.width ?? 400) : undefined;
872
- return /* @__PURE__ */ jsx5(XAxis, {
873
- stroke: "var(--atbl-muted)",
874
- tickFormatter: (value) => typeof value === "number" ? formatNumber2(value) : String(value),
875
- tickLine: false,
876
- axisLine: { stroke: "var(--atbl-border)" },
877
- tick: { fontSize: "var(--atbl-type-meta-size)" },
878
- ...model && axis ? {
879
- type: "number",
880
- scale: "utc",
881
- domain: model.start === model.end ? [
882
- model.start - model.precision / 2,
883
- model.end + model.precision / 2
884
- ] : [model.start, model.end],
885
- ticks: axis.ticks,
886
- interval: 0,
887
- height: 48,
888
- tick: ({ x, y, payload, index }) => {
889
- const label = axis.label(Number(payload.value), index);
890
- return /* @__PURE__ */ jsxs3("text", {
891
- x,
892
- y: Number(y) + 5,
893
- fill: "var(--atbl-muted)",
894
- fontSize: "var(--atbl-type-meta-size)",
895
- textAnchor: index === 0 ? "start" : index === axis.ticks.length - 1 ? "end" : "middle",
896
- children: [
897
- /* @__PURE__ */ jsx5("tspan", {
898
- x,
899
- dy: "0.8em",
900
- children: label.main
901
- }),
902
- label.context && /* @__PURE__ */ jsx5("tspan", {
903
- x,
904
- dy: "1.4em",
905
- children: label.context
906
- })
907
- ]
908
- });
909
- }
910
- } : {},
911
- ...props,
912
- ...model ? {
913
- type: "number",
914
- dataKey: (row) => chartTimestamp(typeof dataKey === "function" ? dataKey(row) : field(row, dataKey), numeric)
915
- } : {}
916
- });
917
- }
918
-
919
- // src/react/ui/chart-primitives.tsx
920
- import { useContext as useContext3, useLayoutEffect } from "react";
921
-
922
- // src/react/ui/chart-interaction.tsx
923
- import {
924
- createContext as createContext2,
925
- useContext as useContext2,
926
- useId,
927
- useEffect as useEffect2
928
- } from "react";
929
- import { jsx as jsx6 } from "react/jsx-runtime";
930
- var ChartInteraction = createContext2(null);
931
- function useChartSeries(id) {
932
- const generatedId = useId();
933
- const interaction = useContext2(ChartInteraction);
934
- const seriesId = id ?? generatedId;
935
- const registerSeries = interaction?.registerSeries;
936
- useEffect2(() => registerSeries?.(seriesId), [registerSeries, seriesId]);
937
- return {
938
- id: seriesId,
939
- active: !interaction?.pointer || interaction.seriesCount === 1 || interaction.hovered === seriesId
940
- };
941
- }
942
- function ChartSeries({
943
- id,
944
- children
945
- }) {
946
- const interaction = useContext2(ChartInteraction);
947
- return /* @__PURE__ */ jsx6("g", {
948
- onPointerOver: () => interaction?.setHovered(id),
949
- onPointerDown: () => interaction?.setHovered(id),
950
- children
951
- });
952
- }
953
-
954
- // src/react/ui/chart-primitives.tsx
955
- import {
956
- Area,
957
- Dot,
958
- Bar,
959
- Line,
960
- Scatter,
961
- YAxis,
962
- CartesianGrid,
963
- Tooltip,
964
- DefaultTooltipContent
965
- } from "recharts";
966
-
967
- // src/react/ui/ChartLegend.tsx
968
- import {
969
- Children,
970
- useId as useId2,
971
- useEffect as useEffect3,
972
- useRef,
973
- useState as useState2
974
- } from "react";
975
- import { jsx as jsx7, jsxs as jsxs4, Fragment } from "react/jsx-runtime";
976
- function ChartLegendRoot({
977
- children,
978
- layout = "horizontal",
979
- align = "start",
980
- maxVisibleItems,
981
- className,
982
- "aria-label": ariaLabel = "Chart legend",
983
- ...props
984
- }) {
985
- const [expanded, setExpanded] = useState2(false);
986
- const listId = useId2();
987
- const containerRef = useRef(null);
988
- const [columns, setColumns] = useState2(2);
989
- useEffect3(() => {
990
- const container = containerRef.current;
991
- if (!container)
992
- return;
993
- function measure() {
994
- const list = containerRef.current?.firstElementChild;
995
- if (list) {
996
- setColumns(getComputedStyle(list).gridTemplateColumns.split(" ").length);
997
- }
998
- }
999
- const observer = new ResizeObserver(measure);
1000
- observer.observe(container);
1001
- measure();
1002
- return () => observer.disconnect();
1003
- }, [layout]);
1004
- const items = Children.toArray(children);
1005
- const rowCapacity = layout === "vertical" ? 6 : columns * (layout === "single-row" ? 1 : 2);
1006
- const configuredLimit = typeof maxVisibleItems === "number" && Number.isFinite(maxVisibleItems) ? Math.max(1, Math.floor(maxVisibleItems)) : rowCapacity;
1007
- const cappedLimit = Math.min(configuredLimit, rowCapacity);
1008
- const limit = layout === "vertical" ? configuredLimit : cappedLimit >= columns ? Math.floor(cappedLimit / columns) * columns : cappedLimit;
1009
- const visibleCount = items.length > limit ? limit - 1 : limit;
1010
- const hiddenCount = Math.max(0, items.length - visibleCount);
1011
- return /* @__PURE__ */ jsx7("div", {
1012
- ref: containerRef,
1013
- className: "altertable-chart-legend-container",
1014
- children: /* @__PURE__ */ jsxs4("ul", {
1015
- id: listId,
1016
- ...props,
1017
- "aria-label": ariaLabel,
1018
- "data-layout": layout,
1019
- "data-align": align,
1020
- className: classNames("altertable-chart-legend", className),
1021
- children: [
1022
- expanded ? items : items.slice(0, visibleCount),
1023
- hiddenCount > 0 && /* @__PURE__ */ jsx7("li", {
1024
- className: "altertable-chart-legend-overflow",
1025
- children: /* @__PURE__ */ jsx7("button", {
1026
- type: "button",
1027
- "data-atbl-control": "action",
1028
- "data-atbl-focus": "ring",
1029
- className: "altertable-chart-legend-action",
1030
- "aria-expanded": expanded,
1031
- "aria-controls": props.id ?? listId,
1032
- onClick: () => setExpanded((value) => !value),
1033
- children: expanded ? "Show fewer" : `+${hiddenCount} more`
1034
- })
1035
- })
1036
- ]
1037
- })
1038
- });
1039
- }
1040
- function ChartLegendItem({
1041
- inactive,
1042
- className,
1043
- ...props
1044
- }) {
1045
- return /* @__PURE__ */ jsx7("li", {
1046
- ...props,
1047
- "data-inactive": inactive || undefined,
1048
- className: classNames("altertable-chart-legend-item", className)
1049
- });
1050
- }
1051
- function ChartLegendMarker({
1052
- kind,
1053
- color = kind === "bar" ? chartBarFill : "var(--atbl-chart-1)",
1054
- className,
1055
- style,
1056
- ...props
1057
- }) {
1058
- return /* @__PURE__ */ jsxs4("svg", {
1059
- ...props,
1060
- "aria-hidden": "true",
1061
- focusable: "false",
1062
- viewBox: kind === "square" ? "0 0 8 8" : "0 0 20 12",
1063
- "data-kind": kind,
1064
- className: classNames("altertable-chart-legend-marker", className),
1065
- style: { color, ...style },
1066
- children: [
1067
- kind === "square" && /* @__PURE__ */ jsx7("rect", {
1068
- width: "8",
1069
- height: "8",
1070
- fill: "currentColor"
1071
- }),
1072
- kind === "bar" && /* @__PURE__ */ jsx7("path", {
1073
- d: "M6 11V3Q6 1 8 1H12Q14 1 14 3V11Z",
1074
- fill: "currentColor"
1075
- }),
1076
- kind === "slice" && /* @__PURE__ */ jsx7("rect", {
1077
- x: "5",
1078
- y: "1",
1079
- width: "10",
1080
- height: "10",
1081
- rx: "2",
1082
- fill: "currentColor"
1083
- }),
1084
- kind === "point" && /* @__PURE__ */ jsx7("circle", {
1085
- cx: "10",
1086
- cy: "6",
1087
- r: "3",
1088
- fill: "currentColor"
1089
- }),
1090
- kind === "line" && /* @__PURE__ */ jsxs4(Fragment, {
1091
- children: [
1092
- /* @__PURE__ */ jsx7("path", {
1093
- d: "M1 6H19",
1094
- fill: "none",
1095
- stroke: "currentColor",
1096
- strokeWidth: "2",
1097
- strokeLinecap: "round"
1098
- }),
1099
- /* @__PURE__ */ jsx7("circle", {
1100
- cx: "10",
1101
- cy: "6",
1102
- r: "2.5",
1103
- fill: "var(--atbl-surface)",
1104
- stroke: "currentColor",
1105
- strokeWidth: "2"
1106
- })
1107
- ]
1108
- }),
1109
- kind === "area" && /* @__PURE__ */ jsxs4(Fragment, {
1110
- children: [
1111
- /* @__PURE__ */ jsx7("path", {
1112
- d: "M1 10L7 5L13 7L19 2V11H1Z",
1113
- fill: "currentColor",
1114
- fillOpacity: "0.14"
1115
- }),
1116
- /* @__PURE__ */ jsx7("path", {
1117
- d: "M1 10L7 5L13 7L19 2",
1118
- fill: "none",
1119
- stroke: "currentColor",
1120
- strokeWidth: "2",
1121
- strokeLinejoin: "round",
1122
- strokeLinecap: "round"
1123
- })
1124
- ]
1125
- })
1126
- ]
1127
- });
1128
- }
1129
- function ChartLegendLabel({
1130
- className,
1131
- children,
1132
- title,
1133
- ...props
1134
- }) {
1135
- return /* @__PURE__ */ jsx7("span", {
1136
- ...props,
1137
- title: title ?? (typeof children === "string" ? children : undefined),
1138
- className: classNames("altertable-chart-legend-label", className),
1139
- children
1140
- });
1141
- }
1142
- var ChartLegend = Object.assign(ChartLegendRoot, {
1143
- Item: ChartLegendItem,
1144
- Marker: ChartLegendMarker,
1145
- Label: ChartLegendLabel
1146
- });
1147
-
1148
- // src/react/ui/chart-primitives.tsx
1149
- import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
1150
- var seriesColor = "var(--atbl-chart-1)";
1151
- function ChartDot({
1152
- active = false,
1153
- stroke = seriesColor,
1154
- fill = active ? stroke : "var(--atbl-surface)",
1155
- r = active ? 4.5 : 3,
1156
- ...props
1157
- }) {
1158
- return /* @__PURE__ */ jsx8(Dot, {
1159
- stroke,
1160
- fill,
1161
- r,
1162
- strokeWidth: 2,
1163
- ...props
1164
- });
1165
- }
1166
- function NearestChartDot({
1167
- seriesId,
1168
- cx,
1169
- cy,
1170
- stroke
1171
- }) {
1172
- const interaction = useContext3(ChartInteraction);
1173
- const registerPoint = interaction?.registerPoint;
1174
- useLayoutEffect(() => {
1175
- if (cx == null || cy == null)
1176
- return;
1177
- return registerPoint?.(seriesId, cx, cy);
1178
- }, [registerPoint, seriesId, cx, cy]);
1179
- const active = !interaction?.pointer || interaction.seriesCount === 1 || interaction.hovered === seriesId;
1180
- return active ? /* @__PURE__ */ jsx8(ChartDot, {
1181
- cx,
1182
- cy,
1183
- stroke,
1184
- active: true,
1185
- style: { pointerEvents: "none" }
1186
- }) : null;
1187
- }
1188
- function ChartBar(props) {
1189
- const series = useChartSeries(props.id);
1190
- return /* @__PURE__ */ jsx8(ChartSeries, {
1191
- id: series.id,
1192
- children: /* @__PURE__ */ jsx8(Bar, {
1193
- fill: chartBarFill,
1194
- radius: props.stackId == null ? [5, 5, 0, 0] : 0,
1195
- maxBarSize: 30,
1196
- activeBar: series.active ? { opacity: 0.75 } : false,
1197
- isAnimationActive: false,
1198
- ...props,
1199
- id: series.id
1200
- })
1201
- });
1202
- }
1203
- function ChartLine({
1204
- stroke = seriesColor,
1205
- dot = false,
1206
- activeDot,
1207
- ...props
1208
- }) {
1209
- const series = useChartSeries(props.id);
1210
- return /* @__PURE__ */ jsx8(ChartSeries, {
1211
- id: series.id,
1212
- children: /* @__PURE__ */ jsx8(Line, {
1213
- type: "linear",
1214
- stroke,
1215
- strokeWidth: 2,
1216
- strokeLinecap: "round",
1217
- strokeLinejoin: "round",
1218
- dot: dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx8(ChartDot, {
1219
- cx,
1220
- cy,
1221
- stroke
1222
- }) : dot,
1223
- activeDot: activeDot === undefined || activeDot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx8(NearestChartDot, {
1224
- seriesId: series.id,
1225
- cx,
1226
- cy,
1227
- stroke
1228
- }) : activeDot,
1229
- isAnimationActive: false,
1230
- ...props,
1231
- id: series.id
1232
- })
1233
- });
1234
- }
1235
- function ChartArea({
1236
- stroke = seriesColor,
1237
- dot = false,
1238
- activeDot,
1239
- ...props
1240
- }) {
1241
- const series = useChartSeries(props.id);
1242
- return /* @__PURE__ */ jsx8(ChartSeries, {
1243
- id: series.id,
1244
- children: /* @__PURE__ */ jsx8(Area, {
1245
- legendType: "square",
1246
- type: "linear",
1247
- stroke,
1248
- strokeWidth: 2,
1249
- strokeLinecap: "round",
1250
- strokeLinejoin: "round",
1251
- fill: stroke,
1252
- fillOpacity: 0.14,
1253
- dot: dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx8(ChartDot, {
1254
- cx,
1255
- cy,
1256
- stroke
1257
- }) : dot,
1258
- activeDot: activeDot === undefined || activeDot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx8(NearestChartDot, {
1259
- seriesId: series.id,
1260
- cx,
1261
- cy,
1262
- stroke
1263
- }) : activeDot,
1264
- isAnimationActive: false,
1265
- ...props,
1266
- id: series.id
1267
- })
1268
- });
1269
- }
1270
- function ChartScatter(props) {
1271
- const series = useChartSeries(props.id);
1272
- return /* @__PURE__ */ jsx8(ChartSeries, {
1273
- id: series.id,
1274
- children: /* @__PURE__ */ jsx8(Scatter, {
1275
- fill: seriesColor,
1276
- isAnimationActive: false,
1277
- ...props,
1278
- id: series.id
1279
- })
1280
- });
1281
- }
1282
- function ChartYAxis(props) {
1283
- return /* @__PURE__ */ jsx8(YAxis, {
1284
- stroke: "var(--atbl-muted)",
1285
- tickFormatter: (value) => typeof value === "number" ? formatNumber2(value) : String(value),
1286
- tickLine: false,
1287
- axisLine: false,
1288
- tick: { fontSize: "var(--atbl-type-meta-size)" },
1289
- ...props
1290
- });
1291
- }
1292
- function ChartGrid(props) {
1293
- return /* @__PURE__ */ jsx8(CartesianGrid, {
1294
- stroke: "var(--atbl-border)",
1295
- vertical: false,
1296
- ...props
1297
- });
1298
- }
1299
- function ChartTooltipContent(props) {
1300
- if (!props.active || !props.payload?.length)
1301
- return null;
1302
- return /* @__PURE__ */ jsx8(TooltipSurface, {
1303
- "data-variant": "chart",
1304
- role: "tooltip",
1305
- children: /* @__PURE__ */ jsx8(DefaultTooltipContent, {
1306
- ...props,
1307
- separator: "",
1308
- payload: props.payload?.map((entry) => ({
1309
- ...entry,
1310
- unit: undefined,
1311
- formatter: (value, name, _item, index, payload) => {
1312
- const formatter = entry.formatter ?? props.formatter;
1313
- const formatted = formatter ? formatter(value, name, entry, index, props.payload ?? payload) : Array.isArray(value) ? value.map((item) => typeof item === "number" ? formatNumber2(item) : item).join(" ~ ") : typeof value === "number" ? formatNumber2(value) : value;
1314
- if (formatted == null)
1315
- return null;
1316
- const [displayValue, displayName] = Array.isArray(formatted) ? formatted : [formatted, name];
1317
- return [
1318
- /* @__PURE__ */ jsxs5("span", {
1319
- className: "altertable-chart-tooltip-row",
1320
- children: [
1321
- /* @__PURE__ */ jsx8(ChartLegend.Marker, {
1322
- kind: "square",
1323
- className: "altertable-chart-tooltip-marker",
1324
- color: entry.color ?? entry.stroke ?? entry.fill ?? "var(--atbl-chart-1)"
1325
- }),
1326
- /* @__PURE__ */ jsxs5("span", {
1327
- className: "altertable-chart-tooltip-reading",
1328
- children: [
1329
- displayName,
1330
- displayName !== undefined && displayName !== "" ? props.separator ?? " : " : "",
1331
- displayValue,
1332
- entry.unit
1333
- ]
1334
- })
1335
- ]
1336
- }, entry.graphicalItemId),
1337
- ""
1338
- ];
1339
- }
1340
- })),
1341
- contentStyle: {
1342
- margin: 0,
1343
- padding: 0,
1344
- background: "transparent",
1345
- border: 0,
1346
- whiteSpace: "normal",
1347
- ...props.contentStyle
1348
- },
1349
- labelStyle: {
1350
- color: "var(--atbl-text)",
1351
- fontSize: "var(--atbl-type-body-size)",
1352
- fontWeight: 650,
1353
- lineHeight: 1.2,
1354
- ...props.labelStyle
1355
- },
1356
- itemStyle: {
1357
- color: "var(--atbl-text)",
1358
- paddingTop: 2,
1359
- paddingBottom: 0,
1360
- ...props.itemStyle
1361
- }
1362
- })
1363
- });
1364
- }
1365
- function ChartTooltip(props) {
1366
- const dateLabel = useDateAxisLabel(props.axisId);
1367
- const interaction = useContext3(ChartInteraction);
1368
- return /* @__PURE__ */ jsx8(Tooltip, {
1369
- labelFormatter: dateLabel,
1370
- content: (content) => /* @__PURE__ */ jsx8(ChartTooltipContent, {
1371
- ...content,
1372
- payload: interaction?.pointer && interaction.seriesCount !== 1 && props.shared !== true ? content.payload.filter((entry) => entry.graphicalItemId === interaction.hovered) : content.payload
1373
- }),
1374
- position: interaction?.pointer && interaction.point ? { y: interaction.point.y } : undefined,
1375
- cursor: false,
1376
- isAnimationActive: false,
1377
- ...props
1378
- });
1379
- }
1380
-
1381
- // src/react/ui/chart-data.ts
1382
- function validateChartItems(kind, items) {
1383
- const ids = new Set;
1384
- for (const item of items) {
1385
- invariant(item.id.trim().length > 0, `${kind} chart IDs must be nonempty and unique: blank ID.`);
1386
- invariant(!ids.has(item.id), `${kind} chart IDs must be nonempty and unique: duplicate "${item.id}".`);
1387
- ids.add(item.id);
1388
- if (kind === "scatter") {
1389
- const point = item;
1390
- invariant(Number.isFinite(point.x) && Number.isFinite(point.y), `scatter chart "${item.id}" requires finite values for x and y.`);
1391
- } else {
1392
- const point = item;
1393
- invariant(Number.isFinite(point.value), `${kind} chart "${item.id}" requires finite values.`);
1394
- invariant(kind !== "bar" && kind !== "pie" || point.value >= 0, `${kind} chart "${item.id}" requires nonnegative values.`);
1395
- }
1396
- }
1397
- }
1398
-
1399
- // src/react/ui/TrendChart.tsx
1400
- import { jsx as jsx9, jsxs as jsxs6, Fragment as Fragment2 } from "react/jsx-runtime";
1401
- function TrendChart({
1402
- items,
1403
- unit,
1404
- ariaLabel,
1405
- formatValue = formatNumber2,
1406
- area = false
1407
- }) {
1408
- validateChartItems(area ? "area" : "line", items);
1409
- const Plot = area ? RechartsAreaChart : RechartsLineChart;
1410
- const [activeIndex, setActiveIndex] = useState3();
1411
- const scrollport = useRef2(null);
1412
- useLayoutEffect2(() => {
1413
- const element = scrollport.current;
1414
- if (element)
1415
- element.scrollLeft = element.scrollWidth - element.clientWidth;
1416
- }, [items]);
1417
- const magnitude = items.reduce((max, item) => Math.max(max, Math.abs(item.value)), 1);
1418
- const low = items.reduce((min, item) => Math.min(min, item.value / magnitude), 0);
1419
- const high = items.reduce((max, item) => Math.max(max, item.value / magnitude), 0);
1420
- return /* @__PURE__ */ jsxs6("section", {
1421
- className: "altertable-trend-chart",
1422
- "aria-label": ariaLabel,
1423
- children: [
1424
- items.length === 0 && /* @__PURE__ */ jsx9("span", {
1425
- children: "No data"
1426
- }),
1427
- items.length > 0 && /* @__PURE__ */ jsx9(Fragment2, {
1428
- children: /* @__PURE__ */ jsx9("div", {
1429
- className: "altertable-trend-scroll",
1430
- ref: scrollport,
1431
- children: /* @__PURE__ */ jsxs6("div", {
1432
- className: "altertable-trend-plot",
1433
- style: { minWidth: items.length * 40 },
1434
- children: [
1435
- /* @__PURE__ */ jsx9("div", {
1436
- className: "altertable-chart-canvas",
1437
- "aria-hidden": "true",
1438
- children: /* @__PURE__ */ jsxs6(Plot, {
1439
- data: items.map((item) => ({
1440
- ...item,
1441
- plotValue: item.value / magnitude
1442
- })),
1443
- responsive: true,
1444
- width: "100%",
1445
- height: 220,
1446
- margin: { top: 12, right: 0, bottom: 12, left: 0 },
1447
- accessibilityLayer: false,
1448
- tabIndex: -1,
1449
- children: [
1450
- /* @__PURE__ */ jsx9(ChartXAxis, {
1451
- hide: true,
1452
- dataKey: "id",
1453
- scale: "band"
1454
- }),
1455
- /* @__PURE__ */ jsx9(ChartYAxis, {
1456
- hide: true,
1457
- domain: [low, high === low ? low + 1 : high]
1458
- }),
1459
- /* @__PURE__ */ jsx9(ReferenceLine, {
1460
- y: 0,
1461
- stroke: "var(--atbl-border)"
1462
- }),
1463
- area && /* @__PURE__ */ jsx9(ChartArea, {
1464
- dataKey: "plotValue",
1465
- stroke: "none",
1466
- fill: "var(--atbl-chart-1)",
1467
- dot: false,
1468
- activeDot: false
1469
- }),
1470
- /* @__PURE__ */ jsx9(ChartLine, {
1471
- dataKey: "plotValue",
1472
- dot: ({ cx, cy, index }) => index === activeIndex ? /* @__PURE__ */ jsx9(ChartDot, {
1473
- cx,
1474
- cy,
1475
- active: index === activeIndex
1476
- }) : /* @__PURE__ */ jsx9("g", {}),
1477
- activeDot: false
1478
- })
1479
- ]
1480
- })
1481
- }),
1482
- /* @__PURE__ */ jsx9("div", {
1483
- className: "altertable-trend-points",
1484
- children: items.map((item, index) => /* @__PURE__ */ jsx9(Tooltip2, {
1485
- variant: "chart",
1486
- onOpenChange: (open) => setActiveIndex((current) => open ? index : current === index ? undefined : current),
1487
- content: /* @__PURE__ */ jsxs6(Fragment2, {
1488
- children: [
1489
- /* @__PURE__ */ jsx9("strong", {
1490
- children: item.label
1491
- }),
1492
- /* @__PURE__ */ jsxs6("span", {
1493
- children: [
1494
- formatValue(item.value),
1495
- " ",
1496
- unit
1497
- ]
1498
- })
1499
- ]
1500
- }),
1501
- className: "altertable-chart-column",
1502
- children: /* @__PURE__ */ jsxs6("button", {
1503
- "data-atbl-focus": "ring",
1504
- "data-atbl-control": "default",
1505
- type: "button",
1506
- tabIndex: -1,
1507
- className: "altertable-trend-point",
1508
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
1509
- children: [
1510
- /* @__PURE__ */ jsx9("span", {
1511
- className: "altertable-trend-hit"
1512
- }),
1513
- /* @__PURE__ */ jsx9("span", {
1514
- className: "altertable-trend-label",
1515
- children: item.label
1516
- })
1517
- ]
1518
- })
1519
- }, item.id))
1520
- })
1521
- ]
1522
- })
1523
- })
1524
- })
1525
- ]
1526
- });
1527
- }
1528
-
1529
- // src/react/ui/LineChart.tsx
1530
- import { jsx as jsx10 } from "react/jsx-runtime";
1531
- function LineChart(props) {
1532
- return /* @__PURE__ */ jsx10(TrendChart, {
1533
- ...props
1534
- });
1535
- }
1536
- // src/react/ui/AreaChart.tsx
1537
- import { jsx as jsx11 } from "react/jsx-runtime";
1538
- function AreaChart(props) {
1539
- return /* @__PURE__ */ jsx11(TrendChart, {
1540
- ...props,
1541
- area: true
1542
- });
1543
- }
1544
- // src/react/ui/PieChart.tsx
1545
- import { useState as useState4 } from "react";
1546
- import { jsx as jsx12, jsxs as jsxs7, Fragment as Fragment3 } from "react/jsx-runtime";
1547
- function PieChart({
1548
- items,
1549
- unit,
1550
- ariaLabel,
1551
- showLegend = true,
1552
- formatValue = (value) => new Intl.NumberFormat().format(value)
1553
- }) {
1554
- validateChartItems("pie", items);
1555
- const [previewId, setPreviewId] = useState4(null);
1556
- const [plotOpen, setPlotOpen] = useState4(false);
1557
- const [legendId, setLegendId] = useState4(null);
1558
- const maximum = items.reduce((max, item) => Math.max(max, item.value), 0);
1559
- const total = maximum ? items.reduce((sum, item) => sum + item.value / maximum, 0) : 0;
1560
- let cursor = -Math.PI / 2;
1561
- const slices = [];
1562
- for (const [index, item] of items.entries()) {
1563
- let point = function(angle) {
1564
- return `${110 + Math.cos(angle) * 100},${110 + Math.sin(angle) * 100}`;
1565
- };
1566
- const share = total ? item.value / maximum / total : 0;
1567
- const start = cursor;
1568
- cursor += share * Math.PI * 2;
1569
- const middle = (start + cursor) / 2;
1570
- slices.push({
1571
- ...item,
1572
- share,
1573
- color: `var(--atbl-chart-${index % 8 + 1})`,
1574
- path: `${share === 1 ? "M" : "M110,110 L"}${point(start)} A100,100 0 0 1 ${point(middle)} A100,100 0 0 1 ${point(cursor)} Z`
1575
- });
1576
- }
1577
- function percent(share) {
1578
- return new Intl.NumberFormat("en-US", {
1579
- style: "percent",
1580
- maximumFractionDigits: 1
1581
- }).format(share);
1582
- }
1583
- function detail(item) {
1584
- return /* @__PURE__ */ jsxs7(Fragment3, {
1585
- children: [
1586
- /* @__PURE__ */ jsx12("strong", {
1587
- children: item.label
1588
- }),
1589
- /* @__PURE__ */ jsxs7("span", {
1590
- children: [
1591
- formatValue(item.value),
1592
- " ",
1593
- unit,
1594
- " · ",
1595
- percent(item.share)
1596
- ]
1597
- })
1598
- ]
1599
- });
1600
- }
1601
- const preview = slices.find((item) => item.id === previewId);
1602
- return /* @__PURE__ */ jsxs7("section", {
1603
- className: "altertable-pie-chart",
1604
- "aria-label": ariaLabel,
1605
- children: [
1606
- items.length === 0 && /* @__PURE__ */ jsx12("span", {
1607
- children: "No data"
1608
- }),
1609
- items.length > 0 && /* @__PURE__ */ jsxs7(Fragment3, {
1610
- children: [
1611
- /* @__PURE__ */ jsxs7("div", {
1612
- className: "altertable-pie-plot",
1613
- children: [
1614
- /* @__PURE__ */ jsx12(Tooltip2, {
1615
- variant: "chart",
1616
- className: "altertable-pie-tooltip",
1617
- onOpenChange: setPlotOpen,
1618
- content: preview ? detail(preview) : null,
1619
- children: /* @__PURE__ */ jsx12("svg", {
1620
- viewBox: "0 0 220 220",
1621
- "aria-hidden": "true",
1622
- focusable: "false",
1623
- children: total === 0 ? /* @__PURE__ */ jsx12("circle", {
1624
- cx: "110",
1625
- cy: "110",
1626
- r: "100",
1627
- className: "altertable-pie-empty"
1628
- }) : slices.filter((item) => item.share > 0).map((item) => /* @__PURE__ */ jsx12("path", {
1629
- d: item.path,
1630
- fill: item.color,
1631
- className: "altertable-pie-slice",
1632
- "data-active": item.id === (plotOpen && previewId ? previewId : showLegend ? legendId : null) || undefined,
1633
- onPointerDown: (event) => {
1634
- if (plotOpen && previewId !== item.id)
1635
- event.preventDefault();
1636
- setPreviewId(item.id);
1637
- },
1638
- onPointerEnter: (event) => {
1639
- if (event.pointerType === "mouse")
1640
- setPreviewId(item.id);
1641
- },
1642
- onPointerLeave: (event) => {
1643
- if (event.pointerType === "mouse")
1644
- setPreviewId(null);
1645
- }
1646
- }, item.id))
1647
- })
1648
- }),
1649
- total === 0 && /* @__PURE__ */ jsx12("span", {
1650
- className: "altertable-pie-empty-label",
1651
- children: "No nonzero values"
1652
- })
1653
- ]
1654
- }),
1655
- showLegend && /* @__PURE__ */ jsx12(ChartLegend, {
1656
- layout: "vertical",
1657
- "aria-label": `${ariaLabel} legend`,
1658
- className: "altertable-pie-legend",
1659
- children: slices.map((item) => /* @__PURE__ */ jsx12(ChartLegend.Item, {
1660
- children: /* @__PURE__ */ jsx12(Tooltip2, {
1661
- variant: "chart",
1662
- content: detail(item),
1663
- onOpenChange: (open) => setLegendId((current) => open ? item.id : current === item.id ? null : current),
1664
- children: /* @__PURE__ */ jsxs7("button", {
1665
- "data-atbl-focus": "ring",
1666
- "data-atbl-control": "default",
1667
- type: "button",
1668
- tabIndex: -1,
1669
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}, ${percent(item.share)}`,
1670
- children: [
1671
- /* @__PURE__ */ jsx12(ChartLegend.Marker, {
1672
- kind: "square",
1673
- color: item.color
1674
- }),
1675
- /* @__PURE__ */ jsx12(ChartLegend.Label, {
1676
- className: "altertable-pie-label",
1677
- children: item.label
1678
- }),
1679
- /* @__PURE__ */ jsx12("strong", {
1680
- children: formatValue(item.value)
1681
- }),
1682
- /* @__PURE__ */ jsx12("span", {
1683
- children: percent(item.share)
1684
- })
1685
- ]
1686
- })
1687
- })
1688
- }, item.id))
1689
- })
1690
- ]
1691
- })
1692
- ]
1693
- });
1694
- }
1695
- // src/react/ui/ScatterChart.tsx
1696
- import { jsx as jsx13, jsxs as jsxs8, Fragment as Fragment4 } from "react/jsx-runtime";
1697
- function formatNumber(value) {
1698
- return new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 }).format(value);
1699
- }
1700
- function scale(values) {
1701
- const magnitude = values.reduce((max, value) => Math.max(max, Math.abs(value)), 1);
1702
- const low = values.reduce((min, value) => Math.min(min, value / magnitude), 0);
1703
- const high = values.reduce((max, value) => Math.max(max, value / magnitude), 0) || (low === 0 ? 1 : 0);
1704
- const span = high - low;
1705
- return {
1706
- position(value) {
1707
- return (value / magnitude - low) / span * 100;
1708
- },
1709
- ticks: [low, low + span / 2, high].map((value) => value * magnitude)
1710
- };
1711
- }
1712
- function ScatterChart({
1713
- items,
1714
- xLabel,
1715
- yLabel,
1716
- xUnit,
1717
- yUnit,
1718
- ariaLabel,
1719
- formatX = formatNumber,
1720
- formatY = formatNumber
1721
- }) {
1722
- validateChartItems("scatter", items);
1723
- const xScale = scale(items.map((item) => item.x));
1724
- const yScale = scale(items.map((item) => item.y));
1725
- return /* @__PURE__ */ jsxs8("section", {
1726
- className: "altertable-scatter-chart",
1727
- "aria-label": ariaLabel,
1728
- children: [
1729
- items.length === 0 && /* @__PURE__ */ jsx13("span", {
1730
- children: "No data"
1731
- }),
1732
- items.length > 0 && /* @__PURE__ */ jsxs8(Fragment4, {
1733
- children: [
1734
- /* @__PURE__ */ jsxs8("p", {
1735
- className: "altertable-scatter-axis-title",
1736
- children: [
1737
- yLabel,
1738
- yUnit && ` (${yUnit})`
1739
- ]
1740
- }),
1741
- /* @__PURE__ */ jsx13("div", {
1742
- className: "altertable-scatter-axes",
1743
- children: /* @__PURE__ */ jsxs8("div", {
1744
- className: "altertable-scatter-plot",
1745
- children: [
1746
- yScale.ticks.map((value, index) => /* @__PURE__ */ jsx13("div", {
1747
- className: "altertable-scatter-gridline",
1748
- style: { bottom: `${index * 50}%` },
1749
- "aria-hidden": "true",
1750
- children: /* @__PURE__ */ jsx13("span", {
1751
- title: formatY(value),
1752
- children: formatY(value)
1753
- })
1754
- }, index)),
1755
- xScale.ticks.map((value, index) => /* @__PURE__ */ jsx13("span", {
1756
- className: "altertable-scatter-x-tick",
1757
- "data-edge": index,
1758
- style: { left: `${index * 50}%` },
1759
- "aria-hidden": "true",
1760
- title: formatX(value),
1761
- children: formatX(value)
1762
- }, index)),
1763
- items.map((item) => /* @__PURE__ */ jsx13(Tooltip2, {
1764
- variant: "chart",
1765
- content: /* @__PURE__ */ jsxs8(Fragment4, {
1766
- children: [
1767
- /* @__PURE__ */ jsx13("strong", {
1768
- children: item.label
1769
- }),
1770
- /* @__PURE__ */ jsxs8("span", {
1771
- children: [
1772
- xLabel,
1773
- ": ",
1774
- formatX(item.x),
1775
- " ",
1776
- xUnit
1777
- ]
1778
- }),
1779
- /* @__PURE__ */ jsxs8("span", {
1780
- children: [
1781
- yLabel,
1782
- ": ",
1783
- formatY(item.y),
1784
- " ",
1785
- yUnit
1786
- ]
1787
- })
1788
- ]
1789
- }),
1790
- className: "altertable-scatter-tooltip",
1791
- style: {
1792
- left: `${xScale.position(item.x)}%`,
1793
- bottom: `${yScale.position(item.y)}%`
1794
- },
1795
- children: /* @__PURE__ */ jsx13("button", {
1796
- "data-atbl-focus": "ring",
1797
- "data-atbl-control": "default",
1798
- type: "button",
1799
- tabIndex: -1,
1800
- className: "altertable-scatter-point",
1801
- "aria-label": `${item.label}: ${xLabel} ${formatX(item.x)} ${xUnit}, ${yLabel} ${formatY(item.y)} ${yUnit}`,
1802
- children: /* @__PURE__ */ jsx13("span", {})
1803
- })
1804
- }, item.id))
1805
- ]
1806
- })
1807
- }),
1808
- /* @__PURE__ */ jsxs8("p", {
1809
- className: "altertable-scatter-axis-title altertable-scatter-x-title",
1810
- children: [
1811
- xLabel,
1812
- xUnit && ` (${xUnit})`
1813
- ]
1814
- })
1815
- ]
1816
- })
1817
- ]
1818
- });
1819
- }
1820
- // src/react/ui/BarChart.tsx
1821
- import { useLayoutEffect as useLayoutEffect3, useRef as useRef3, useState as useState5 } from "react";
1822
- import { BarChart as RechartsBarChart, Cell } from "recharts";
1823
- import { jsx as jsx14, jsxs as jsxs9, Fragment as Fragment5 } from "react/jsx-runtime";
1824
- function BarChart({
1825
- items,
1826
- unit,
1827
- ariaLabel,
1828
- formatValue = formatNumber2
1829
- }) {
1830
- validateChartItems("bar", items);
1831
- const [activeId, setActiveId] = useState5();
1832
- const scrollport = useRef3(null);
1833
- useLayoutEffect3(() => {
1834
- const element = scrollport.current;
1835
- if (element)
1836
- element.scrollLeft = element.scrollWidth - element.clientWidth;
1837
- }, [items]);
1838
- const maximum = items.reduce((max, item) => Math.max(max, item.value), 1);
1839
- return /* @__PURE__ */ jsxs9("section", {
1840
- className: "altertable-selectable-bars",
1841
- "aria-label": ariaLabel,
1842
- children: [
1843
- items.length === 0 && /* @__PURE__ */ jsx14("span", {
1844
- children: "No data"
1845
- }),
1846
- /* @__PURE__ */ jsx14("div", {
1847
- className: "altertable-selectable-bars-scroll",
1848
- ref: scrollport,
1849
- children: /* @__PURE__ */ jsxs9("div", {
1850
- className: "altertable-selectable-bars-plot",
1851
- style: { minWidth: items.length * 45 },
1852
- children: [
1853
- /* @__PURE__ */ jsx14("div", {
1854
- className: "altertable-chart-canvas",
1855
- "aria-hidden": "true",
1856
- children: /* @__PURE__ */ jsxs9(RechartsBarChart, {
1857
- data: items.map((item) => ({
1858
- ...item,
1859
- plotValue: item.value / maximum
1860
- })),
1861
- responsive: true,
1862
- width: "100%",
1863
- height: 220,
1864
- margin: { top: 0, right: 0, bottom: 0, left: 0 },
1865
- accessibilityLayer: false,
1866
- tabIndex: -1,
1867
- barCategoryGap: "24%",
1868
- children: [
1869
- /* @__PURE__ */ jsx14(ChartXAxis, {
1870
- hide: true,
1871
- dataKey: "id",
1872
- scale: "band"
1873
- }),
1874
- /* @__PURE__ */ jsx14(ChartYAxis, {
1875
- hide: true,
1876
- domain: [0, 1],
1877
- allowDataOverflow: true
1878
- }),
1879
- /* @__PURE__ */ jsx14(ChartBar, {
1880
- dataKey: "plotValue",
1881
- minPointSize: (value) => (value ?? 0) > 0 ? 7 : 0,
1882
- children: items.map((item) => /* @__PURE__ */ jsx14(Cell, {
1883
- fill: chartBarFill,
1884
- opacity: activeId === item.id ? 0.75 : 1
1885
- }, item.id))
1886
- })
1887
- ]
1888
- })
1889
- }),
1890
- /* @__PURE__ */ jsx14("div", {
1891
- className: "altertable-selectable-bars-items",
1892
- children: items.map((item) => /* @__PURE__ */ jsx14(Tooltip2, {
1893
- variant: "chart",
1894
- onOpenChange: (open) => setActiveId((current) => open ? item.id : current === item.id ? undefined : current),
1895
- content: /* @__PURE__ */ jsxs9(Fragment5, {
1896
- children: [
1897
- /* @__PURE__ */ jsx14("strong", {
1898
- children: item.label
1899
- }),
1900
- /* @__PURE__ */ jsxs9("span", {
1901
- children: [
1902
- formatValue(item.value),
1903
- " ",
1904
- unit
1905
- ]
1906
- })
1907
- ]
1908
- }),
1909
- className: "altertable-chart-column",
1910
- children: /* @__PURE__ */ jsxs9("button", {
1911
- "data-atbl-focus": "ring",
1912
- "data-atbl-control": "default",
1913
- type: "button",
1914
- tabIndex: -1,
1915
- className: "altertable-selectable-bars-item",
1916
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
1917
- children: [
1918
- /* @__PURE__ */ jsx14("span", {
1919
- className: "altertable-selectable-bars-area"
1920
- }),
1921
- /* @__PURE__ */ jsx14("span", {
1922
- className: "altertable-selectable-bars-label",
1923
- children: item.label
1924
- })
1925
- ]
1926
- })
1927
- }, item.id))
1928
- })
1929
- ]
1930
- })
1931
- })
1932
- ]
1933
- });
1934
- }
1935
- // src/react/ui/RadioGroup.tsx
1936
- import {
1937
- RadioGroup as AriaRadioGroup,
1938
- Radio as AriaRadio,
1939
- Label
1940
- } from "react-aria-components";
1941
- import { jsx as jsx15, jsxs as jsxs10, Fragment as Fragment6 } from "react/jsx-runtime";
1942
- function RadioGroup({
1943
- label,
1944
- className,
1945
- children,
1946
- ...props
1947
- }) {
1948
- return /* @__PURE__ */ jsxs10(AriaRadioGroup, {
1949
- ...props,
1950
- className: classNames("altertable-radio-group", className),
1951
- children: [
1952
- /* @__PURE__ */ jsx15(Label, {
1953
- className: "altertable-control-label",
1954
- children: label
1955
- }),
1956
- children
1957
- ]
1958
- });
1959
- }
1960
- function Radio({ className, children, ...props }) {
1961
- return /* @__PURE__ */ jsx15(AriaRadio, {
1962
- ...props,
1963
- "data-atbl-control": "action",
1964
- "data-atbl-focus": "ring",
1965
- className: classNames("altertable-radio", className),
1966
- children: (state) => /* @__PURE__ */ jsxs10(Fragment6, {
1967
- children: [
1968
- /* @__PURE__ */ jsx15("span", {
1969
- className: "altertable-radio-mark",
1970
- "aria-hidden": "true"
1971
- }),
1972
- typeof children === "function" ? children(state) : children
1973
- ]
1974
- })
1975
- });
1976
- }
1977
- function SegmentedControl({
1978
- options,
1979
- className,
1980
- ...props
1981
- }) {
1982
- validateChoiceOptions(options);
1983
- return /* @__PURE__ */ jsx15(RadioGroup, {
1984
- ...props,
1985
- orientation: "horizontal",
1986
- className: classNames("altertable-segmented-control", className),
1987
- children: /* @__PURE__ */ jsx15("div", {
1988
- className: "altertable-segmented-options",
1989
- children: options.map((option) => /* @__PURE__ */ jsx15(Radio, {
1990
- value: option.id,
1991
- "data-atbl-internal-surface": "option",
1992
- children: option.label
1993
- }, option.id))
1994
- })
1995
- });
1996
- }
1997
- // src/react/ui/CheckboxGroup.tsx
1998
- import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
1999
- function CheckboxGroup({
2000
- label,
2001
- values,
2002
- onChange,
2003
- className,
2004
- children,
2005
- disabled,
2006
- ...props
2007
- }) {
2008
- invariant(new Set(values).size === values.length, "Checkbox group values must be unique.");
2009
- return /* @__PURE__ */ jsxs11("fieldset", {
2010
- ...props,
2011
- disabled,
2012
- className: classNames("altertable-checkbox-group", className),
2013
- children: [
2014
- /* @__PURE__ */ jsx16("legend", {
2015
- children: label
2016
- }),
2017
- /* @__PURE__ */ jsx16(CheckboxGroupContext, {
2018
- value: {
2019
- values,
2020
- disabled,
2021
- onChange(value, checked) {
2022
- onChange(checked ? [...values.filter((item) => item !== value), value] : values.filter((item) => item !== value));
2023
- }
2024
- },
2025
- children
2026
- })
2027
- ]
2028
- });
2029
- }
2030
- // src/react/ui/ComposedChart.tsx
2031
- import {
2032
- useState as useState6,
2033
- useCallback as useCallback2,
2034
- useRef as useRef4,
2035
- useLayoutEffect as useLayoutEffect4
2036
- } from "react";
2037
-
2038
- // src/react/ui/ComposedChartLegend.tsx
2039
- import { Legend } from "recharts";
2040
- import { jsx as jsx17, jsxs as jsxs12, Fragment as Fragment7 } from "react/jsx-runtime";
2041
- var legendMarkerKinds = {
2042
- square: "area",
2043
- rect: "bar",
2044
- line: "line",
2045
- plainline: "line"
2046
- };
2047
- function LegendContent({
2048
- payload = [],
2049
- maxVisibleItems,
2050
- formatter,
2051
- layout,
2052
- align,
2053
- labelStyle,
2054
- iconType,
2055
- iconSize = 8,
2056
- inactiveColor = "var(--atbl-muted)",
2057
- position,
2058
- verticalAlign,
2059
- onClick,
2060
- onMouseEnter,
2061
- onMouseLeave,
2062
- "aria-label": ariaLabel
2063
- }) {
2064
- if (!payload.some((entry) => entry.type !== "none"))
2065
- return null;
2066
- const vertical = layout === "vertical" || layout === "auto" && (position === "left" || position === "right");
2067
- return /* @__PURE__ */ jsx17(ChartLegend, {
2068
- "aria-label": ariaLabel,
2069
- className: position === "top" || position == null && verticalAlign === "top" ? "altertable-composed-chart-legend-above" : position === "bottom" || position == null && verticalAlign !== "middle" && !vertical ? "altertable-composed-chart-legend-below" : undefined,
2070
- maxVisibleItems,
2071
- layout: vertical ? "vertical" : "horizontal",
2072
- align: align === "right" ? "end" : align === "left" ? "start" : "center",
2073
- children: payload.map((entry, index) => {
2074
- if (entry.type === "none")
2075
- return null;
2076
- const type = iconType ?? entry.type;
2077
- const kind = iconType ? legendMarkerKinds[type ?? "none"] ?? "point" : "square";
2078
- const formatLabel = entry.formatter ?? formatter;
2079
- const label = formatLabel ? formatLabel(entry.value, entry, index) : entry.value;
2080
- const content = /* @__PURE__ */ jsxs12(Fragment7, {
2081
- children: [
2082
- type !== "none" && (entry.legendIcon ?? /* @__PURE__ */ jsx17(ChartLegend.Marker, {
2083
- kind,
2084
- color: entry.inactive ? inactiveColor : entry.color,
2085
- style: {
2086
- width: iconSize,
2087
- height: kind === "square" ? iconSize : iconSize * 0.6
2088
- }
2089
- })),
2090
- /* @__PURE__ */ jsx17(ChartLegend.Label, {
2091
- style: labelStyle,
2092
- children: label
2093
- })
2094
- ]
2095
- });
2096
- return /* @__PURE__ */ jsx17(ChartLegend.Item, {
2097
- inactive: entry.inactive,
2098
- onMouseEnter: onMouseEnter ? (event) => onMouseEnter(entry, index, event) : undefined,
2099
- onMouseLeave: onMouseLeave ? (event) => onMouseLeave(entry, index, event) : undefined,
2100
- children: onClick ? /* @__PURE__ */ jsx17("button", {
2101
- type: "button",
2102
- "data-atbl-control": "action",
2103
- "data-atbl-focus": "ring",
2104
- className: "altertable-chart-legend-action",
2105
- onClick: (event) => onClick(entry, index, event),
2106
- children: content
2107
- }) : content
2108
- }, index);
2109
- })
2110
- });
2111
- }
2112
- function ComposedChartLegend({
2113
- maxVisibleItems,
2114
- ...props
2115
- }) {
2116
- return /* @__PURE__ */ jsx17(Legend, {
2117
- iconSize: 8,
2118
- inactiveColor: "var(--atbl-muted)",
2119
- content: /* @__PURE__ */ jsx17(LegendContent, {
2120
- maxVisibleItems
2121
- }),
2122
- ...props
2123
- });
2124
- }
2125
-
2126
- // src/react/ui/ComposedChart.tsx
2127
- import {
2128
- ComposedChart as RechartsComposedChart,
2129
- ZAxis,
2130
- ReferenceLine as ReferenceLine2,
2131
- ReferenceArea,
2132
- ReferenceDot,
2133
- Brush,
2134
- Cell as Cell2,
2135
- Label as Label2,
2136
- LabelList,
2137
- ErrorBar
2138
- } from "recharts";
2139
- import { jsx as jsx18 } from "react/jsx-runtime";
2140
- function closestSeries(hovered, points, position) {
2141
- let selected = hovered;
2142
- if (position && points.size > 0 && (hovered == null || points.has(hovered))) {
2143
- let distance = Infinity;
2144
- for (const [id, point] of points) {
2145
- const candidate = Math.hypot(point.x - position.x, point.y - position.y);
2146
- if (candidate < distance) {
2147
- distance = candidate;
2148
- selected = id;
2149
- }
2150
- }
2151
- }
2152
- return selected;
2153
- }
2154
- function ComposedChartRoot({
2155
- data,
2156
- ariaLabel,
2157
- width = "100%",
2158
- height = 300,
2159
- responsive = true,
2160
- className,
2161
- ...props
2162
- }) {
2163
- const [pointerFocus, setPointerFocus] = useState6(false);
2164
- const [pointer, setPointer] = useState6(false);
2165
- const [hovered, setHovered] = useState6(null);
2166
- const pointerPosition = useRef4(null);
2167
- const [nearest, setNearest] = useState6(null);
2168
- const [points, setPoints] = useState6(() => new Map);
2169
- const registerPoint = useCallback2((id, x, y) => {
2170
- setPoints((current) => new Map(current).set(id, { x, y }));
2171
- return () => setPoints((current) => {
2172
- const next = new Map(current);
2173
- next.delete(id);
2174
- return next;
2175
- });
2176
- }, []);
2177
- function trackPointer(event) {
2178
- setPointer(true);
2179
- const svg = event.currentTarget.querySelector('svg[role="application"]');
2180
- if (!(svg instanceof SVGSVGElement))
2181
- return;
2182
- const matrix = svg.getScreenCTM();
2183
- if (!matrix)
2184
- return;
2185
- const point = new DOMPoint(event.clientX, event.clientY).matrixTransform(matrix.inverse());
2186
- pointerPosition.current = { x: point.x, y: point.y };
2187
- setNearest(closestSeries(hovered, points, pointerPosition.current));
2188
- }
2189
- useLayoutEffect4(() => {
2190
- setNearest(closestSeries(hovered, points, pointerPosition.current));
2191
- }, [hovered, points]);
2192
- const [seriesIds, setSeriesIds] = useState6(() => new Set);
2193
- const registerSeries = useCallback2((id) => {
2194
- setSeriesIds((current) => new Set(current).add(id));
2195
- return () => {
2196
- setSeriesIds((current) => {
2197
- const next = new Set(current);
2198
- next.delete(id);
2199
- return next;
2200
- });
2201
- };
2202
- }, []);
2203
- return /* @__PURE__ */ jsx18(ChartInteraction.Provider, {
2204
- value: {
2205
- pointer,
2206
- hovered: nearest,
2207
- point: nearest == null ? undefined : points.get(nearest),
2208
- registerPoint,
2209
- setHovered,
2210
- seriesCount: seriesIds.size,
2211
- registerSeries
2212
- },
2213
- children: /* @__PURE__ */ jsx18("section", {
2214
- className: ["altertable-composed-chart", className].filter(Boolean).join(" "),
2215
- "aria-label": ariaLabel,
2216
- "data-atbl-internal-pointer-focus": pointerFocus || undefined,
2217
- onPointerDownCapture: (event) => {
2218
- setPointerFocus(true);
2219
- trackPointer(event);
2220
- },
2221
- onPointerOverCapture: trackPointer,
2222
- onPointerMoveCapture: trackPointer,
2223
- onPointerLeave: (event) => {
2224
- if (event.pointerType !== "touch") {
2225
- setHovered(null);
2226
- pointerPosition.current = null;
2227
- setNearest(null);
2228
- }
2229
- },
2230
- onKeyDownCapture: () => {
2231
- setPointerFocus(false);
2232
- setPointer(false);
2233
- pointerPosition.current = null;
2234
- setNearest(null);
2235
- setHovered(null);
2236
- },
2237
- onBlurCapture: (event) => {
2238
- if (!event.currentTarget.contains(event.relatedTarget))
2239
- setPointerFocus(false);
2240
- },
2241
- children: /* @__PURE__ */ jsx18(ChartDateAxes, {
2242
- data,
2243
- children: /* @__PURE__ */ jsx18(RechartsComposedChart, {
2244
- "data-atbl-focus": "inset",
2245
- ...props,
2246
- data,
2247
- width,
2248
- height,
2249
- responsive,
2250
- "aria-label": ariaLabel
2251
- })
2252
- })
2253
- })
2254
- });
2255
- }
2256
- var ComposedChart = Object.assign(ComposedChartRoot, {
2257
- Dot: ChartDot,
2258
- Area: ChartArea,
2259
- Bar: ChartBar,
2260
- Line: ChartLine,
2261
- Scatter: ChartScatter,
2262
- XAxis: ChartXAxis,
2263
- YAxis: ChartYAxis,
2264
- ZAxis,
2265
- CartesianGrid: ChartGrid,
2266
- Tooltip: ChartTooltip,
2267
- Legend: ComposedChartLegend,
2268
- ReferenceLine: ReferenceLine2,
2269
- ReferenceArea,
2270
- ReferenceDot,
2271
- Brush,
2272
- Cell: Cell2,
2273
- Label: Label2,
2274
- LabelList,
2275
- ErrorBar
2276
- });
2277
- // src/react/ui/FunnelChart.tsx
2278
- import { Fragment as Fragment8, useEffect as useEffect4, useRef as useRef5, useState as useState7 } from "react";
2279
-
2280
- // src/react/ui/useSvgId.ts
2281
- import { useId as useId3 } from "react";
2282
- function useSvgId() {
2283
- const id = useId3();
2284
- return `svg-${Array.from(id, (character) => /[a-zA-Z0-9-]/.test(character) ? character : `_${character.codePointAt(0).toString(16)}_`).join("")}`;
2285
- }
2286
-
2287
- // src/react/ui/FunnelChart.tsx
2288
- import { jsx as jsx19, jsxs as jsxs13, Fragment as Fragment9 } from "react/jsx-runtime";
2289
- function FunnelChart({
2290
- steps,
2291
- series,
2292
- unit,
2293
- ariaLabel,
2294
- className,
2295
- formatValue = formatNumber2
2296
- }) {
2297
- const chartId = useSvgId();
2298
- const [highlighted, setHighlighted] = useState7(null);
2299
- const clearTimer = useRef5(null);
2300
- function cancelClear() {
2301
- if (clearTimer.current !== null)
2302
- clearTimeout(clearTimer.current);
2303
- clearTimer.current = null;
2304
- }
2305
- useEffect4(() => cancelClear, []);
2306
- function highlight(id, conversion, step) {
2307
- cancelClear();
2308
- setHighlighted({ id, conversion, step });
2309
- }
2310
- function clearHighlight() {
2311
- cancelClear();
2312
- setHighlighted(null);
2313
- }
2314
- function scheduleClear() {
2315
- cancelClear();
2316
- clearTimer.current = setTimeout(() => setHighlighted(null), 100);
2317
- }
2318
- for (const [kind, items] of [
2319
- ["funnel step", steps],
2320
- ["funnel series", series]
2321
- ]) {
2322
- const ids = new Set;
2323
- for (const item of items) {
2324
- invariant(item.id.trim().length > 0 && !ids.has(item.id), `${kind} chart IDs must be nonblank and unique.`);
2325
- ids.add(item.id);
2326
- }
2327
- }
2328
- for (const item of series) {
2329
- invariant(item.values.length === steps.length, "funnel chart counts must align with steps.");
2330
- item.values.forEach((value, index) => {
2331
- invariant(Number.isFinite(value) && value >= 0, "funnel chart counts must be finite and nonnegative.");
2332
- invariant(index === 0 || value <= item.values[index - 1], "funnel chart counts must be nonincreasing.");
2333
- });
2334
- }
2335
- function reading(item, index) {
2336
- const first = item.values[0] ?? 0;
2337
- const current = item.values[index];
2338
- const previous = item.values[Math.max(0, index - 1)];
2339
- return {
2340
- current,
2341
- previous,
2342
- dropped: previous - current,
2343
- conversion: first > 0 ? current / first : null,
2344
- dropOff: first > 0 ? (previous - current) / first : null
2345
- };
2346
- }
2347
- const data = steps.map((step, index) => ({
2348
- label: step.label,
2349
- index,
2350
- ...Object.fromEntries(series.flatMap((item, seriesIndex) => {
2351
- const value = reading(item, index);
2352
- return [
2353
- [`conversion${seriesIndex}`, (value.conversion ?? 0) * 100],
2354
- [
2355
- `drop${seriesIndex}`,
2356
- (value.dropOff ?? (index === 0 ? 1 : 0)) * 100
2357
- ]
2358
- ];
2359
- }))
2360
- }));
2361
- return /* @__PURE__ */ jsx19("section", {
2362
- className: classNames("altertable-funnel-chart", className),
2363
- "aria-label": ariaLabel,
2364
- onKeyDownCapture: clearHighlight,
2365
- children: steps.length === 0 || series.length === 0 ? /* @__PURE__ */ jsx19("span", {
2366
- children: "No data"
2367
- }) : /* @__PURE__ */ jsxs13(Fragment9, {
2368
- children: [
2369
- /* @__PURE__ */ jsxs13("div", {
2370
- className: "altertable-funnel-header",
2371
- children: [
2372
- /* @__PURE__ */ jsx19(ChartLegend, {
2373
- "aria-label": "Funnel series",
2374
- layout: "single-row",
2375
- children: series.map((item, index) => /* @__PURE__ */ jsxs13(ChartLegend.Item, {
2376
- className: "altertable-funnel-summary-item",
2377
- children: [
2378
- /* @__PURE__ */ jsxs13("span", {
2379
- className: "altertable-funnel-series-label",
2380
- children: [
2381
- /* @__PURE__ */ jsx19(ChartLegend.Marker, {
2382
- kind: "square",
2383
- color: `var(--atbl-chart-${index % 8 + 1})`
2384
- }),
2385
- /* @__PURE__ */ jsx19(ChartLegend.Label, {
2386
- children: item.label
2387
- })
2388
- ]
2389
- }),
2390
- /* @__PURE__ */ jsx19("strong", {
2391
- className: "altertable-funnel-series-value",
2392
- children: formatPercent2(reading(item, steps.length - 1).conversion)
2393
- })
2394
- ]
2395
- }, item.id))
2396
- }),
2397
- /* @__PURE__ */ jsxs13("p", {
2398
- className: "altertable-funnel-path",
2399
- children: [
2400
- steps[0].label,
2401
- " → ",
2402
- steps.at(-1).label
2403
- ]
2404
- })
2405
- ]
2406
- }),
2407
- /* @__PURE__ */ jsx19("div", {
2408
- className: "altertable-funnel-scroll",
2409
- children: /* @__PURE__ */ jsx19("div", {
2410
- style: {
2411
- minWidth: steps.length * Math.max(96, series.length * 40)
2412
- },
2413
- children: /* @__PURE__ */ jsxs13(ComposedChart, {
2414
- data,
2415
- ariaLabel: `${ariaLabel} plot`,
2416
- height: 300,
2417
- barCategoryGap: "4%",
2418
- barGap: 1,
2419
- onMouseLeave: clearHighlight,
2420
- children: [
2421
- /* @__PURE__ */ jsx19(ComposedChart.CartesianGrid, {}),
2422
- /* @__PURE__ */ jsx19(ComposedChart.XAxis, {
2423
- dataKey: "label",
2424
- interval: 0,
2425
- height: 48
2426
- }),
2427
- /* @__PURE__ */ jsx19(ComposedChart.YAxis, {
2428
- domain: [0, 100],
2429
- width: 42,
2430
- tickFormatter: (value) => formatPercent2(value / 100)
2431
- }),
2432
- /* @__PURE__ */ jsx19("defs", {
2433
- children: series.map((item, index) => /* @__PURE__ */ jsxs13("pattern", {
2434
- id: `${chartId}-hatch-${index}`,
2435
- patternUnits: "userSpaceOnUse",
2436
- width: "6",
2437
- height: "6",
2438
- patternTransform: "rotate(45)",
2439
- children: [
2440
- /* @__PURE__ */ jsx19("rect", {
2441
- width: "8",
2442
- height: "8",
2443
- fill: `var(--atbl-chart-${index % 8 + 1})`,
2444
- fillOpacity: 0.16
2445
- }),
2446
- /* @__PURE__ */ jsx19("line", {
2447
- x1: "0",
2448
- y1: "0",
2449
- x2: "0",
2450
- y2: "8",
2451
- stroke: `var(--atbl-chart-${index % 8 + 1})`,
2452
- strokeOpacity: 0.4,
2453
- strokeWidth: "2"
2454
- })
2455
- ]
2456
- }, item.id))
2457
- }),
2458
- series.map((item, index) => /* @__PURE__ */ jsxs13(Fragment8, {
2459
- children: [
2460
- /* @__PURE__ */ jsx19(ComposedChart.Bar, {
2461
- dataKey: `conversion${index}`,
2462
- name: item.label,
2463
- stackId: item.id,
2464
- fill: `var(--atbl-chart-${index % 8 + 1})`,
2465
- radius: 0,
2466
- maxBarSize: undefined,
2467
- activeBar: false,
2468
- minPointSize: 0,
2469
- opacity: !highlighted || highlighted.id === item.id ? 1 : 0.2,
2470
- onMouseEnter: (bar) => highlight(item.id, true, bar.payload.index),
2471
- onMouseLeave: scheduleClear,
2472
- onClick: (bar) => highlight(item.id, true, bar.payload.index)
2473
- }),
2474
- /* @__PURE__ */ jsx19(ComposedChart.Bar, {
2475
- dataKey: `drop${index}`,
2476
- name: `${item.label} drop-off`,
2477
- stackId: item.id,
2478
- fill: `url(#${chartId}-hatch-${index})`,
2479
- opacity: !highlighted || highlighted.id === item.id ? 1 : 0.2,
2480
- onMouseEnter: (bar) => highlight(item.id, false, bar.payload.index),
2481
- onMouseLeave: scheduleClear,
2482
- onClick: (bar) => highlight(item.id, false, bar.payload.index),
2483
- radius: 0,
2484
- maxBarSize: undefined,
2485
- activeBar: false
2486
- })
2487
- ]
2488
- }, item.id)),
2489
- /* @__PURE__ */ jsx19(ComposedChart.Tooltip, {
2490
- content: ({ active, payload }) => {
2491
- const index = payload?.[0]?.payload.index;
2492
- if (!active || typeof index !== "number")
2493
- return null;
2494
- const tooltipItems = series.filter((item) => !highlighted || highlighted.step !== index || item.id === highlighted.id).flatMap((item) => {
2495
- const value = reading(item, index);
2496
- const selected = highlighted?.step === index;
2497
- const readings = selected ? [highlighted.conversion] : [true, false];
2498
- const seriesIndex = series.indexOf(item);
2499
- return readings.map((conversion) => ({
2500
- name: item.label,
2501
- graphicalItemId: `${item.id}-${conversion ? "conversion" : "drop-off"}`,
2502
- dataKey: `${item.id}-${conversion ? "conversion" : "drop-off"}`,
2503
- color: `var(--atbl-chart-${seriesIndex % 8 + 1})`,
2504
- value: (conversion ? value.conversion : value.dropOff) ?? 0,
2505
- formatter: () => /* @__PURE__ */ jsxs13(Fragment9, {
2506
- children: [
2507
- formatPercent2(conversion ? value.conversion : value.dropOff),
2508
- " ",
2509
- conversion ? "conversion" : "drop-off",
2510
- /* @__PURE__ */ jsxs13("span", {
2511
- className: "altertable-funnel-tooltip-detail",
2512
- children: [
2513
- formatValue(conversion ? value.current : value.dropped),
2514
- " ",
2515
- "of ",
2516
- formatValue(value.previous),
2517
- " ",
2518
- unit
2519
- ]
2520
- })
2521
- ]
2522
- })
2523
- }));
2524
- });
2525
- return /* @__PURE__ */ jsx19(ChartTooltipContent, {
2526
- active: true,
2527
- label: steps[index].label,
2528
- payload: tooltipItems
2529
- });
2530
- }
2531
- })
2532
- ]
2533
- })
2534
- })
2535
- }),
2536
- /* @__PURE__ */ jsx19("ul", {
2537
- className: "altertable-sr-only",
2538
- children: steps.map((step, index) => /* @__PURE__ */ jsxs13("li", {
2539
- children: [
2540
- step.label,
2541
- series.map((item) => {
2542
- const value = reading(item, index);
2543
- return /* @__PURE__ */ jsxs13("span", {
2544
- children: [
2545
- " ",
2546
- "· ",
2547
- item.label,
2548
- ": ",
2549
- formatValue(value.current),
2550
- " ",
2551
- unit,
2552
- ",",
2553
- " ",
2554
- formatPercent2(value.conversion),
2555
- " conversion,",
2556
- " ",
2557
- formatValue(value.dropped),
2558
- " dropped off"
2559
- ]
2560
- }, item.id);
2561
- })
2562
- ]
2563
- }, step.id))
2564
- })
2565
- ]
2566
- })
2567
- });
2568
- }
2569
- // src/react/ui/RetentionChart.tsx
2570
- import { Fragment as Fragment10 } from "react";
2571
- import { jsx as jsx20, jsxs as jsxs14, Fragment as Fragment11 } from "react/jsx-runtime";
2572
- function RetentionChart({
2573
- series,
2574
- unit,
2575
- ariaLabel,
2576
- className,
2577
- formatValue = formatNumber2
2578
- }) {
2579
- const ids = new Set;
2580
- const offsets = new Map;
2581
- for (const item of series) {
2582
- invariant(item.id.trim().length > 0 && !ids.has(item.id), "retention series chart IDs must be nonblank and unique.");
2583
- ids.add(item.id);
2584
- invariant(Number.isFinite(item.cohortSize) && item.cohortSize >= 0, "retention chart counts must be finite and nonnegative.");
2585
- const seen = new Set;
2586
- for (const point of item.points) {
2587
- invariant(Number.isSafeInteger(point.offset) && point.offset >= 0 && !seen.has(point.offset), "retention chart offsets must be unique nonnegative integers within each series.");
2588
- seen.add(point.offset);
2589
- invariant(point.rate === null || Number.isFinite(point.rate) && point.rate >= 0 && point.rate <= 1, "retention chart rates must be finite fractions between 0 and 1, or null.");
2590
- invariant(point.rate === null === (point.retainedCount === null), "retention chart unobserved rates and counts must both be null.");
2591
- if (point.retainedCount !== null) {
2592
- invariant(Number.isFinite(point.retainedCount) && point.retainedCount >= 0, "retention chart counts must be finite and nonnegative.");
2593
- invariant(point.retainedCount <= item.cohortSize, "retention chart retained counts cannot exceed cohort size.");
2594
- }
2595
- invariant(!offsets.has(point.offset) || offsets.get(point.offset) === point.label, "retention chart labels must agree for the same offset.");
2596
- offsets.set(point.offset, point.label);
2597
- }
2598
- }
2599
- const data = [...offsets].sort(([a], [b]) => a - b).map(([offset, label]) => ({
2600
- offset,
2601
- label,
2602
- ...Object.fromEntries(series.flatMap((_, index) => [
2603
- [`rate${index}`, null],
2604
- [`tail${index}`, null]
2605
- ]))
2606
- }));
2607
- series.forEach((item, index) => {
2608
- const points = [...item.points].sort((a, b) => a.offset - b.offset);
2609
- points.forEach((point, pointIndex) => {
2610
- const row = data.find((row) => row.offset === point.offset);
2611
- row[point.incomplete ? `tail${index}` : `rate${index}`] = point.rate === null ? null : point.rate * 100;
2612
- if (point.incomplete && pointIndex > 0) {
2613
- const previous = points[pointIndex - 1];
2614
- data.find((row) => row.offset === previous.offset)[`tail${index}`] = previous.rate === null ? null : previous.rate * 100;
2615
- }
2616
- });
2617
- });
2618
- return /* @__PURE__ */ jsx20("section", {
2619
- className: classNames("altertable-retention-chart", className),
2620
- "aria-label": ariaLabel,
2621
- children: data.length === 0 ? /* @__PURE__ */ jsx20("span", {
2622
- children: "No data"
2623
- }) : /* @__PURE__ */ jsxs14(Fragment11, {
2624
- children: [
2625
- /* @__PURE__ */ jsxs14(ComposedChart, {
2626
- data,
2627
- ariaLabel: `${ariaLabel} plot`,
2628
- children: [
2629
- /* @__PURE__ */ jsx20(ComposedChart.CartesianGrid, {}),
2630
- /* @__PURE__ */ jsx20(ComposedChart.XAxis, {
2631
- dataKey: "offset",
2632
- type: "number",
2633
- domain: [0, Math.max(1, ...offsets.keys())],
2634
- tickFormatter: (value) => offsets.get(Number(value)) ?? (data[0]?.label.replace(/\d+(?:\.\d+)?/, String(value)) || String(value))
2635
- }),
2636
- /* @__PURE__ */ jsx20(ComposedChart.YAxis, {
2637
- domain: [0, 100],
2638
- width: 42,
2639
- tickFormatter: (value) => `${value}%`
2640
- }),
2641
- series.map((item, index) => /* @__PURE__ */ jsxs14(Fragment10, {
2642
- children: [
2643
- /* @__PURE__ */ jsx20(ComposedChart.Line, {
2644
- dataKey: `rate${index}`,
2645
- name: item.label,
2646
- stroke: `var(--atbl-chart-${index % 8 + 1})`,
2647
- connectNulls: false
2648
- }),
2649
- /* @__PURE__ */ jsx20(ComposedChart.Line, {
2650
- dataKey: `tail${index}`,
2651
- name: item.label,
2652
- stroke: `var(--atbl-chart-${index % 8 + 1})`,
2653
- strokeDasharray: "3 3",
2654
- dot: false,
2655
- activeDot: false,
2656
- connectNulls: false
2657
- })
2658
- ]
2659
- }, item.id)),
2660
- /* @__PURE__ */ jsx20(ComposedChart.Tooltip, {
2661
- filterNull: false,
2662
- content: ({ active, payload }) => {
2663
- const offset = payload?.[0]?.payload.offset;
2664
- if (!active || typeof offset !== "number")
2665
- return null;
2666
- return /* @__PURE__ */ jsxs14(TooltipSurface, {
2667
- "data-variant": "chart",
2668
- role: "tooltip",
2669
- children: [
2670
- /* @__PURE__ */ jsx20("strong", {
2671
- children: offsets.get(offset)
2672
- }),
2673
- series.map((item) => {
2674
- const point = item.points.find((point) => point.offset === offset);
2675
- if (!point)
2676
- return null;
2677
- return /* @__PURE__ */ jsxs14("span", {
2678
- children: [
2679
- item.label,
2680
- ":",
2681
- " ",
2682
- point.rate === null ? "Not observed" : `${formatPercent2(point.rate)} · ${formatValue(point.retainedCount)} / ${formatValue(item.cohortSize)} ${unit}${point.incomplete ? " · Incomplete period" : ""}`
2683
- ]
2684
- }, item.id);
2685
- })
2686
- ]
2687
- });
2688
- }
2689
- })
2690
- ]
2691
- }),
2692
- /* @__PURE__ */ jsx20(ChartLegend, {
2693
- "aria-label": `${ariaLabel} cohorts`,
2694
- children: series.map((item, index) => /* @__PURE__ */ jsxs14(ChartLegend.Item, {
2695
- children: [
2696
- /* @__PURE__ */ jsx20(ChartLegend.Marker, {
2697
- kind: "square",
2698
- color: `var(--atbl-chart-${index % 8 + 1})`
2699
- }),
2700
- /* @__PURE__ */ jsx20(ChartLegend.Label, {
2701
- children: item.label
2702
- })
2703
- ]
2704
- }, item.id))
2705
- }),
2706
- /* @__PURE__ */ jsx20("ul", {
2707
- className: "altertable-sr-only",
2708
- children: series.map((item) => /* @__PURE__ */ jsxs14("li", {
2709
- children: [
2710
- item.label,
2711
- item.points.map((point) => /* @__PURE__ */ jsxs14("span", {
2712
- children: [
2713
- " ",
2714
- "· ",
2715
- point.label,
2716
- ":",
2717
- " ",
2718
- point.rate === null ? "Not observed" : `${formatPercent2(point.rate)} · ${formatValue(point.retainedCount)} / ${formatValue(item.cohortSize)} ${unit}${point.incomplete ? " · Incomplete period" : ""}`
2719
- ]
2720
- }, point.offset))
2721
- ]
2722
- }, item.id))
2723
- })
2724
- ]
2725
- })
2726
- });
2727
- }
2728
- // src/react/ui/JourneyChart.tsx
2729
- import { useLayoutEffect as useLayoutEffect5, useRef as useRef6, useState as useState8 } from "react";
2730
-
2731
- // src/react/ui/journey-flow.ts
2732
- var journeyOutcomeLabels = {
2733
- truncated: "More steps",
2734
- "drop-off": "Drop-off",
2735
- converted: "Converted",
2736
- end: "End of path"
2737
- };
2738
- function journeyNodes(path) {
2739
- const nodes = path.steps.map((step, depth) => ({
2740
- key: JSON.stringify([depth, "event", step.event, step.property]),
2741
- label: step.property === null ? step.event : `${step.event} · ${step.property}`,
2742
- depth,
2743
- outcome: "event"
2744
- }));
2745
- const outcome = path.truncated ? "truncated" : path.converted === false ? "drop-off" : path.converted === true ? "converted" : "end";
2746
- nodes.push({
2747
- key: JSON.stringify([nodes.length, outcome]),
2748
- label: journeyOutcomeLabels[outcome],
2749
- depth: nodes.length,
2750
- outcome
2751
- });
2752
- return nodes;
2753
- }
2754
- function buildJourneyFlow(paths, expandedBranch) {
2755
- const nodes = new Map;
2756
- const links = new Map;
2757
- for (const path of paths) {
2758
- const fullSequence = journeyNodes(path);
2759
- if (path.truncated)
2760
- fullSequence.pop();
2761
- const sequence = expandedBranch === undefined ? fullSequence : fullSequence.flatMap((node, index) => {
2762
- const branchKeys = fullSequence.slice(0, index + 1).map((step) => step.key);
2763
- const parentExpanded = index <= 1 || branchKeys.slice(0, index).every((key, depth) => expandedBranch[depth] === key);
2764
- if (!parentExpanded)
2765
- return [];
2766
- return [
2767
- {
2768
- ...node,
2769
- key: JSON.stringify(branchKeys),
2770
- branchKeys,
2771
- expandable: index >= 1 && index < fullSequence.length - 1,
2772
- expanded: branchKeys.every((key, depth) => expandedBranch[depth] === key)
2773
- }
2774
- ];
2775
- });
2776
- sequence.forEach((node, index) => {
2777
- const current = nodes.get(node.key) ?? {
2778
- ...node,
2779
- count: 0,
2780
- pathKeys: []
2781
- };
2782
- current.count += path.count;
2783
- if ("expandable" in node && node.expandable)
2784
- current.expandable = true;
2785
- current.pathKeys.push(path.id);
2786
- nodes.set(node.key, current);
2787
- const previous = sequence[index - 1];
2788
- if (!previous)
2789
- return;
2790
- const key = JSON.stringify([previous.key, node.key]);
2791
- const link = links.get(key) ?? {
2792
- key,
2793
- source: previous.key,
2794
- target: node.key,
2795
- count: 0,
2796
- pathKeys: []
2797
- };
2798
- link.count += path.count;
2799
- link.pathKeys.push(path.id);
2800
- links.set(key, link);
2801
- });
2802
- }
2803
- return { nodes: [...nodes.values()], links: [...links.values()] };
2804
- }
2805
- function limitJourneyFlow(graph, visibleEventsByDepth = {}) {
2806
- const nodes = [];
2807
- const replacements = new Map;
2808
- for (const depth of new Set(graph.nodes.map((node) => node.depth))) {
2809
- const column = graph.nodes.filter((node) => node.depth === depth).sort((a, b) => Number(Boolean(b.expanded)) - Number(Boolean(a.expanded)) || b.count - a.count || a.key.localeCompare(b.key));
2810
- const events = column.filter((node) => node.outcome === "event");
2811
- const outcomes = column.filter((node) => node.outcome !== "event");
2812
- const limit = visibleEventsByDepth[depth] ?? 3;
2813
- if (events.length <= limit) {
2814
- nodes.push(...column);
2815
- continue;
2816
- }
2817
- nodes.push(...events.slice(0, limit), ...outcomes);
2818
- const hidden = events.slice(limit);
2819
- const key = JSON.stringify(["other", depth]);
2820
- hidden.forEach((node) => replacements.set(node.key, key));
2821
- nodes.push({
2822
- key,
2823
- label: "More events",
2824
- depth,
2825
- outcome: "other",
2826
- hiddenBranchCount: hidden.length,
2827
- count: hidden.reduce((sum, node) => sum + node.count, 0),
2828
- pathKeys: [...new Set(hidden.flatMap((node) => node.pathKeys))]
2829
- });
2830
- }
2831
- const links = new Map;
2832
- for (const link of graph.links) {
2833
- const source = replacements.get(link.source) ?? link.source;
2834
- const target = replacements.get(link.target) ?? link.target;
2835
- const key = JSON.stringify([source, target]);
2836
- const existing = links.get(key);
2837
- if (existing) {
2838
- existing.count += link.count;
2839
- existing.pathKeys.push(...link.pathKeys);
2840
- } else {
2841
- links.set(key, {
2842
- ...link,
2843
- key,
2844
- source,
2845
- target,
2846
- pathKeys: [...link.pathKeys]
2847
- });
2848
- }
2849
- }
2850
- return { nodes, links: [...links.values()] };
2851
- }
2852
-
2853
- // src/react/ui/JourneyChart.tsx
2854
- import { jsx as jsx21, jsxs as jsxs15 } from "react/jsx-runtime";
2855
- function JourneyChart({
2856
- paths,
2857
- unit,
2858
- ariaLabel,
2859
- className,
2860
- formatValue = formatNumber2
2861
- }) {
2862
- const ids = new Set;
2863
- let total = 0;
2864
- for (const path of paths) {
2865
- invariant(path.id.trim().length > 0 && !ids.has(path.id), "journey path chart IDs must be nonblank and unique.");
2866
- ids.add(path.id);
2867
- invariant(Number.isFinite(path.count) && path.count >= 0, "journey chart counts must be finite and nonnegative.");
2868
- total += path.count;
2869
- invariant(path.steps.length > 0 && path.steps.every((step) => step.event.trim().length > 0), "journey chart paths require nonblank events.");
2870
- }
2871
- invariant(Number.isFinite(total), "journey chart total count must be finite.");
2872
- return /* @__PURE__ */ jsx21("section", {
2873
- className: classNames("altertable-journey-chart", className),
2874
- "aria-label": ariaLabel,
2875
- children: paths.length === 0 ? /* @__PURE__ */ jsx21("span", {
2876
- children: "No data"
2877
- }) : /* @__PURE__ */ jsx21(JourneyFlow, {
2878
- paths,
2879
- unit,
2880
- formatValue
2881
- }, JSON.stringify(paths))
2882
- });
2883
- }
2884
- function JourneyFlow({
2885
- paths,
2886
- unit,
2887
- formatValue
2888
- }) {
2889
- const [expandedBranch, setExpandedBranch] = useState8([]);
2890
- const [visibleEventsByDepth, setVisibleEventsByDepth] = useState8({});
2891
- const graph = limitJourneyFlow(buildJourneyFlow(paths, expandedBranch), visibleEventsByDepth);
2892
- const scrollRef = useRef6(null);
2893
- const pendingDepth = useRef6(null);
2894
- const depthCount = Math.max(0, ...graph.nodes.map((node) => node.depth)) + 1;
2895
- const startingCount = graph.nodes.filter((node) => node.depth === 0).reduce((sum, node) => sum + node.count, 0);
2896
- function percent(count) {
2897
- return formatPercent2(startingCount > 0 ? count / startingCount : null);
2898
- }
2899
- const nodeWidth = 176;
2900
- const nodeHeight = 96;
2901
- const barWidth = 16;
2902
- const rowSpacing = nodeHeight + 80;
2903
- const columnSpacing = nodeWidth + 112;
2904
- const width = 34 + nodeWidth + (depthCount - 1) * columnSpacing;
2905
- function columnX(depth) {
2906
- return 10 + depth * columnSpacing;
2907
- }
2908
- useLayoutEffect5(() => {
2909
- const depth = pendingDepth.current;
2910
- const container = scrollRef.current;
2911
- if (depth === null || !container || depth >= depthCount)
2912
- return;
2913
- pendingDepth.current = null;
2914
- const left = columnX(depth);
2915
- const right = left + nodeWidth + 24;
2916
- const nextLeft = left < container.scrollLeft ? left - 24 : right > container.scrollLeft + container.clientWidth ? right - container.clientWidth : container.scrollLeft;
2917
- if (nextLeft !== container.scrollLeft)
2918
- container.scrollTo({
2919
- left: Math.max(0, nextLeft),
2920
- behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth"
2921
- });
2922
- });
2923
- const columns = Array.from({ length: depthCount }, (_, depth) => graph.nodes.filter((node) => node.depth === depth).sort((a, b) => {
2924
- function rank(node) {
2925
- return node.outcome === "event" ? 0 : node.outcome === "other" ? 1 : 2;
2926
- }
2927
- return rank(a) - rank(b) || b.count - a.count || a.key.localeCompare(b.key);
2928
- }));
2929
- const positions = new Map;
2930
- columns.forEach((column, depth) => {
2931
- const parent = columns[depth - 1]?.find((node) => node.expanded);
2932
- const parentY = parent ? positions.get(parent.key)?.y : undefined;
2933
- const top = Math.max(104, (parentY ?? 104) - (column.length > 1 ? rowSpacing : 0));
2934
- column.forEach((node, index) => positions.set(node.key, {
2935
- node,
2936
- x: columnX(depth),
2937
- y: top + index * rowSpacing
2938
- }));
2939
- });
2940
- const height = Math.max(280, ...[...positions.values()].map((position) => position.y + nodeHeight + 40));
2941
- const outgoingOffsets = new Map;
2942
- const incomingOffsets = new Map;
2943
- const orderedLinks = [...graph.links].sort((a, b) => (positions.get(a.source)?.y ?? 0) - (positions.get(b.source)?.y ?? 0) || (positions.get(a.target)?.y ?? 0) - (positions.get(b.target)?.y ?? 0));
2944
- const links = orderedLinks.flatMap((link) => {
2945
- const source = positions.get(link.source);
2946
- const target = positions.get(link.target);
2947
- if (!source || !target || link.count <= 0 || startingCount <= 0)
2948
- return [];
2949
- const x0 = source.x + barWidth;
2950
- const x1 = target.x;
2951
- const mid = (x0 + x1) / 2;
2952
- const sourceTop = source.y + (outgoingOffsets.get(link.source) ?? 0);
2953
- const targetTop = target.y + (incomingOffsets.get(link.target) ?? 0);
2954
- const thickness = link.count / startingCount * nodeHeight;
2955
- outgoingOffsets.set(link.source, (outgoingOffsets.get(link.source) ?? 0) + thickness);
2956
- incomingOffsets.set(link.target, (incomingOffsets.get(link.target) ?? 0) + thickness);
2957
- return [
2958
- {
2959
- muted: target.node.outcome === "end" || target.node.outcome === "other",
2960
- d: `M${x0},${sourceTop} C${mid},${sourceTop} ${mid},${targetTop} ${x1},${targetTop} L${x1},${targetTop + thickness} C${mid},${targetTop + thickness} ${mid},${sourceTop + thickness} ${x0},${sourceTop + thickness} Z`
2961
- }
2962
- ];
2963
- });
2964
- return /* @__PURE__ */ jsx21("div", {
2965
- ref: scrollRef,
2966
- className: "altertable-journey-scroll",
2967
- children: /* @__PURE__ */ jsxs15("div", {
2968
- className: "altertable-journey-plot",
2969
- style: { minWidth: width, minHeight: height },
2970
- children: [
2971
- /* @__PURE__ */ jsxs15("svg", {
2972
- width: "100%",
2973
- height: "100%",
2974
- "aria-hidden": "true",
2975
- focusable: "false",
2976
- children: [
2977
- /* @__PURE__ */ jsx21("path", {
2978
- d: links.filter((link) => !link.muted).map((link) => link.d).join(" "),
2979
- fill: "color-mix(in srgb, var(--atbl-chart-5) 22%, var(--atbl-surface))"
2980
- }),
2981
- /* @__PURE__ */ jsx21("path", {
2982
- d: links.filter((link) => link.muted).map((link) => link.d).join(" "),
2983
- fill: "color-mix(in srgb, var(--atbl-muted) 22%, var(--atbl-surface))"
2984
- })
2985
- ]
2986
- }),
2987
- columns.map((column, depth) => /* @__PURE__ */ jsx21("span", {
2988
- className: "altertable-journey-stage",
2989
- style: { left: columnX(depth) },
2990
- children: column.length > 0 && column.every((node) => node.outcome !== "event" && node.outcome !== "other") ? "Outcome" : `Step ${depth + 1}`
2991
- }, depth)),
2992
- [...positions.values()].map(({ node, x, y }) => /* @__PURE__ */ jsxs15("div", {
2993
- className: "altertable-journey-node",
2994
- style: {
2995
- left: x,
2996
- top: y,
2997
- width: nodeWidth,
2998
- height: startingCount > 0 ? node.count / startingCount * nodeHeight : 0
2999
- },
3000
- children: [
3001
- /* @__PURE__ */ jsx21("div", {
3002
- className: "altertable-journey-bar",
3003
- "data-event": node.outcome === "event" || undefined,
3004
- "aria-hidden": "true",
3005
- style: { width: barWidth }
3006
- }),
3007
- /* @__PURE__ */ jsxs15("section", {
3008
- "aria-label": `${node.label}, step ${node.depth + 1}, ${formatValue(node.count)} ${unit}`,
3009
- className: "altertable-journey-label",
3010
- children: [
3011
- /* @__PURE__ */ jsx21("span", {
3012
- className: "altertable-journey-name",
3013
- title: node.label,
3014
- children: node.label
3015
- }),
3016
- /* @__PURE__ */ jsxs15("span", {
3017
- children: [
3018
- formatValue(node.count),
3019
- " ",
3020
- unit,
3021
- " · ",
3022
- percent(node.count)
3023
- ]
3024
- }),
3025
- node.hiddenBranchCount ? /* @__PURE__ */ jsxs15("span", {
3026
- children: [
3027
- node.hiddenBranchCount,
3028
- " hidden",
3029
- " ",
3030
- node.hiddenBranchCount === 1 ? "event" : "events"
3031
- ]
3032
- }) : null
3033
- ]
3034
- }),
3035
- node.expandable && /* @__PURE__ */ jsx21(Button2, {
3036
- variant: "outline",
3037
- size: "icon-compact",
3038
- className: "altertable-journey-expand",
3039
- "aria-label": `${node.expanded ? "Less" : "More"} after ${node.label}, step ${node.depth + 1}`,
3040
- "aria-expanded": Boolean(node.expanded),
3041
- onClick: () => {
3042
- pendingDepth.current = node.expanded ? null : node.depth + 1;
3043
- setVisibleEventsByDepth((limits) => Object.fromEntries(Object.entries(limits).filter(([depth]) => Number(depth) <= node.depth)));
3044
- setExpandedBranch(node.expanded ? (node.branchKeys ?? []).slice(0, -1) : node.branchKeys ?? []);
3045
- },
3046
- children: node.expanded ? "−" : "›"
3047
- }),
3048
- node.outcome === "other" && /* @__PURE__ */ jsx21(Button2, {
3049
- size: "compact",
3050
- variant: "ghost",
3051
- className: "altertable-journey-more",
3052
- "aria-label": `Show more events at step ${node.depth + 1}`,
3053
- onClick: () => setVisibleEventsByDepth((limits) => ({
3054
- ...limits,
3055
- [node.depth]: (limits[node.depth] ?? 3) + 3
3056
- })),
3057
- children: "Show more events"
3058
- })
3059
- ]
3060
- }, node.key))
3061
- ]
3062
- })
3063
- });
3064
- }
3065
- export {
3066
- AboutData2 as AboutData,
3067
- AppIcon2 as AppIcon,
3068
- AreaChart,
3069
- BarChart,
3070
- ChartLegend,
3071
- Checkbox2 as Checkbox,
3072
- CheckboxGroup,
3073
- ChoicePicker2 as ChoicePicker,
3074
- ComposedChart,
3075
- DataApp,
3076
- DataAppProvider2 as DataAppProvider,
3077
- DataTable2 as DataTable,
3078
- DataTableEmptyRow2 as DataTableEmptyRow,
3079
- DataTableShare2 as DataTableShare,
3080
- DataTableTimestamp2 as DataTableTimestamp,
3081
- DataValue2 as DataValue,
3082
- DataWidget2 as DataWidget,
3083
- DateDisplay2 as DateDisplay,
3084
- DateRangePicker2 as DateRangePicker,
3085
- DimensionPicker2 as DimensionPicker,
3086
- FilterActions2 as FilterActions,
3087
- FilterBar2 as FilterBar,
3088
- FunnelChart,
3089
- GettingStarted,
3090
- GlossaryDefinition,
3091
- GlossaryExplanation,
3092
- GradientScroll2 as GradientScroll,
3093
- HelpPopover2 as HelpPopover,
3094
- JourneyChart,
3095
- LineChart,
3096
- LiveControl2 as LiveControl,
3097
- Menu2 as Menu,
3098
- PressButton as MenuButton,
3099
- MenuItem2 as MenuItem,
3100
- MenuPopover2 as MenuPopover,
3101
- MenuSection2 as MenuSection,
3102
- MenuSeparator2 as MenuSeparator,
3103
- MenuTrigger2 as MenuTrigger,
3104
- MetricWidget2 as MetricWidget,
3105
- NumberField2 as NumberField,
3106
- NumberFilterPicker2 as NumberFilterPicker,
3107
- NumberRangeField2 as NumberRangeField,
3108
- PieChart,
3109
- PresentStory2 as PresentStory,
3110
- Radio,
3111
- RadioGroup,
3112
- RetentionChart,
3113
- ScatterChart,
3114
- SearchField2 as SearchField,
3115
- SearchMatch2 as SearchMatch,
3116
- SearchTypeahead2 as SearchTypeahead,
3117
- SectionHeading2 as SectionHeading,
3118
- SegmentedControl,
3119
- Select2 as Select,
3120
- Sheet2 as Sheet,
3121
- Tab2 as Tab,
3122
- TabList2 as TabList,
3123
- TabPanel2 as TabPanel,
3124
- TabPanels2 as TabPanels,
3125
- TableWidget2 as TableWidget,
3126
- Tabs2 as Tabs,
3127
- TextWidget2 as TextWidget,
3128
- Tooltip2 as Tooltip,
3129
- TooltipProvider2 as TooltipProvider,
3130
- VariableBar2 as VariableBar,
3131
- VisualizationWidget2 as VisualizationWidget,
3132
- injectDataAppStyles2 as injectDataAppStyles,
3133
- isPlainKeyEvent2 as isPlainKeyEvent,
3134
- matchSearchText2 as matchSearchText,
3135
- searchItems2 as searchItems,
3136
- useAppVariables2 as useAppVariables,
3137
- useDateFormatting2 as useDateFormatting,
3138
- useSvgId,
3139
- useViewTab2 as useViewTab
3140
- };
3141
-
3142
- //# debugId=3D3A9CC87FD5C9DB64756E2164756E21