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
package/README.md CHANGED
@@ -21,8 +21,8 @@ row rules when you have them, nothing extra when you do not.
21
21
  npm install derive-dashboards
22
22
  ```
23
23
 
24
- One package. The React UI needs `react`, and the line and bar charts need `recharts`: install
25
- them only if you use those parts. The `derive-dashboards` command (`npx derive-dashboards init`)
24
+ One package. The React UI needs `react`, and the Recharts line and bar tiles need `recharts`:
25
+ install them only if you use those parts. The package's own charts need nothing more. The `derive-dashboards` command (`npx derive-dashboards init`)
26
26
  comes with it.
27
27
 
28
28
  Then follow the [quick start](https://github.com/derive-to/dashboards/blob/main/docs/quick-start.md). To have a coding agent add dashboards to your app end to end, investigating your access rules and proving no customer sees another's data: `npx skills add derive-to/dashboards --skill add-dashboards`. For the library's API alone: `npx skills add derive-to/dashboards --skill derive-dashboards`. [llms.txt](https://github.com/derive-to/dashboards/blob/main/llms.txt) indexes every page, and ships in the package.
@@ -37,6 +37,8 @@ Embedded dashboards on Postgres, end to end, run by the Acme Tasks sample (`exam
37
37
  | `derive-dashboards` | `deriveDashboards(options)`: a fetch handler for every endpoint, a Postgres source and store for any driver, the result cache, the query log, `createTables`, and the store contract suite (`/testing`). |
