derive-dashboards 0.5.1 → 0.7.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 (342) hide show
  1. package/README.md +4 -2
  2. package/dist/body.mjs +2 -2
  3. package/dist/charts/data/buckets.d.mts +11 -0
  4. package/dist/charts/data/buckets.mjs +66 -0
  5. package/dist/charts/data/clean.mjs +55 -0
  6. package/dist/charts/data/format.d.mts +19 -0
  7. package/dist/charts/data/format.mjs +174 -0
  8. package/dist/charts/data/input-error.d.mts +5 -0
  9. package/dist/charts/data/input-error.mjs +11 -0
  10. package/dist/charts/data/range.mjs +14 -0
  11. package/dist/charts/data/rows.d.mts +13 -0
  12. package/dist/charts/data/rows.mjs +31 -0
  13. package/dist/charts/data/shares.mjs +55 -0
  14. package/dist/charts/data/types.d.mts +106 -0
  15. package/dist/charts/data/words.d.mts +44 -0
  16. package/dist/charts/data/words.mjs +31 -0
  17. package/dist/charts/describe.mjs +110 -0
  18. package/dist/charts/index.d.mts +34 -0
  19. package/dist/charts/index.mjs +24 -0
  20. package/dist/charts/kinds/area-marks.mjs +120 -0
  21. package/dist/charts/kinds/area.d.mts +23 -0
  22. package/dist/charts/kinds/area.mjs +71 -0
  23. package/dist/charts/kinds/bars-data.d.mts +11 -0
  24. package/dist/charts/kinds/bars-data.mjs +30 -0
  25. package/dist/charts/kinds/bars-layout.mjs +30 -0
  26. package/dist/charts/kinds/bars-marks.mjs +93 -0
  27. package/dist/charts/kinds/bars-words.mjs +56 -0
  28. package/dist/charts/kinds/bars.d.mts +17 -0
  29. package/dist/charts/kinds/bars.mjs +68 -0
  30. package/dist/charts/kinds/columns-data.mjs +116 -0
  31. package/dist/charts/kinds/columns-layout.mjs +29 -0
  32. package/dist/charts/kinds/columns-marks.mjs +200 -0
  33. package/dist/charts/kinds/columns-words.mjs +26 -0
  34. package/dist/charts/kinds/columns.d.mts +13 -0
  35. package/dist/charts/kinds/columns.mjs +80 -0
  36. package/dist/charts/kinds/dumbbell-data.d.mts +22 -0
  37. package/dist/charts/kinds/dumbbell-data.mjs +59 -0
  38. package/dist/charts/kinds/dumbbell-layout.mjs +113 -0
  39. package/dist/charts/kinds/dumbbell-marks.mjs +119 -0
  40. package/dist/charts/kinds/dumbbell-words.d.mts +7 -0
  41. package/dist/charts/kinds/dumbbell-words.mjs +94 -0
  42. package/dist/charts/kinds/dumbbell.d.mts +14 -0
  43. package/dist/charts/kinds/dumbbell.mjs +67 -0
  44. package/dist/charts/kinds/funnel-data.d.mts +11 -0
  45. package/dist/charts/kinds/funnel-data.mjs +70 -0
  46. package/dist/charts/kinds/funnel-layout.mjs +32 -0
  47. package/dist/charts/kinds/funnel-marks.mjs +204 -0
  48. package/dist/charts/kinds/funnel-words.mjs +77 -0
  49. package/dist/charts/kinds/funnel.d.mts +11 -0
  50. package/dist/charts/kinds/funnel.mjs +75 -0
  51. package/dist/charts/kinds/grid-data.d.mts +18 -0
  52. package/dist/charts/kinds/grid-data.mjs +35 -0
  53. package/dist/charts/kinds/grid-layout.mjs +77 -0
  54. package/dist/charts/kinds/grid-marks.mjs +140 -0
  55. package/dist/charts/kinds/grid-time.mjs +41 -0
  56. package/dist/charts/kinds/grid-words.mjs +86 -0
  57. package/dist/charts/kinds/grid.d.mts +22 -0
  58. package/dist/charts/kinds/grid.mjs +55 -0
  59. package/dist/charts/kinds/histogram-data.mjs +142 -0
  60. package/dist/charts/kinds/histogram-layout.mjs +144 -0
  61. package/dist/charts/kinds/histogram-marks.mjs +110 -0
  62. package/dist/charts/kinds/histogram-words.mjs +104 -0
  63. package/dist/charts/kinds/histogram.d.mts +15 -0
  64. package/dist/charts/kinds/histogram.mjs +47 -0
  65. package/dist/charts/kinds/line-marks.mjs +36 -0
  66. package/dist/charts/kinds/line.d.mts +17 -0
  67. package/dist/charts/kinds/line.mjs +52 -0
  68. package/dist/charts/kinds/multiples-grid.mjs +107 -0
  69. package/dist/charts/kinds/multiples-head.mjs +44 -0
  70. package/dist/charts/kinds/multiples-layout.mjs +159 -0
  71. package/dist/charts/kinds/multiples-marks.mjs +95 -0
  72. package/dist/charts/kinds/multiples-words.mjs +110 -0
  73. package/dist/charts/kinds/multiples.d.mts +26 -0
  74. package/dist/charts/kinds/multiples.mjs +42 -0
  75. package/dist/charts/kinds/row-chart.mjs +112 -0
  76. package/dist/charts/kinds/row-marks.mjs +121 -0
  77. package/dist/charts/kinds/scatter-data.d.mts +18 -0
  78. package/dist/charts/kinds/scatter-data.mjs +123 -0
  79. package/dist/charts/kinds/scatter-layout.mjs +189 -0
  80. package/dist/charts/kinds/scatter-marks.mjs +149 -0
  81. package/dist/charts/kinds/scatter-words.mjs +80 -0
  82. package/dist/charts/kinds/scatter.d.mts +21 -0
  83. package/dist/charts/kinds/scatter.mjs +72 -0
  84. package/dist/charts/kinds/stat-data.mjs +91 -0
  85. package/dist/charts/kinds/stat-layout.mjs +108 -0
  86. package/dist/charts/kinds/stat-marks.mjs +85 -0
  87. package/dist/charts/kinds/stat-words.mjs +57 -0
  88. package/dist/charts/kinds/stat.d.mts +28 -0
  89. package/dist/charts/kinds/stat.mjs +35 -0
  90. package/dist/charts/kinds/time-chart.mjs +74 -0
  91. package/dist/charts/kinds/time-frame.mjs +113 -0
  92. package/dist/charts/kinds/time-notes.mjs +36 -0
  93. package/dist/charts/kinds/time-plan.d.mts +8 -0
  94. package/dist/charts/kinds/time-plan.mjs +57 -0
  95. package/dist/charts/kinds/time-plot.mjs +56 -0
  96. package/dist/charts/kinds/time-stops.mjs +56 -0
  97. package/dist/charts/kinds/value-plot.mjs +33 -0
  98. package/dist/charts/kinds/waterfall-data.d.mts +7 -0
  99. package/dist/charts/kinds/waterfall-data.mjs +71 -0
  100. package/dist/charts/kinds/waterfall-layout.mjs +38 -0
  101. package/dist/charts/kinds/waterfall-marks.mjs +82 -0
  102. package/dist/charts/kinds/waterfall-words.mjs +118 -0
  103. package/dist/charts/kinds/waterfall.d.mts +17 -0
  104. package/dist/charts/kinds/waterfall.mjs +66 -0
  105. package/dist/charts/layout/boxes.mjs +28 -0
  106. package/dist/charts/layout/dodge.mjs +75 -0
  107. package/dist/charts/layout/extent.mjs +25 -0
  108. package/dist/charts/layout/frame.mjs +97 -0
  109. package/dist/charts/layout/place-labels.mjs +101 -0
  110. package/dist/charts/layout/stack.mjs +31 -0
  111. package/dist/charts/marks/axes.mjs +137 -0
  112. package/dist/charts/marks/dot.mjs +31 -0
  113. package/dist/charts/marks/end-labels.mjs +124 -0
  114. package/dist/charts/marks/legend.mjs +141 -0
  115. package/dist/charts/marks/lines.d.mts +2 -0
  116. package/dist/charts/marks/lines.mjs +38 -0
  117. package/dist/charts/marks/lit.d.mts +3 -0
  118. package/dist/charts/marks/lit.mjs +63 -0
  119. package/dist/charts/marks/more.mjs +18 -0
  120. package/dist/charts/marks/notes.mjs +253 -0
  121. package/dist/charts/marks/series-line.mjs +110 -0
  122. package/dist/charts/marks/thin.mjs +138 -0
  123. package/dist/charts/marks/x-axis.mjs +32 -0
  124. package/dist/charts/scale/calendar.mjs +174 -0
  125. package/dist/charts/scale/time-ticks.mjs +154 -0
  126. package/dist/charts/scale/time.mjs +33 -0
  127. package/dist/charts/scale/value.mjs +161 -0
  128. package/dist/charts/scene/defs.mjs +33 -0
  129. package/dist/charts/scene/markup.mjs +35 -0
  130. package/dist/charts/scene/nearest.d.mts +11 -0
  131. package/dist/charts/scene/nearest.mjs +49 -0
  132. package/dist/charts/scene/paint.d.mts +12 -0
  133. package/dist/charts/scene/paint.mjs +13 -0
  134. package/dist/charts/scene/svg.d.mts +18 -0
  135. package/dist/charts/scene/svg.mjs +185 -0
  136. package/dist/charts/scene/types.d.mts +177 -0
  137. package/dist/charts/text/measure.d.mts +9 -0
  138. package/dist/charts/text/measure.mjs +123 -0
  139. package/dist/charts/theme.d.mts +47 -0
  140. package/dist/charts/theme.mjs +239 -0
  141. package/dist/charts-react/Chart.d.mts +91 -0
  142. package/dist/charts-react/Chart.mjs +166 -0
  143. package/dist/charts-react/Overlay.mjs +171 -0
  144. package/dist/charts-react/Picture.mjs +22 -0
  145. package/dist/charts-react/Reader.mjs +147 -0
  146. package/dist/charts-react/bucket-names.mjs +29 -0
  147. package/dist/charts-react/chart-unlayered.css +1 -0
  148. package/dist/charts-react/chart-unlayered.css.d.ts +1 -0
  149. package/dist/charts-react/chart.css +1 -0
  150. package/dist/charts-react/chart.css.d.ts +1 -0
  151. package/dist/charts-react/events.mjs +72 -0
  152. package/dist/charts-react/exact-sum.mjs +24 -0
  153. package/dist/charts-react/from-answer.mjs +185 -0
  154. package/dist/charts-react/index.d.mts +3 -0
  155. package/dist/charts-react/index.mjs +4 -0
  156. package/dist/charts-react/keys.mjs +117 -0
  157. package/dist/charts-react/opens.mjs +28 -0
  158. package/dist/charts-react/plan-bars.mjs +95 -0
  159. package/dist/charts-react/plan-funnel.mjs +120 -0
  160. package/dist/charts-react/plan-grid.mjs +121 -0
  161. package/dist/charts-react/plan-parts.d.mts +2 -0
  162. package/dist/charts-react/plan-parts.mjs +30 -0
  163. package/dist/charts-react/plan-time.mjs +84 -0
  164. package/dist/charts-react/plan.d.mts +3 -0
  165. package/dist/charts-react/plan.mjs +37 -0
  166. package/dist/charts-react/point-keys.mjs +22 -0
  167. package/dist/charts-react/pointer.mjs +99 -0
  168. package/dist/charts-react/reader-page.d.mts +8 -0
  169. package/dist/charts-react/reader-page.mjs +116 -0
  170. package/dist/charts-react/tiles.d.mts +24 -0
  171. package/dist/charts-react/tiles.mjs +142 -0
  172. package/dist/charts-react/tip-place.mjs +107 -0
  173. package/dist/charts-react/tip-room.mjs +31 -0
  174. package/dist/charts-react/useClientLayoutEffect.mjs +8 -0
  175. package/dist/charts-react/useScene.mjs +76 -0
  176. package/dist/charts-react/useSize.mjs +44 -0
  177. package/dist/charts-react/useStop.mjs +68 -0
  178. package/dist/core/conformance/memory/aggregate.mjs +2 -1
  179. package/dist/core/conformance/memory/rows.mjs +1 -1
  180. package/dist/core/conformance/memory/source.mjs +3 -2
  181. package/dist/core/document/display-comparisons.mjs +49 -0
  182. package/dist/core/document/display-entries.mjs +2 -1
  183. package/dist/core/document/display-validation.d.mts +12 -0
  184. package/dist/core/document/display-validation.mjs +56 -0
  185. package/dist/core/document/display.d.mts +27 -12
  186. package/dist/core/document/display.mjs +40 -49
  187. package/dist/core/document/view-layout.mjs +16 -0
  188. package/dist/core/engine/access.mjs +4 -2
  189. package/dist/core/engine/context.mjs +5 -7
  190. package/dist/core/engine/custom/cells.mjs +1 -1
  191. package/dist/core/engine/custom/records.mjs +2 -1
  192. package/dist/core/engine/dialect.d.mts +2 -0
  193. package/dist/core/engine/index.mjs +1 -1
  194. package/dist/core/engine/levels.mjs +33 -1
  195. package/dist/core/engine/plan.d.mts +2 -0
  196. package/dist/core/engine/postgres.mjs +1 -0
  197. package/dist/core/engine/rank.mjs +1 -1
  198. package/dist/core/engine/reader.d.mts +4 -0
  199. package/dist/core/engine/sql-partition.mjs +45 -0
  200. package/dist/core/engine/sql-reads.mjs +4 -1
  201. package/dist/core/engine/statement.mjs +4 -4
  202. package/dist/core/engine/version.d.mts +1 -1
  203. package/dist/core/engine/version.mjs +1 -1
  204. package/dist/core/error/codes.d.mts +1 -1
  205. package/dist/core/error/codes.mjs +1 -1
  206. package/dist/core/exact/decimal.d.mts +1 -4
  207. package/dist/core/exact/decimal.mjs +1 -14
  208. package/dist/core/exact/text.d.mts +5 -0
  209. package/dist/core/exact/text.mjs +19 -0
  210. package/dist/core/index.d.mts +9 -6
  211. package/dist/core/index.mjs +11 -8
  212. package/dist/core/model/types.d.mts +2 -0
  213. package/dist/core/model/validate/fields.mjs +1 -1
  214. package/dist/core/model/validate/known-members.mjs +2 -0
  215. package/dist/core/model/validate/shape.mjs +5 -1
  216. package/dist/core/oracle/visibility.mjs +2 -2
  217. package/dist/core/policy/bind.mjs +29 -1
  218. package/dist/core/query/drill/compose.d.mts +2 -0
  219. package/dist/core/query/drill/compose.mjs +1 -1
  220. package/dist/core/query/drill/synthetic.mjs +2 -1
  221. package/dist/core/query/drill/types.d.mts +7 -0
  222. package/dist/core/query/drill/types.mjs +3 -1
  223. package/dist/core/result/number.mjs +2 -1
  224. package/dist/core/result/time-axis.mjs +2 -1
  225. package/dist/core/schema/answers.d.mts +1176 -362
  226. package/dist/core/schema/commands.mjs +2 -1
  227. package/dist/core/schema/document.mjs +27 -2
  228. package/dist/core/schema/drill-answers.mjs +19 -1
  229. package/dist/core/schema/drill.d.mts +21 -6
  230. package/dist/core/schema/drill.mjs +7 -1
  231. package/dist/core/schema/index.d.mts +2 -1
  232. package/dist/core/schema/index.mjs +2 -1
  233. package/dist/core/schema/null-ops.d.mts +6 -0
  234. package/dist/core/schema/null-ops.mjs +18 -0
  235. package/dist/core/schema/query.mjs +30 -4
  236. package/dist/core/schema/tools.mjs +13 -0
  237. package/dist/core/schema/union-error.mjs +38 -0
  238. package/dist/core/time/bucket.mjs +2 -1
  239. package/dist/core/time/index.d.mts +3 -2
  240. package/dist/core/time/instant.d.mts +1 -2
  241. package/dist/core/time/instant.mjs +2 -30
  242. package/dist/core/time/range.mjs +2 -1
  243. package/dist/core/time/stored.mjs +2 -1
  244. package/dist/core/time/text-time.d.mts +10 -0
  245. package/dist/core/time/text-time.mjs +80 -0
  246. package/dist/core/types/api.d.mts +1 -1
  247. package/dist/core/types/api.mjs +1 -1
  248. package/dist/core/types/drill-api.d.mts +22 -2
  249. package/dist/dashboard-documents.d.mts +8 -0
  250. package/dist/dashboard-documents.mjs +52 -0
  251. package/dist/drill-access.mjs +40 -3
  252. package/dist/drill-comparison.mjs +71 -0
  253. package/dist/drill-crumbs.mjs +21 -2
  254. package/dist/drill-group-seal.mjs +13 -0
  255. package/dist/drill-open.mjs +7 -1
  256. package/dist/drill-seal.mjs +4 -6
  257. package/dist/drill-views.mjs +5 -13
  258. package/dist/drill.mjs +28 -58
  259. package/dist/editing.mjs +1 -1
  260. package/dist/endpoints/drill.mjs +2 -3
  261. package/dist/endpoints/index.d.mts +20 -0
  262. package/dist/index.d.mts +2 -1
  263. package/dist/index.mjs +6 -27
  264. package/dist/llms.txt +1 -1
  265. package/dist/react/Cell.mjs +2 -2
  266. package/dist/react/DashboardList.mjs +3 -3
  267. package/dist/react/Editing.mjs +3 -3
  268. package/dist/react/Header.mjs +2 -2
  269. package/dist/react/History.mjs +3 -3
  270. package/dist/react/Parts.mjs +2 -2
  271. package/dist/react/RowBody.d.mts +2 -4
  272. package/dist/react/RowBody.mjs +14 -39
  273. package/dist/react/Tile.mjs +4 -5
  274. package/dist/react/builder/FilterEditor.mjs +2 -2
  275. package/dist/react/builder/Picker.mjs +3 -3
  276. package/dist/react/builder/RangeEditor.mjs +3 -3
  277. package/dist/react/builder/Time.mjs +3 -3
  278. package/dist/react/builder/Values.mjs +2 -2
  279. package/dist/react/builder/WidgetBuilder.mjs +2 -2
  280. package/dist/react/digits.mjs +1 -1
  281. package/dist/react/drill/Bars.mjs +34 -38
  282. package/dist/react/drill/Comparison.mjs +204 -0
  283. package/dist/react/drill/Controls.mjs +8 -12
  284. package/dist/react/drill/DrillDrawer.mjs +42 -0
  285. package/dist/react/drill/DrillPanel.mjs +61 -41
  286. package/dist/react/drill/Header.mjs +65 -35
  287. package/dist/react/drill/ItemLink.mjs +40 -0
  288. package/dist/react/drill/Items.d.mts +2 -1
  289. package/dist/react/drill/Items.mjs +126 -99
  290. package/dist/react/drill/ItemsBody.mjs +38 -0
  291. package/dist/react/drill/ItemsFoot.mjs +24 -19
  292. package/dist/react/drill/Notes.mjs +23 -13
  293. package/dist/react/drill/PanelBody.mjs +7 -25
  294. package/dist/react/drill/RecordRow.mjs +47 -0
  295. package/dist/react/drill/Trend.mjs +186 -0
  296. package/dist/react/drill/board.mjs +21 -11
  297. package/dist/react/drill/drawer-context.mjs +5 -0
  298. package/dist/react/drill/item-parts.mjs +53 -35
  299. package/dist/react/drill/item-type.d.mts +2 -2
  300. package/dist/react/drill/lazy.d.mts +1 -4
  301. package/dist/react/drill/lazy.mjs +29 -11
  302. package/dist/react/drill/panel-focus.mjs +18 -7
  303. package/dist/react/drill/props.d.mts +7 -1
  304. package/dist/react/drill/props.mjs +39 -8
  305. package/dist/react/drill/record-page.mjs +61 -0
  306. package/dist/react/drill/state.mjs +17 -2
  307. package/dist/react/drill/trend-touch.mjs +33 -0
  308. package/dist/react/drill/useDrill.d.mts +3 -3
  309. package/dist/react/drill/useDrill.mjs +35 -15
  310. package/dist/react/drill/words.d.mts +14 -0
  311. package/dist/react/drill/words.mjs +20 -8
  312. package/dist/react/english.d.mts +4 -1
  313. package/dist/react/english.mjs +17 -2
  314. package/dist/react/filters/chip.mjs +2 -2
  315. package/dist/react/filters/menu-search.mjs +5 -5
  316. package/dist/react/filters/menu.mjs +2 -2
  317. package/dist/react/filters/number.mjs +2 -2
  318. package/dist/react/filters/operator.mjs +2 -2
  319. package/dist/react/filters/phone.mjs +2 -2
  320. package/dist/react/filters/values.mjs +4 -4
  321. package/dist/react/format-time.d.mts +2 -1
  322. package/dist/react/format-time.mjs +42 -34
  323. package/dist/react/format.mjs +15 -3
  324. package/dist/react/index.d.mts +4 -3
  325. package/dist/react/index.mjs +4 -3
  326. package/dist/react/messages.d.mts +23 -2
  327. package/dist/react/renderers/entries.d.mts +11 -0
  328. package/dist/react/renderers/list.mjs +8 -10
  329. package/dist/react/renderers/table-cells.mjs +38 -9
  330. package/dist/react/renderers/table-measure.mjs +2 -0
  331. package/dist/react/renderers/table-row.mjs +64 -7
  332. package/dist/react/renderers/table-sort.mjs +2 -8
  333. package/dist/react/renderers/table.mjs +16 -15
  334. package/dist/react/series.mjs +8 -3
  335. package/dist/react/theme-unlayered.css +1 -3144
  336. package/dist/react/theme.css +1 -3146
  337. package/dist/recharts/parts.mjs +1 -1
  338. package/dist/skills/derive-dashboards/SKILL.md +10 -5
  339. package/dist/store/apply.mjs +2 -2
  340. package/dist/store/editor.mjs +2 -2
  341. package/dist/store/writer.mjs +2 -2
  342. package/package.json +27 -2
