derive-dashboards 0.1.0 → 0.2.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 (410) hide show
  1. package/README.md +8 -5
  2. package/dist/adapter/sql-adapter.mjs +4 -4
  3. package/dist/body.mjs +11 -1
  4. package/dist/cache.d.mts +1 -1
  5. package/dist/cli/add.mjs +130 -0
  6. package/dist/cli/check.mjs +14 -1
  7. package/dist/cli/cli.mjs +14 -12
  8. package/dist/cli/config.mjs +12 -1
  9. package/dist/cli/doctor.mjs +147 -0
  10. package/dist/cli/import/dbt-schema.mjs +2 -2
  11. package/dist/cli/import/index.mjs +2 -2
  12. package/dist/cli/init.mjs +3 -2
  13. package/dist/cli/json.mjs +21 -0
  14. package/dist/cli/layers.mjs +33 -0
  15. package/dist/core/conformance/cases.d.mts +3 -0
  16. package/dist/core/conformance/cases.mjs +20 -4
  17. package/dist/core/conformance/check.mjs +6 -3
  18. package/dist/core/conformance/drill-cases.mjs +120 -0
  19. package/dist/core/document/layout.mjs +1 -1
  20. package/dist/core/document/view-layout.d.mts +14 -0
  21. package/dist/core/document/view-layout.mjs +157 -0
  22. package/dist/core/document/view.d.mts +26 -7
  23. package/dist/core/document/view.mjs +42 -11
  24. package/dist/core/engine/filter.mjs +2 -2
  25. package/dist/core/engine/index.d.mts +14 -2
  26. package/dist/core/engine/index.mjs +12 -1
  27. package/dist/core/engine/leaf.mjs +9 -4
  28. package/dist/core/engine/members.mjs +2 -2
  29. package/dist/core/engine/postgres.mjs +1 -1
  30. package/dist/core/engine/record-layout.d.mts +11 -0
  31. package/dist/core/engine/record-layout.mjs +7 -7
  32. package/dist/core/engine/records.d.mts +3 -2
  33. package/dist/core/engine/records.mjs +2 -1
  34. package/dist/core/engine/segmented.mjs +5 -2
  35. package/dist/core/engine/sql-records.mjs +2 -1
  36. package/dist/core/engine/statement.mjs +37 -3
  37. package/dist/core/engine/types.d.mts +3 -0
  38. package/dist/core/engine/version.d.mts +1 -1
  39. package/dist/core/engine/version.mjs +1 -1
  40. package/dist/core/error/codes.d.mts +33 -1
  41. package/dist/core/error/codes.mjs +30 -2
  42. package/dist/core/index.d.mts +13 -7
  43. package/dist/core/index.mjs +9 -5
  44. package/dist/core/model/catalog/check.mjs +1 -1
  45. package/dist/core/model/hints.d.mts +36 -0
  46. package/dist/core/model/member.d.mts +4 -2
  47. package/dist/core/model/member.mjs +19 -3
  48. package/dist/core/model/types.d.mts +21 -19
  49. package/dist/core/model/validate/drill.mjs +70 -0
  50. package/dist/core/model/validate/index.mjs +3 -0
  51. package/dist/core/model/validate/members.mjs +7 -4
  52. package/dist/core/model/validate/shape.mjs +150 -0
  53. package/dist/core/model/validate/source.mjs +5 -3
  54. package/dist/core/policy/bind-query.d.mts +12 -0
  55. package/dist/core/policy/bind-query.mjs +53 -0
  56. package/dist/core/query/alias.mjs +7 -1
  57. package/dist/core/query/drill/compose.d.mts +22 -0
  58. package/dist/core/query/drill/compose.mjs +85 -0
  59. package/dist/core/query/drill/fields.d.mts +21 -0
  60. package/dist/core/query/drill/fields.mjs +91 -0
  61. package/dist/core/query/drill/internal.d.mts +11 -0
  62. package/dist/core/query/drill/items.d.mts +29 -0
  63. package/dist/core/query/drill/items.mjs +98 -0
  64. package/dist/core/query/drill/line.d.mts +31 -0
  65. package/dist/core/query/drill/line.mjs +183 -0
  66. package/dist/core/query/drill/links.d.mts +33 -0
  67. package/dist/core/query/drill/links.mjs +31 -0
  68. package/dist/core/query/drill/operand.mjs +7 -0
  69. package/dist/core/query/drill/scopes.d.mts +22 -0
  70. package/dist/core/query/drill/scopes.mjs +58 -0
  71. package/dist/core/query/drill/selection.d.mts +37 -0
  72. package/dist/core/query/drill/selection.mjs +144 -0
  73. package/dist/core/query/drill/steps.d.mts +14 -0
  74. package/dist/core/query/drill/steps.mjs +35 -0
  75. package/dist/core/query/drill/synthetic-expr.mjs +85 -0
  76. package/dist/core/query/drill/synthetic.d.mts +22 -0
  77. package/dist/core/query/drill/synthetic.mjs +165 -0
  78. package/dist/core/query/drill/time.d.mts +11 -0
  79. package/dist/core/query/drill/time.mjs +71 -0
  80. package/dist/core/query/drill/types.d.mts +155 -0
  81. package/dist/core/query/drill/types.mjs +4 -0
  82. package/dist/core/query/drill/views.d.mts +62 -0
  83. package/dist/core/query/drill/views.mjs +257 -0
  84. package/dist/core/query/filter.d.mts +6 -0
  85. package/dist/core/query/picks.d.mts +8 -2
  86. package/dist/core/query/picks.mjs +11 -4
  87. package/dist/core/query/segments.d.mts +12 -2
  88. package/dist/core/query/segments.mjs +5 -2
  89. package/dist/core/result/columns.mjs +20 -4
  90. package/dist/core/result/types.d.mts +5 -1
  91. package/dist/core/schema/aliases.d.mts +7 -0
  92. package/dist/core/schema/aliases.mjs +77 -0
  93. package/dist/core/schema/answer-parts.mjs +117 -0
  94. package/dist/core/schema/answers.d.mts +2109 -128
  95. package/dist/core/schema/answers.mjs +11 -113
  96. package/dist/core/schema/commands.d.mts +2 -2
  97. package/dist/core/schema/document.d.mts +1 -1
  98. package/dist/core/schema/drill-answers.mjs +179 -0
  99. package/dist/core/schema/drill.d.mts +260 -0
  100. package/dist/core/schema/drill.mjs +107 -0
  101. package/dist/core/schema/index.d.mts +6 -3
  102. package/dist/core/schema/index.mjs +6 -3
  103. package/dist/core/schema/picks.d.mts +35 -0
  104. package/dist/core/schema/picks.mjs +23 -0
  105. package/dist/core/schema/query.d.mts +82 -1
  106. package/dist/core/schema/query.mjs +9 -5
  107. package/dist/core/schema/tools.mjs +1 -1
  108. package/dist/core/schema/view.d.mts +0 -35
  109. package/dist/core/schema/view.mjs +19 -24
  110. package/dist/core/store/schema.d.mts +5 -0
  111. package/dist/core/store/schema.mjs +10 -0
  112. package/dist/core/types/api.d.mts +21 -1
  113. package/dist/core/types/api.mjs +1 -1
  114. package/dist/core/types/drill-api.d.mts +210 -0
  115. package/dist/core/types/options.d.mts +21 -0
  116. package/dist/core/types/viewer.d.mts +5 -0
  117. package/dist/cursor-seal.d.mts +8 -0
  118. package/dist/cursor-seal.mjs +98 -0
  119. package/dist/dashboard-id.mjs +1 -1
  120. package/dist/dashboards.mjs +4 -0
  121. package/dist/drill-access.mjs +93 -0
  122. package/dist/drill-change.mjs +76 -0
  123. package/dist/drill-crumbs.mjs +113 -0
  124. package/dist/drill-distinct.mjs +130 -0
  125. package/dist/drill-explain.mjs +64 -0
  126. package/dist/drill-identity.mjs +35 -0
  127. package/dist/drill-item-id.mjs +35 -0
  128. package/dist/drill-items.mjs +132 -0
  129. package/dist/drill-open.mjs +169 -0
  130. package/dist/drill-seal.mjs +170 -0
  131. package/dist/drill-secret.mjs +14 -0
  132. package/dist/drill-share.mjs +53 -0
  133. package/dist/drill-summary.mjs +158 -0
  134. package/dist/drill-targets.mjs +53 -0
  135. package/dist/drill-totals.mjs +8 -0
  136. package/dist/drill-views.mjs +175 -0
  137. package/dist/drill.mjs +157 -0
  138. package/dist/editing.mjs +3 -3
  139. package/dist/endpoints/dashboards.mjs +28 -5
  140. package/dist/endpoints/drill.mjs +55 -0
  141. package/dist/endpoints/index.d.mts +245 -4
  142. package/dist/endpoints/index.mjs +5 -1
  143. package/dist/endpoints/meta.mjs +10 -1
  144. package/dist/endpoints/query.mjs +26 -4
  145. package/dist/execute.d.mts +19 -1
  146. package/dist/execute.mjs +34 -27
  147. package/dist/handler.mjs +5 -1
  148. package/dist/index.d.mts +3 -1
  149. package/dist/index.mjs +29 -2
  150. package/dist/llms.txt +22 -0
  151. package/dist/mcp/drill.mjs +61 -0
  152. package/dist/mcp/format.mjs +69 -11
  153. package/dist/mcp/index.d.mts +15 -4
  154. package/dist/mcp/index.mjs +13 -7
  155. package/dist/mcp/query.d.mts +7 -2
  156. package/dist/mcp/query.mjs +40 -6
  157. package/dist/node-postgres.d.mts +8 -4
  158. package/dist/node-postgres.mjs +29 -6
  159. package/dist/owner.mjs +3 -3
  160. package/dist/postgres-connection.d.mts +8 -2
  161. package/dist/postgres-connection.mjs +2 -1
  162. package/dist/postgres-store.mjs +1 -0
  163. package/dist/react/Canvas.mjs +28 -5
  164. package/dist/react/Cell.mjs +2 -1
  165. package/dist/react/Dashboard.d.mts +10 -5
  166. package/dist/react/Dashboard.mjs +62 -22
  167. package/dist/react/DashboardList.mjs +52 -24
  168. package/dist/react/DashboardListRow.mjs +49 -0
  169. package/dist/react/Discard.mjs +12 -4
  170. package/dist/react/Editing.mjs +19 -5
  171. package/dist/react/FilterBar.d.mts +7 -9
  172. package/dist/react/Grid.mjs +19 -24
  173. package/dist/react/Header.mjs +10 -1
  174. package/dist/react/History.mjs +5 -0
  175. package/dist/react/Parts.mjs +6 -2
  176. package/dist/react/ReadFailed.mjs +23 -0
  177. package/dist/react/ReviewPanel.mjs +13 -2
  178. package/dist/react/RowBody.d.mts +19 -0
  179. package/dist/react/RowBody.mjs +55 -0
  180. package/dist/react/Spaces.mjs +15 -1
  181. package/dist/react/Tile.d.mts +3 -1
  182. package/dist/react/Tile.mjs +84 -32
  183. package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
  184. package/dist/react/arrange-steps.mjs +16 -13
  185. package/dist/react/arrange.mjs +10 -3
  186. package/dist/react/builder/Calcs.mjs +35 -11
  187. package/dist/react/builder/FilterEditor.mjs +196 -0
  188. package/dist/react/builder/Filters.mjs +172 -116
  189. package/dist/react/builder/Formula.mjs +82 -0
  190. package/dist/react/builder/Groups.mjs +1 -0
  191. package/dist/react/builder/Preview.mjs +1 -1
  192. package/dist/react/builder/RangeEditor.mjs +184 -0
  193. package/dist/react/builder/Sections.mjs +41 -6
  194. package/dist/react/builder/Time.mjs +138 -60
  195. package/dist/react/builder/Values.mjs +85 -0
  196. package/dist/react/builder/WidgetBuilder.mjs +50 -49
  197. package/dist/react/builder/base.d.mts +5 -0
  198. package/dist/react/builder/base.mjs +33 -8
  199. package/dist/react/builder/calc.mjs +15 -1
  200. package/dist/react/builder/escape.d.mts +1 -0
  201. package/dist/react/builder/escape.mjs +62 -0
  202. package/dist/react/builder/filter-tree.d.mts +9 -0
  203. package/dist/react/builder/filter-tree.mjs +186 -0
  204. package/dist/react/builder/formula-parse.d.mts +18 -0
  205. package/dist/react/builder/formula-parse.mjs +136 -0
  206. package/dist/react/builder/labels.d.mts +1 -1
  207. package/dist/react/builder/state.d.mts +2 -1
  208. package/dist/react/builder/state.mjs +23 -37
  209. package/dist/react/builder/useBuilder.d.mts +12 -1
  210. package/dist/react/builder/useBuilder.mjs +6 -3
  211. package/dist/react/builder/words.d.mts +59 -0
  212. package/dist/react/builder/words.mjs +73 -0
  213. package/dist/react/client.d.mts +2 -0
  214. package/dist/react/client.mjs +1 -0
  215. package/dist/react/context.d.mts +28 -1
  216. package/dist/react/context.mjs +25 -4
  217. package/dist/react/drill/Bars.mjs +179 -0
  218. package/dist/react/drill/Controls.mjs +173 -0
  219. package/dist/react/drill/DashboardTile.d.mts +18 -0
  220. package/dist/react/drill/DashboardTile.mjs +107 -0
  221. package/dist/react/drill/DrillPanel.d.mts +31 -0
  222. package/dist/react/drill/DrillPanel.mjs +104 -0
  223. package/dist/react/drill/DrillTabs.mjs +52 -0
  224. package/dist/react/drill/Header.mjs +131 -0
  225. package/dist/react/drill/Items.d.mts +22 -0
  226. package/dist/react/drill/Items.mjs +164 -0
  227. package/dist/react/drill/ItemsFoot.mjs +60 -0
  228. package/dist/react/drill/Notes.mjs +58 -0
  229. package/dist/react/drill/PanelBody.mjs +74 -0
  230. package/dist/react/drill/PanelStates.mjs +37 -0
  231. package/dist/react/drill/board.d.mts +18 -0
  232. package/dist/react/drill/board.mjs +91 -0
  233. package/dist/react/drill/counts.mjs +14 -0
  234. package/dist/react/drill/host.mjs +26 -0
  235. package/dist/react/drill/item-parts.d.mts +5 -0
  236. package/dist/react/drill/item-parts.mjs +76 -0
  237. package/dist/react/drill/item-type.d.mts +26 -0
  238. package/dist/react/drill/item-type.mjs +7 -0
  239. package/dist/react/drill/lazy.d.mts +6 -0
  240. package/dist/react/drill/lazy.mjs +17 -0
  241. package/dist/react/drill/pages.mjs +48 -0
  242. package/dist/react/drill/panel-focus.mjs +51 -0
  243. package/dist/react/drill/props.d.mts +25 -0
  244. package/dist/react/drill/props.mjs +72 -0
  245. package/dist/react/drill/state.d.mts +18 -0
  246. package/dist/react/drill/state.mjs +68 -0
  247. package/dist/react/drill/useDrill.d.mts +46 -0
  248. package/dist/react/drill/useDrill.mjs +194 -0
  249. package/dist/react/drill/words.d.mts +101 -0
  250. package/dist/react/drill/words.mjs +79 -0
  251. package/dist/react/english.mjs +29 -6
  252. package/dist/react/filters/bar.d.mts +12 -0
  253. package/dist/react/filters/bar.mjs +135 -0
  254. package/dist/react/filters/calendar.mjs +193 -0
  255. package/dist/react/filters/chip.mjs +174 -0
  256. package/dist/react/filters/context.d.mts +22 -0
  257. package/dist/react/filters/context.mjs +78 -0
  258. package/dist/react/filters/dates.mjs +89 -0
  259. package/dist/react/filters/days.d.mts +36 -0
  260. package/dist/react/filters/days.mjs +87 -0
  261. package/dist/react/filters/field-step.mjs +81 -0
  262. package/dist/react/filters/hooks.d.mts +34 -0
  263. package/dist/react/filters/hooks.mjs +94 -0
  264. package/dist/react/filters/listbox.mjs +131 -0
  265. package/dist/react/filters/logic.d.mts +59 -0
  266. package/dist/react/filters/logic.mjs +109 -0
  267. package/dist/react/filters/menu-search.mjs +211 -0
  268. package/dist/react/filters/menu.mjs +85 -0
  269. package/dist/react/filters/number.mjs +127 -0
  270. package/dist/react/filters/numbers.d.mts +47 -0
  271. package/dist/react/filters/numbers.mjs +151 -0
  272. package/dist/react/filters/operator.mjs +104 -0
  273. package/dist/react/filters/phone.mjs +104 -0
  274. package/dist/react/filters/popover.d.mts +19 -0
  275. package/dist/react/filters/popover.mjs +153 -0
  276. package/dist/react/filters/rules.d.mts +8 -0
  277. package/dist/react/filters/rules.mjs +55 -0
  278. package/dist/react/filters/sheet.mjs +196 -0
  279. package/dist/react/filters/state.mjs +132 -0
  280. package/dist/react/filters/suggest.d.mts +47 -0
  281. package/dist/react/filters/suggest.mjs +97 -0
  282. package/dist/react/filters/values.mjs +166 -0
  283. package/dist/react/filters/words.d.mts +81 -0
  284. package/dist/react/filters/words.mjs +73 -0
  285. package/dist/react/format.d.mts +3 -3
  286. package/dist/react/format.mjs +45 -16
  287. package/dist/react/index.d.mts +34 -5
  288. package/dist/react/index.mjs +15 -4
  289. package/dist/react/messages.d.mts +47 -2
  290. package/dist/react/place.mjs +7 -3
  291. package/dist/react/renderers/index.d.mts +10 -2
  292. package/dist/react/renderers/index.mjs +116 -14
  293. package/dist/react/renderers/list.d.mts +22 -0
  294. package/dist/react/renderers/list.mjs +118 -0
  295. package/dist/react/review-words.mjs +1 -1
  296. package/dist/react/review.mjs +2 -2
  297. package/dist/react/scope.mjs +2 -7
  298. package/dist/react/series.d.mts +54 -0
  299. package/dist/react/series.mjs +191 -0
  300. package/dist/react/theme.css +2734 -1296
  301. package/dist/react/theme.css.d.ts +1 -0
  302. package/dist/react/tile-store.mjs +15 -3
  303. package/dist/react/useBoard.d.mts +7 -0
  304. package/dist/react/useBoard.mjs +4 -1
  305. package/dist/react/useDashboard.d.mts +4 -0
  306. package/dist/react/useDashboard.mjs +8 -1
  307. package/dist/react/useTiles.mjs +50 -15
  308. package/dist/react/view-grid.mjs +16 -0
  309. package/dist/react/view.d.mts +9 -0
  310. package/dist/react/view.mjs +22 -10
  311. package/dist/reading.d.mts +2 -0
  312. package/dist/reading.mjs +9 -1
  313. package/dist/recharts/axes.mjs +28 -0
  314. package/dist/recharts/axis.mjs +84 -0
  315. package/dist/recharts/bar.d.mts +7 -0
  316. package/dist/recharts/bar.mjs +140 -0
  317. package/dist/recharts/charts.d.mts +4 -6
  318. package/dist/recharts/charts.mjs +2 -114
  319. package/dist/recharts/index.d.mts +5 -3
  320. package/dist/recharts/index.mjs +6 -3
  321. package/dist/recharts/line.d.mts +2 -0
  322. package/dist/recharts/line.mjs +111 -0
  323. package/dist/recharts/marks.mjs +112 -0
  324. package/dist/recharts/parts.mjs +88 -0
  325. package/dist/recharts/series.d.mts +2 -22
  326. package/dist/recharts/series.mjs +1 -64
  327. package/dist/recharts/table.mjs +71 -0
  328. package/dist/records-read.mjs +44 -0
  329. package/dist/registry/filter-bar.json +26 -0
  330. package/dist/skills/derive-dashboards/SKILL.md +69 -0
  331. package/dist/store/apply.mjs +5 -5
  332. package/dist/store/commands.mjs +4 -4
  333. package/dist/store/discard.mjs +7 -7
  334. package/dist/store/drafts.mjs +5 -5
  335. package/dist/store/editor.mjs +1 -1
  336. package/dist/store/publish.mjs +12 -12
  337. package/dist/store/reader.mjs +41 -22
  338. package/dist/store/review.mjs +16 -16
  339. package/dist/store/rows.mjs +20 -20
  340. package/dist/store/undo.mjs +3 -3
  341. package/dist/store/unpublished.mjs +4 -4
  342. package/dist/store/versions.mjs +14 -14
  343. package/dist/testing/adapter-suite.mjs +4 -4
  344. package/dist/tiles.mjs +37 -3
  345. package/package.json +12 -10
  346. package/dist/react/FilterBar.mjs +0 -119
  347. package/dist/react/Records.d.mts +0 -12
  348. package/dist/react/Records.mjs +0 -97
  349. package/src/adapter/sql-adapter.ts +0 -95
  350. package/src/adapter/statement.ts +0 -185
  351. package/src/authorize.ts +0 -73
  352. package/src/body.ts +0 -169
  353. package/src/bounded.ts +0 -43
  354. package/src/cache.ts +0 -192
  355. package/src/checks.ts +0 -170
  356. package/src/custom-source.ts +0 -59
  357. package/src/dashboard-id.ts +0 -36
  358. package/src/dashboards.ts +0 -132
  359. package/src/editing.ts +0 -148
  360. package/src/endpoints/access.ts +0 -41
  361. package/src/endpoints/dashboards.ts +0 -92
  362. package/src/endpoints/drafts.ts +0 -138
  363. package/src/endpoints/index.ts +0 -21
  364. package/src/endpoints/meta.ts +0 -137
  365. package/src/endpoints/query.ts +0 -86
  366. package/src/endpoints/read.ts +0 -92
  367. package/src/endpoints/review.ts +0 -89
  368. package/src/endpoints/values.ts +0 -62
  369. package/src/endpoints/versions.ts +0 -104
  370. package/src/execute.ts +0 -207
  371. package/src/handler.ts +0 -232
  372. package/src/http.ts +0 -66
  373. package/src/index.ts +0 -163
  374. package/src/introspect.ts +0 -205
  375. package/src/mcp/api.ts +0 -59
  376. package/src/mcp/format.ts +0 -67
  377. package/src/mcp/index.ts +0 -151
  378. package/src/mcp/query.ts +0 -153
  379. package/src/mcp/resolve.ts +0 -114
  380. package/src/node-postgres.ts +0 -81
  381. package/src/owner.ts +0 -36
  382. package/src/postgres-connection.ts +0 -143
  383. package/src/postgres-store.ts +0 -82
  384. package/src/principal.ts +0 -39
  385. package/src/reading.ts +0 -56
  386. package/src/request-rows.ts +0 -23
  387. package/src/request.ts +0 -22
  388. package/src/storage.ts +0 -63
  389. package/src/store/apply.ts +0 -129
  390. package/src/store/commands.ts +0 -75
  391. package/src/store/conflicts.ts +0 -98
  392. package/src/store/create-tables.ts +0 -104
  393. package/src/store/discard.ts +0 -42
  394. package/src/store/drafts.ts +0 -133
  395. package/src/store/editor.ts +0 -28
  396. package/src/store/log.ts +0 -28
  397. package/src/store/publish.ts +0 -199
  398. package/src/store/publisher.ts +0 -21
  399. package/src/store/reader.ts +0 -139
  400. package/src/store/review.ts +0 -239
  401. package/src/store/rows.ts +0 -250
  402. package/src/store/tenant.ts +0 -28
  403. package/src/store/undo.ts +0 -56
  404. package/src/store/unpublished.ts +0 -33
  405. package/src/store/versions.ts +0 -106
  406. package/src/store/writer.ts +0 -19
  407. package/src/testing/adapter-suite.ts +0 -239
  408. package/src/testing/index.ts +0 -2
  409. package/src/tile-doc.ts +0 -46
  410. package/src/tiles.ts +0 -120