38
38
  | `derive-dashboards/react` | `Dashboard` with edit mode (Edit, + Add widget, drag and resize, a change count with undo and redo, review before publish, History with in-place preview, Share), `DashboardList` with + New dashboard, `useDraft` and `useReview` for your own edit and review UI, the filter bar (`FilterBar`, with chips, a Filter menu, a phone sheet and `filterRules` for your own), `Tile`, the built-in tiles (`NumberTile`, `TableTile` with a viewer's sort, bars and shading), a tile's answer as CSV (`downloadCsv`, `csvOf`, `exportRows`), drill-in (`DrillPanel`, `DashboardTile`, `useDrill`, and `toSeries` and `rowAt` for any chart kit), the widget builder (`WidgetBuilder`, `useBuilder`) and `theme.css`. |
39
39
  | `derive-dashboards/recharts` | Line and bar tiles, drawn with Recharts, each mark a drill (install `recharts` to use them; any other chart library plugs into `renderers`). |
40
+ | `derive-dashboards/charts-react` | The package's own charts as tiles (`CHARTS_RENDERERS`): line, bar, area, small multiples, heat grid and funnel, each with a tooltip, keyboard steps, a table for screen readers and drill, and `Chart` to draw one yourself. Include `chart.css`. |
41
+ | `derive-dashboards/charts` | The charts as plain functions, with no React: data in, a picture out as SVG (`lineChart`, `barChart`, `areaChart`, `gridChart`, `funnelChart` and more, and `renderSvg`). |
40
42
  | `derive-dashboards/mcp` | Two tools for the MCP server you already run (`addDashboardTools`): `dashboards_query` to ask and read, `dashboards_api` for everything else. See [MCP](https://github.com/derive-to/dashboards/blob/main/docs/mcp.md). |
41
43
  | `derive-dashboards/cli` | `defineConfig` for `derive-dashboards.config.ts`; the `derive-dashboards` command runs `init`, `doctor`, `check`, `generate`, `create-tables`. |
42
44
 
package/dist/body.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { HttpError } from "./http.mjs";
2
- import { commandSchema, drillStateSchema, jsonSchema, picksSchema, wireQuerySchema } from "derive-dashboards/core/schema";
2
+ import { commandSchema, drillStateSchema, jsonSchema, picksSchema, wireQuerySchema, withNullOpValues } from "derive-dashboards/core/schema";
3
3
  import { z } from "zod";
4
4
  // src/body.ts
5
5
  /** The request bodies every endpoint checks before anything reads them. Unknown keys are refused. */
@@ -167,7 +167,7 @@ function described(error) {
167
167
  * A free query's body is refused as `QUERY_INVALID`, any other as `BODY_INVALID`.
168
168
  */
169
169
  function parseWith(schema, input, code = "BODY_INVALID") {
170
- const parsed = schema.safeParse(input);
170
+ const parsed = schema.safeParse(withNullOpValues(input));
171
171
  if (!parsed.success) throw new HttpError(400, code, described(parsed.error));
172
172
  return parsed.data;
173
173
  }
@@ -0,0 +1,11 @@
1
+ import { Grain, TimeX } from "./types.mjs";
2
+ /**
3
+ * `count` buckets of a grain from a date (`2025-01-01`). With `running`, the last one's data
4
+ * stops part of the way through it; with `late`, the first one's starts part of the way in.
5
+ */
6
+ export declare function timeBuckets(from: string, how: {
7
+ grain: Exclude<Grain, "hour">;
8
+ count: number;
9
+ running?: boolean;
10
+ late?: boolean;
11
+ }): TimeX;
@@ -0,0 +1,66 @@
1
+ import { ChartInputError } from "./input-error.mjs";
2
+ // src/data/buckets.ts
3
+ const DAY = 864e5;
4
+ const label = (ms) => new Date(ms).toISOString().slice(0, 10);
5
+ /** The first instant of the bucket `steps` after `start`. */
6
+ function step(start, grain, steps) {
7
+ const date = new Date(start);
8
+ if (grain === "day") return start + steps * DAY;
9
+ if (grain === "week") return start + steps * 7 * DAY;
10
+ const months = {
11
+ month: 1,
12
+ quarter: 3,
13
+ year: 12
14
+ }[grain] * steps;
15
+ const year = date.getUTCFullYear();
16
+ const month = date.getUTCMonth() + months;
17
+ const last = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
18
+ return Date.UTC(year, month, Math.min(date.getUTCDate(), last));
19
+ }
20
+ /** What a bucket's data covers only part of: its start, its end, or both when it is the only bucket. */
21
+ function partOf(late, running) {
22
+ if (late && running) return { partial: "both" };
23
+ if (late) return { partial: "start" };
24
+ return running ? { partial: "end" } : {};
25
+ }
26
+ /**
27
+ * `count` buckets of a grain from a date (`2025-01-01`). With `running`, the last one's data
28
+ * stops part of the way through it; with `late`, the first one's starts part of the way in.
29
+ */
30
+ function timeBuckets(from, how) {
31
+ if (![
32
+ "day",
33
+ "week",
34
+ "month",
35
+ "quarter",
36
+ "year"
37
+ ].includes(how.grain)) throw new ChartInputError("grain", "Expected day, week, month, quarter or year.");
38
+ if (!Number.isSafeInteger(how.count) || how.count < 0) throw new ChartInputError("count", "Expected a nonnegative whole number of buckets.");
39
+ const start = Date.parse(`${from}T00:00:00Z`);
40
+ if (!Number.isFinite(start) || label(start) !== from) throw new ChartInputError("from", "Expected a calendar date such as 2026-01-31.");
41
+ const list = Array.from({ length: how.count }, (_v, i) => {
42
+ const at = step(start, how.grain, i);
43
+ return {
44
+ label: label(at),
45
+ from: at,
46
+ to: step(start, how.grain, i + 1),
47
+ ...partOf(how.late === true && i === 0, how.running === true && i === how.count - 1)
48
+ };
49
+ });
50
+ return {
51
+ grain: how.grain,
52
+ buckets: list
53
+ };
54
+ }
55
+ /** Whether a bucket follows the one before it with no bucket missing between. */
56
+ function follows(buckets, index) {
57
+ const before = buckets[index - 1];
58
+ const bucket = buckets[index];
59
+ if (before === void 0 || bucket === void 0) return false;
60
+ return bucket.from - before.to < (bucket.to - bucket.from) / 2;
61
+ }
62
+ /** Whether a bucket's value is not whole at its start: the data begins part of the way into it. */
63
+ const starting = (bucket) => bucket?.partial === "start" || bucket?.partial === "both";
64
+ /** Whether a bucket's value is not whole at its end: the period still running. */
65
+ const running = (bucket) => bucket?.partial === "end" || bucket?.partial === "both";
66
+ export { follows, running, starting, timeBuckets };
@@ -0,0 +1,55 @@
1
+ import { ChartInputError } from "./input-error.mjs";
2
+ import { otherLast } from "./rows.mjs";
3
+ // src/data/clean.ts
4
+ /** The value when it can be drawn, else none. */
5
+ function drawable(value) {
6
+ if (value === null || value === void 0) return null;
7
+ if (typeof value !== "number") throw new ChartInputError("value", "Expected a number or null. Convert database strings before drawing.");
8
+ return Number.isFinite(value) ? value : null;
9
+ }
10
+ /** A series can omit trailing values. An extra value cannot be placed on the time axis. */
11
+ function cleanSeries(series, index, buckets) {
12
+ const { previous, ...rest } = series;
13
+ for (const field of ["values", "previous"]) {
14
+ const length = series[field]?.length ?? 0;
15
+ if (length > buckets) throw new ChartInputError(`series[${String(index)}].${field}`, `Series "${series.key}" has ${String(length)} values for ${String(buckets)} time buckets.`);
16
+ }
17
+ return {
18
+ ...rest,
19
+ values: series.values.map((value) => drawable(value)),
20
+ ...previous === void 0 ? {} : { previous: previous.map((value) => drawable(value)) }
21
+ };
22
+ }
23
+ /** Each bucket must cover a finite interval and follow the previous one. Calendar gaps are valid. */
24
+ function cleanTable(table) {
25
+ let end = -Infinity;
26
+ for (const [i, bucket] of table.x.buckets.entries()) {
27
+ if (!Number.isFinite(bucket.from) || !Number.isFinite(bucket.to) || bucket.from < end || bucket.to <= bucket.from) throw new ChartInputError(`x.buckets[${String(i)}]`, "Expected a non-overlapping time interval in chronological order.");
28
+ end = bucket.to;
29
+ }
30
+ return {
31
+ x: table.x,
32
+ series: table.series.map((s, index) => cleanSeries(s, index, table.x.buckets.length))
33
+ };
34
+ }
35
+ /**
36
+ * A range a host asks for, its lower end first whichever way round it was given, when both its
37
+ * ends are finite; none otherwise, as for any number that is not finite. Every kind that takes
38
+ * a range (a grid's shading, a histogram's highlight) reads it here.
39
+ */
40
+ function finiteRange(range) {
41
+ if (range?.every((end) => Number.isFinite(end)) !== true) return void 0;
42
+ return range[0] <= range[1] ? range : [range[1], range[0]];
43
+ }
44
+ /**
45
+ * A table cleaned for a chart of one panel per series: Other, the rest of the whole, is put
46
+ * last wherever a host gave it, as every chart draws it last.
47
+ */
48
+ function panelTable(table) {
49
+ const cleaned = cleanTable(table);
50
+ return {
51
+ ...cleaned,
52
+ series: otherLast(cleaned.series)
53
+ };
54
+ }
55
+ export { cleanTable, drawable, finiteRange, panelTable };
@@ -0,0 +1,19 @@
1
+ import { Measure } from "./types.mjs";
2
+ export type MeasureStyle = {
3
+ /** An ISO 4217 code: the values are money. */
4
+ currency?: string;
5
+ /** The values are fractions of one, read as percents. */
6
+ percent?: boolean;
7
+ whole?: boolean;
8
+ additive?: boolean;
9
+ better?: "up" | "down";
10
+ locale?: string;
11
+ };
12
+ /** A measure whose values are plain numbers, money or percents, formatted by the locale's rules. */
13
+ export declare function measure(label: string, style?: MeasureStyle): Measure;
14
+ /**
15
+ * How a host writes a number of points: "4 pts" for 4. It is given a size, never below zero:
16
+ * each kind says which way the change went itself (a sign, an arrow, a word), so one writer
17
+ * serves every kind.
18
+ */
19
+ export type Points = (size: number) => string;
@@ -0,0 +1,174 @@
1
+ // src/data/format.ts
2
+ /** The minus sign a number is written with: the true one, as wide as a plus, not a hyphen. */
3
+ const typeset = (text) => text.replace("-", "−");
4
+ /** What every form of a measure's numbers shares: its unit, and how nothing and whole numbers are written. */
5
+ function unitOf(style) {
6
+ return {
7
+ ...style.currency === void 0 ? style.percent === true ? { style: "percent" } : {} : {
8
+ style: "currency",
9
+ currency: style.currency
10
+ },
11
+ signDisplay: "negative",
12
+ minimumFractionDigits: 0
13
+ };
14
+ }
15
+ /** How a measure's numbers are written in full: money keeps its cents when it has any ($4.99), and drops them when it has none ($1,200). */
16
+ function fullOf(style) {
17
+ if (style.currency !== void 0) return {
18
+ minimumFractionDigits: 2,
19
+ maximumFractionDigits: 2,
20
+ trailingZeroDisplay: "stripIfInteger"
21
+ };
22
+ return { maximumFractionDigits: style.percent === true ? 1 : 2 };
23
+ }
24
+ /** Below this a plain number has no figure left in two decimals: 0.0031 would be written "0". */
25
+ const FINE = .1;
26
+ /** Below this a number's leading zeros run long, and it is written by its power of ten. */
27
+ const MINUTE = 1e-6;
28
+ /**
29
+ * How a plain number too small for two decimals is written: by its first two figures (0.0031,
30
+ * never "0"), and by its power of ten when even those sit past a run of zeros (5E−324), so a
31
+ * value that is not zero is never written as zero and a fall from 0.0042 to 0.0031 is not
32
+ * called no change. Money keeps its cents and a percent its tenths, by their own conventions,
33
+ * and whole things have no fractions: for those, and for any number a tenth or more, nothing.
34
+ */
35
+ function fineOf(style, unit) {
36
+ const plain = style.currency === void 0 && style.percent !== true && style.whole !== true;
37
+ const figures = {
38
+ ...unit,
39
+ maximumSignificantDigits: 2
40
+ };
41
+ const small = new Intl.NumberFormat(style.locale, figures);
42
+ const minute = new Intl.NumberFormat(style.locale, {
43
+ ...figures,
44
+ notation: "scientific"
45
+ });
46
+ return (value) => {
47
+ const size = Math.abs(value);
48
+ if (!plain || !(size > 0) || size >= FINE) return void 0;
49
+ return (size < MINUTE ? minute : small).format(value);
50
+ };
51
+ }
52
+ /** A measure whose values are plain numbers, money or percents, formatted by the locale's rules. */
53
+ function measure(label, style = {}) {
54
+ const unit = unitOf(style);
55
+ const percent = style.percent === true;
56
+ const compact = new Intl.NumberFormat(style.locale, {
57
+ ...unit,
58
+ ...percent ? {} : { notation: "compact" },
59
+ maximumFractionDigits: 1
60
+ });
61
+ const whole = new Intl.NumberFormat(style.locale, {
62
+ ...unit,
63
+ maximumFractionDigits: 0
64
+ });
65
+ const short = (value) => percent && Math.abs(value) >= .1 ? whole.format(value) : compact.format(value);
66
+ const full = new Intl.NumberFormat(style.locale, {
67
+ ...unit,
68
+ ...fullOf(style)
69
+ });
70
+ const fine = fineOf(style, unit);
71
+ return {
72
+ label,
73
+ ...percent ? { share: true } : {},
74
+ tick: (value) => typeset(fine(value) ?? short(value)),
75
+ text: (value) => typeset(fine(value) ?? full.format(value)),
76
+ ...style.whole === void 0 ? {} : { whole: style.whole },
77
+ additive: style.additive ?? !percent,
78
+ ...style.better === void 0 ? {} : { better: style.better }
79
+ };
80
+ }
81
+ /**
82
+ * How a share of a whole is written wherever a chart says one (a step's share of the first, a
83
+ * bin's share of all values, a change): the full form of a percent, 66.7%.
84
+ */
85
+ function percentText(locale) {
86
+ return measure("", {
87
+ percent: true,
88
+ ...locale === void 0 ? {} : { locale }
89
+ }).text;
90
+ }
91
+ /**
92
+ * A series' value at a place as it is written: the host's own text for it when it gave one,
93
+ * else the measure's. Nothing where there is no value.
94
+ */
95
+ function textAt(series, index) {
96
+ const value = series.values[index] ?? null;
97
+ if (value === null) return void 0;
98
+ return said(series.texts?.[index]) ?? series.measure.text(value);
99
+ }
100
+ /** A size with the sign of the way it went: "+4 pts", "−4 pts", and as it is for no change. */
101
+ const signed = (sign, size) => sign > 0 ? `+${size}` : sign < 0 ? `−${size}` : size;
102
+ /**
103
+ * How far something changed between two values, as it may be written, and which way it reads
104
+ * as having gone: the one rule every kind that writes a change goes by. A change in a share is
105
+ * written in points when the host says how, and it went the way it moved unless its points
106
+ * read as the points of none or its two values read alike. With no points writer it is not
107
+ * written at all (40% to 46% is not "6%"): the kind says it another way (an arrow alone, its
108
+ * two values), and it went the way its two values read. Any other measure's change is the
109
+ * kind's `own` to write and read.
110
+ */
111
+ function changeWritten(ends, reads, how) {
112
+ if (reads.share !== true) return how.own();
113
+ const went = orderAsWritten(ends.to, ends.from, reads.text);
114
+ if (how.points === void 0) return {
115
+ text: void 0,
116
+ sign: went
117
+ };
118
+ const size = how.points(Math.abs(ends.to - ends.from));
119
+ return {
120
+ text: size,
121
+ sign: size === how.points(0) ? 0 : went
122
+ };
123
+ }
124
+ /** The arrow that says which way a change went, beside the colour that says it too: none for no change. */
125
+ const arrowOf = (sign) => sign > 0 ? "↑" : sign < 0 ? "↓" : "";
126
+ /** A text with the arrow of the way it went before it ("↑ 88%"), in every kind; the text alone for no change. */
127
+ const arrowed = (sign, text) => sign === 0 ? text : `${arrowOf(sign)} ${text}`;
128
+ /** A host's own text for a value, when it gave one that says something: an empty text is none. */
129
+ const said = (text) => text === void 0 || text === "" ? void 0 : text;
130
+ /**
131
+ * The sign of a change as it is written: nothing when its text is the text of no change. A
132
+ * chart colours, arrows and names a change by this, so it never calls a rise what its own
133
+ * number shows as zero.
134
+ */
135
+ function signAsWritten(change, text) {
136
+ if (!(Math.abs(change) > 0) || text(Math.abs(change)) === text(0)) return 0;
137
+ return change > 0 ? 1 : -1;
138
+ }
139
+ /** Which way one written number stands to another: 0 when the two are written alike. */
140
+ function orderAsWritten(a, b, text) {
141
+ if (text(a) === text(b) || a === b) return 0;
142
+ return a > b ? 1 : -1;
143
+ }
144
+ /**
145
+ * Which way a value moved from another, as the two are written: 0 when they read alike, or
146
+ * when the change between them reads as none. What a chart calls a rise or a fall.
147
+ */
148
+ function movedAsWritten(from, to, text) {
149
+ return orderAsWritten(to, from, text) === 0 ? 0 : signAsWritten(to - from, text);
150
+ }
151
+ /**
152
+ * The one of some things with the largest value, as the values are written; nothing when there
153
+ * are fewer than two things, or when the largest two that may be named read alike: a chart
154
+ * names no "highest" of one thing alone, and none among equals. `counts` says which of the
155
+ * things may be named (a waterfall's rises among its changes, a funnel's drops among its
156
+ * rates): the others only make up the two it takes to compare. Every kind's "highest",
157
+ * "largest" and "moved most" is picked here.
158
+ */
159
+ function topAsWritten(things, value, text, counts = () => true) {
160
+ if (things.length < 2) return void 0;
161
+ const [first, second] = things.filter((thing) => counts(thing)).toSorted((a, b) => value(b) - value(a));
162
+ if (first === void 0) return void 0;
163
+ return second !== void 0 && orderAsWritten(value(first), value(second), text) === 0 ? void 0 : first;
164
+ }
165
+ /**
166
+ * Whether a change went its measure's better way: 1 the better way, -1 the worse, 0 for a change
167
+ * that reads as none or a measure that says neither way is better. The colour of a change and
168
+ * the words about it both go by this, so they cannot disagree.
169
+ */
170
+ function betterWay(sign, reads) {
171
+ if (reads.better === void 0 || sign === 0) return 0;
172
+ return sign > 0 === (reads.better === "up") ? 1 : -1;
173
+ }
174
+ export { arrowOf, arrowed, betterWay, changeWritten, measure, movedAsWritten, orderAsWritten, percentText, said, signAsWritten, signed, textAt, topAsWritten };
@@ -0,0 +1,5 @@
1
+ /** A standalone chart received an input it cannot represent, with the field the caller can fix. */
2
+ export declare class ChartInputError extends TypeError {
3
+ readonly field: string;
4
+ constructor(field: string, message: string);
5
+ }
@@ -0,0 +1,11 @@
1
+ // src/data/input-error.ts
2
+ /** A standalone chart received an input it cannot represent, with the field the caller can fix. */
3
+ var ChartInputError = class extends TypeError {
4
+ field;
5
+ constructor(field, message) {
6
+ super(`${field}: ${message}`);
7
+ this.name = "ChartInputError";
8
+ this.field = field;
9
+ }
10
+ };
11
+ export { ChartInputError };
@@ -0,0 +1,14 @@
1
+ // src/data/range.ts
2
+ /** The largest of some numbers, or `floor` when there are none or all are below it. */
3
+ const most = (values, floor = Number.NEGATIVE_INFINITY) => values.reduce((found, value) => Math.max(found, value), floor);
4
+ /** The smallest of some numbers, or `ceiling` when there are none or all are above it. */
5
+ const least = (values, ceiling = Number.POSITIVE_INFINITY) => values.reduce((found, value) => Math.min(found, value), ceiling);
6
+ /** Fraction along a finite range. Halving both ends keeps a span across the largest floats finite. */
7
+ function fractionAlong(low, high) {
8
+ const span = high - low;
9
+ if (span === 0) return () => 0;
10
+ if (Number.isFinite(span)) return (value) => (value - low) / span;
11
+ const halfSpan = high / 2 - low / 2;
12
+ return (value) => (value / 2 - low / 2) / halfSpan;
13
+ }
14
+ export { fractionAlong, least, most };
@@ -0,0 +1,13 @@
1
+ /** A thing a chart draws one of: a row, a step, a point. */
2
+ export type Named = {
3
+ label: string;
4
+ /** Its name in the data, when two may share a label; its label when left out. */
5
+ key?: string;
6
+ };
7
+ /** A thing's identity: its key, else its label. A hover stop, a focus and a mark all use this. */
8
+ export declare const keyOf: (thing: Named) => string;
9
+ /**
10
+ * The identity of a thing in two parts: a series and a bucket, a row and a column. Written so
11
+ * no two pairs can read alike, whatever is in their parts: a label may hold any character.
12
+ */
13
+ export declare const pairKey: (first: string, second: string) => string;
@@ -0,0 +1,31 @@
1
+ // src/data/rows.ts
2
+ /** A thing's identity: its key, else its label. A hover stop, a focus and a mark all use this. */
3
+ const keyOf = (thing) => thing.key ?? thing.label;
4
+ /** The place of the last value there is in a list; -1 when there is none. */
5
+ const lastAt = (values) => values.findLastIndex((v) => v !== null);
6
+ /**
7
+ * The identity of a thing in two parts: a series and a bucket, a row and a column. Written so
8
+ * no two pairs can read alike, whatever is in their parts: a label may hold any character.
9
+ */
10
+ const pairKey = (first, second) => JSON.stringify([first, second]);
11
+ /**
12
+ * Rows in ranked order: those with a value to rank by first, largest first, then those with
13
+ * none, then those `last` names (Other); ties, and every row when the order is given, keep the
14
+ * order they came in.
15
+ */
16
+ function ranked(rows, by) {
17
+ const group = (row) => {
18
+ if (by.last?.(row) === true) return 2;
19
+ return by.value(row) === null && !by.given ? 1 : 0;
20
+ };
21
+ const size = (row) => by.given ? 0 : by.value(row) ?? 0;
22
+ return rows.map((row, index) => ({
23
+ row,
24
+ index
25
+ })).toSorted((a, b) => group(a.row) - group(b.row) || size(b.row) - size(a.row) || a.index - b.index).map(({ row }) => row);
26
+ }
27
+ /** The things that may be ranked: Other is what was left over, so it is never the highest or the lowest. */
28
+ const rankable = (things) => things.filter((thing) => thing.other !== true);
29
+ /** Some things with Other after the rest, in the order given otherwise: Other is what was left over, so it comes last in a ranking, and on top of a stack. */
30
+ const otherLast = (things) => [...things.filter((thing) => thing.other !== true), ...things.filter((thing) => thing.other === true)];
31
+ export { keyOf, lastAt, otherLast, pairKey, rankable, ranked };
@@ -0,0 +1,55 @@
1
+ import { measure } from "./format.mjs";
2
+ import { otherLast } from "./rows.mjs";
3
+ // src/data/shares.ts
4
+ /**
5
+ * Each value as its share of its place's total. A place has no shares when its total is not
6
+ * above zero, or when any value there is below zero: a whole with a negative part has no parts
7
+ * to speak of, and drawing the negative as nothing would be drawing a number that is not there.
8
+ */
9
+ function shares(series, places) {
10
+ const at = (values, i) => values[i] ?? null;
11
+ const wholes = Array.from({ length: places }, (_v, i) => {
12
+ const parts = series.map((values) => at(values, i) ?? 0);
13
+ const most = Math.max(0, ...parts);
14
+ return {
15
+ most,
16
+ total: parts.some((part) => part < 0) || most <= 0 ? 0 : parts.reduce((sum, part) => sum + part / most, 0)
17
+ };
18
+ });
19
+ return series.map((values) => Array.from({ length: places }, (_v, i) => {
20
+ const value = at(values, i);
21
+ const { most, total } = wholes[i] ?? {
22
+ most: 0,
23
+ total: 0
24
+ };
25
+ return value === null || total <= 0 ? null : value / most / total;
26
+ }));
27
+ }
28
+ /** Whether every series' values may be added to the others'. */
29
+ const addsUp = (series) => series.every((s) => s.measure.additive !== false);
30
+ /** The series as shares of each place's total, read as percents. */
31
+ function asShares(series, places, locale) {
32
+ const parts = shares(series.map((s) => s.values), places);
33
+ const shareOf = (label) => measure(`${label}, share of total`, {
34
+ percent: true,
35
+ additive: true,
36
+ ...locale === void 0 ? {} : { locale }
37
+ });
38
+ return series.map((s, i) => {
39
+ const { previous: _previous, texts: _texts, ...rest } = s;
40
+ return {
41
+ ...rest,
42
+ values: parts[i] ?? [],
43
+ measure: shareOf(s.measure.label)
44
+ };
45
+ });
46
+ }
47
+ /** The series in the order they are stacked or stood side by side: as given, with Other last, so it is on top. */
48
+ const stackOrder = (series) => otherLast(series);
49
+ /**
50
+ * The levels a chart of shares is read against: each a share of the whole, from none of it to
51
+ * all of it. A level outside that has no place on a scale that ends at the whole, so it is not
52
+ * drawn: the stack fills the plot, whatever a host asks to mark.
53
+ */
54
+ const levelsOfShares = (references) => (references ?? []).filter((level) => level.value >= 0 && level.value <= 1);
55
+ export { addsUp, asShares, levelsOfShares, stackOrder };
@@ -0,0 +1,106 @@
1
+ import { TextMeasurer } from "../text/measure.mjs";
2
+ import { Words } from "./words.mjs";
3
+ /** A value to draw; null where there is none, which leaves a gap and is never drawn as zero. */
4
+ export type Value = number | null;
5
+ /** How a measure's values read and what they mean. */
6
+ export type Measure = {
7
+ label: string;
8
+ /** A short form for an axis: 12K, $1.2M. */
9
+ tick: (value: number) => string;
10
+ /** The full form, for a label or a tooltip. */
11
+ text: (value: number) => string;
12
+ /** Counts: the axis steps in whole numbers. */
13
+ whole?: boolean;
14
+ /** False for a rate or an average: its values are never stacked or summed. */
15
+ additive?: boolean;
16
+ /**
17
+ * Its values are shares of a whole, written as percents. A change in one is said in points
18
+ * or as its two values, never as a percent of a percent (4% to 3% is not "down 25%").
19
+ */
20
+ share?: boolean;
21
+ /** Which way is good, so a change can be read as better or worse. */
22
+ better?: "up" | "down";
23
+ };
24
+ /**
25
+ * The colour a thing asks for, in every kind that colours things one by one (a series, a
26
+ * ranked bar, a scatter's point): its place in the palette, which follows the thing so a
27
+ * filter repaints no survivor; or a colour of its own, which wins over the palette's.
28
+ */
29
+ export type Tint = {
30
+ slot?: number;
31
+ color?: string;
32
+ };
33
+ /** A thing that may be Other: everything a limit folded together, drawn last, in the quiet grey unless it brings a colour of its own. */
34
+ export type Toned = Tint & {
35
+ other?: boolean;
36
+ };
37
+ export type Series = Toned & {
38
+ key: string;
39
+ label: string;
40
+ /** One value per place on the x axis. */
41
+ values: readonly Value[];
42
+ /**
43
+ * Each value as the host writes it, place for place, when it has a more exact way than the
44
+ * measure's (a decimal a float cannot hold). The picture is still placed by `values`.
45
+ */
46
+ texts?: readonly (string | undefined)[];
47
+ measure: Measure;
48
+ /** The same series over the comparison period, place for place. */
49
+ previous?: readonly Value[];
50
+ };
51
+ export type Grain = "hour" | "day" | "week" | "month" | "quarter" | "year";
52
+ /**
53
+ * A time bucket: its name (a local date, or an hour's instant), its first instant and the first
54
+ * instant after it, in milliseconds, and whether the data covers only part of it.
55
+ */
56
+ export type Bucket = {
57
+ label: string;
58
+ from: number;
59
+ to: number;
60
+ partial?: "start" | "end" | "both";
61
+ };
62
+ export type TimeX = {
63
+ grain: Grain;
64
+ buckets: readonly Bucket[];
65
+ /**
66
+ * Each bucket's whole name as the host writes it, bucket for bucket, for a tooltip and the
67
+ * summary. Left out, a bucket is named from the calendar ("Nov 2 – 8, 2026" for a week).
68
+ */
69
+ titles?: readonly (string | undefined)[];
70
+ /** The zone hour buckets are named in; day and longer buckets name local dates already. */
71
+ zone?: string;
72
+ };
73
+ /**
74
+ * Series over time. A chart reads every series of a table on one value axis, whose numbers its
75
+ * first series' measure writes: series may be measures of different names (tasks and hours),
76
+ * but they are read in one unit. Measures in different units belong in different charts, or in
77
+ * small multiples with a scale each.
78
+ */
79
+ export type TimeTable = {
80
+ x: TimeX;
81
+ series: readonly Series[];
82
+ };
83
+ /** Where a chart is drawn: its size, how wide a text is, the reader's locale and words. */
84
+ export type Env = {
85
+ width: number;
86
+ height: number;
87
+ measure: TextMeasurer;
88
+ locale?: string;
89
+ words?: Words;
90
+ };
91
+ /** What a chart says of itself, drawn inside it so a saved picture stands alone. */
92
+ export type Header = {
93
+ title?: string;
94
+ subtitle?: string;
95
+ source?: string;
96
+ };
97
+ /** A value marked across the plot: a goal, an average, a limit. */
98
+ export type Reference = {
99
+ value: number;
100
+ label: string;
101
+ };
102
+ /** A moment marked on a time axis: a launch, a price change. */
103
+ export type EventMark = {
104
+ at: number;
105
+ label: string;
106
+ };
@@ -0,0 +1,44 @@
1
+ import { Grain } from "./types.mjs";
2
+ export type Words = {
3
+ /** Beside a period still running: its value is not final. */
4
+ soFar: string;
5
+ /** Names the comparison period's value, written as a value: "before $40K". */
6
+ before: (value: string) => string;
7
+ /** Names what a number is read against, by its name or its value: "vs last month". */
8
+ versus: (what: string) => string;
9
+ /** Beside a period the data covers only part of, other than one still running. */
10
+ partial: string;
11
+ /** Says how many rows, panels or series there was no room to draw. */
12
+ more: (count: number) => string;
13
+ /**
14
+ * Beside a period drawn in one column with others, in a chart of more periods than pixels:
15
+ * how many periods the column is the average of. English when left out.
16
+ */
17
+ averaged?: (count: number) => string;
18
+ /** Visible explanation when the plotted columns average several periods. */
19
+ merged?: (count: number, grain: Grain, approximate: boolean) => string;
20
+ funnel: {
21
+ /** Between two steps: the share of the step above that went on, written as a percent. */
22
+ continues: (percent: string) => string;
23
+ /** Beside the step that loses the most. */
24
+ largestDrop: string;
25
+ /** Beside a step's value: its share of the first step, written as a percent. */
26
+ ofAll: (percent: string) => string;
27
+ /** In a step's tooltip: its share of the first step, and of the step before. */
28
+ ofFirstStep: (percent: string) => string;
29
+ ofStepBefore: (percent: string) => string;
30
+ };
31
+ waterfall: {
32
+ /** In a row's tooltip: the running total after it, written as a value. */
33
+ runningTotal: (value: string) => string;
34
+ };
35
+ histogram: {
36
+ /** Names how many values a bin holds. */
37
+ count: string;
38
+ /** Names a bin by its two edges, as a pointer's title: "400 to 450". */
39
+ range: (from: string, to: string) => string;
40
+ };
41
+ };
42
+ /** Every word a chart draws: a host's table with English for each word added since it was written. */
43
+ export type AllWords = Required<Words>;
44
+ export declare const ENGLISH: AllWords;