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,149 @@
1
+ import "../scene/paint.mjs";
2
+ import { placeLabels } from "../layout/place-labels.mjs";
3
+ import { X_ROOM, valueGrid, zeroLine } from "../marks/axes.mjs";
4
+ import { dot } from "../marks/dot.mjs";
5
+ import { levelNotes, marked, uprightNotes } from "../marks/notes.mjs";
6
+ import { xGrid } from "../marks/x-axis.mjs";
7
+ import { fitText } from "../text/measure.mjs";
8
+ import { TEXT } from "../theme.mjs";
9
+ import { NAME_ROOM, clearOf } from "./scatter-layout.mjs";
10
+ // src/kinds/scatter-marks.ts
11
+ /**
12
+ * Dots are drawn a little see-through, so where many overlap the pile reads darker than one dot.
13
+ * The scatter's own: no other kind draws dots that may lie on top of each other.
14
+ */
15
+ const SEE_THROUGH = .85;
16
+ /** A name is never wider than this share of the plot, nor narrower than this. */
17
+ const WIDEST = .4;
18
+ const NARROWEST = 40;
19
+ /**
20
+ * The box a name takes beside its dot: its text and a pixel of air above and below. Not a line
21
+ * of names (`LINE.name`): a name stands alone, and a tight box lets names sit among close dots.
22
+ */
23
+ const NAME_BOX = TEXT.name.size + 2;
24
+ /** A point's colour: its group's, grey when it has none among groups, or the chart's own. */
25
+ function colorOf(point, at) {
26
+ if (at.groups.length === 0) return at.own;
27
+ return at.groups.find((g) => g.name === point.group)?.color ?? "--dd-other";
28
+ }
29
+ /** Both axes' hairlines and numbers, and the zero line of each axis that crosses zero. */
30
+ function gridNodes(layout, at) {
31
+ const { plot, x, y } = layout;
32
+ const { rule, env } = at;
33
+ return [
34
+ ...valueGrid(layout.yAxis, {
35
+ plot,
36
+ place: y,
37
+ reads: rule.y
38
+ }),
39
+ ...xGrid(layout.xAxis, {
40
+ plot,
41
+ place: x,
42
+ reads: rule.x,
43
+ measure: env.measure,
44
+ min: 0,
45
+ max: env.width
46
+ }),
47
+ ...zeroLine(layout.yAxis, {
48
+ plot,
49
+ place: y
50
+ }),
51
+ ...zeroLine(layout.xAxis, {
52
+ plot,
53
+ place: x,
54
+ upright: true
55
+ })
56
+ ];
57
+ }
58
+ /** The two axes' names, flat: y's over the plot at the left, x's under the plot at the right. */
59
+ function axisNames(layout, at) {
60
+ const { plot } = layout;
61
+ const { env, rule } = at;
62
+ const right = plot.x + plot.width;
63
+ const name = (text, place) => ({
64
+ kind: "text",
65
+ part: "axis-name",
66
+ text: fitText(text, place.anchor === "end" ? right : env.width, TEXT.tick, env.measure),
67
+ ...TEXT.tick,
68
+ baseline: "hanging",
69
+ ...place
70
+ });
71
+ return [name(rule.y.label, {
72
+ x: 0,
73
+ y: plot.y - NAME_ROOM,
74
+ anchor: "start"
75
+ }), name(rule.x.label, {
76
+ x: right,
77
+ y: plot.y + plot.height + X_ROOM + 1,
78
+ anchor: "end"
79
+ })];
80
+ }
81
+ /** The reference lines of both axes, their names clear of every dot and of each other. */
82
+ function notesOf(layout, at) {
83
+ const { plot } = layout;
84
+ const { rule, env } = at;
85
+ const refs = rule.references ?? {};
86
+ const room = {
87
+ plot,
88
+ measure: env.measure,
89
+ dots: layout.dots.map((d) => clearOf(d))
90
+ };
91
+ return marked([...levelNotes(refs.y ?? [], {
92
+ place: layout.y,
93
+ text: rule.y.text
94
+ }, room), ...uprightNotes(refs.x ?? [], {
95
+ place: layout.x,
96
+ text: rule.x.text
97
+ }, room)], room);
98
+ }
99
+ /**
100
+ * Dots, largest drawn first so the small ones stay on top and can be reached; a dot with no size
101
+ * in a sized chart hollow, ringed in its colour.
102
+ */
103
+ function dotNodes(dots, at) {
104
+ return dots.toSorted((a, b) => b.r - a.r || a.index - b.index).map((d) => dot({
105
+ x: d.x,
106
+ y: d.y,
107
+ r: d.r,
108
+ color: colorOf(d.point, at),
109
+ hollow: d.hollow,
110
+ part: "dot",
111
+ key: d.key,
112
+ opacity: SEE_THROUGH
113
+ }));
114
+ }
115
+ /**
116
+ * The names of the chosen dots, each beside its dot where a spot is free, most important first,
117
+ * and keyed as its dot. No name covers any dot, another name, or a box already `taken`, and
118
+ * none is set nearer another dot than its own.
119
+ */
120
+ function nameNodes(layout, at) {
121
+ const { env } = at;
122
+ const { dots, plot } = layout;
123
+ const chosen = at.chosen.flatMap((i) => dots[i] ?? []);
124
+ const widest = Math.max(NARROWEST, plot.width * WIDEST);
125
+ const texts = chosen.map((d) => fitText(d.point.label, widest, TEXT.name, env.measure));
126
+ const wanted = chosen.map((d, i) => ({
127
+ ...clearOf(d),
128
+ width: env.measure(texts[i] ?? "", TEXT.name),
129
+ height: NAME_BOX
130
+ }));
131
+ const spots = placeLabels(wanted, plot, {
132
+ dots: dots.map((d) => clearOf(d)),
133
+ taken: at.taken
134
+ });
135
+ return chosen.flatMap((d, i) => {
136
+ const spot = spots[i];
137
+ return spot === void 0 ? [] : [{
138
+ kind: "text",
139
+ part: "name",
140
+ key: d.key,
141
+ ...spot,
142
+ text: texts[i] ?? "",
143
+ ...TEXT.name,
144
+ baseline: "middle",
145
+ halo: true
146
+ }];
147
+ });
148
+ }
149
+ export { axisNames, colorOf, dotNodes, gridNodes, nameNodes, notesOf };
@@ -0,0 +1,80 @@
1
+ import { counted, noValue, summary } from "../describe.mjs";
2
+ import { colorOf } from "./scatter-marks.mjs";
3
+ // src/kinds/scatter-words.ts
4
+ /** Fewer points than this say nothing about how two measures move together. */
5
+ const FEWEST = 5;
6
+ const STRONG = .5;
7
+ /** The correlation coefficient of the points' x and y; nothing when either does not vary. */
8
+ function correlation(points) {
9
+ const n = points.length;
10
+ if (n < 2) return void 0;
11
+ const mx = points.reduce((sum, p) => sum + p.x, 0) / n;
12
+ const my = points.reduce((sum, p) => sum + p.y, 0) / n;
13
+ let sxy = 0;
14
+ let sxx = 0;
15
+ let syy = 0;
16
+ for (const p of points) {
17
+ sxy += (p.x - mx) * (p.y - my);
18
+ sxx += (p.x - mx) ** 2;
19
+ syy += (p.y - my) ** 2;
20
+ }
21
+ const r = sxy / Math.sqrt(sxx * syy);
22
+ return Number.isFinite(r) ? r : void 0;
23
+ }
24
+ /** "Revenue tends to rise with Seats", when the correlation is strong enough to say. */
25
+ function direction(points, at) {
26
+ const r = points.length < FEWEST ? void 0 : correlation(points);
27
+ if (r === void 0 || Math.abs(r) <= STRONG) return void 0;
28
+ return r > 0 ? `${at.y.label} tends to rise with ${at.x.label}` : `${at.y.label} tends to fall as ${at.x.label} rises`;
29
+ }
30
+ /**
31
+ * What a scatter shows: how many points it was given; when dots are drawn (`shown` of them),
32
+ * how many groups their colours tell apart (said of two or more, as a legend names them) and
33
+ * the measure their sizes show; how the measures move together, the points that had no place
34
+ * because a value was missing, and in a sized chart the points drawn with no size.
35
+ */
36
+ function describeScatter(data, at) {
37
+ const { points, given, groups } = data;
38
+ const drawn = at.shown > 0;
39
+ const sized = drawn ? at.size : void 0;
40
+ const sizeless = sized === void 0 ? 0 : points.filter((p) => p.size === void 0).length;
41
+ return summary([
42
+ `Scatter of ${at.y.label} against ${at.x.label}`,
43
+ counted(given, "point"),
44
+ drawn && groups > 1 ? counted(groups, "group") : void 0,
45
+ sized === void 0 ? void 0 : `sized by ${sized.label}`
46
+ ], [
47
+ direction(points, at),
48
+ noValue(given - points.length, "point"),
49
+ noValue(sizeless, "point with no size", "points with no size")
50
+ ]);
51
+ }
52
+ /**
53
+ * What a pointer finds at a dot: its name, its two values, and its size when it has one. Each
54
+ * item carries the dot's radius, so the lit ring goes round the whole of a large dot.
55
+ */
56
+ function stopOf(dot, at) {
57
+ const color = colorOf(dot.point, at);
58
+ const item = (key, measure, value) => ({
59
+ key,
60
+ label: measure.label,
61
+ value: measure.text(value),
62
+ color,
63
+ x: dot.x,
64
+ y: dot.y,
65
+ r: dot.r
66
+ });
67
+ const { size } = dot.point;
68
+ return {
69
+ key: dot.key,
70
+ x: dot.x,
71
+ y: dot.y,
72
+ title: dot.point.label,
73
+ items: [
74
+ item("x", at.x, dot.point.x),
75
+ item("y", at.y, dot.point.y),
76
+ ...at.size === void 0 || size === void 0 ? [] : [item("size", at.size, size)]
77
+ ]
78
+ };
79
+ }
80
+ export { describeScatter, stopOf };
@@ -0,0 +1,21 @@
1
+ import { Env, Header, Measure, Reference } from "../data/types.mjs";
2
+ import { Scene } from "../scene/types.mjs";
3
+ import { ScatterNamed, ScatterPoint } from "./scatter-data.mjs";
4
+ export type ScatterOptions = Header & {
5
+ x: Measure;
6
+ y: Measure;
7
+ /** A dot's area shows this measure, from each point's `size`, when the plot is tall enough. */
8
+ size?: Measure;
9
+ /** Which dots are named: the notable ones (the default), all of them, or those listed by key. */
10
+ named?: ScatterNamed;
11
+ /** Medians, averages or goals on either axis, drawn as dashed grey lines. */
12
+ references?: {
13
+ x?: readonly Reference[];
14
+ y?: readonly Reference[];
15
+ };
16
+ /** The palette place of the chart's own colour: every dot's when they fall into no groups. */
17
+ slot?: number;
18
+ };
19
+ /** A scatter of things by two measures, optionally sized by a third and coloured by group. */
20
+ export declare function scatterChart(points: readonly ScatterPoint[], options: ScatterOptions, env: Env): Scene;
21
+ export type { ScatterNamed, ScatterPoint };
@@ -0,0 +1,72 @@
1
+ import { bare, headerNodes, roomy } from "../layout/frame.mjs";
2
+ import { seriesPaint } from "../theme.mjs";
3
+ import { chosenOf, cleaned } from "./scatter-data.mjs";
4
+ import { layoutOf } from "./scatter-layout.mjs";
5
+ import { axisNames, dotNodes, gridNodes, nameNodes, notesOf } from "./scatter-marks.mjs";
6
+ import { describeScatter, stopOf } from "./scatter-words.mjs";
7
+ // src/kinds/scatter.ts
8
+ /** A scatter of things by two measures, optionally sized by a third and coloured by group. */
9
+ function scatterChart(points, options, env) {
10
+ const all = cleaned(points);
11
+ const layout = layoutOf(all, options, env);
12
+ const roomy$1 = all.length > 0 && roomy(layout.plot);
13
+ const size = layout.sized ? options.size : void 0;
14
+ const summary = describeScatter({
15
+ points: all,
16
+ given: points.length,
17
+ groups: layout.groups.length
18
+ }, {
19
+ x: options.x,
20
+ y: options.y,
21
+ size,
22
+ shown: roomy$1 ? all.length : 0
23
+ });
24
+ if (!roomy$1) return bare(env, options, summary);
25
+ const own = seriesPaint(options.slot ?? 0);
26
+ const at = {
27
+ groups: layout.groups,
28
+ own,
29
+ env
30
+ };
31
+ const notes = notesOf(layout, {
32
+ rule: options,
33
+ env
34
+ });
35
+ const chosen = chosenOf(all, options.named ?? "notable");
36
+ return {
37
+ width: env.width,
38
+ height: env.height,
39
+ plot: layout.plot,
40
+ summary,
41
+ nodes: [
42
+ ...headerNodes(env, options),
43
+ ...layout.legend?.nodes ?? [],
44
+ ...gridNodes(layout, {
45
+ rule: options,
46
+ env
47
+ }),
48
+ ...axisNames(layout, {
49
+ rule: options,
50
+ env
51
+ }),
52
+ ...notes.lines,
53
+ ...dotNodes(layout.dots, at),
54
+ ...notes.names,
55
+ ...nameNodes(layout, {
56
+ chosen,
57
+ taken: notes.taken,
58
+ env
59
+ })
60
+ ],
61
+ hover: {
62
+ snap: "nearest",
63
+ stops: layout.dots.map((dot) => stopOf(dot, {
64
+ ...at,
65
+ x: options.x,
66
+ y: options.y,
67
+ size
68
+ }))
69
+ }
70
+ };
71
+ }
72
+ export { scatterChart };
@@ -0,0 +1,91 @@
1
+ import { running, starting } from "../data/buckets.mjs";
2
+ import { cleanTable, drawable } from "../data/clean.mjs";
3
+ import { arrowOf, arrowed, changeWritten, movedAsWritten, said } from "../data/format.mjs";
4
+ // src/kinds/stat-data.ts
5
+ /**
6
+ * The arrow a change is said with, so its colour is never its only sign. A stat's change is a
7
+ * line of its own, so no change has an arrow too (the stat's own): beside a mark it has none.
8
+ */
9
+ const ARROW = {
10
+ up: arrowOf(1),
11
+ down: arrowOf(-1),
12
+ flat: "→"
13
+ };
14
+ /**
15
+ * The change from what the number is read against; nothing when either is missing. How far it
16
+ * moved is the percent of what it is read against (which nothing can be a percent of when
17
+ * that is zero or below), and it is flat when the two numbers read alike or that percent reads as
18
+ * none; a share's change is written and read by the shared rule.
19
+ */
20
+ function changeOf(value, given, percent) {
21
+ const against = drawable(given.against ?? null);
22
+ if (value === null || against === null) return void 0;
23
+ const written = changeWritten({
24
+ from: against,
25
+ to: value
26
+ }, given.measure, {
27
+ points: given.points,
28
+ own: () => {
29
+ const text = against > 0 ? percent(Math.abs((value - against) / against)) : void 0;
30
+ const moved = movedAsWritten(against, value, given.measure.text);
31
+ return {
32
+ text,
33
+ sign: text === percent(0) ? 0 : moved
34
+ };
35
+ }
36
+ });
37
+ const flat = written.sign === 0;
38
+ const way = written.sign > 0 ? "up" : "down";
39
+ return {
40
+ way: flat ? "flat" : way,
41
+ sign: written.sign,
42
+ amount: flat ? void 0 : written.text,
43
+ by: flat ? 0 : value - against,
44
+ against: given.againstLabel ?? given.measure.text(against)
45
+ };
46
+ }
47
+ /** The stat cleaned, with its change worked out. */
48
+ function statOf(given, percent) {
49
+ const value = drawable(given.value);
50
+ return {
51
+ title: given.title,
52
+ measure: given.measure,
53
+ value,
54
+ text: value === null ? void 0 : said(given.text) ?? given.measure.text(value),
55
+ short: value === null ? void 0 : given.measure.tick(value),
56
+ change: changeOf(value, given, percent)
57
+ };
58
+ }
59
+ /** The change as it is written under the number: its arrow and how far, then what it is against. */
60
+ function changeParts(change, versus) {
61
+ return {
62
+ head: change.amount === void 0 ? ARROW[change.way] : arrowed(change.sign, change.amount),
63
+ tail: ` ${versus(change.against)}`
64
+ };
65
+ }
66
+ /**
67
+ * The stat's course: its first series over its whole periods. A stat has no room to say that
68
+ * a point is unfinished, so a period still running, or one the data starts part of the way
69
+ * into, is left out; and it is one line, the comparison period being said in the change.
70
+ */
71
+ function settled(given) {
72
+ if (given === void 0) return void 0;
73
+ const table = cleanTable(given);
74
+ const { buckets } = table.x;
75
+ const from = starting(buckets[0]) ? 1 : 0;
76
+ const to = buckets.length - (buckets.length > from && running(buckets.at(-1)) ? 1 : 0);
77
+ const { titles } = table.x;
78
+ return {
79
+ x: {
80
+ ...table.x,
81
+ buckets: buckets.slice(from, to),
82
+ ...titles === void 0 ? {} : { titles: titles.slice(from, to) }
83
+ },
84
+ series: table.series.slice(0, 1).map(({ previous: _previous, texts, ...s }) => ({
85
+ ...s,
86
+ values: s.values.slice(from, to),
87
+ ...texts === void 0 ? {} : { texts: texts.slice(from, to) }
88
+ }))
89
+ };
90
+ }
91
+ export { changeParts, settled, statOf };
@@ -0,0 +1,108 @@
1
+ import { least, most } from "../data/range.mjs";
2
+ import { INK } from "../scene/paint.mjs";
3
+ import { wordsOf } from "../data/words.mjs";
4
+ import { timeScale } from "../scale/time.mjs";
5
+ import { placeOn, placeable } from "../scale/value.mjs";
6
+ import { TEXT } from "../theme.mjs";
7
+ import { changeParts } from "./stat-data.mjs";
8
+ import { END_ROOM } from "./time-plot.mjs";
9
+ // src/kinds/stat-layout.ts
10
+ /** The number: large, since it is the headline. The stat's own. */
11
+ const BIG = {
12
+ size: 30,
13
+ weight: 650,
14
+ fill: INK
15
+ };
16
+ /**
17
+ * Where each of the stat's lines starts, from the top, and where the course starts under them.
18
+ * The stat's own: they are set around its large number, not by the line heights of a header.
19
+ */
20
+ const TOPS = {
21
+ title: 1,
22
+ number: 23,
23
+ change: 60,
24
+ under: 86
25
+ };
26
+ /** The room between the number and the course, when the change has no room to be written. */
27
+ const CLEAR = 8;
28
+ /** The smallest the number is set: a name's size. */
29
+ const SMALLEST = TEXT.name.size;
30
+ /** Room kept inside the course's box: above and below the line, and either side for the dot at its end. */
31
+ const INSET = {
32
+ down: 4,
33
+ left: 4,
34
+ right: END_ROOM
35
+ };
36
+ /** The size a text is set at to fit the width: the number's own, or smaller; nothing when even the smallest is too wide. */
37
+ function sizeFor(text, env) {
38
+ const wide = env.measure(text, BIG);
39
+ if (wide <= env.width) return BIG.size;
40
+ const size = Math.floor(BIG.size * env.width / wide);
41
+ return size >= SMALLEST ? size : void 0;
42
+ }
43
+ /**
44
+ * The number, never cut: a cut number is a wrong one. Too long for the tile, it is set smaller;
45
+ * too long even then, it is written in its short form ($1.2T); and left out when that does not
46
+ * fit either, or when the picture is too short for it.
47
+ */
48
+ function numberOf(stat, env) {
49
+ const [fit] = [stat.text, stat.short].flatMap((text) => {
50
+ const size = text === void 0 ? void 0 : sizeFor(text, env);
51
+ return text === void 0 || size === void 0 ? [] : [{
52
+ text,
53
+ size
54
+ }];
55
+ });
56
+ return fit === void 0 || TOPS.number + fit.size > env.height ? void 0 : fit;
57
+ }
58
+ /**
59
+ * How much of the change has room, across (measured as it is set) and down. What it is read
60
+ * against gives way first: the arrow and how far it went are the tile's one reading of good or
61
+ * bad, so they are kept alone before the change is given up.
62
+ */
63
+ function changeShown(stat, env) {
64
+ if (stat.change === void 0 || TOPS.change + TEXT.name.size > env.height) return "none";
65
+ const { head, tail } = changeParts(stat.change, wordsOf(env).versus);
66
+ const wide = env.measure(head, TEXT.value);
67
+ if (wide + env.measure(tail, TEXT.name) <= env.width) return "all";
68
+ return wide <= env.width ? "head" : "none";
69
+ }
70
+ /** Where the course goes in its box; nothing for a course with no values. */
71
+ function courseOf(table, plot) {
72
+ const [series] = table.series;
73
+ const values = series === void 0 ? [] : series.values.filter((v) => v !== null).map((v) => placeable(v));
74
+ if (series === void 0 || values.length === 0) return void 0;
75
+ const scale = placeOn({
76
+ min: least(values),
77
+ max: most(values),
78
+ ticks: []
79
+ }, plot.y + plot.height - INSET.down, plot.y + INSET.down);
80
+ const place = (value) => scale(placeable(value));
81
+ return {
82
+ series,
83
+ center: timeScale(table.x, {
84
+ from: plot.x + INSET.left,
85
+ to: plot.x + plot.width - INSET.right
86
+ }, false).center,
87
+ place
88
+ };
89
+ }
90
+ /** Where the stat's parts go, and which of them have room. */
91
+ function layoutOf(stat, table, env) {
92
+ const change = changeShown(stat, env);
93
+ const top = change === "none" ? TOPS.change + CLEAR : TOPS.under;
94
+ const plot = {
95
+ x: 0,
96
+ y: top,
97
+ width: env.width,
98
+ height: Math.max(1, env.height - top - INSET.down)
99
+ };
100
+ return {
101
+ title: TOPS.title + TEXT.subtitle.size <= env.height,
102
+ number: numberOf(stat, env),
103
+ change,
104
+ plot,
105
+ course: table === void 0 || plot.height < 24 ? void 0 : courseOf(table, plot)
106
+ };
107
+ }
108
+ export { BIG, TOPS, layoutOf };
@@ -0,0 +1,85 @@
1
+ import { wordsOf } from "../data/words.mjs";
2
+ import { INK } from "../scene/paint.mjs";
3
+ import { seriesLine } from "../marks/series-line.mjs";
4
+ import { fitText } from "../text/measure.mjs";
5
+ import { TEXT, ownPaint, signPaint } from "../theme.mjs";
6
+ import { changeParts } from "./stat-data.mjs";
7
+ import { BIG, TOPS } from "./stat-layout.mjs";
8
+ // src/kinds/stat-marks.ts
9
+ /**
10
+ * The colour of a change, by the way it is written as having gone: good or bad by the measure,
11
+ * grey when it reads as none. When the measure says neither way is better it is ink, not the
12
+ * chart's colour: the change is words under the number, and words are ink.
13
+ */
14
+ const changeColor = (change, stat) => signPaint(change.sign, stat.measure, INK);
15
+ /** The course's colour: the series' own when it brings one (Other's grey when it is that), else the chart's. A series' slot is not read. */
16
+ const colorOf = (series, at) => ownPaint(series) ?? at.own;
17
+ /**
18
+ * The change under the number: its arrow and how far in its colour, then what it is against,
19
+ * when the layout gave that room too.
20
+ */
21
+ function changeNode(change, at) {
22
+ const parts = changeParts(change, wordsOf(at.env).versus);
23
+ const tail = at.layout.change === "all" ? parts.tail : "";
24
+ return {
25
+ kind: "text",
26
+ part: "change",
27
+ x: 0,
28
+ y: TOPS.change,
29
+ text: `${parts.head}${tail}`,
30
+ runs: [{
31
+ text: parts.head,
32
+ fill: changeColor(change, at.stat),
33
+ weight: TEXT.value.weight
34
+ }, ...tail === "" ? [] : [{
35
+ text: tail,
36
+ fill: TEXT.tick.fill
37
+ }]],
38
+ ...TEXT.name,
39
+ baseline: "hanging"
40
+ };
41
+ }
42
+ /** The title, the number and its change, from the top: each only when the layout gave it room. */
43
+ function headNodes(at) {
44
+ const { stat, layout, env } = at;
45
+ const title = {
46
+ kind: "text",
47
+ part: "header",
48
+ x: 0,
49
+ y: TOPS.title,
50
+ text: fitText(stat.title, env.width, TEXT.subtitle, env.measure),
51
+ ...TEXT.subtitle,
52
+ baseline: "hanging"
53
+ };
54
+ const number = layout.number === void 0 ? [] : [{
55
+ kind: "text",
56
+ part: "value",
57
+ x: 0,
58
+ y: TOPS.number,
59
+ text: layout.number.text,
60
+ ...BIG,
61
+ size: layout.number.size,
62
+ baseline: "hanging"
63
+ }];
64
+ return [
65
+ ...layout.title ? [title] : [],
66
+ ...number,
67
+ ...layout.change !== "none" && stat.change !== void 0 ? [changeNode(stat.change, at)] : []
68
+ ];
69
+ }
70
+ /** The course drawn: its line, a wash under it, and the dot at its end. */
71
+ function courseNodes(at, table) {
72
+ const { course, plot } = at.layout;
73
+ if (course === void 0) return [];
74
+ const where = {
75
+ buckets: table.x.buckets,
76
+ center: course.center,
77
+ place: course.place
78
+ };
79
+ return seriesLine(course.series, where, {
80
+ color: colorOf(course.series, at),
81
+ curve: "straight",
82
+ washTo: plot.y + plot.height
83
+ });
84
+ }
85
+ export { colorOf, courseNodes, headNodes };
@@ -0,0 +1,57 @@
1
+ import { course, missingOf, noValue, periodOf, spanOf, summary, worthSaid } from "../describe.mjs";
2
+ import { bucketTitles } from "../scale/calendar.mjs";
3
+ import { colorOf } from "./stat-marks.mjs";
4
+ import { timeStops } from "./time-stops.mjs";
5
+ // src/kinds/stat-words.ts
6
+ /** The change in words, and whether it is the better way, for a reader who cannot see its colour. */
7
+ function changeSentence(change, stat) {
8
+ if (change.way === "flat") return `No change vs ${change.against}`;
9
+ return `${change.way === "up" ? "Up" : "Down"}${change.amount === void 0 ? "" : ` ${change.amount}`} vs ${change.against}${worthSaid(change.sign, stat.measure)}`;
10
+ }
11
+ /** The course under the number, in words: where it went from and to, and over what. */
12
+ function courseSaid(table, env) {
13
+ const [series] = table?.series ?? [];
14
+ if (table === void 0 || series === void 0) return void 0;
15
+ const titles = bucketTitles(table.x, env.locale);
16
+ const went = course({
17
+ ...series,
18
+ label: "It"
19
+ }, {
20
+ titles,
21
+ table
22
+ });
23
+ const valued = spanOf(series, titles);
24
+ const over = periodOf(valued);
25
+ return went === void 0 || over === void 0 || valued.length < 2 ? went : `${went}, ${over}`;
26
+ }
27
+ /**
28
+ * What the stat shows, in words: the number, its change, and the course under it. A stat
29
+ * leaves nothing out for want of room, so it takes no count of what was shown.
30
+ */
31
+ function describeStat(stat, { table, env }) {
32
+ return summary([`Stat of ${stat.measure.label}`, stat.text], [
33
+ stat.change === void 0 ? void 0 : changeSentence(stat.change, stat),
34
+ courseSaid(table, env),
35
+ noValue(stat.value === null ? 1 : 0, "number"),
36
+ ...table === void 0 ? [] : missingOf(table)
37
+ ]);
38
+ }
39
+ /** What a pointer finds along the course: one stop a period, with the value there. */
40
+ function stopsOf(at, table) {
41
+ const { course: drawn, plot } = at.layout;
42
+ if (drawn === void 0) return [];
43
+ return timeStops({
44
+ x: table.x,
45
+ series: [drawn.series]
46
+ }, at.env, {
47
+ plot,
48
+ center: drawn.center,
49
+ titles: bucketTitles(table.x, at.env.locale),
50
+ paints: [colorOf(drawn.series, at)],
51
+ y: (series, i) => {
52
+ const value = series.values[i] ?? null;
53
+ return value === null ? void 0 : drawn.place(value);
54
+ }
55
+ });
56
+ }
57
+ export { describeStat, stopsOf };
@@ -0,0 +1,28 @@
1
+ import { Points } from "../data/format.mjs";
2
+ import { Env, Measure, TimeTable, Value } from "../data/types.mjs";
3
+ import { Scene } from "../scene/types.mjs";
4
+ export type StatOptions = {
5
+ title: string;
6
+ measure: Measure;
7
+ /** The number the stat is about. */
8
+ value: Value;
9
+ /** The number as the host writes it, when it has a more exact way than the measure's. */
10
+ text?: string;
11
+ /**
12
+ * What it is read against, and the name of that: "last month". The name stands for the
13
+ * value (a stat says "vs last month"; its value is said only when it has no name), where
14
+ * ranked bars, which have room in a tooltip, say both.
15
+ */
16
+ against?: Value;
17
+ againstLabel?: string;
18
+ /**
19
+ * How a change is written when the values are shares: "4 pts" for a size of 4, with no sign
20
+ * (the stat's arrow says which way). Without it a share's change is said by its arrow and
21
+ * what it is against, never as a percent of a percent.
22
+ */
23
+ points?: Points;
24
+ /** The palette place of the course's colour. */
25
+ slot?: number;
26
+ };
27
+ /** A stat: a number, its change, and (given a series) its course underneath. */
28
+ export declare function statChart(given: TimeTable | undefined, options: StatOptions, env: Env): Scene;