@@ -1,29 +1,125 @@
1
1
  import { formatCell } from "../format.mjs";
2
+ import { ListTile } from "./list.mjs";
2
3
  import { isMark } from "derive-dashboards/core";
3
4
  import { jsx, jsxs } from "react/jsx-runtime";
4
5
  // src/renderers/index.tsx
5
6
  const isMeasure = (column) => column.id.startsWith("m") || column.id.startsWith("c");
6
7
  const isAll = (cell) => isMark(cell) && cell.mark === "all";
8
+ /** A calc is what the query was built to show (a share, a rate); else its first value. */
9
+ const shownIndex = (columns) => {
10
+ const calc = columns.findIndex((c) => c.id.startsWith("c") && c.signed !== true);
11
+ return calc === -1 ? columns.findIndex((c) => isMeasure(c)) : calc;
12
+ };
7
13
  /**
8
- * The first value column, large, from the total row when there is one, else the first row;
14
+ * The first calc or value column, large, from the total row when there is one, else the first row;
9
15
  * a change calc (a signed column) sits under it.
10
16
  */
11
17
  function NumberTile(props) {
12
18
  const { answer } = props;
13
- const index = answer.columns.findIndex(isMeasure);
19
+ const index = shownIndex(answer.columns);
14
20
  const change = answer.columns.findIndex((c) => c.signed === true);
15
21
  const row = answer.rows.find((cells) => cells.some((cell) => isAll(cell))) ?? answer.rows[0];
16
22
  const cell = row?.[index] ?? null;
23
+ const entry = answer.columns[index]?.id;
24
+ const marks = row === void 0 ? void 0 : props.drill?.props(row, entry);
17
25
  return /* @__PURE__ */ jsxs("div", {
18
26
  className: "dd-number",
19
- children: [/* @__PURE__ */ jsx("span", {
20
- className: "dd-number-value",
21
- title: formatCell(cell, answer.columns[index], props),
22
- children: formatCell(cell, answer.columns[index], props)
23
- }), change === -1 ? null : /* @__PURE__ */ jsx("span", {
24
- className: "dd-number-change",
25
- children: formatCell(row?.[change] ?? null, answer.columns[change], props)
26
- })]
27
+ children: [
28
+ /* @__PURE__ */ jsx("span", {
29
+ className: "dd-number-value",
30
+ title: formatCell(cell, answer.columns[index], props),
31
+ ...marks,
32
+ children: formatCell(cell, answer.columns[index], props)
33
+ }),
34
+ change === -1 ? null : /* @__PURE__ */ jsx("span", {
35
+ className: "dd-number-change",
36
+ children: formatCell(row?.[change] ?? null, answer.columns[change], props)
37
+ }),
38
+ /* @__PURE__ */ jsx(Before, {
39
+ ...props,
40
+ index
41
+ })
42
+ ]
43
+ });
44
+ }
45
+ /** A cell as a number, for the change against the period before. */
46
+ const numberOf = (cell) => {
47
+ if (typeof cell === "number") return cell;
48
+ if (cell !== null && typeof cell === "object" && "v" in cell) return Number(cell.v);
49
+ };
50
+ const PLAIN_DECIMAL = /^-?\d+(\.\d+)?$/u;
51
+ /** A cell's exact digits ("12.50"), when it has them: exact cells, and whole JS numbers. */
52
+ const digitsOf = (cell) => {
53
+ if (typeof cell === "number") return Number.isSafeInteger(cell) ? String(cell) : void 0;
54
+ if (cell !== null && typeof cell === "object" && "v" in cell && typeof cell.v === "string") return PLAIN_DECIMAL.test(cell.v) ? cell.v : void 0;
55
+ };
56
+ /** A decimal as an integer of `scale` fraction digits: "12.5" at scale 2 is 1250n. */
57
+ const scaled = (digits, scale) => {
58
+ const negative = digits.startsWith("-");
59
+ const [whole = "0", fraction = ""] = digits.replace("-", "").split(".");
60
+ return BigInt(`${negative ? "-" : ""}${whole}${fraction.padEnd(scale, "0")}`);
61
+ };
62
+ /** now − was in floats, for values that are not exact digits. */
63
+ function floatDifference(now, was) {
64
+ const [x, y] = [numberOf(now), numberOf(was)];
65
+ if (x === void 0 || y === void 0) return void 0;
66
+ return {
67
+ sign: Math.sign(x - y),
68
+ size: Math.abs(x - y)
69
+ };
70
+ }
71
+ /** a − b of two decimal strings, exactly, as a cell of `type`. */
72
+ function exactDifference(a, b, type) {
73
+ const scale = Math.max(a.split(".")[1]?.length ?? 0, b.split(".")[1]?.length ?? 0);
74
+ const d = scaled(a, scale) - scaled(b, scale);
75
+ const abs = (d < 0n ? -d : d).toString().padStart(scale + 1, "0");
76
+ const v = scale === 0 ? abs : `${abs.slice(0, -scale)}.${abs.slice(-scale)}`;
77
+ return {
78
+ sign: d === 0n ? 0 : d > 0n ? 1 : -1,
79
+ size: {
80
+ t: type,
81
+ v
82
+ }
83
+ };
84
+ }
85
+ /**
86
+ * now − was, exactly when both are exact (a 2^53 amount that moved by 1 moved by 1), else in
87
+ * floats; its sign and its size as a cell to format. Undefined when either is not a number.
88
+ */
89
+ function difference(now, was) {
90
+ const [a, b] = [digitsOf(now), digitsOf(was)];
91
+ if (a === void 0 || b === void 0) return floatDifference(now, was);
92
+ return exactDifference(a, b, typeof now === "object" && now !== null && "t" in now ? now.t : "decimal");
93
+ }
94
+ /** What the period before says: "+17 from 0", "No change from 12", or the bare value when it is not a number. */
95
+ function beforeText(props, column, now, was) {
96
+ const wasText = formatCell(was, column, props);
97
+ const delta = difference(now, was);
98
+ if (delta === void 0) return props.messages.drillBefore(wasText);
99
+ if (delta.sign === 0) return props.messages.beforeSame(wasText);
100
+ const change = `${delta.sign > 0 ? "+" : "−"}${formatCell(delta.size, column, props)}`;
101
+ return props.messages.beforeChange(change, wasText);
102
+ }
103
+ /**
104
+ * The change against the period before, when the answer compares ("+17 from 0"): it opens that
105
+ * period's rows. No value before (a rate over no rows) says nothing, so it is left out.
106
+ */
107
+ function Before(props) {
108
+ const { answer, index } = props;
109
+ const before = answer.compare?.rows[0];
110
+ const column = answer.columns[index];
111
+ const was = before?.[index] ?? null;
112
+ if (before === void 0 || column === void 0 || was === null) return null;
113
+ const marks = props.drill?.props(before, column.id);
114
+ const text = beforeText(props, column, answer.rows[0]?.[index], was);
115
+ const named = marks === void 0 ? marks : {
116
+ ...marks,
117
+ "aria-label": props.messages.drillMark(text)
118
+ };
119
+ return /* @__PURE__ */ jsx("span", {
120
+ className: "dd-number-before",
121
+ ...named,
122
+ children: text
27
123
  });
28
124
  }
