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,31 @@
1
+ // src/data/words.ts
2
+ const ENGLISH = {
3
+ soFar: "so far",
4
+ before: (value) => `before ${value}`,
5
+ versus: (what) => `vs ${what}`,
6
+ partial: "part of the period",
7
+ more: (count) => `and ${String(count)} more`,
8
+ averaged: (count) => `drawn as an average of ${String(count)}`,
9
+ merged: (count, grain, approximate) => "Each column is the average of " + (approximate ? "about " : "") + String(count) + " " + grain + (count === 1 ? "" : "s"),
10
+ funnel: {
11
+ continues: (percent) => `${percent} continue`,
12
+ largestDrop: "largest drop",
13
+ ofAll: (percent) => `${percent} of all`,
14
+ ofFirstStep: (percent) => `${percent} of the first step`,
15
+ ofStepBefore: (percent) => `${percent} of the step before`
16
+ },
17
+ waterfall: { runningTotal: (value) => `running total ${value}` },
18
+ histogram: {
19
+ count: "Count",
20
+ range: (from, to) => `${from} to ${to}`
21
+ }
22
+ };
23
+ /**
24
+ * The words a chart is drawn with: the host's, else English. A word added to the table after a
25
+ * host wrote its own is optional there, and is English until the host gives it.
26
+ */
27
+ const wordsOf = (env) => ({
28
+ ...ENGLISH,
29
+ ...env.words
30
+ });
31
+ export { ENGLISH, wordsOf };
@@ -0,0 +1,110 @@
1
+ import { running } from "./data/buckets.mjs";
2
+ import { betterWay, textAt } from "./data/format.mjs";
3
+ import { lastAt } from "./data/rows.mjs";
4
+ // src/describe.ts
5
+ /**
6
+ * How a count is written in a summary: the sentences are English, so its grouping is too. A
7
+ * value the data gave is written by its measure, in the host's locale, as it is in the picture.
8
+ */
9
+ const COUNT = new Intl.NumberFormat("en-US");
10
+ /** A count with its noun: "1 row", "4 rows", "300,000 values". */
11
+ const counted = (count, one, many = `${one}s`) => `${COUNT.format(count)} ${count === 1 ? one : many}`;
12
+ /**
13
+ * How many series a chart over time has, said only of several: one series is the chart itself,
14
+ * and what has no value says so of none.
15
+ */
16
+ const seriesSaid = (count) => count > 1 ? counted(count, "series", "series") : void 0;
17
+ /**
18
+ * How many things a chart was given, and how many it had room to draw: "9 rows, 3 shown". A
19
+ * chart that drew none says only what it was given: a summary describes the data, and does not
20
+ * add that there was no room for the picture.
21
+ */
22
+ const shownOf = (all, shown, one, many) => shown >= all || shown === 0 ? counted(all, one, many) : `${counted(all, one, many)}, ${COUNT.format(shown)} shown`;
23
+ /**
24
+ * A summary: its opening ("Bar chart of Revenue", then what it is over and how much of it there
25
+ * is, each after a comma), and the sentences after it. Every sentence ends in a full stop.
26
+ */
27
+ function summary(opening, sentences = []) {
28
+ return [opening.filter((part) => part !== void 0 && part !== "").join(", "), ...sentences].flatMap((s) => s === void 0 || s === "" ? [] : [s.endsWith(".") ? s : `${s}.`]).join(" ");
29
+ }
30
+ /** What had no value and so was drawn as nothing: "No value: 2 rows"; nothing to say for none. */
31
+ const noValue = (count, one, many) => count > 0 ? `No value: ${counted(count, one, many)}` : void 0;
32
+ /** What the chart keeps in colour while the rest is grey context; nothing to say for none. */
33
+ const focusSaid = (labels) => labels.length > 0 ? `In focus: ${labels.join(", ")}` : void 0;
34
+ /** Said after a value whose period is still running; nothing after one that is final. */
35
+ const soFar = (bucket) => running(bucket) ? " so far" : "";
36
+ /** What a time axis runs over: its first bucket to its last, or its one bucket. */
37
+ function periodOf(titles) {
38
+ const first = titles[0];
39
+ const last = titles.at(-1);
40
+ if (first === void 0 || last === void 0) return void 0;
41
+ return titles.length === 1 ? first : `${first} to ${last}`;
42
+ }
43
+ /**
44
+ * A series' course in words: "Pro went from $12K to $48K"; "Pro began and ended at $12K" when
45
+ * its first and last values read alike, since nothing "went" anywhere a reader can see; or,
46
+ * with one value, "Pro was $12K in March 2026". "So far" when its last period is still
47
+ * running. Nothing for a series with no value.
48
+ */
49
+ function course(series, at) {
50
+ const first = series.values.findIndex((v) => v !== null);
51
+ const last = lastAt(series.values);
52
+ if (first === -1) return void 0;
53
+ const from = textAt(series, first) ?? "";
54
+ const to = textAt(series, last) ?? "";
55
+ const open = soFar(at.table.x.buckets[last]);
56
+ if (first === last) return `${series.label} was ${to}${open} in ${at.titles[last] ?? ""}`;
57
+ if (from === to) return `${series.label} began and ended at ${to}${open}`;
58
+ return `${series.label} went from ${from} to ${to}${open}`;
59
+ }
60
+ /** The most series a summary names one by one; the rest are counted. */
61
+ const NAMED = 4;
62
+ /**
63
+ * What each series of a table did, in one sentence: the first few one by one, the rest counted
64
+ * ("A went from $1 to $3; B was $2 in March 2026; 3 more series"). Every chart of a table over
65
+ * time says it. Nothing when no series has a value.
66
+ */
67
+ function coursesSaid(table, titles) {
68
+ const courses = table.series.flatMap((s) => course(s, {
69
+ titles,
70
+ table
71
+ }) ?? []);
72
+ const left = courses.length - NAMED;
73
+ const more = left > 0 ? [counted(left, "more series", "more series")] : [];
74
+ return courses.length === 0 ? void 0 : [...courses.slice(0, NAMED), ...more].join("; ");
75
+ }
76
+ /**
77
+ * How many of a series' values are missing, before, between and after the ones it has: what a
78
+ * chart says had no value, as every kind counts it. None for a series with no value at all,
79
+ * which is said as a series.
80
+ */
81
+ const unvalued = (series) => series.values.every((v) => v === null) ? 0 : series.values.filter((v) => v === null).length;
82
+ /** The buckets a series has values over: from its first value to its last. */
83
+ const spanOf = (series, buckets) => buckets.slice(series.values.findIndex((v) => v !== null), lastAt(series.values) + 1);
84
+ /**
85
+ * How the summary of any chart of a table over time opens: what it is, of what measure, how
86
+ * many series (as `count` says it, else only of several), and over what period.
87
+ */
88
+ function openingOf(table, at) {
89
+ const measures = [...new Set(table.series.map((s) => s.measure.label))];
90
+ const last = measures.at(-1);
91
+ const named = measures.length > 1 ? `${measures.slice(0, -1).join(", ")} and ${last ?? ""}` : last;
92
+ return [
93
+ named === void 0 ? at.what : `${at.what} of ${named}`,
94
+ at.count ?? seriesSaid(table.series.length),
95
+ periodOf(at.titles)
96
+ ];
97
+ }
98
+ /** What had no value in a table over time: the series with none, then the values the other series are missing. */
99
+ const missingOf = (table) => [noValue(table.series.filter((s) => s.values.every((v) => v === null)).length, "series", "series"), noValue(table.series.reduce((sum, s) => sum + unvalued(s), 0), "value")];
100
+ /**
101
+ * Whether a change went the better way, for a reader who cannot see its colour: said after
102
+ * the change in every kind that colours one good or bad. Nothing for a change that reads as
103
+ * none, or a measure that says neither way is better.
104
+ */
105
+ function worthSaid(sign, measure) {
106
+ const way = betterWay(sign, measure);
107
+ if (way === 0) return "";
108
+ return way > 0 ? ", which is better" : ", which is worse";
109
+ }
110
+ export { counted, course, coursesSaid, focusSaid, missingOf, noValue, openingOf, periodOf, shownOf, soFar, spanOf, summary, worthSaid };
@@ -0,0 +1,34 @@
1
+ import { timeBuckets } from "./data/buckets.mjs";
2
+ import { MeasureStyle, Points, measure } from "./data/format.mjs";
3
+ import { ChartInputError } from "./data/input-error.mjs";
4
+ import { Named, keyOf, pairKey } from "./data/rows.mjs";
5
+ import { Bucket, Env, EventMark, Grain, Header, Measure, Reference, Series, TimeTable, TimeX, Tint, Toned, Value } from "./data/types.mjs";
6
+ import { ENGLISH, Words } from "./data/words.mjs";
7
+ import { AreaOptions, areaChart, areaDraws } from "./kinds/area.mjs";
8
+ import { BarOptions, barChart } from "./kinds/bars.mjs";
9
+ import { ColumnOptions, columnChart } from "./kinds/columns.mjs";
10
+ import { DumbbellOptions, dumbbellChart } from "./kinds/dumbbell.mjs";
11
+ import { FunnelOptions, funnelChart } from "./kinds/funnel.mjs";
12
+ import { BarRow, BarSort } from "./kinds/bars-data.mjs";
13
+ import { GridOptions, gridChart } from "./kinds/grid.mjs";
14
+ import { HistogramOptions, histogramChart } from "./kinds/histogram.mjs";
15
+ import { DumbbellRow, DumbbellSort } from "./kinds/dumbbell-data.mjs";
16
+ import { LineOptions, lineChart } from "./kinds/line.mjs";
17
+ import { MultiplesOptions, multiplesChart } from "./kinds/multiples.mjs";
18
+ import { ScatterOptions, scatterChart } from "./kinds/scatter.mjs";
19
+ import { FunnelStep } from "./kinds/funnel-data.mjs";
20
+ import { StatOptions, statChart } from "./kinds/stat.mjs";
21
+ import { GridData } from "./kinds/grid-data.mjs";
22
+ import { Naming, TimeNotes } from "./kinds/time-plan.mjs";
23
+ import { WaterfallOptions, waterfallChart } from "./kinds/waterfall.mjs";
24
+ import { Curve } from "./marks/lines.mjs";
25
+ import { litNodes } from "./marks/lit.mjs";
26
+ import { ScatterNamed, ScatterPoint } from "./kinds/scatter-data.mjs";
27
+ import { nearestItem, nearestStop } from "./scene/nearest.mjs";
28
+ import { BAD, GOOD, INK, MUTED, OTHER, RULE, SURFACE, paintCss } from "./scene/paint.mjs";
29
+ import { WaterfallStep } from "./kinds/waterfall-data.mjs";
30
+ import { SvgOptions, renderNodes, renderSvg } from "./scene/svg.mjs";
31
+ import { Box, CircleNode, Corners, Fade, Fill, GroupNode, Hover, HoverColumn, HoverItem, HoverStop, LineNode, Paint, Part, PathNode, RectNode, Scene, SceneNode, TextNode, TextRun } from "./scene/types.mjs";
32
+ import { Font, TextMeasurer, tableMeasure } from "./text/measure.mjs";
33
+ import { PALETTE, THEMES, paintsOf, seriesPaint } from "./theme.mjs";
34
+ export { type AreaOptions, BAD, type BarOptions, type BarRow, type BarSort, type Box, type Bucket, ChartInputError, type CircleNode, type ColumnOptions, type Corners, type Curve, type DumbbellOptions, type DumbbellRow, type DumbbellSort, ENGLISH, type Env, type EventMark, type Fade, type Fill, type Font, type FunnelOptions, type FunnelStep, GOOD, type Grain, type GridData, type GridOptions, type GroupNode, type Header, type HistogramOptions, type Hover, type HoverColumn, type HoverItem, type HoverStop, INK, type LineNode, type LineOptions, MUTED, type Measure, type MeasureStyle, type MultiplesOptions, type Named, type Naming, OTHER, PALETTE, type Paint, type Part, type PathNode, type Points, RULE, type RectNode, type Reference, SURFACE, type ScatterNamed, type ScatterOptions, type ScatterPoint, type Scene, type SceneNode, type Series, type StatOptions, type SvgOptions, THEMES, type TextMeasurer, type TextNode, type TextRun, type TimeNotes, type TimeTable, type TimeX, type Tint, type Toned, type Value, type WaterfallOptions, type WaterfallStep, type Words, areaChart, areaDraws, barChart, columnChart, dumbbellChart, funnelChart, gridChart, histogramChart, keyOf, lineChart, litNodes, measure, multiplesChart, nearestItem, nearestStop, paintCss, paintsOf, pairKey, renderNodes, renderSvg, scatterChart, seriesPaint, statChart, tableMeasure, timeBuckets, waterfallChart };
@@ -0,0 +1,24 @@
1
+ import { timeBuckets } from "./data/buckets.mjs";
2
+ import { measure } from "./data/format.mjs";
3
+ import { ChartInputError } from "./data/input-error.mjs";
4
+ import { keyOf, pairKey } from "./data/rows.mjs";
5
+ import { ENGLISH } from "./data/words.mjs";
6
+ import { areaChart, areaDraws } from "./kinds/area.mjs";
7
+ import { barChart } from "./kinds/bars.mjs";
8
+ import { columnChart } from "./kinds/columns.mjs";
9
+ import { dumbbellChart } from "./kinds/dumbbell.mjs";
10
+ import { funnelChart } from "./kinds/funnel.mjs";
11
+ import { gridChart } from "./kinds/grid.mjs";
12
+ import { histogramChart } from "./kinds/histogram.mjs";
13
+ import { lineChart } from "./kinds/line.mjs";
14
+ import { multiplesChart } from "./kinds/multiples.mjs";
15
+ import { scatterChart } from "./kinds/scatter.mjs";
16
+ import { statChart } from "./kinds/stat.mjs";
17
+ import { waterfallChart } from "./kinds/waterfall.mjs";
18
+ import { litNodes } from "./marks/lit.mjs";
19
+ import { nearestItem, nearestStop } from "./scene/nearest.mjs";
20
+ import { BAD, GOOD, INK, MUTED, OTHER, RULE, SURFACE, paintCss } from "./scene/paint.mjs";
21
+ import { renderNodes, renderSvg } from "./scene/svg.mjs";
22
+ import { tableMeasure } from "./text/measure.mjs";
23
+ import { PALETTE, THEMES, paintsOf, seriesPaint } from "./theme.mjs";
24
+ export { BAD, ChartInputError, ENGLISH, GOOD, INK, MUTED, OTHER, PALETTE, RULE, SURFACE, THEMES, areaChart, areaDraws, barChart, columnChart, dumbbellChart, funnelChart, gridChart, histogramChart, keyOf, lineChart, litNodes, measure, multiplesChart, nearestItem, nearestStop, paintCss, paintsOf, pairKey, renderNodes, renderSvg, scatterChart, seriesPaint, statChart, tableMeasure, timeBuckets, waterfallChart };
@@ -0,0 +1,120 @@
1
+ import { running, starting } from "../data/buckets.mjs";
2
+ import { stacked } from "../layout/stack.mjs";
3
+ import { MUTED, SURFACE } from "../scene/paint.mjs";
4
+ import { bandPath, broken, linePath } from "../marks/lines.mjs";
5
+ import { thinnedBand } from "../marks/thin.mjs";
6
+ import { MARK, paintAt } from "../theme.mjs";
7
+ // src/kinds/area-marks.ts
8
+ /** Each series' upper and lower edge, place for place. */
9
+ function bandsOf(spans, frame) {
10
+ const edge = (pick) => spans.map((row) => row.map((span, i) => span === void 0 ? void 0 : {
11
+ x: frame.time.center(i),
12
+ y: frame.place(pick(span))
13
+ }));
14
+ return {
15
+ tops: edge((span) => span.to),
16
+ bottoms: edge((span) => span.from)
17
+ };
18
+ }
19
+ /** The bands, each with a hair of surface along its upper edge to part it from the next. */
20
+ function bandNodes(bands, look) {
21
+ const gapped = (points) => broken(points, look.buckets);
22
+ return bands.tops.flatMap((top, s) => {
23
+ const edges = thinnedBand(gapped(top), gapped(bands.bottoms[s] ?? []));
24
+ return [{
25
+ kind: "path",
26
+ part: "band",
27
+ ...look.keys[s] === void 0 ? {} : { key: look.keys[s] },
28
+ d: bandPath(edges.top, edges.bottom, look.curve),
29
+ fill: paintAt(look.paints, s),
30
+ opacity: MARK.areaFill
31
+ }, {
32
+ kind: "path",
33
+ part: "edge",
34
+ d: linePath(edges.top, look.curve),
35
+ stroke: look.dense ? paintAt(look.paints, s) : SURFACE,
36
+ strokeWidth: MARK.hair
37
+ }];
38
+ });
39
+ }
40
+ /**
41
+ * How far past the plot a clip of the bands reaches, across (twice that up and down): past the
42
+ * edge of a band's stroke and its names' halo, so a clip cuts the bands in time and nothing else.
43
+ */
44
+ const CLIP_PAD = 2;
45
+ /** A boundary between settled and partial data can belong to both ends of a short series. */
46
+ const partialEdges = (late, from, open, to) => [.../* @__PURE__ */ new Set([...late ? [from] : [], ...open ? [to] : []])];
47
+ /**
48
+ * The bands with what is not whole drawn faint: the first step, when the data starts part of
49
+ * the way into its first period, and the last, when its period is still running. So neither
50
+ * reads as a rise or a fall, as a line's dotted step and a column's faint bar do not.
51
+ */
52
+ function settledAndOpen(nodes, frame) {
53
+ const last = frame.buckets.length - 1;
54
+ const late = last >= 1 && starting(frame.buckets[0]);
55
+ const open = last >= 1 && running(frame.buckets[last]);
56
+ if (!late && !open) return nodes;
57
+ const { plot } = frame;
58
+ const from = late ? frame.time.center(1) : plot.x - CLIP_PAD;
59
+ const to = open ? frame.time.center(last - 1) : plot.x + plot.width + CLIP_PAD;
60
+ const tall = {
61
+ y: plot.y - 4,
62
+ height: plot.height + 8
63
+ };
64
+ const faint = (x, width) => ({
65
+ kind: "group",
66
+ part: "open",
67
+ clip: {
68
+ x,
69
+ width,
70
+ ...tall
71
+ },
72
+ opacity: MARK.partialFill,
73
+ children: nodes
74
+ });
75
+ const boundary = (x) => ({
76
+ kind: "line",
77
+ part: "open",
78
+ x1: x,
79
+ x2: x,
80
+ y1: plot.y,
81
+ y2: plot.y + plot.height,
82
+ stroke: MUTED,
83
+ strokeWidth: MARK.hair,
84
+ dash: MARK.moment
85
+ });
86
+ return [
87
+ ...late ? [faint(plot.x - CLIP_PAD, from - plot.x + CLIP_PAD)] : [],
88
+ {
89
+ kind: "group",
90
+ part: "settled",
91
+ clip: {
92
+ x: from,
93
+ width: to - from,
94
+ ...tall
95
+ },
96
+ children: nodes
97
+ },
98
+ ...open ? [faint(to, plot.x + plot.width + CLIP_PAD - to)] : [],
99
+ ...partialEdges(late, from, open, to).map((x) => boundary(x))
100
+ ];
101
+ }
102
+ /** The stacked bands, each named at the middle of its right end. */
103
+ function bandsIn(frame, series, look) {
104
+ const bands = bandsOf(stacked(series.map((s) => s.values), frame.buckets.length), frame);
105
+ return {
106
+ nodes: settledAndOpen(bandNodes(bands, {
107
+ ...look,
108
+ dense: frame.time.band < 1,
109
+ keys: series.map((s) => s.key),
110
+ buckets: frame.buckets
111
+ }), frame),
112
+ labelY: (s) => {
113
+ const top = bands.tops[s]?.at(-1);
114
+ const bottom = bands.bottoms[s]?.at(-1);
115
+ return top === void 0 || bottom === void 0 ? void 0 : (top.y + bottom.y) / 2;
116
+ },
117
+ dotY: (one, i) => bands.tops[series.indexOf(one)]?.[i]?.y
118
+ };
119
+ }
120
+ export { bandsIn };
@@ -0,0 +1,23 @@
1
+ import { Env, Header, TimeTable } from "../data/types.mjs";
2
+ import { Scene } from "../scene/types.mjs";
3
+ import { Curve } from "../marks/lines.mjs";
4
+ import { Naming, TimeNotes } from "./time-plan.mjs";
5
+ export type AreaOptions = Header & TimeNotes & {
6
+ /**
7
+ * Stacked (the default), or each band as its share of the whole, the stack filling the
8
+ * plot: its scale ends at 100%, and a level marked outside 0 to 100% is not drawn.
9
+ */
10
+ arrange?: "stacked" | "share";
11
+ curve?: Curve;
12
+ naming?: Naming;
13
+ };
14
+ /**
15
+ * What an area chart draws of a table. Bands, where its values add up. Lines, where they do
16
+ * not: a rate on a rate is a height that means nothing. Columns, for one period, which has no
17
+ * course to draw, and for a series that changes sign: a band from a gain to a loss would cross
18
+ * the others, and no band's height would be its value. A host that names the picture (a
19
+ * caption, a legend) asks this, so it names what is drawn.
20
+ */
21
+ export declare function areaDraws(given: TimeTable): "area" | "lines" | "columns";
22
+ /** A stacked area chart of series over time. */
23
+ export declare function areaChart(given: TimeTable, options: AreaOptions, env: Env): Scene;
@@ -0,0 +1,71 @@
1
+ import { cleanTable } from "../data/clean.mjs";
2
+ import { addsUp, asShares, levelsOfShares, stackOrder } from "../data/shares.mjs";
3
+ import { stackHeights } from "../layout/stack.mjs";
4
+ import { paintsOf } from "../theme.mjs";
5
+ import { bandsIn } from "./area-marks.mjs";
6
+ import { namingOf, reachEnd } from "./time-plan.mjs";
7
+ import { columnChart } from "./columns.mjs";
8
+ import { lineChart } from "./line.mjs";
9
+ import { timeChart } from "./time-chart.mjs";
10
+ // src/kinds/area.ts
11
+ /** The options a line chart shares with this one. */
12
+ function asLines(options) {
13
+ const { arrange: _arrange, ...rest } = options;
14
+ return rest;
15
+ }
16
+ /** Whether some values lie above zero and some below. */
17
+ const crossesZero = (values) => values.some((v) => v !== null && v > 0) && values.some((v) => v !== null && v < 0);
18
+ /**
19
+ * What an area chart draws of a table. Bands, where its values add up. Lines, where they do
20
+ * not: a rate on a rate is a height that means nothing. Columns, for one period, which has no
21
+ * course to draw, and for a series that changes sign: a band from a gain to a loss would cross
22
+ * the others, and no band's height would be its value. A host that names the picture (a
23
+ * caption, a legend) asks this, so it names what is drawn.
24
+ */
25
+ function areaDraws(given) {
26
+ const table = cleanTable(given);
27
+ if (!addsUp(table.series)) return "lines";
28
+ return table.x.buckets.length < 2 || table.series.some((s) => crossesZero(s.values)) ? "columns" : "area";
29
+ }
30
+ /** A stacked area chart of series over time. */
31
+ function areaChart(given, options, env) {
32
+ const table = cleanTable(given);
33
+ const draws = areaDraws(table);
34
+ if (draws === "lines") return lineChart(table, asLines(options), env);
35
+ if (draws === "columns") return columnChart(table, {
36
+ ...asLines(options),
37
+ ...options.arrange === void 0 ? {} : { arrange: options.arrange }
38
+ }, env);
39
+ const places = table.x.buckets.length;
40
+ const ordered = stackOrder(table.series);
41
+ const share = options.arrange === "share";
42
+ const series = share ? asShares(ordered, places, env.locale) : ordered;
43
+ const paints = paintsOf(series);
44
+ return timeChart({
45
+ what: "Stacked area chart",
46
+ table: {
47
+ x: table.x,
48
+ series
49
+ },
50
+ header: options,
51
+ notes: share ? {
52
+ ...options,
53
+ references: levelsOfShares(options.references)
54
+ } : options,
55
+ paints,
56
+ naming: namingOf(options.naming, {
57
+ series: series.length,
58
+ named: series.length,
59
+ atEnds: reachEnd(series),
60
+ header: options,
61
+ env
62
+ }),
63
+ values: stackHeights(series.map((one) => one.values), places),
64
+ zero: "always",
65
+ bands: false
66
+ }, env, (frame) => bandsIn(frame, series, {
67
+ paints,
68
+ curve: options.curve ?? "straight"
69
+ }));
70
+ }
71
+ export { areaChart, areaDraws };
@@ -0,0 +1,11 @@
1
+ import { Named } from "../data/rows.mjs";
2
+ import { Toned, Value } from "../data/types.mjs";
3
+ export type BarRow = Named & Toned & {
4
+ value: Value;
5
+ /** The value as the host writes it, when it has a more exact way than the measure's. */
6
+ text?: string;
7
+ /** What this row is read against: drawn as a tick on its bar. */
8
+ against?: number;
9
+ };
10
+ /** How rows are ordered: by their values, largest first (the default), or as given. */
11
+ export type BarSort = "value" | "given";
@@ -0,0 +1,30 @@
1
+ import { drawable } from "../data/clean.mjs";
2
+ import { said } from "../data/format.mjs";
3
+ import { keyOf, ranked } from "../data/rows.mjs";
4
+ // src/kinds/bars-data.ts
5
+ /** How a row's value is written: the host's own text for it, else the measure's. */
6
+ const textOf = (row, value, measure) => said(row.text) ?? measure.text(value);
7
+ /**
8
+ * The rows in drawing order: by value, largest first, with rows that have none after them;
9
+ * or in the order given. Other is last either way.
10
+ */
11
+ const ordered = (rows, sort) => ranked(rows, {
12
+ value: (row) => row.value,
13
+ given: sort === "given",
14
+ last: (row) => row.other === true
15
+ });
16
+ /** Whether a row is one the chart is about: every row, or with a focus only the rows in it. */
17
+ const inFocus = (row, focus) => focus === void 0 || focus.includes(keyOf(row));
18
+ /** The rows as they can be drawn: a value or a tick that is not a finite number is none. */
19
+ function cleaned(rows) {
20
+ return rows.map((row) => {
21
+ const { against, ...rest } = row;
22
+ const mark = against === void 0 ? null : drawable(against);
23
+ return {
24
+ ...rest,
25
+ value: drawable(row.value),
26
+ ...mark === null ? {} : { against: mark }
27
+ };
28
+ });
29
+ }
30
+ export { cleaned, inFocus, ordered, textOf };
@@ -0,0 +1,30 @@
1
+ import { lengthsOn } from "../scale/value.mjs";
2
+ import { inFocus, textOf } from "./bars-data.mjs";
3
+ import { keptRows, reachOf, rowFrame, rowPlot, slotsOf, slotted } from "./row-chart.mjs";
4
+ // src/kinds/bars-layout.ts
5
+ /** Where the rows go and which of them are drawn. */
6
+ function layoutOf(rows, options, env) {
7
+ const { measure, focus } = options;
8
+ const matters = (row) => focus !== void 0 && inFocus(row, focus);
9
+ const frame = rowFrame(rows.map((row) => row.label), {
10
+ header: options,
11
+ labelsOf: (shown) => keptRows(rows, shown, matters).map((row) => row.label)
12
+ }, env);
13
+ const lengths = rows.flatMap((row) => [row.value ?? 0, row.against ?? 0]);
14
+ const texts = rows.flatMap((row) => row.value === null ? [] : [textOf(row, row.value, measure)]);
15
+ const reach = reachOf(frame, texts, {
16
+ env,
17
+ bothSides: lengths.some((v) => v < 0)
18
+ });
19
+ const slots = slotted(rows, keptRows(rows, frame.shown, matters));
20
+ return {
21
+ frame,
22
+ reach,
23
+ x: lengthsOn(lengths, reach.from, reach.to),
24
+ ...slots,
25
+ drawn: rows.some((row) => row.value !== null),
26
+ numbers: reach.fits,
27
+ plot: rowPlot(frame, reach, slotsOf(slots.kept))
28
+ };
29
+ }
30
+ export { layoutOf };
@@ -0,0 +1,93 @@
1
+ import { keyOf } from "../data/rows.mjs";
2
+ import { INK, OTHER, SURFACE } from "../scene/paint.mjs";
3
+ import { MARK, SPACE, TEXT } from "../theme.mjs";
4
+ import { inFocus, textOf } from "./bars-data.mjs";
5
+ import { rowBar, rowName, rowValue } from "./row-marks.mjs";
6
+ import { barThick } from "./row-chart.mjs";
7
+ // src/kinds/bars-marks.ts
8
+ /**
9
+ * A row's colour: the quiet grey for a row out of focus, whatever colour it brought (as a line
10
+ * out of focus is grey); else the colour the shared palette rule gives it (`paintsOf`): its
11
+ * own, Other's grey, its slot's place among the rows' slots, or the chart's colour.
12
+ */
13
+ function colorOf(row, at) {
14
+ return inFocus(row, at.focus) ? at.paints.get(row) ?? at.own : OTHER;
15
+ }
16
+ /** How far the tick reaches past its bar, above and below. */
17
+ const OVER = 3;
18
+ /** The tick on a bar at what it is read against, ringed so it reads on the bar and off it. */
19
+ function tick(x, mid, thick) {
20
+ const line = {
21
+ kind: "line",
22
+ part: "against",
23
+ x1: x,
24
+ x2: x,
25
+ y1: mid - thick / 2 - OVER,
26
+ y2: mid + thick / 2 + OVER
27
+ };
28
+ return [{
29
+ ...line,
30
+ stroke: SURFACE,
31
+ strokeWidth: MARK.line + 2 * MARK.ring
32
+ }, {
33
+ ...line,
34
+ stroke: INK,
35
+ strokeWidth: MARK.line
36
+ }];
37
+ }
38
+ /**
39
+ * Where a row's number is written from: past its bar's end, so it reads as the bar's. Only
40
+ * when the tick stands where the number would be written does the number go past the tick.
41
+ */
42
+ function numberFrom(text, ends, at) {
43
+ const reach = at.env.measure(text, TEXT.value) + 2 * SPACE.value;
44
+ const past = ends.up ? ends.mark - ends.end : ends.end - ends.mark;
45
+ return past > 0 && past < reach ? ends.mark : ends.end;
46
+ }
47
+ /** A row's bar, its tick, and its number past the bar's end. */
48
+ function barNodes(row, value, slot, at) {
49
+ const { frame } = at;
50
+ const mid = frame.middle(slot);
51
+ const thick = barThick(frame.rowHeight);
52
+ const zero = at.x(0);
53
+ const end = at.x(value);
54
+ const up = value >= 0;
55
+ const mark = row.against === void 0 ? end : at.x(row.against);
56
+ const text = textOf(row, value, at.measure);
57
+ const from = numberFrom(text, {
58
+ end,
59
+ mark,
60
+ up
61
+ }, at);
62
+ const number = at.numbers ? rowValue(text, {
63
+ left: Math.min(zero, from),
64
+ right: Math.max(zero, from),
65
+ toRight: up,
66
+ y: mid,
67
+ frame,
68
+ env: at.env
69
+ }) : [];
70
+ return [
71
+ rowBar({
72
+ from: zero,
73
+ to: end,
74
+ mid,
75
+ thick,
76
+ fill: colorOf(row, at),
77
+ key: keyOf(row)
78
+ }),
79
+ ...row.against === void 0 ? [] : tick(mark, mid, thick),
80
+ ...number
81
+ ];
82
+ }
83
+ /** One row: its name, and its bar when it has a value. */
84
+ function rowNodes(row, slot, at) {
85
+ const name = rowName(row.label, {
86
+ frame: at.frame,
87
+ slot,
88
+ env: at.env,
89
+ key: keyOf(row)
90
+ });
91
+ return row.value === null ? [name] : [name, ...barNodes(row, row.value, slot, at)];
92
+ }
93
+ export { colorOf, rowNodes };
@@ -0,0 +1,56 @@
1
+ import { topAsWritten } from "../data/format.mjs";
2
+ import { keyOf, rankable } from "../data/rows.mjs";
3
+ import { wordsOf } from "../data/words.mjs";
4
+ import { focusSaid, noValue, shownOf, summary } from "../describe.mjs";
5
+ import { inFocus, textOf } from "./bars-data.mjs";
6
+ import { colorOf } from "./bars-marks.mjs";
7
+ import { rowStop } from "./row-marks.mjs";
8
+ // src/kinds/bars-words.ts
9
+ /** What a pointer finds on a row: its value, and what it is read against. */
10
+ function stopOf(row, slot, at) {
11
+ const { measure, frame } = at;
12
+ const read = (against) => {
13
+ const value = measure.text(against);
14
+ const what = at.againstLabel === void 0 ? value : `${at.againstLabel} ${value}`;
15
+ return { aside: wordsOf(at.env).versus(what) };
16
+ };
17
+ const items = row.value === null ? [] : [{
18
+ key: "value",
19
+ label: measure.label,
20
+ value: textOf(row, row.value, measure),
21
+ color: colorOf(row, at),
22
+ x: at.x(row.value),
23
+ y: frame.middle(slot),
24
+ ...row.against === void 0 ? {} : read(row.against)
25
+ }];
26
+ return rowStop(row.label, {
27
+ frame,
28
+ slot,
29
+ key: keyOf(row),
30
+ items,
31
+ nodes: at.nodes,
32
+ env: at.env
33
+ });
34
+ }
35
+ /**
36
+ * The row with the highest value, as the values are written; nothing when the top two read
37
+ * alike. Other is what was left over, not a row to rank: it is never the highest.
38
+ */
39
+ function highestOf(rows, measure) {
40
+ const valued = rankable(rows).flatMap((row) => row.value === null ? [] : [{
41
+ row,
42
+ value: row.value
43
+ }]);
44
+ const top = topAsWritten(valued, (one) => one.value, measure.text);
45
+ return top === void 0 ? void 0 : `Highest: ${top.row.label}, ${textOf(top.row, top.value, measure)}`;
46
+ }
47
+ /** The chart in words: what it is of, how many rows, the highest, what is in focus, what has no value. */
48
+ function describeBars(rows, at) {
49
+ const focused = at.focus === void 0 ? [] : rows.filter((row) => inFocus(row, at.focus)).map((r) => r.label);
50
+ return summary([`Bar chart of ${at.measure.label}`, shownOf(rows.length, at.shown, "row")], [
51
+ highestOf(rows, at.measure),
52
+ focusSaid(focused),
53
+ noValue(rows.filter((row) => row.value === null).length, "row")
54
+ ]);
55
+ }
56
+ export { describeBars, stopOf };
@@ -0,0 +1,17 @@
1
+ import { Env, Header, Measure } from "../data/types.mjs";
2
+ import { Scene } from "../scene/types.mjs";
3
+ import { BarRow, BarSort } from "./bars-data.mjs";
4
+ export type BarOptions = Header & {
5
+ measure: Measure;
6
+ /** By value, largest first (the default), or in the order given. */
7
+ sort?: BarSort;
8
+ /** The rows to keep in colour, by key (a row's label when it has no key); the others are grey context. */
9
+ focus?: readonly string[];
10
+ /** The name of what the ticks mark, said before its value in the tooltip: "vs all plans 30%". */
11
+ againstLabel?: string;
12
+ /** The palette place of the bars' colour. */
13
+ slot?: number;
14
+ };
15
+ /** Ranked bars of one measure by category. */
16
+ export declare function barChart(rows: readonly BarRow[], options: BarOptions, env: Env): Scene;
17
+ export type { BarRow, BarSort };