@@ -1,56 +1,60 @@
1
+ import { lastIncludedMillisecond } from "derive-dashboards/core";
1
2
  // src/format-time.ts
2
3
  /** Date formats by locale and style, made once: a table would make one for every cell of a time column. */
3
4
  const FORMATS = /* @__PURE__ */ new Map();
4
- /** The date format for a locale and a style, made once. */
5
- function dateFormat(locale, style) {
6
- const key = `${locale ?? ""}|${JSON.stringify(style)}`;
7
- const made = FORMATS.get(key) ?? new Intl.DateTimeFormat(locale, style);
8
- FORMATS.set(key, made);
9
- return made;
10
- }
11
5
  const DATE_LABEL = /^\d{4}-\d{2}-\d{2}$/u;
12
- const BUCKET_FORMATS = {
6
+ const STYLES = {
13
7
  day: {
14
8
  month: "short",
15
9
  day: "numeric"
16
10
  },
17
- week: {
18
- month: "short",
19
- day: "numeric"
20
- },
21
- month: {
11
+ dated: {
22
12
  month: "short",
13
+ day: "numeric",
23
14
  year: "numeric"
24
15
  },
25
- quarter: {
16
+ month: {
26
17
  month: "short",
27
18
  year: "numeric"
28
19
  },
29
- year: { year: "numeric" }
20
+ year: { year: "numeric" },
21
+ hour: {
22
+ dateStyle: "medium",
23
+ timeStyle: "short"
24
+ }
30
25
  };
26
+ function styleFor(grain, withYear = false) {
27
+ if (grain === "week" || grain === "day") return withYear ? "dated" : "day";
28
+ return grain === "quarter" ? "month" : grain;
29
+ }
30
+ function dateFormat(locale, style, timeZone) {
31
+ const key = `${locale ?? ""}|${style}|${timeZone ?? ""}`;
32
+ const cached = FORMATS.get(key);
33
+ if (cached !== void 0) return cached;
34
+ const made = new Intl.DateTimeFormat(locale, {
35
+ ...STYLES[style],
36
+ timeZone
37
+ });
38
+ FORMATS.set(key, made);
39
+ return made;
40
+ }
31
41
  /**
32
42
  * A time bucket's label for a person: "Nov 2" for a day or week, "Jun 2026" for a month or
33
43
  * the month a (possibly fiscal) quarter starts. The label names a calendar date, so it is formatted as that date,
34
44
  * not as an instant in any zone. Hour labels stay as sent.
35
45
  */
36
- function formatBucket(label, grain, locale) {
46
+ function formatBucket(label, grain, locale, withYear = false) {
37
47
  if (grain === "hour" || !DATE_LABEL.test(label)) return label;
38
48
  const [year = 0, month = 1, day = 1] = label.split("-").map(Number);
39
- const date = new Date(Date.UTC(year, month - 1, day));
40
- return dateFormat(locale, {
41
- ...BUCKET_FORMATS[grain],
42
- timeZone: "UTC"
43
- }).format(date);
49
+ const date = /* @__PURE__ */ new Date(0);
50
+ date.setUTCFullYear(year, month - 1, day);
51
+ return dateFormat(locale, styleFor(grain, withYear), "UTC").format(date);
44
52
  }
45
53
  /** An instant (text time to the microsecond) as a date and time, in a zone (the dashboard's) or the viewer's own. */
46
54
  function formatInstant(text, locale, timeZone) {
47
55
  const date = new Date(text.replace(/(\.\d{3})\d+/u, "$1"));
48
56
  if (Number.isNaN(date.getTime())) return text;
49
- return dateFormat(locale, {
50
- dateStyle: "medium",
51
- timeStyle: "short",
52
- ...timeZone === void 0 ? {} : { timeZone }
53
- }).format(date);
57
+ return dateFormat(locale, "hour", timeZone).format(date);
54
58
  }
55
59
  /**
56
60
  * The bucket an instant starts, named at its grain in a zone, as a chart names it: "Nov 9" for
@@ -60,12 +64,16 @@ function formatInstant(text, locale, timeZone) {
60
64
  function formatInstantAt(text, grain, locale, timeZone) {
61
65
  const date = new Date(text.replace(/(\.\d{3})\d+/u, "$1"));
62
66
  if (Number.isNaN(date.getTime())) return text;
63
- return dateFormat(locale, {
64
- ...grain === "hour" ? {
65
- dateStyle: "medium",
66
- timeStyle: "short"
67
- } : BUCKET_FORMATS[grain],
68
- ...timeZone === void 0 ? {} : { timeZone }
69
- }).format(date);
67
+ return dateFormat(locale, styleFor(grain), timeZone).format(date);
68
+ }
69
+ /** The included calendar days in a receipt, shared by tiles and every drill view. */
70
+ function formatPeriod(range, format, timeZone) {
71
+ const last = lastIncludedMillisecond(range);
72
+ if (last === void 0) return format.messages.noData;
73
+ const first = new Date(range.from);
74
+ const year = dateFormat(format.locale, "year", timeZone);
75
+ const crossesYear = year.format(first) !== year.format(last);
76
+ const day = dateFormat(format.locale, styleFor("day", crossesYear), timeZone);
77
+ return format.messages.drillRange(day.format(first), day.format(last));
70
78
  }
71
- export { formatBucket, formatInstant, formatInstantAt };
79
+ export { formatBucket, formatInstant, formatInstantAt, formatPeriod };
@@ -17,6 +17,15 @@ function plotValue(cell) {
17
17
  const value = Number(typeof cell === "string" ? cell : cell.v);
18
18
  return Number.isFinite(value) ? value : null;
19
19
  }
20
+ /** The unformatted key used for group matching, lexical sorting and template links. */
21
+ function rawCellText(cell) {
22
+ if (cell === void 0 || cell === null || isMark(cell)) return void 0;
23
+ return typeof cell === "object" ? cell.v : String(cell);
24
+ }
25
+ /** A dimension label identifies the missing field in tables and drill selections alike. */
26
+ function groupText(cell, column, format) {
27
+ return cell === null ? format.messages.drillNone(column?.label ?? "") : formatCell(cell, column, format);
28
+ }
20
29
  /**
21
30
  * A cell as text for a person, in their locale and words. A renderer can pass its own props as
22
31
  * `format`: they carry both.
@@ -34,7 +43,10 @@ const FORMATS = /* @__PURE__ */ new Map();
34
43
  /** The number format for a locale and a style, made once. */
35
44
  function numberFormat(locale, style) {
36
45
  const key = `${locale ?? ""}|${JSON.stringify(style)}`;
37
- const made = FORMATS.get(key) ?? new Intl.NumberFormat(locale, style);
46
+ const made = FORMATS.get(key) ?? new Intl.NumberFormat(locale, {
47
+ signDisplay: "negative",
48
+ ...style
49
+ });
38
50
  FORMATS.set(key, made);
39
51
  return made;
40
52
  }
@@ -66,7 +78,7 @@ function percentText(cell, how, locale) {
66
78
  const style = {
67
79
  style: "percent",
68
80
  ...percentDigits(weigh(cell), how.fraction ? 1 : 100),
69
- signDisplay: signed ? "exceptZero" : "auto"
81
+ signDisplay: signed ? "exceptZero" : "negative"
70
82
  };
71
83
  const digits = typeof cell === "number" ? floatText(cell) : plainText(cell.v) ?? cell.v;
72
84
  return numberFormat(locale, style).format(`${digits}${shift}`);
@@ -147,4 +159,4 @@ function formatTick(value, column, locale) {
147
159
  ...style
148
160
  }).format(value);
149
161
  }
150
- export { formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, plotValue };
162
+ export { formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, groupText, plotValue, rawCellText };
@@ -33,14 +33,15 @@ import { downloadCsv } from "./export/download.mjs";
33
33
  import "./FilterBar.mjs";
34
34
  import { formatCell, formatTick, plotValue } from "./format.mjs";
35
35
  import { HistoryPanel, VersionBar } from "./History.mjs";
36
- import { CellFormat, Messages } from "./messages.mjs";
36
+ import { CellFormat, ChartKind, Messages } from "./messages.mjs";
37
37
  import { ChangeList, Panel } from "./Panel.mjs";
38
38
  import { ReviewPanel } from "./ReviewPanel.mjs";
39
39
  import { ClientSchemas } from "./read.mjs";
40
+ import { answerIds } from "./renderers/entries.mjs";
40
41
  import { NumberTile } from "./renderers/index.mjs";
41
42
  import { ListDisplay, ListTile } from "./renderers/list.mjs";
42
- import { Moved, Review, useReview } from "./review.mjs";
43
43
  import { formatBucket, formatInstant, formatInstantAt } from "./format-time.mjs";
44
+ import { Moved, Review, useReview } from "./review.mjs";
44
45
  import { ENGLISH_REVIEW, ReviewMessages } from "./review-words.mjs";
45
46
  import { SeriesSlotsContext } from "./scope.mjs";
46
47
  import { Drawn, OTHER_KEY, Point, Series, lastBucketOpen, toSeries } from "./series.mjs";
@@ -62,4 +63,4 @@ export interface Register {}
62
63
  export type Item = Register extends {
63
64
  server: infer S;
64
65
  } ? ItemFor<S> : DrillItem;
65
- export { type Attempt, type Builder, type CellFormat, ChangeList, type ClientOptions, type ClientSchemas, type Components, Dashboard, type DashboardDrillProps, DashboardList, type DashboardProps, DashboardTile, type DashboardTileProps, type DashboardsClient, DashboardsError, type DashboardsErrorCode, DashboardsProvider, type DashboardsProviderProps, type DashboardsServer, type DraftClosed, type DraftEditor, type DraftStatus, type Drawn, type DrillChange, type DrillController, type DrillEvent, type DrillHistory, type DrillMarkProps, type DrillMessages, type DrillOptions, DrillPanel, type DrillPanelProps, ENGLISH, ENGLISH_DRILL, ENGLISH_FILTERS, ENGLISH_REVIEW, EditBar, FilterBar, type FilterBarOptions, type FilterBarProps, type FilterIcon, type FilterWords, HistoryPanel, type ItemFor, type ItemHelpers, type ItemOptions, type LinkComponent, type LinkProps, type ListDisplay, ListTile, type Messages, type Moved, NumberTile, OTHER_KEY, Panel, type Point, Popover, type Review, type ReviewMessages, ReviewPanel, type Series, type SeriesSlots, SeriesSlotsContext, type SplitSeries, TableTile, Tile, type TileDrill, type TileRenderer, type TileRendererProps, type TypedCall, VersionBar, type ViewChange, WidgetBuilder, type WidgetBuilderProps, WidgetPreview, chartColors, createDashboardsClient, csvOf, downloadCsv, drillFrom, exactDigits, exportRows, fieldOf, rules_d_exports as filterRules, formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, lastBucketOpen, plotValue, pointCell, pointText, rowAt, seriesSlots, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
66
+ export { type Attempt, type Builder, type CellFormat, ChangeList, type ChartKind, type ClientOptions, type ClientSchemas, type Components, Dashboard, type DashboardDrillProps, DashboardList, type DashboardProps, DashboardTile, type DashboardTileProps, type DashboardsClient, DashboardsError, type DashboardsErrorCode, DashboardsProvider, type DashboardsProviderProps, type DashboardsServer, type DraftClosed, type DraftEditor, type DraftStatus, type Drawn, type DrillChange, type DrillController, type DrillEvent, type DrillHistory, type DrillMarkProps, type DrillMessages, type DrillOptions, DrillPanel, type DrillPanelProps, ENGLISH, ENGLISH_DRILL, ENGLISH_FILTERS, ENGLISH_REVIEW, EditBar, FilterBar, type FilterBarOptions, type FilterBarProps, type FilterIcon, type FilterWords, HistoryPanel, type ItemFor, type ItemHelpers, type ItemOptions, type LinkComponent, type LinkProps, type ListDisplay, ListTile, type Messages, type Moved, NumberTile, OTHER_KEY, Panel, type Point, Popover, type Review, type ReviewMessages, ReviewPanel, type Series, type SeriesSlots, SeriesSlotsContext, type SplitSeries, TableTile, Tile, type TileDrill, type TileRenderer, type TileRendererProps, type TypedCall, VersionBar, type ViewChange, WidgetBuilder, type WidgetBuilderProps, WidgetPreview, answerIds, chartColors, createDashboardsClient, csvOf, downloadCsv, drillFrom, exactDigits, exportRows, fieldOf, rules_d_exports as filterRules, formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, lastBucketOpen, plotValue, pointCell, pointText, rowAt, seriesSlots, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
@@ -13,11 +13,11 @@ import { formatBucket, formatInstant, formatInstantAt } from "./format-time.mjs"
13
13
  import { exactDigits } from "./renderers/exact.mjs";
14
14
  import { drillFrom } from "./drill/state.mjs";
15
15
  import { useDrill } from "./drill/useDrill.mjs";
16
- import { TableTile } from "./renderers/table.mjs";
17
16
  import { ENGLISH_DRILL } from "./drill/words.mjs";
17
+ import { TableTile } from "./renderers/table.mjs";
18
18
  import { EditBar } from "./EditBar.mjs";
19
- import { DashboardsError } from "./errors.mjs";
20
19
  import { csvOf, exportRows } from "./export/csv.mjs";
20
+ import { DashboardsError } from "./errors.mjs";
21
21
  import { downloadCsv } from "./export/download.mjs";
22
22
  import { ENGLISH_FILTERS } from "./filters/words.mjs";
23
23
  import { FilterBar } from "./filters/bar.mjs";
@@ -29,6 +29,7 @@ import { HistoryPanel, VersionBar } from "./History.mjs";
29
29
  import { ENGLISH } from "./english.mjs";
30
30
  import { ChangeList, Panel } from "./Panel.mjs";
31
31
  import { ReviewPanel } from "./ReviewPanel.mjs";
32
+ import { answerIds } from "./renderers/entries.mjs";
32
33
  import { NumberTile } from "./renderers/index.mjs";
33
34
  import { ListTile } from "./renderers/list.mjs";
34
35
  import { useReview } from "./review.mjs";
@@ -41,4 +42,4 @@ import { Tile } from "./Tile.mjs";
41
42
  import { useBoard } from "./useBoard.mjs";
42
43
  import { useDashboard } from "./useDashboard.mjs";
43
44
  import { useTiles } from "./useTiles.mjs";
44
- export { ChangeList, Dashboard, DashboardList, DashboardTile, DashboardsError, DashboardsProvider, DrillPanel, ENGLISH, ENGLISH_DRILL, ENGLISH_FILTERS, ENGLISH_REVIEW, EditBar, FilterBar, HistoryPanel, ListTile, NumberTile, OTHER_KEY, Panel, Popover, ReviewPanel, SeriesSlotsContext, TableTile, Tile, VersionBar, WidgetBuilder, WidgetPreview, chartColors, createDashboardsClient, csvOf, downloadCsv, drillFrom, exactDigits, exportRows, fieldOf, rules_exports as filterRules, formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, lastBucketOpen, plotValue, pointCell, pointText, rowAt, seriesSlots, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
45
+ export { ChangeList, Dashboard, DashboardList, DashboardTile, DashboardsError, DashboardsProvider, DrillPanel, ENGLISH, ENGLISH_DRILL, ENGLISH_FILTERS, ENGLISH_REVIEW, EditBar, FilterBar, HistoryPanel, ListTile, NumberTile, OTHER_KEY, Panel, Popover, ReviewPanel, SeriesSlotsContext, TableTile, Tile, VersionBar, WidgetBuilder, WidgetPreview, answerIds, chartColors, createDashboardsClient, csvOf, downloadCsv, drillFrom, exactDigits, exportRows, fieldOf, rules_exports as filterRules, formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, lastBucketOpen, plotValue, pointCell, pointText, rowAt, seriesSlots, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
@@ -3,7 +3,9 @@ import { DrillMessages } from "./drill/words.mjs";
3
3
  import { FilterWords } from "./filters/words.mjs";
4
4
  import { ReviewMessages } from "./review-words.mjs";
5
5
  import { ENGLISH } from "./english.mjs";
6
- import { RelativeRange } from "derive-dashboards/core";
6
+ import { Grain, RelativeRange } from "derive-dashboards/core";
7
+ /** The kinds of chart a tile draws, as a chart's table names its picture to a screen reader. */
8
+ export type ChartKind = "line" | "bar" | "area" | "multiples" | "heatmap" | "funnel";
7
9
  /**
8
10
  * Every word the built-in components show. English by default; pass `messages` to the
9
11
  * provider to change any of them, for another language or another house style.
@@ -106,11 +108,30 @@ export type Messages = ReviewMessages & DrillMessages & BuilderMessages & {
106
108
  /** A chart's data table caption, read by screen readers in place of the picture. */
107
109
  chartTable: (chart: {
108
110
  title: string;
109
- kind: "line" | "bar";
111
+ kind: ChartKind;
110
112
  points: number;
111
113
  }) => string;
112
114
  /** The name of a chart's list of points to open; arrow keys move along it. */
113
115
  chartPoints: string;
116
+ /** When there is data but the plot has no room. */
117
+ chartTooSmall?: string;
118
+ /** Navigation for a large chart reader table. */
119
+ chartTablePages?: {
120
+ previous: string;
121
+ next: string;
122
+ range: (first: number, last: number, total: number, axis: "rows" | "columns") => string;
123
+ };
124
+ /** Wording for native chart marks, tooltips and visible aggregation notes. */
125
+ chartPartial?: string;
126
+ chartAveraged?: (count: number) => string;
127
+ chartMerged?: (count: number, grain: Grain, approximate: boolean) => string;
128
+ chartFunnel?: {
129
+ continues: (percent: string) => string;
130
+ largestDrop: string;
131
+ ofAll: (percent: string) => string;
132
+ ofFirstStep: (percent: string) => string;
133
+ ofStepBefore: (percent: string) => string;
134
+ };
114
135
  /** What the builder keeps as it was, though it cannot edit it. */
115
136
  keptAside: (kept: {
116
137
  display: boolean;
@@ -0,0 +1,11 @@
1
+ import { Widget } from "derive-dashboards/core";
2
+ /**
3
+ * How a widget's `display` names an entry of its query, as the id its column has in the answer.
4
+ * The answer names a query's entries by place (m1.. measures, d1.. groups, c1.. calcs), as the
5
+ * server runs it (core's `entryAliases` is that rule); `display` names them as the widget's
6
+ * query does. An id the query does not have is given back as it is, so a column's own id
7
+ * still names it.
8
+ */
9
+ export declare function answerIds(widget: {
10
+ queries?: Widget["queries"];
11
+ }): (entry: string) => string;
@@ -1,5 +1,5 @@
1
1
  import { isValue } from "../columns.mjs";
2
- import { formatCell } from "../format.mjs";
2
+ import { formatCell, rawCellText } from "../format.mjs";
3
3
  import { RowBody } from "../RowBody.mjs";
4
4
  import { answerIds } from "./entries.mjs";
5
5
  import { displayOf, isMark } from "derive-dashboards/core";
@@ -39,12 +39,12 @@ const text = ({ cells, at, props }, id) => {
39
39
  const linkOf = (template, line) => {
40
40
  let missing = false;
41
41
  const href = template.replaceAll(/\{([^}]+)\}/gu, (_, id) => {
42
- const cell = line.cells[line.at(id)];
43
- if (cell === void 0 || cell === null || isMark(cell)) {
42
+ const raw = rawCellText(line.cells[line.at(id)]);
43
+ if (raw === void 0) {
44
44
  missing = true;
45
45
  return "";
46
46
  }
47
- return encodeURIComponent(typeof cell === "object" ? cell.v : String(cell));
47
+ return encodeURIComponent(raw);
48
48
  });
49
49
  return missing ? void 0 : href;
50
50
  };
@@ -81,16 +81,14 @@ function ListTile(props) {
81
81
  title: text(line, shown.title) || props.messages.empty,
82
82
  meta: shown.subtitle.map((id) => text(line, id)).filter(Boolean),
83
83
  lead: shown.avatar === void 0 ? void 0 : initials(text(line, shown.avatar)),
84
- value: text(line, shown.meta)
84
+ value: text(line, shown.meta),
85
+ valueLabel: answer.columns[at(shown.meta)]?.label
85
86
  };
86
- const body = /* @__PURE__ */ jsx(RowBody, {
87
- row,
88
- family: "lines"
89
- });
87
+ const body = /* @__PURE__ */ jsx(RowBody, { row });
90
88
  const href = shown.href === void 0 ? void 0 : linkOf(shown.href, line);
91
89
  return /* @__PURE__ */ jsx("li", { children: href === void 0 ? /* @__PURE__ */ jsx("div", {
92
90
  className: "dd-lines-row",
93
- ...props.drill?.props(cells),
91
+ ...props.drill?.props(cells, shown.meta),
94
92
  children: body
95
93
  }) : /* @__PURE__ */ jsx(Anchor, {
96
94
  href,
@@ -1,5 +1,6 @@
1
1
  import { isNumeric, isValue } from "../columns.mjs";
2
- import { formatCell, plotValue } from "../format.mjs";
2
+ import { compareGroupLabel } from "../drill/words.mjs";
3
+ import { formatCell, groupText, plotValue } from "../format.mjs";
3
4
  import { depthOf, reachOf } from "./table-scale.mjs";
4
5
  import { isMark } from "derive-dashboards/core";
5
6
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -37,7 +38,13 @@ function shadeOf(cell, how) {
37
38
  * and its column's name is written before it for the eye alone, the header still naming it
38
39
  * for a screen reader.
39
40
  */
40
- const inCard = (at) => at.cards ? { role: "cell" } : {};
41
+ const semantics = (at) => {
42
+ if (at.heading) return {
43
+ scope: "row",
44
+ role: at.cards ? "rowheader" : void 0
45
+ };
46
+ return at.cards ? { role: "cell" } : {};
47
+ };
41
48
  /** The column's name before a card's cell. */
42
49
  function Label({ column, at }) {
43
50
  if (!at.cards) return null;
@@ -65,15 +72,16 @@ function valueBody(text, cell, at, how) {
65
72
  /** A cell of a column of values: its number, with its bar or its shade when the column draws one. */
66
73
  function ValueCell(props) {
67
74
  const { cell, column, at, marks } = props;
75
+ const Tag = at.heading ? "th" : "td";
68
76
  const how = at.total || cell === null ? void 0 : at.measured.get(column.id);
69
77
  const text = how?.texts.get(at.place) ?? formatCell(cell, column, at.format);
70
78
  const shade = shadeOf(cell, how);
71
- return /* @__PURE__ */ jsxs("td", {
79
+ return /* @__PURE__ */ jsxs(Tag, {
72
80
  "data-numeric": "true",
73
81
  "data-empty": cell === null ? "true" : void 0,
74
82
  "data-heat": shade === void 0 ? void 0 : "true",
75
83
  style: shade,
76
- ...inCard(at),
84
+ ...semantics(at),
77
85
  ...marks,
78
86
  children: [/* @__PURE__ */ jsx(Label, {
79
87
  column,
@@ -83,8 +91,9 @@ function ValueCell(props) {
83
91
  }
84
92
  /** A cell of words: yes or no as a badge, anything else on one line, cut where it has no room. */
85
93
  function WordCell({ cell, column, at }) {
86
- if (typeof cell === "boolean") return /* @__PURE__ */ jsxs("td", {
87
- ...inCard(at),
94
+ const Tag = at.heading ? "th" : "td";
95
+ if (typeof cell === "boolean") return /* @__PURE__ */ jsxs(Tag, {
96
+ ...semantics(at),
88
97
  children: [/* @__PURE__ */ jsx(Label, {
89
98
  column,
90
99
  at
@@ -94,10 +103,10 @@ function WordCell({ cell, column, at }) {
94
103
  children: formatCell(cell, column, at.format)
95
104
  })]
96
105
  });
97
- const text = cell === null ? at.format.messages.drillNone(column.label) : formatCell(cell, column, at.format);
98
- return /* @__PURE__ */ jsxs("td", {
106
+ const text = groupText(cell, column, at.format);
107
+ return /* @__PURE__ */ jsxs(Tag, {
99
108
  "data-empty": cell === null ? "true" : void 0,
100
- ...inCard(at),
109
+ ...semantics(at),
101
110
  children: [/* @__PURE__ */ jsx(Label, {
102
111
  column,
103
112
  at
@@ -116,6 +125,26 @@ function Cell$1(props) {
116
125
  role: at.cards ? "rowheader" : void 0,
117
126
  children: formatCell(cell, column, at.format)
118
127
  });
128
+ if (props.compare) {
129
+ const text = formatCell(cell, column, at.format);
130
+ const name = (at.format.messages.drillCompareGroup ?? compareGroupLabel)(props.compare.label);
131
+ return /* @__PURE__ */ jsxs("th", {
132
+ scope: "row",
133
+ role: at.cards ? "rowheader" : void 0,
134
+ children: [/* @__PURE__ */ jsx(Label, {
135
+ column,
136
+ at
137
+ }), /* @__PURE__ */ jsx("button", {
138
+ type: "button",
139
+ className: "dd-compare-label",
140
+ "aria-label": name,
141
+ title: name,
142
+ "aria-haspopup": "dialog",
143
+ onClick: props.compare.open,
144
+ children: text
145
+ })]
146
+ });
147
+ }
119
148
  return isValue(column) || isNumeric(column) && cell !== null ? /* @__PURE__ */ jsx(ValueCell, {
120
149
  cell,
121
150
  column,
@@ -18,12 +18,14 @@ function measure(asked, at, column, draws) {
18
18
  heat: draws.shaded ? rangeOf(rows, at) : void 0
19
19
  };
20
20
  }
21
+ const NO_MEASURES = /* @__PURE__ */ new Map();
21
22
  /**
22
23
  * The value columns a widget draws beyond their numbers, by column id. `display.bars` and
23
24
  * `display.heat` name entries as the widget's query does, or as the answer does.
24
25
  */
25
26
  function measuredOf(asked) {
26
27
  const display = displayOf("table", asked.widget.display);
28
+ if ((display.bars?.length ?? 0) === 0 && (display.heat?.length ?? 0) === 0) return NO_MEASURES;
27
29
  const answerId = answerIds(asked.widget);
28
30
  const bars = new Set((display.bars ?? []).map((entry) => answerId(entry)));
29
31
  const heat = new Set((display.heat ?? []).map((entry) => answerId(entry)));
@@ -1,8 +1,9 @@
1
1
  import { isValue } from "../columns.mjs";
2
+ import { groupText, rawCellText } from "../format.mjs";
2
3
  import { Cell as Cell$1 } from "./table-cells.mjs";
3
4
  import { isSummary, isTotal } from "./table-scale.mjs";
4
- import { memo } from "react";
5
- import { isMark } from "derive-dashboards/core";
5
+ import { memo, useMemo } from "react";
6
+ import { isMark, roleOf } from "derive-dashboards/core";
6
7
  import { jsx } from "react/jsx-runtime";
7
8
  // src/renderers/table-row.tsx
8
9
  /** Cells as table cells: a run of equal marks is one cell spanning its columns. */
@@ -24,11 +25,63 @@ const markOf = (cells) => {
24
25
  if (isTotal(cells)) return "all";
25
26
  return isSummary(cells) ? "other" : void 0;
26
27
  };
28
+ /** Keep a comparable row’s accessible name and action when sorting or resizing the table. */
29
+ function useComparisons(columns, groups, drill, format) {
30
+ const { locale, messages, timeZone } = format;
31
+ return useMemo(() => {
32
+ if (!groups || !drill?.compare) return;
33
+ const openGroup = drill.compare.bind(drill);
34
+ const place = columns.findIndex((c) => roleOf(c) === "dimension");
35
+ if (place < 0) return;
36
+ const labels = columns.flatMap((column, i) => isValue(column) ? [] : [{
37
+ column,
38
+ i
39
+ }]);
40
+ const known = /* @__PURE__ */ new WeakMap();
41
+ return (cells) => {
42
+ const cached = known.get(cells);
43
+ if (cached) return cached;
44
+ const name = rawCellText(cells[place]);
45
+ if (name === void 0 || !Object.hasOwn(groups, name) || isSummary(cells)) return;
46
+ const fields = groups[name];
47
+ if (!fields) return;
48
+ const [member, thenBy] = fields;
49
+ const open = openGroup(cells, {
50
+ by: "comparison",
51
+ member,
52
+ ...thenBy !== void 0 && { thenBy }
53
+ });
54
+ if (!open) return;
55
+ const label = labels.map(({ column, i }) => groupText(cells[i] ?? null, column, {
56
+ locale,
57
+ messages,
58
+ timeZone
59
+ })).join(" · ");
60
+ const action = {
61
+ open,
62
+ place,
63
+ label
64
+ };
65
+ known.set(cells, action);
66
+ return action;
67
+ };
68
+ }, [
69
+ columns,
70
+ groups,
71
+ drill,
72
+ locale,
73
+ messages,
74
+ timeZone
75
+ ]);
76
+ }
27
77
  /** One table row. A row that folds dimensions is a summary, labelled where it folds them. */
28
- function RowOf({ cells, columns, ruled, drill, ...at }) {
78
+ function RowOf(props) {
79
+ const { cells, columns, ruled, drill, ...at } = props;
80
+ const compare = props.comparison?.(cells);
29
81
  const mark = markOf(cells);
30
- const whole = drill?.props(cells);
82
+ const whole = compare ? void 0 : drill?.props(cells);
31
83
  const cellMarks = (column) => whole === void 0 && column !== void 0 && isValue(column) ? drill?.props(cells, column.id) : void 0;
84
+ const heading = columns.findIndex((column) => roleOf(column) === "dimension");
32
85
  const cellAt = {
33
86
  ...at,
34
87
  total: mark === "all",
@@ -46,8 +99,12 @@ function RowOf({ cells, columns, ruled, drill, ...at }) {
46
99
  cell,
47
100
  column,
48
101
  span,
49
- at: cellAt,
50
- marks: cellMarks(column)
102
+ at: {
103
+ ...cellAt,
104
+ heading: place === heading
105
+ },
106
+ marks: cellMarks(column),
107
+ compare: compare?.place === place ? compare : void 0
51
108
  }, column?.id ?? place);
52
109
  })
53
110
  });
@@ -58,4 +115,4 @@ function RowOf({ cells, columns, ruled, drill, ...at }) {
58
115
  * object made anew at every draw.
59
116
  */
60
117
  const Row = memo(RowOf);
61
- export { Row };
118
+ export { Row, useComparisons };
@@ -1,7 +1,7 @@
1
1
  import { isNumeric, isValue } from "../columns.mjs";
2
+ import { rawCellText } from "../format.mjs";
2
3
  import { compareExact, digitsOf } from "./exact.mjs";
3
4
  import { isSummary } from "./table-scale.mjs";
4
- import { isMark } from "derive-dashboards/core";
5
5
  // src/renderers/table-sort.ts
6
6
  /**
7
7
  * Whether a table's rows can be sorted: every row that folds dimensions comes after every row
@@ -37,12 +37,6 @@ const floatOf = (cell) => {
37
37
  if (typeof cell === "string") return cell.trim() === "" ? NaN : Number(cell);
38
38
  return cell !== null && typeof cell === "object" && "v" in cell ? Number(cell.v) : NaN;
39
39
  };
40
- /** A cell as words to sort by: text as it is, yes after no, an exact value by its digits. */
41
- function wordsOf(cell) {
42
- if (typeof cell === "string") return cell;
43
- if (typeof cell === "number" || typeof cell === "boolean") return String(cell);
44
- return cell === null || isMark(cell) ? "" : cell.v;
45
- }
46
40
  /**
47
41
  * Numbers by size. Each cell is read as a float once, before the sort. Two that differ as
48
42
  * floats stand as their floats do, since a float never puts a larger decimal below a smaller
@@ -64,7 +58,7 @@ function byNumber(cells, floats) {
64
58
  * anything else as words in the reader's language.
65
59
  */
66
60
  function byWords(column, cells, locale) {
67
- const words = cells.map((cell) => wordsOf(cell));
61
+ const words = cells.map((cell) => rawCellText(cell) ?? "");
68
62
  if (column.type === "time") return (a, b) => words[a] === words[b] ? 0 : (words[a] ?? "") < (words[b] ?? "") ? -1 : 1;
69
63
  const collator = new Intl.Collator(locale, {
70
64
  numeric: true,
@@ -1,21 +1,24 @@
1
1
  import { nameCut, useFit } from "./table-fit.mjs";
2
2
  import { Head } from "./table-head.mjs";
3
3
  import { drawnOf, measuredOf } from "./table-measure.mjs";
4
- import { Row } from "./table-row.mjs";
4
+ import { Row, useComparisons } from "./table-row.mjs";
5
5
  import { isSummary, isTotal } from "./table-scale.mjs";
6
6
  import { orderOf, sortable } from "./table-sort.mjs";
7
7
  import { useMemo, useState } from "react";
8
8
  import { displayOf } from "derive-dashboards/core";
9
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
10
10
  // src/renderers/table.tsx
11
11
  /** Under a long table that draws its first rows only: the button that draws more. Nothing under a table drawn whole. */
12
- function More({ hidden, of, onMore, tile }) {
12
+ function More({ hidden, of, onMore, table, tile }) {
13
13
  if (hidden <= 0) return null;
14
14
  const written = (count) => count.toLocaleString(tile.locale);
15
15
  return /* @__PURE__ */ jsx("button", {
16
16
  type: "button",
17
17
  className: "dd-table-more",
18
- onClick: onMore,
18
+ onClick: () => {
19
+ if (hidden <= 500) table.current?.focus();
20
+ onMore();
21
+ },
19
22
  children: tile.messages.showMoreRows(written(Math.min(hidden, 500)), written(of))
20
23
  });
21
24
  }
@@ -78,16 +81,12 @@ function TableTile(props) {
78
81
  const [table, fit] = useFit(props.answer);
79
82
  const cards = fit === "cards";
80
83
  const { measured, drawn, drawMore, plain, hidden } = useRows(props, sort);
81
- const onMore = () => {
82
- if (hidden <= 500) table.current?.focus();
83
- drawMore();
84
- };
85
- const compact = displayOf("table", props.widget.display).compact === true;
86
- const onSort = sortable(rows) ? setSort : void 0;
87
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("table", {
84
+ const { compact, comparisons } = displayOf("table", props.widget.display);
85
+ const comparison = useComparisons(columns, comparisons, props.drill, props);
86
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("table", {
88
87
  ref: table,
89
88
  className: "dd-table",
90
- "data-density": compact ? "compact" : void 0,
89
+ "data-density": compact === true ? "compact" : void 0,
91
90
  "data-layout": fit === "columns" ? void 0 : fit,
92
91
  role: cards ? "table" : void 0,
93
92
  tabIndex: -1,
@@ -95,7 +94,7 @@ function TableTile(props) {
95
94
  children: [/* @__PURE__ */ jsx(Head, {
96
95
  columns,
97
96
  sort,
98
- onSort,
97
+ onSort: sortable(rows) ? setSort : void 0,
99
98
  cards,
100
99
  messages: props.messages
101
100
  }), /* @__PURE__ */ jsx("tbody", {
@@ -108,13 +107,15 @@ function TableTile(props) {
108
107
  place,
109
108
  cards,
110
109
  ruled: isTotal(rows[drawn[i + 1] ?? -1] ?? []),
111
- drill: props.drill
110
+ drill: props.drill,
111
+ comparison
112
112
  }, place))
113
113
  })]
114
114
  }), /* @__PURE__ */ jsx(More, {
115
115
  hidden,
116
116
  of: plain,
117
- onMore,
117
+ onMore: drawMore,
118
+ table,
118
119
  tile: props
119
120
  })] });
120
121
  }
@@ -27,9 +27,14 @@ const scaleOf = (c) => JSON.stringify([
27
27
  * left out, the chart keeps a book of its own.
28
28
  */
29
29
  function toSeries(answer, format = {}, slots) {
30
- const at = /* @__PURE__ */ new Map();
30
+ const bySeries = /* @__PURE__ */ new Map();
31
31
  const shape = shapeOf(answer, format, slots ?? seriesSlots(), (point, key, row) => {
32
- at.set(`${String(point)}|${key}`, row);
32
+ let rows = bySeries.get(key);
33
+ if (rows === void 0) {
34
+ rows = /* @__PURE__ */ new Map();
35
+ bySeries.set(key, rows);
36
+ }
37
+ rows.set(point, row);
33
38
  });
34
39
  const { xs, ...drawn } = drawSeries(answer, shape);
35
40
  return {
@@ -39,7 +44,7 @@ function toSeries(answer, format = {}, slots) {
39
44
  xAt: (point) => xs[point] ?? null,
40
45
  rowAt: (point, key) => {
41
46
  const index = typeof point === "number" ? point : drawn.points.indexOf(point);
42
- return at.get(`${String(index)}|${key}`) ?? at.get(`${String(index)}|*`);
47
+ return bySeries.get(key)?.get(index) ?? bySeries.get("*")?.get(index);
43
48
  }
44
49
  };
45
50
  }