29
125
  /** Cells as table cells: a run of equal marks is one cell spanning its columns. */
@@ -41,10 +137,13 @@ function spans(cells) {
41
137
  return out;
42
138
  }
43
139
  /** One table row. A row that folds dimensions is a summary, labelled where it folds them. */
44
- function Row({ cells, columns, format }) {
140
+ function Row({ cells, columns, format, drill }) {
45
141
  const summary = cells.some((cell) => isMark(cell));
142
+ const whole = drill?.props(cells);
143
+ const cellMarks = (column) => whole === void 0 && column !== void 0 && isMeasure(column) ? drill?.props(cells, column.id) : void 0;
46
144
  return /* @__PURE__ */ jsx("tr", {
47
145
  className: summary ? "dd-table-summary" : void 0,
146
+ ...whole,
48
147
  children: spans(cells).map(({ cell, at, span }) => {
49
148
  const column = columns[at];
50
149
  const numeric = column !== void 0 && isMeasure(column);
@@ -55,7 +154,8 @@ function Row({ cells, columns, format }) {
55
154
  }, column?.id ?? at);
56
155
  return /* @__PURE__ */ jsx("td", {
57
156
  "data-numeric": numeric,
58
- children: cell === null && column !== void 0 && !numeric ? format.messages.empty : formatCell(cell, column, format)
157
+ ...cellMarks(column),
158
+ children: cell === null && column !== void 0 && !numeric ? format.messages.drillNone(column.label) : formatCell(cell, column, format)
59
159
  }, column?.id ?? at);
60
160
  })
61
161
  });
@@ -74,12 +174,14 @@ function TableTile(props) {
74
174
  }, c.id)) }) }), /* @__PURE__ */ jsx("tbody", { children: answer.rows.map((cells) => /* @__PURE__ */ jsx(Row, {
75
175
  cells,
76
176
  columns,
77
- format: props
177
+ format: props,
178
+ drill: props.drill
78
179
  }, JSON.stringify(cells.slice(0, keys)))) })]
