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
@@ -0,0 +1,185 @@
1
+ import { defs, ids } from "./defs.mjs";
2
+ import { attrs, escapeText, round, stamp } from "./markup.mjs";
3
+ import { SURFACE, paintCss } from "./paint.mjs";
4
+ // src/scene/svg.ts
5
+ /** The width of the surface ring behind a text that asks for a halo. */
6
+ const HALO = 3;
7
+ /** The page's own font when the page styles the picture; a system face when it stands alone. */
8
+ const PAGE_FONT = "var(--dd-font, system-ui, sans-serif)";
9
+ const OWN_FONT = "system-ui, -apple-system, 'Segoe UI', sans-serif";
10
+ const isFade = (fill) => typeof fill === "object";
11
+ /** Every node of a scene, groups and their children alike. */
12
+ const flat = (nodes) => nodes.flatMap((node) => node.kind === "group" ? [node, ...flat(node.children)] : [node]);
13
+ /**
14
+ * Some nodes as SVG text, with the fades and clip boxes they refer to and no `<svg>` around
15
+ * them: for a layer drawn over a picture, such as what lights at a hover stop.
16
+ */
17
+ function renderNodes(nodes, options = {}) {
18
+ const all = flat(nodes);
19
+ const fillDefs = all.flatMap((n) => "fill" in n && isFade(n.fill) ? [n.fill] : []);
20
+ const clipDefs = all.flatMap((n) => n.kind === "group" && n.clip !== void 0 ? [n.clip] : []);
21
+ const id = options.id ?? (fillDefs.length + clipDefs.length === 0 ? "dd" : `dd-${stamp(JSON.stringify(nodes))}`);
22
+ const fades = ids(fillDefs, `${id}-f`);
23
+ const clips = ids(clipDefs, `${id}-c`);
24
+ const paint = (p) => paintCss(p, options.theme);
25
+ const context = {
26
+ markKeys: options.markKeys !== false,
27
+ paint,
28
+ fill: (fill) => {
29
+ if (isFade(fill)) return `url(#${fades.get(JSON.stringify(fill)) ?? ""})`;
30
+ return fill === void 0 ? void 0 : paint(fill);
31
+ },
32
+ clip: (box) => box === void 0 ? void 0 : `url(#${clips.get(JSON.stringify(box)) ?? ""})`
33
+ };
34
+ return `${defs(fades, clips, paint)}${nodes.map((node) => nodeSvg(node, context)).join("")}`;
35
+ }
36
+ /** The picture as SVG text. */
37
+ function renderSvg(scene, options = {}) {
38
+ return `<svg${attrs({
39
+ xmlns: "http://www.w3.org/2000/svg",
40
+ viewBox: `0 0 ${round(scene.width)} ${round(scene.height)}`,
41
+ width: scene.width,
42
+ height: scene.height,
43
+ role: "img",
44
+ "aria-label": scene.summary,
45
+ "font-family": options.font ?? (options.theme === void 0 ? PAGE_FONT : OWN_FONT),
46
+ style: "font-variant-numeric: tabular-nums"
47
+ })}>${renderNodes(scene.nodes, options)}</svg>`;
48
+ }
49
+ const shared = (node, context) => ({
50
+ opacity: node.opacity,
51
+ "data-part": node.part,
52
+ "data-key": context.markKeys ? node.key : void 0
53
+ });
54
+ function nodeSvg(node, context) {
55
+ switch (node.kind) {
56
+ case "group": {
57
+ const children = node.children.map((child) => nodeSvg(child, context)).join("");
58
+ return `<g${attrs({
59
+ ...shared(node, context),
60
+ "clip-path": context.clip(node.clip)
61
+ })}>${children}</g>`;
62
+ }
63
+ case "rect": return rectSvg(node, context);
64
+ case "path": return pathSvg(node, context);
65
+ case "circle": return circleSvg(node, context);
66
+ case "line": return lineSvg(node, context);
67
+ case "text": return textSvg(node, context);
68
+ }
69
+ }
70
+ function pathSvg(node, context) {
71
+ return `<path${attrs({
72
+ ...shared(node, context),
73
+ d: node.d,
74
+ fill: context.fill(node.fill) ?? "none",
75
+ ...stroke(node, context),
76
+ "stroke-linejoin": "round",
77
+ "stroke-linecap": "round"
78
+ })}/>`;
79
+ }
80
+ function circleSvg(node, context) {
81
+ return `<circle${attrs({
82
+ ...shared(node, context),
83
+ cx: node.cx,
84
+ cy: node.cy,
85
+ r: node.r,
86
+ fill: context.fill(node.fill) ?? "none",
87
+ ...stroke(node, context)
88
+ })}/>`;
89
+ }
90
+ function lineSvg(node, context) {
91
+ const straight = node.x1 === node.x2 || node.y1 === node.y2;
92
+ return `<line${attrs({
93
+ ...shared(node, context),
94
+ x1: node.x1,
95
+ y1: node.y1,
96
+ x2: node.x2,
97
+ y2: node.y2,
98
+ ...stroke(node, context),
99
+ "shape-rendering": straight ? "crispEdges" : void 0
100
+ })}/>`;
101
+ }
102
+ const stroke = (node, context) => ({
103
+ stroke: node.stroke === void 0 ? void 0 : context.paint(node.stroke),
104
+ "stroke-width": node.stroke === void 0 ? void 0 : node.strokeWidth ?? 1,
105
+ "stroke-dasharray": node.dash
106
+ });
107
+ function rectSvg(node, context) {
108
+ const paint = {
109
+ fill: context.fill(node.fill),
110
+ ...stroke(node, context)
111
+ };
112
+ if (typeof node.radius === "object") return `<path${attrs({
113
+ ...shared(node, context),
114
+ d: cornered(node, node.radius),
115
+ ...paint
116
+ })}/>`;
117
+ return `<rect${attrs({
118
+ ...shared(node, context),
119
+ x: node.x,
120
+ y: node.y,
121
+ width: node.width,
122
+ height: node.height,
123
+ rx: node.radius,
124
+ ...paint
125
+ })}/>`;
126
+ }
127
+ /** A box with a radius per corner, as a path; no radius is more than half the box. */
128
+ function cornered(box, radius) {
129
+ const most = Math.min(box.width, box.height) / 2;
130
+ const fit = (r) => Math.max(0, Math.min(r, most));
131
+ const [tl, tr, br, bl] = [
132
+ fit(radius[0]),
133
+ fit(radius[1]),
134
+ fit(radius[2]),
135
+ fit(radius[3])
136
+ ];
137
+ const { x, y, width: w, height: h } = box;
138
+ const arc = (r, dx, dy) => `a${round(r)},${round(r)} 0 0 1 ${round(dx)},${round(dy)}`;
139
+ return [
140
+ `M${round(x + tl)},${round(y)}`,
141
+ `h${round(w - tl - tr)}`,
142
+ arc(tr, tr, tr),
143
+ `v${round(h - tr - br)}`,
144
+ arc(br, -br, br),
145
+ `h${round(-(w - br - bl))}`,
146
+ arc(bl, -bl, -bl),
147
+ `v${round(-(h - bl - tl))}`,
148
+ arc(tl, tl, -tl),
149
+ "Z"
150
+ ].join("");
151
+ }
152
+ /** How far below `y` the baseline sits, in ems, so no renderer's own baseline rule is relied on. */
153
+ const DROP = {
154
+ alphabetic: 0,
155
+ middle: .35,
156
+ hanging: .78
157
+ };
158
+ function textSvg(node, context) {
159
+ const halo = node.halo === true;
160
+ return `<text${attrs({
161
+ ...shared(node, context),
162
+ x: node.x,
163
+ y: node.y + DROP[node.baseline ?? "alphabetic"] * node.size,
164
+ "text-anchor": node.anchor,
165
+ "font-size": node.size,
166
+ "font-weight": node.weight,
167
+ fill: context.paint(node.fill),
168
+ stroke: halo ? context.paint(SURFACE) : void 0,
169
+ "stroke-width": halo ? HALO : void 0,
170
+ "stroke-linejoin": halo ? "round" : void 0,
171
+ "paint-order": halo ? "stroke" : void 0
172
+ })}>${runsSvg(node, context)}</text>`;
173
+ }
174
+ /** The text's parts as spans, the browser setting each after the last; or the text itself. */
175
+ function runsSvg(node, context) {
176
+ if (node.runs === void 0) return escapeText(node.text);
177
+ return node.runs.map((run) => {
178
+ const fill = run.fill === void 0 ? void 0 : context.paint(run.fill);
179
+ return `<tspan${attrs({
180
+ fill,
181
+ "font-weight": run.weight
182
+ })}>${escapeText(run.text)}</tspan>`;
183
+ }).join("");
184
+ }
185
+ export { renderNodes, renderSvg };
@@ -0,0 +1,177 @@
1
+ /**
2
+ * A colour: a theme token (`--dd-ink`), which the page's CSS or a given theme resolves, or any
3
+ * CSS colour. Marks name tokens, so one scene wears a light and a dark theme.
4
+ */
5
+ export type Paint = string;
6
+ /** A fill that fades down from its colour: the wash under a single line. */
7
+ export type Fade = {
8
+ fade: Paint;
9
+ from: number;
10
+ to: number;
11
+ };
12
+ export type Fill = Paint | Fade;
13
+ /** A box: its top-left corner and its size. */
14
+ export type Box = {
15
+ x: number;
16
+ y: number;
17
+ width: number;
18
+ height: number;
19
+ };
20
+ /**
21
+ * What a mark is, for the host's CSS and for a test. One vocabulary across every kind, so "all
22
+ * bars" or "all names" can be styled at once: a kind takes a name from here and adds none. A
23
+ * label at a line's end is one text that holds a series' name and its last value together (so
24
+ * the two move as one when labels are spread apart): it is an `end-label`, not a `name` and a
25
+ * `value`.
26
+ */
27
+ export type Part = "header" | "legend" | "more" | "grid" | "tick" | "zero" | "axis-name" | "column" | "reference" | "event" | "guide" | "series" | "line" | "wash" | "before" | "dot" | "end" | "from" | "to" | "link" | "leader" | "bar" | "lost" | "against" | "join" | "band" | "edge" | "settled" | "open" | "cell" | "name" | "value" | "size" | "change" | "share" | "rate" | "leak" | "end-label";
28
+ type Shared = {
29
+ /** What the mark is of, as the data names it: a row's, a series' or a cell's key. Every mark of one thing carries it (a row's name and its bar), and so does its hover stop. */
30
+ key?: string;
31
+ opacity?: number;
32
+ part?: Part;
33
+ };
34
+ /** Corner radii, clockwise from the top-left. */
35
+ export type Corners = readonly [number, number, number, number];
36
+ export type RectNode = Shared & Box & {
37
+ kind: "rect";
38
+ fill: Fill;
39
+ radius?: number | Corners;
40
+ stroke?: Paint;
41
+ strokeWidth?: number;
42
+ dash?: string;
43
+ };
44
+ export type PathNode = Shared & {
45
+ kind: "path";
46
+ d: string;
47
+ fill?: Fill;
48
+ stroke?: Paint;
49
+ strokeWidth?: number;
50
+ dash?: string;
51
+ };
52
+ export type CircleNode = Shared & {
53
+ kind: "circle";
54
+ cx: number;
55
+ cy: number;
56
+ r: number;
57
+ fill?: Paint;
58
+ stroke?: Paint;
59
+ strokeWidth?: number;
60
+ };
61
+ export type LineNode = Shared & {
62
+ kind: "line";
63
+ x1: number;
64
+ y1: number;
65
+ x2: number;
66
+ y2: number;
67
+ stroke: Paint;
68
+ strokeWidth?: number;
69
+ dash?: string;
70
+ };
71
+ export type TextNode = Shared & {
72
+ kind: "text";
73
+ x: number;
74
+ y: number;
75
+ text: string;
76
+ size: number;
77
+ fill: Paint;
78
+ anchor?: "start" | "middle" | "end";
79
+ /** Where `y` is on the text: its baseline, its middle or its top. */
80
+ baseline?: "alphabetic" | "middle" | "hanging";
81
+ weight?: number;
82
+ /** A ring of the surface colour behind the text, so it reads over a line. */
83
+ halo?: boolean;
84
+ /**
85
+ * The text in parts, each with its own colour or weight, set one after another: a name and
86
+ * its value. `text` is the whole of it.
87
+ */
88
+ runs?: readonly TextRun[];
89
+ };
90
+ export type TextRun = {
91
+ text: string;
92
+ fill?: Paint;
93
+ weight?: number;
94
+ };
95
+ export type GroupNode = Shared & {
96
+ kind: "group";
97
+ children: readonly SceneNode[];
98
+ /** Children are cut to this box. */
99
+ clip?: Box;
100
+ };
101
+ export type SceneNode = RectNode | PathNode | CircleNode | LineNode | TextNode | GroupNode;
102
+ /** One value at a hover stop: what a tooltip row says, and where its dot sits. */
103
+ export type HoverItem = {
104
+ /**
105
+ * What the value is of, the same in every stop: a series' key over time, else what is
106
+ * measured (`value`, `from`, `x`). Items with one key make one column of a table.
107
+ */
108
+ key: string;
109
+ label: string;
110
+ value: string;
111
+ color: Paint;
112
+ x: number;
113
+ y: number;
114
+ /** The painted rectangle of a shared column or segment that this reading contributes to. */
115
+ bounds?: Box;
116
+ /** The radius of the mark the value is drawn as, when it is a dot larger than a lit one. */
117
+ r?: number;
118
+ /** A second, quieter text beside the value: the comparison period's, what it is read against, a share, a running total, a change in points. */
119
+ aside?: string;
120
+ };
121
+ /** A place a pointer snaps to: its title, its series values, and the band it lights. */
122
+ export type HoverStop = {
123
+ /** For a two-dimensional table, the row and column this stop describes. */
124
+ cell?: readonly [row: number, column: number];
125
+ /** What the stop is about, as the data names it: a row's key, a bucket's name. */
126
+ key: string;
127
+ x: number;
128
+ y: number;
129
+ title: string;
130
+ /** Said beside the title: "so far" on a period still running, "part of the period" on one the data starts part of the way into. */
131
+ note?: string;
132
+ items: readonly HoverItem[];
133
+ /** Stop indices in the same merged time column, end exclusive. */
134
+ span?: readonly [number, number];
135
+ band?: Box;
136
+ /** On a row's stop: how far right the row's marks and words reach, so a tooltip sits past them. */
137
+ end?: number;
138
+ /** In a scene of several plots: the one this stop is in, which a guide line is drawn across. */
139
+ plot?: Box;
140
+ };
141
+ /** What some of a stop's values are of: the key their items carry, and its name. */
142
+ export type HoverColumn = {
143
+ key: string;
144
+ label: string;
145
+ };
146
+ /**
147
+ * What a pointer finds: stops along x (a crosshair), along y (ranked bars), or the nearest in
148
+ * both (a scatter). `columns` is what the stops' values are of, where a chart knows more than
149
+ * its items say: every series of a chart over time, one with no value at any stop too, so a
150
+ * table of the stops has a column for it. Left out, the items' own keys and labels say it.
151
+ */
152
+ export type Hover = {
153
+ snap: "x" | "y" | "nearest";
154
+ stops: readonly HoverStop[];
155
+ columns?: readonly HoverColumn[];
156
+ /** Table axes when stops represent single cells. Rows can include periods with no value in any panel. */
157
+ matrix?: {
158
+ rows: readonly HoverColumn[];
159
+ columns: readonly HoverColumn[];
160
+ heading?: string;
161
+ /** All cells are stops in row order, including empty cells (a navigable heat grid). */
162
+ rowMajor?: boolean;
163
+ };
164
+ };
165
+ export type Scene = {
166
+ width: number;
167
+ height: number;
168
+ /** The plot's box, inside the axes. */
169
+ plot: Box;
170
+ /** What the picture shows, in a sentence, for a reader who cannot see it. */
171
+ summary: string;
172
+ /** Context to show beside the picture, such as the period covered by a merged column. */
173
+ footnote?: string;
174
+ nodes: readonly SceneNode[];
175
+ hover?: Hover;
176
+ };
177
+ export {};
@@ -0,0 +1,9 @@
1
+ /** How a text is set: its size in pixels and its weight. */
2
+ export type Font = {
3
+ size: number;
4
+ weight?: number;
5
+ };
6
+ /** The width of a text in pixels, set in a font. */
7
+ export type TextMeasurer = (text: string, font: Font) => number;
8
+ /** Measures by the table of widths: the same answer everywhere, with no DOM. */
9
+ export declare const tableMeasure: TextMeasurer;
@@ -0,0 +1,123 @@
1
+ // src/text/measure.ts
2
+ /**
3
+ * Advance widths in thousandths of an em: a grotesque sans (Helvetica's metrics), widened where
4
+ * the system faces are wider. Digits are the width of tabular figures, which is how a chart sets
5
+ * them. Checked against San Francisco; Segoe and Roboto run a little narrower, so a label that
6
+ * fits by this table fits in them too.
7
+ */
8
+ const WIDTHS = {
9
+ " ": 278,
10
+ "!": 278,
11
+ "\"": 405,
12
+ "#": 610,
13
+ $: 610,
14
+ "%": 889,
15
+ "&": 667,
16
+ "'": 255,
17
+ "(": 333,
18
+ ")": 333,
19
+ "*": 389,
20
+ "+": 584,
21
+ ",": 278,
22
+ "-": 430,
23
+ ".": 278,
24
+ "/": 278,
25
+ ":": 278,
26
+ ";": 278,
27
+ "<": 584,
28
+ "=": 584,
29
+ ">": 584,
30
+ "?": 556,
31
+ "@": 1015,
32
+ "[": 325,
33
+ "]": 325,
34
+ _: 556,
35
+ "·": 278,
36
+ "–": 556,
37
+ "—": 1e3,
38
+ "…": 1e3,
39
+ "’": 222,
40
+ "€": 610,
41
+ "£": 610,
42
+ "°": 400,
43
+ "↑": 790,
44
+ "↓": 790,
45
+ "→": 1e3,
46
+ "×": 584,
47
+ "−": 584
48
+ };
49
+ /** Runs of letters by width, so the table stays short. */
50
+ const RUNS = [
51
+ ["0123456789", 610],
52
+ ["abdeghnopqu", 556],
53
+ ["cksvxyz", 500],
54
+ ["ft", 305],
55
+ ["j", 278],
56
+ ["il", 222],
57
+ ["r", 333],
58
+ ["m", 833],
59
+ ["w", 722],
60
+ ["ABEKPSVXY", 667],
61
+ ["CDHNRU", 722],
62
+ ["FTZ", 611],
63
+ ["GOQ", 778],
64
+ ["I", 278],
65
+ ["J", 500],
66
+ ["L", 556],
67
+ ["M", 833],
68
+ ["W", 944]
69
+ ];
70
+ const BY_CHAR = new Map([...Object.entries(WIDTHS), ...RUNS.flatMap(([letters, width]) => Array.from(letters, (c) => [c, width]))]);
71
+ /** A character the table does not hold: a wide one (CJK, emoji) takes a full em, any other a letter's width. */
72
+ const fallback = (char) => (char.codePointAt(0) ?? 0) >= 11904 ? 1e3 : 556;
73
+ /**
74
+ * Heavier weights run wider. The margin covers what the table leaves out (kerning, a face a few
75
+ * percent wider), so a label that fits by the table fits when drawn.
76
+ */
77
+ const MEDIUM = 1.035;
78
+ const BOLD = 1.07;
79
+ const MARGIN = 1.08;
80
+ const weightOf = (weight) => weight >= 600 ? BOLD : weight >= 500 ? MEDIUM : 1;
81
+ /** Measures by the table of widths: the same answer everywhere, with no DOM. */
82
+ const tableMeasure = (text, font) => {
83
+ let units = 0;
84
+ for (const char of text) units += BY_CHAR.get(char) ?? fallback(char);
85
+ return units / 1e3 * font.size * weightOf(font.weight ?? 400) * MARGIN;
86
+ };
87
+ /** The widest of some texts in a font; nothing for none. Not a spread: a long list would not fit on the stack. */
88
+ function widest(texts, font, measure) {
89
+ return texts.reduce((most, text) => Math.max(most, measure(text, font)), 0);
90
+ }
91
+ const SLACK = .01;
92
+ /**
93
+ * A text cut to a width, ending in an ellipsis when it was cut; the whole text when it fits.
94
+ * Cut no shorter than two characters and the ellipsis (a shorter text that does not fit is cut
95
+ * to what it has, down to the ellipsis alone), even where that is still too wide: a label
96
+ * that must fit or go is `fitOrNone`'s.
97
+ */
98
+ function fitText(text, width, font, measure) {
99
+ if (measure(text, font) <= width + SLACK) return text;
100
+ const chars = Array.from(text);
101
+ let keep = chars.length - 1;
102
+ while (keep > 2 && measure(`${chars.slice(0, keep).join("").trimEnd()}…`, font) > width + SLACK) keep--;
103
+ return `${chars.slice(0, keep).join("").trimEnd()}…`;
104
+ }
105
+ /**
106
+ * A text for a width: whole when it fits; else cut, when the width is at least `least` and the
107
+ * cut fits (a cut never goes below two letters, so it can still be too wide); else nothing. A
108
+ * layout that would rather leave a name out than run it over something asks this.
109
+ */
110
+ function fitOrNone(text, at) {
111
+ if (at.measure(text, at.font) <= at.width + SLACK) return text;
112
+ if (at.width < (at.least ?? 0)) return void 0;
113
+ const cut = fitText(text, at.width, at.font, at.measure);
114
+ return at.measure(cut, at.font) <= at.width + SLACK ? cut : void 0;
115
+ }
116
+ /** Whether texts set in a row, each centred on its `x`, all clear the one before by `gap`. */
117
+ function spaced(texts, gap) {
118
+ return texts.every((text, i) => {
119
+ const before = texts[i - 1];
120
+ return before === void 0 || text.x - before.x >= (text.width + before.width) / 2 + gap;
121
+ });
122
+ }
123
+ export { fitOrNone, fitText, spaced, tableMeasure, widest };
@@ -0,0 +1,47 @@
1
+ import { Toned } from "./data/types.mjs";
2
+ import { Paint } from "./scene/types.mjs";
3
+ import { INK, MUTED, OTHER, RULE, SURFACE } from "./scene/paint.mjs";
4
+ /** The palette's colours, `--dd-series-1` to `--dd-series-6`. */
5
+ export declare const PALETTE = 6;
6
+ /** The palette's colour at a place. */
7
+ export declare const seriesPaint: (place: number) => Paint;
8
+ /**
9
+ * Each thing's colour, in the things' order: its own, else Other's quiet grey, else the
10
+ * palette's at its place. With `own` (a chart whose things wear one colour unless they ask for
11
+ * another: ranked bars), a thing that asks for no place wears `own`, and only those with a
12
+ * slot take places.
13
+ */
14
+ export declare function paintsOf(things: readonly Toned[], own?: Paint): Paint[];
15
+ /** The library's own themes: every token a scene names, as a colour. */
16
+ export declare const THEMES: {
17
+ readonly light: {
18
+ readonly "--dd-surface": "#ffffff";
19
+ readonly "--dd-ink": "#18181b";
20
+ readonly "--dd-muted": "#626571";
21
+ readonly "--dd-line": "#e4e4e7";
22
+ readonly "--dd-other": "#737380";
23
+ readonly "--dd-good": "#15803d";
24
+ readonly "--dd-danger": "#b91c1c";
25
+ readonly "--dd-series-1": "#4c6ba7";
26
+ readonly "--dd-series-2": "#a3664c";
27
+ readonly "--dd-series-3": "#2d5b51";
28
+ readonly "--dd-series-4": "#675522";
29
+ readonly "--dd-series-5": "#946379";
30
+ readonly "--dd-series-6": "#6e5b86";
31
+ };
32
+ readonly dark: {
33
+ readonly "--dd-surface": "#18181b";
34
+ readonly "--dd-ink": "#fafafa";
35
+ readonly "--dd-muted": "#a1a1aa";
36
+ readonly "--dd-line": "#27272a";
37
+ readonly "--dd-other": "#93939e";
38
+ readonly "--dd-good": "#4ade80";
39
+ readonly "--dd-danger": "#f87171";
40
+ readonly "--dd-series-1": "#91bcf5";
41
+ readonly "--dd-series-2": "#d0947b";
42
+ readonly "--dd-series-3": "#6ea59b";
43
+ readonly "--dd-series-4": "#d9c68e";
44
+ readonly "--dd-series-5": "#e8aeca";
45
+ readonly "--dd-series-6": "#ae9dc9";
46
+ };
47
+ };