79
180
  });
80
181
  }
81
182
  const BUILTIN_RENDERERS = {
82
183
  number: NumberTile,
83
- table: TableTile
184
+ table: TableTile,
185
+ list: ListTile
84
186
  };
85
187
  export { BUILTIN_RENDERERS, NumberTile, TableTile };
@@ -0,0 +1,22 @@
1
+ import { TileRendererProps } from "./index.mjs";
2
+ /**
3
+ * How a list draws its rows, by the query's entry ids. Every key is optional: with none, the
4
+ * first group is the title, the other groups the subtitle, and the last value the number.
5
+ */
6
+ export type ListDisplay = {
7
+ /** The entry shown as the row's title. */
8
+ title?: string;
9
+ /** Entries shown under the title, joined with a dot. */
10
+ subtitle?: readonly string[];
11
+ /** The entry whose initials make the row's avatar. */
12
+ avatar?: string;
13
+ /** The number at the end of the row. */
14
+ meta?: string;
15
+ /** A link per row, with `{entry}` replaced by that entry's value: "/a/{t}". */
16
+ href?: string;
17
+ };
18
+ /**
19
+ * Rows as a list: an avatar, a title, a subtitle and one number, each row a link into the
20
+ * app (`display.href`) or, without one, a drill like a table row. Summary rows are left out.
21
+ */
22
+ export declare function ListTile(props: TileRendererProps): import("react").JSX.Element;
@@ -0,0 +1,118 @@
1
+ import { formatCell } from "../format.mjs";
2
+ import { RowBody } from "../RowBody.mjs";
3
+ import { isMark } from "derive-dashboards/core";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/renderers/list.tsx
6
+ const initials = (text) => text.split(/[\s._@-]+/u).filter(Boolean).slice(0, 2).map((word) => word[0]?.toUpperCase()).join("");
7
+ const asText = (value) => typeof value === "string" ? value : void 0;
8
+ const asList = (value) => Array.isArray(value) && value.every((v) => typeof v === "string") ? value : void 0;
9
+ const isValue = (c) => c.id.startsWith("m") || c.id.startsWith("c");
10
+ /** With no display, the first group is the title, the others the subtitle, the last value the number. */
11
+ function defaults(columns) {
12
+ const groups = columns.filter((c) => !isValue(c)).map((c) => c.id);
13
+ const meta = columns.findLast((c) => isValue(c))?.id;
14
+ return {
15
+ title: groups[0],
16
+ subtitle: groups.slice(1),
17
+ meta
18
+ };
19
+ }
20
+ /**
21
+ * The answer names a query's entries by place (m1.. measures, d1.. groups, c1.. calcs), as the
22
+ * server runs it; `display` names them as the widget's query does. This maps one to the other.
23
+ */
24
+ function answerIds(widget) {
25
+ const query = widget.queries.main;
26
+ if (query === void 0) return /* @__PURE__ */ new Map();
27
+ return new Map([
28
+ ...query.measures.map((entry, i) => [entry.id, `m${String(i + 1)}`]),
29
+ ...(query.dimensions ?? []).map((entry, i) => [entry.id, `d${String(i + 1)}`]),
30
+ ...(query.calc ?? []).map((entry, i) => [entry.id, `c${String(i + 1)}`])
31
+ ]);
32
+ }
33
+ function readDisplay(widget, columns) {
34
+ const display = widget.display ?? {};
35
+ const ids = answerIds(widget);
36
+ const id = (entry) => entry === void 0 ? void 0 : ids.get(entry) ?? entry;
37
+ const fallback = defaults(columns);
38
+ const href = asText(display.href);
39
+ return {
40
+ title: id(asText(display.title)) ?? fallback.title,
41
+ subtitle: asList(display.subtitle)?.map((entry) => id(entry) ?? entry) ?? fallback.subtitle,
42
+ avatar: id(asText(display.avatar)),
43
+ meta: id(asText(display.meta)) ?? fallback.meta,
44
+ href: href?.replaceAll(/\{([^}]+)\}/gu, (_, entry) => `{${id(entry) ?? entry}}`)
45
+ };
46
+ }
47
+ const text = ({ cells, at, props }, id) => {
48
+ const index = at(id);
49
+ if (index === -1) return "";
50
+ const cell = cells[index] ?? null;
51
+ return cell === null ? "" : formatCell(cell, props.answer.columns[index], props);
52
+ };
53
+ /** A row's link: each `{entry}` in the template becomes that entry's raw value, encoded. */
54
+ const linkOf = (template, line) => {
55
+ let missing = false;
56
+ const href = template.replaceAll(/\{([^}]+)\}/gu, (_, id) => {
57
+ const cell = line.cells[line.at(id)];
58
+ if (cell === void 0 || cell === null || isMark(cell)) {
59
+ missing = true;
60
+ return "";
61
+ }
62
+ return encodeURIComponent(typeof cell === "object" ? cell.v : String(cell));
63
+ });
64
+ return missing ? void 0 : href;
65
+ };
66
+ function Anchor(props) {
67
+ const Link = props.link;
68
+ return Link === void 0 ? /* @__PURE__ */ jsx("a", {
69
+ className: "dd-lines-row",
70
+ href: props.href,
71
+ children: props.children
72
+ }) : /* @__PURE__ */ jsx(Link, {
73
+ className: "dd-lines-row",
74
+ href: props.href,
75
+ children: props.children
76
+ });
77
+ }
78
+ /**
79
+ * Rows as a list: an avatar, a title, a subtitle and one number, each row a link into the
80
+ * app (`display.href`) or, without one, a drill like a table row. Summary rows are left out.
81
+ */
82
+ function ListTile(props) {
83
+ const { answer } = props;
84
+ const shown = readDisplay(props.widget, answer.columns);
85
+ const at = (id) => answer.columns.findIndex((c) => c.id === id);
86
+ const rows = answer.rows.filter((cells) => !cells.some((cell) => isMark(cell)));
87
+ return /* @__PURE__ */ jsx("ul", {
88
+ className: "dd-lines",
89
+ children: rows.map((cells) => {
90
+ const line = {
91
+ cells,
92
+ at,
93
+ props
94
+ };
95
+ const row = {
96
+ title: text(line, shown.title) || props.messages.empty,
97
+ meta: shown.subtitle.map((id) => text(line, id)).filter(Boolean),
98
+ lead: shown.avatar === void 0 ? void 0 : initials(text(line, shown.avatar)),
99
+ value: text(line, shown.meta)
100
+ };
101
+ const body = /* @__PURE__ */ jsx(RowBody, {
102
+ row,
103
+ family: "lines"
104
+ });
105
+ const href = shown.href === void 0 ? void 0 : linkOf(shown.href, line);
106
+ return /* @__PURE__ */ jsx("li", { children: href === void 0 ? /* @__PURE__ */ jsx("div", {
107
+ className: "dd-lines-row",
108
+ ...props.drill?.props(cells),
109
+ children: body
110
+ }) : /* @__PURE__ */ jsx(Anchor, {
111
+ href,
112
+ link: props.link,
113
+ children: body
114
+ }) }, JSON.stringify(cells));
115
+ })
116
+ });
117
+ }
118
+ export { ListTile };
@@ -95,7 +95,7 @@ const ENGLISH_REVIEW = {
95
95
  decideFirst: "Decide each change that no longer applies, then publish.",
96
96
  addWidgetFirst: "Add a widget to publish this dashboard.",
97
97
  headMoved: (n, who) => `${who ?? "Someone"} published version ${String(n)} just now. Showing your changes on top of it.`,
98
- widgetGone: "was removed in the version you are publishing over.",
98
+ widgetGone: "its tile was removed in the version you are publishing over.",
99
99
  layoutGaps: "The layout has gaps.",
100
100
  closeGaps: "Pull tiles left",
101
101
  pullLeft: "Pull tiles left",
@@ -4,7 +4,7 @@ import { useState } from "react";
4
4
  // src/review.ts
5
5
  /** The preview of what publishing would do, loaded on request, with its failure kept to show. */
6
6
  function usePreview(dashboardId) {
7
- const { client } = useDashboards();
7
+ const { client, messages } = useDashboards();
8
8
  const [preview, setPreview] = useState();
9
9
  const [loading, setLoading] = useState(false);
10
10
  const [failed, setFailed] = useState();
@@ -16,7 +16,7 @@ function usePreview(dashboardId) {
16
16
  setPreview(next);
17
17
  return next;
18
18
  } catch (failure) {
19
- setFailed(failure instanceof Error ? failure.message : String(failure));
19
+ setFailed(failure instanceof TypeError ? messages.unreachable : failure instanceof Error ? failure.message : String(failure));
20
20
  return null;
21
21
  } finally {
22
22
  setLoading(false);
@@ -1,9 +1,4 @@
1
- import { createContext, useContext } from "react";
1
+ import { createContext } from "react";
2
2
  // src/scope.tsx
3
3
  const ScopeContext = createContext(null);
4
- function useDashboardScope() {
5
- const scope = useContext(ScopeContext);
6
- if (scope === null) throw new Error("This part is drawn only inside a <Dashboard>.");
7
- return scope;
8
- }
9
- export { ScopeContext, useDashboardScope };
4
+ export { ScopeContext };
@@ -0,0 +1,54 @@
1
+ import { CellFormat } from "./messages.mjs";
2
+ import { Receipt, ResultColumn, TileAnswer } from "derive-dashboards/core";
3
+ /** One point of a chart: its x label, its place (`#`, never an entry id) and a number per series key. */
4
+ export type Point = {
5
+ x: string;
6
+ } & Record<string, number | string | null>;
7
+ /**
8
+ * A drawn series: its key in each point, its label and the column it reads. `axis` is the side
9
+ * of the chart its scale is read on: values in another unit than the first get the right axis.
10
+ */
11
+ export type Series = {
12
+ key: string;
13
+ label: string;
14
+ column: ResultColumn;
15
+ axis: "left" | "right";
16
+ };
17
+ /** The series key a dimension's Other draws as. */
18
+ export declare const OTHER_KEY = "other";
19
+ /**
20
+ * Chart data from an answer. Key columns (in any order) are the x axis (the first, a time bucket
21
+ * when there is one) and, after it, what splits the series; value columns are what is drawn.
22
+ * With split keys, the first value (the first calc, when there are calcs) becomes one series per
23
+ * combination of the keys ("Design · High"), Other one more. Without, every value is a series.
24
+ * Values in a second unit are read on a right axis; a third unit, or more values than a split can
25
+ * draw, are not drawn and are named in `notDrawn`, never silently dropped. Points and series are
26
+ * keyed by raw values, so two that read alike stay apart. Totals are not drawn.
27
+ */
28
+ export declare function toSeries(answer: Pick<TileAnswer, "columns" | "rows">, format?: CellFormat): Drawn;
29
+ /**
30
+ * What a chart draws, and the way back from any chart kit's point to the answer's row:
31
+ * `rowAt(point, seriesKey)` gives the row's index in `answer.rows` (for a drill), or undefined
32
+ * for a point no row stands behind. `notDrawn` lists the values the chart leaves to the table.
33
+ */
34
+ export type Drawn = {
35
+ points: Point[];
36
+ series: Series[];
37
+ split: boolean;
38
+ notDrawn: ResultColumn[];
39
+ rowAt: (point: number | Point, seriesKey: string) => number | undefined;
40
+ };
41
+ /**
42
+ * The row of the answer behind a point of any chart kit's series, by the point's place (or the
43
+ * point) and the series key; undefined for a point no row stands behind. Pass it to
44
+ * `drill.open(row, series.column.id)` to open what is behind the point.
45
+ */
46
+ export declare const rowAt: (drawn: Drawn, point: number | Point, seriesKey: string) => number | undefined;
47
+ /**
48
+ * Whether the answer's last time bucket is still running: the range ends before the bucket
49
+ * does, as this week does on its Monday. Its value is not final, so a chart marks it rather
50
+ * than draw it as a fall.
51
+ */
52
+ export declare function lastBucketOpen(answer: Pick<TileAnswer, "columns" | "rows"> & {
53
+ receipt: Pick<Receipt, "range" | "calendar">;
54
+ }): boolean;
@@ -0,0 +1,191 @@
1
+ import { formatCell, plotValue } from "./format.mjs";
2
+ import { ENGLISH } from "./english.mjs";
3
+ import { isMark } from "derive-dashboards/core";
4
+ // src/series.ts
5
+ const isValue = (c) => c.id.startsWith("m") || c.id.startsWith("c");
6
+ /** The series key a dimension's Other draws as. */
7
+ const OTHER_KEY = "other";
8
+ const isAll = (cell) => isMark(cell) && cell.mark === "all";
9
+ /** What a value is read against: two columns share an axis only when this is equal. */
10
+ const scaleOf = (c) => JSON.stringify([
11
+ c.unit ?? null,
12
+ c.format ?? null,
13
+ c.fraction ?? null
14
+ ]);
15
+ /**
16
+ * Chart data from an answer. Key columns (in any order) are the x axis (the first, a time bucket
17
+ * when there is one) and, after it, what splits the series; value columns are what is drawn.
18
+ * With split keys, the first value (the first calc, when there are calcs) becomes one series per
19
+ * combination of the keys ("Design · High"), Other one more. Without, every value is a series.
20
+ * Values in a second unit are read on a right axis; a third unit, or more values than a split can
21
+ * draw, are not drawn and are named in `notDrawn`, never silently dropped. Points and series are
22
+ * keyed by raw values, so two that read alike stay apart. Totals are not drawn.
23
+ */
24
+ function toSeries(answer, format = {}) {
25
+ const at = /* @__PURE__ */ new Map();
26
+ const drawn = drawSeries(answer, format, (point, key, row) => {
27
+ at.set(`${String(point)}|${key}`, row);
28
+ });
29
+ return {
30
+ ...drawn,
31
+ rowAt: (point, key) => {
32
+ const index = typeof point === "number" ? point : drawn.points.indexOf(point);
33
+ return at.get(`${String(index)}|${key}`) ?? at.get(`${String(index)}|*`);
34
+ }
35
+ };
36
+ }
37
+ /** The values to draw: calcs when there are any (what the widget was built to see), else measures. */
38
+ function valuesOf(columns) {
39
+ const all = columns.filter((c) => isValue(c));
40
+ const calcs = all.filter((c) => c.id.startsWith("c"));
41
+ return calcs.length > 0 ? calcs : all;
42
+ }
43
+ function drawSeries(answer, format, seen) {
44
+ const keys = answer.columns.flatMap((c, i) => isValue(c) ? [] : [i]);
45
+ const values = valuesOf(answer.columns);
46
+ const rows = answer.rows.map((row, index) => ({
47
+ row,
48
+ index
49
+ })).filter(({ row }) => !row.some((cell) => isAll(cell)));
50
+ const keyText = (cell, column) => {
51
+ if (cell !== null && cell !== "") return formatCell(cell, column, format);
52
+ const words = format.messages ?? ENGLISH;
53
+ return column === void 0 ? words.empty : words.drillNone(column.label);
54
+ };
55
+ const shape = {
56
+ answer,
57
+ keys,
58
+ keyText,
59
+ seen
60
+ };
61
+ return keys.length < 2 ? plainSeries(rows, values, shape) : splitSeries(rows, values, shape);
62
+ }
63
+ /** The x label of a row, from its first key. */
64
+ const xOf = (shape, row) => {
65
+ const at = shape.keys[0];
66
+ return at === void 0 ? "" : shape.keyText(row[at] ?? null, shape.answer.columns[at]);
67
+ };
68
+ /** One series per value: the first unit on the left axis, a second on the right, a third not drawn. */
69
+ function plainSeries(rows, values, shape) {
70
+ const scales = [...new Set(values.map((c) => scaleOf(c)))];
71
+ const side = (c) => scales.indexOf(scaleOf(c));
72
+ const drawn = values.filter((c) => side(c) < 2);
73
+ const series = drawn.map((column) => ({
74
+ key: column.id,
75
+ label: column.label,
76
+ column,
77
+ axis: side(column) === 0 ? "left" : "right"
78
+ }));
79
+ return {
80
+ points: rows.map(({ row, index }, i) => {
81
+ shape.seen(i, "*", index);
82
+ const cells = drawn.map((c) => [c.id, plotValue(row[shape.answer.columns.indexOf(c)] ?? null)]);
83
+ return {
84
+ x: xOf(shape, row),
85
+ "#": i,
86
+ ...Object.fromEntries(cells)
87
+ };
88
+ }),
89
+ series,
90
+ split: false,
91
+ notDrawn: values.filter((c) => side(c) >= 2)
92
+ };
93
+ }
94
+ /** One value split into a series per combination of the keys after the first; other values are not drawn. */
95
+ function splitSeries(rows, values, shape) {
96
+ const [first, ...rest] = values;
97
+ if (first === void 0) return {
98
+ points: [],
99
+ series: [],
100
+ split: true,
101
+ notDrawn: []
102
+ };
103
+ const { answer, keys, keyText } = shape;
104
+ const valueAt = answer.columns.indexOf(first);
105
+ const byX = /* @__PURE__ */ new Map();
106
+ const names = /* @__PURE__ */ new Map();
107
+ for (const { row, index } of rows) {
108
+ const splitCells = keys.slice(1).map((i) => row[i] ?? null);
109
+ const key = splitKey(splitCells);
110
+ const label = splitCells.map((cell, i) => keyText(cell, answer.columns[keys[i + 1] ?? -1]));
111
+ names.set(key, label.join(" · "));
112
+ const xKey = JSON.stringify(row[keys[0] ?? 0] ?? null);
113
+ const point = byX.get(xKey) ?? {
114
+ x: xOf(shape, row),
115
+ "#": byX.size
116
+ };
117
+ point[key] = plotValue(row[valueAt] ?? null);
118
+ byX.set(xKey, point);
119
+ shape.seen(Number(point["#"]), key, index);
120
+ }
121
+ const series = [...names].map(([key, label]) => ({
122
+ key,
123
+ label,
124
+ column: first,
125
+ axis: "left"
126
+ })).toSorted((a, b) => Number(a.key === OTHER_KEY) - Number(b.key === OTHER_KEY));
127
+ return {
128
+ points: [...byX.values()],
129
+ series,
130
+ split: true,
131
+ notDrawn: rest
132
+ };
133
+ }
134
+ /** A series' key from its split cells: Other stays "other", any value is its raw JSON. */
135
+ function splitKey(cells) {
136
+ const [only] = cells;
137
+ if (cells.length === 1 && only !== void 0 && isMark(only)) return only.mark;
138
+ return `s${JSON.stringify(cells.length === 1 ? only ?? null : cells)}`;
139
+ }
140
+ /**
141
+ * The row of the answer behind a point of any chart kit's series, by the point's place (or the
142
+ * point) and the series key; undefined for a point no row stands behind. Pass it to
143
+ * `drill.open(row, series.column.id)` to open what is behind the point.
144
+ */
145
+ const rowAt = (drawn, point, seriesKey) => drawn.rowAt(point, seriesKey);
146
+ const DAY = 864e5;
147
+ const DAYS = {
148
+ day: 1,
149
+ week: 7
150
+ };
151
+ const MONTHS = {
152
+ month: 1,
153
+ quarter: 3,
154
+ year: 12
155
+ };
156
+ /** A calendar date ("2026-11-16") as the UTC midnight that names it. */
157
+ const dateOf = (text) => {
158
+ const [year = 0, month = 1, day = 1] = text.slice(0, 10).split("-").map(Number);
159
+ return Date.UTC(year, month - 1, day);
160
+ };
161
+ /** Where a bucket that starts on a calendar date ends, at its grain; none for a grain it cannot step. */
162
+ function bucketEnd(start, grain) {
163
+ const days = DAYS[grain];
164
+ if (days !== void 0) return start + days * DAY;
165
+ const months = MONTHS[grain];
166
+ if (months === void 0) return void 0;
167
+ const at = new Date(start);
168
+ return Date.UTC(at.getUTCFullYear(), at.getUTCMonth() + months, at.getUTCDate());
169
+ }
170
+ /** An instant as the calendar day it falls on in a zone, named as a bucket names its day. */
171
+ const dayIn = (instant, timeZone) => new Intl.DateTimeFormat("en-CA", {
172
+ timeZone,
173
+ year: "numeric",
174
+ month: "2-digit",
175
+ day: "2-digit"
176
+ }).format(new Date(instant));
177
+ /**
178
+ * Whether the answer's last time bucket is still running: the range ends before the bucket
179
+ * does, as this week does on its Monday. Its value is not final, so a chart marks it rather
180
+ * than draw it as a fall.
181
+ */
182
+ function lastBucketOpen(answer) {
183
+ const grain = answer.columns[0]?.grain;
184
+ const to = answer.receipt.range?.to;
185
+ const last = answer.rows.findLast((row) => typeof row[0] === "string")?.[0];
186
+ if (grain === void 0 || to === void 0 || typeof last !== "string") return false;
187
+ if (!/^\d{4}-\d{2}-\d{2}/u.test(last)) return false;
188
+ const end = bucketEnd(dateOf(last), grain);
189
+ return end !== void 0 && dateOf(dayIn(to, answer.receipt.calendar.timezone)) + DAY < end;
190
+ }
191
+ export { OTHER_KEY, lastBucketOpen, rowAt, toSeries };