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,35 @@
1
+ import { percentText } from "../data/format.mjs";
2
+ import { seriesPaint } from "../theme.mjs";
3
+ import { settled, statOf } from "./stat-data.mjs";
4
+ import { layoutOf } from "./stat-layout.mjs";
5
+ import { courseNodes, headNodes } from "./stat-marks.mjs";
6
+ import { describeStat, stopsOf } from "./stat-words.mjs";
7
+ // src/kinds/stat.ts
8
+ /** A stat: a number, its change, and (given a series) its course underneath. */
9
+ function statChart(given, options, env) {
10
+ const stat = statOf(options, percentText(env.locale));
11
+ const table = settled(given);
12
+ const layout = layoutOf(stat, table, env);
13
+ const at = {
14
+ stat,
15
+ layout,
16
+ own: seriesPaint(options.slot ?? 0),
17
+ env
18
+ };
19
+ const stops = table === void 0 ? [] : stopsOf(at, table);
20
+ return {
21
+ width: env.width,
22
+ height: env.height,
23
+ plot: layout.plot,
24
+ summary: describeStat(stat, {
25
+ table,
26
+ env
27
+ }),
28
+ nodes: [...headNodes(at), ...table === void 0 ? [] : courseNodes(at, table)],
29
+ ...stops.length === 0 ? {} : { hover: {
30
+ snap: "x",
31
+ stops
32
+ } }
33
+ };
34
+ }
35
+ export { statChart };
@@ -0,0 +1,74 @@
1
+ import { bare } from "../layout/frame.mjs";
2
+ import { zeroLine } from "../marks/axes.mjs";
3
+ import { bucketTitles } from "../scale/calendar.mjs";
4
+ import { endNames, framedOrNone } from "./time-frame.mjs";
5
+ import { notesOf } from "./time-notes.mjs";
6
+ import { describePlan, namingOf, reachEnd } from "./time-plan.mjs";
7
+ import { END_ROOM, anyValueIn, valuesOf } from "./time-plot.mjs";
8
+ import { timeStops } from "./time-stops.mjs";
9
+ // src/kinds/time-chart.ts
10
+ /** The frame a plan is drawn in; nothing with no value to draw, or no room for a plot. */
11
+ const framedOf = (plan, env) => anyValueIn(plan.table) ? framedOrNone(plan, env) : void 0;
12
+ /** A chart over time: the frame, what the kind paints in it, and the notes and names over that. */
13
+ const timeChart = (given, env, paint) => framedChart(given, env, {
14
+ room: framedOf(given, env),
15
+ paint
16
+ });
17
+ /**
18
+ * A chart over time in a frame already made for its plan (`framedOf`): for a kind that frames
19
+ * its chart itself to settle what it draws (columns of several buckets), so the chart is not
20
+ * framed a second time.
21
+ */
22
+ function framedChart(given, env, how) {
23
+ const titles = bucketTitles(given.table.x, env.locale);
24
+ const summary = describePlan(given, titles);
25
+ const { room } = how;
26
+ if (room === void 0) return bare(env, given.header, summary);
27
+ const { plan, frame, legend } = room;
28
+ const painted = how.paint(frame);
29
+ const { plot, place } = frame;
30
+ const notes = notesOf(plan, frame, {
31
+ env,
32
+ painted
33
+ });
34
+ return {
35
+ width: env.width,
36
+ height: env.height,
37
+ plot,
38
+ summary,
39
+ ...plan.footnote === void 0 ? {} : { footnote: plan.footnote },
40
+ nodes: [
41
+ ...frame.base,
42
+ ...legend === void 0 ? [] : legend.nodes,
43
+ ...notes.moments.lines,
44
+ ...painted.nodes,
45
+ ...zeroLine(frame.axis, {
46
+ plot,
47
+ place
48
+ }),
49
+ ...notes.levels.lines,
50
+ ...notes.levels.names,
51
+ ...notes.moments.names,
52
+ ...endNames(room, painted, env)
53
+ ],
54
+ hover: {
55
+ snap: "x",
56
+ columns: plan.table.series.map(({ key, label }) => ({
57
+ key,
58
+ label
59
+ })),
60
+ stops: timeStops(plan.table, env, {
61
+ plot,
62
+ center: frame.time.center,
63
+ titles,
64
+ paints: plan.paints,
65
+ noteAt: plan.noteAt,
66
+ ...painted.dotY === void 0 ? {} : { y: painted.dotY },
67
+ ...painted.markAt === void 0 ? {} : { markAt: painted.markAt },
68
+ ...painted.spanAt === void 0 ? {} : { spanAt: painted.spanAt },
69
+ ...painted.band === void 0 ? {} : { band: painted.band }
70
+ })
71
+ }
72
+ };
73
+ }
74
+ export { END_ROOM, anyValueIn, framedChart, framedOf, namingOf, reachEnd, timeChart, timeStops, valuesOf };
@@ -0,0 +1,113 @@
1
+ import { textAt } from "../data/format.mjs";
2
+ import { lastAt } from "../data/rows.mjs";
3
+ import { roomy } from "../layout/frame.mjs";
4
+ import { endLabels, endRoom } from "../marks/end-labels.mjs";
5
+ import { cappedLegend, firstLegend, underHeader } from "../marks/legend.mjs";
6
+ import { paintAt } from "../theme.mjs";
7
+ import { fitted, namedOf } from "./time-plan.mjs";
8
+ import { END_ROOM, timePlot } from "./time-plot.mjs";
9
+ // src/kinds/time-frame.ts
10
+ /**
11
+ * The name beside each named series' end: the series (when there are several) and its last
12
+ * value. `across` is where a bucket's marks stand, for a kind whose marks end at their last
13
+ * value (lines): a series that stops before the last bucket says how far across it ends.
14
+ */
15
+ function labelsOf(plan, painted, across) {
16
+ const several = plan.table.series.length > 1;
17
+ return namedOf(plan).flatMap((i) => {
18
+ const series = plan.table.series[i];
19
+ const last = series === void 0 ? -1 : lastAt(series.values);
20
+ const value = series === void 0 ? void 0 : textAt(series, last);
21
+ const y = painted === void 0 ? 0 : painted.labelY(i);
22
+ if (series === void 0 || value === void 0 || y === void 0) return [];
23
+ const name = several ? { name: series.label } : {};
24
+ const x = across === void 0 ? {} : { x: across(last) };
25
+ return [{
26
+ key: series.key,
27
+ value,
28
+ color: paintAt(plan.paints, i),
29
+ y,
30
+ ...name,
31
+ ...x
32
+ }];
33
+ });
34
+ }
35
+ /** The legend over the plot, when that is how the series are named. */
36
+ function legendOf(plan, env, rows) {
37
+ if (plan.naming !== "legend") return void 0;
38
+ const items = namedOf(plan).flatMap((i) => {
39
+ const series = plan.table.series[i];
40
+ return series === void 0 ? [] : [{
41
+ key: series.key,
42
+ label: series.label,
43
+ color: paintAt(plan.paints, i),
44
+ ...plan.swatch === void 0 ? {} : { shape: plan.swatch }
45
+ }];
46
+ });
47
+ return cappedLegend(items, {
48
+ ...underHeader(plan.header, env),
49
+ rows,
50
+ env
51
+ });
52
+ }
53
+ /** The most of the width the names at the marks' ends take. */
54
+ const ENDS = .4;
55
+ /** The plot's frame, with room above for a legend and to the right for names. */
56
+ function frameOf(plan, env, room) {
57
+ const references = plan.notes.references ?? [];
58
+ return timePlot(plan.table, env, {
59
+ header: plan.header,
60
+ values: [...plan.values, ...references.map((r) => r.value)],
61
+ zero: plan.zero,
62
+ bands: plan.bands,
63
+ ...plan.gutter === void 0 ? {} : { gutter: plan.gutter },
64
+ ...room
65
+ });
66
+ }
67
+ /** The plan framed: the room its names take measured, and the plot put in what is left. */
68
+ function framed(plan, env, rows) {
69
+ const legend = legendOf(plan, env, rows);
70
+ const right = plan.naming === "end" ? endRoom(labelsOf(plan), {
71
+ measure: env.measure,
72
+ most: env.width * ENDS
73
+ }) : END_ROOM;
74
+ return {
75
+ plan,
76
+ frame: frameOf(plan, env, {
77
+ top: legend === void 0 ? 0 : legend.height,
78
+ right
79
+ }),
80
+ legend,
81
+ right
82
+ };
83
+ }
84
+ /** Whether a frame holds its plan: its plot has room, and a legend the plan needs has been placed. */
85
+ const holds = (tried) => roomy(tried.frame.plot) && (tried.plan.naming !== "legend" || tried.legend !== void 0);
86
+ /**
87
+ * The frame the chart is drawn in; nothing when it has no room, and the chart is its header
88
+ * alone. A legend gives up a row before the plot gives up its room. Several series with no
89
+ * room for any legend are not drawn: their colours would name nothing. One series needs no
90
+ * name, so it gives its legend up and is drawn.
91
+ */
92
+ function framedOrNone(given, env) {
93
+ const plan = fitted(given, env);
94
+ const found = plan.naming === "legend" ? firstLegend((rows) => framed(plan, env, rows), holds) : [framed(plan, env, 0)].find((tried) => holds(tried));
95
+ if (found !== void 0 || plan.table.series.length > 1) return found;
96
+ const plain = framed({
97
+ ...plan,
98
+ naming: "none"
99
+ }, env, 0);
100
+ return holds(plain) ? plain : void 0;
101
+ }
102
+ /** The names at the marks' ends, when that is how the series are named. */
103
+ function endNames(room, painted, env) {
104
+ if (room.plan.naming !== "end") return [];
105
+ const { plot, time } = room.frame;
106
+ const across = room.plan.bands ? void 0 : time.center;
107
+ return endLabels(labelsOf(room.plan, painted, across), {
108
+ plot,
109
+ room: room.right,
110
+ measure: env.measure
111
+ });
112
+ }
113
+ export { endNames, framedOrNone };
@@ -0,0 +1,36 @@
1
+ import { alongLine, eventNotes, levelNotes, marked } from "../marks/notes.mjs";
2
+ // src/kinds/time-notes.ts
3
+ /**
4
+ * The places along the lines painted: what a level's name keeps clear of where it can. A kind
5
+ * that paints no lines (columns) gives none.
6
+ */
7
+ const traced = (plan, frame, painted) => plan.table.series.flatMap((series) => alongLine(frame.buckets.map((_bucket, i) => {
8
+ const y = painted.dotY?.(series, i);
9
+ return y === void 0 ? void 0 : {
10
+ x: frame.time.center(i),
11
+ y
12
+ };
13
+ })));
14
+ /** What the chart is read against, drawn: moments under the marks, level lines and names over. */
15
+ function notesOf(plan, frame, at) {
16
+ const { plot, place } = frame;
17
+ const [first] = plan.table.series;
18
+ const noted = (plan.notes.references ?? []).length + (plan.notes.events ?? []).length > 0;
19
+ const room = {
20
+ plot,
21
+ measure: at.env.measure,
22
+ lines: noted ? traced(plan, frame, at.painted) : []
23
+ };
24
+ const levels = marked(levelNotes(plan.notes.references ?? [], {
25
+ place,
26
+ text: first === void 0 ? String : first.measure.text
27
+ }, room), room);
28
+ return {
29
+ levels,
30
+ moments: marked(eventNotes(plan.notes.events ?? [], { x: frame.time.at }, room), {
31
+ ...room,
32
+ taken: levels.taken
33
+ })
34
+ };
35
+ }
36
+ export { notesOf };
@@ -0,0 +1,8 @@
1
+ import { EventMark, Reference } from "../data/types.mjs";
2
+ /** Where the series are named: at their marks' right ends, in a legend above, or nowhere. */
3
+ export type Naming = "end" | "legend" | "none";
4
+ /** What a chart over time is read against: level lines and marked moments. */
5
+ export type TimeNotes = {
6
+ references?: readonly Reference[];
7
+ events?: readonly EventMark[];
8
+ };
@@ -0,0 +1,57 @@
1
+ import { coursesSaid, focusSaid, missingOf, openingOf, summary } from "../describe.mjs";
2
+ import { plotBox } from "../layout/frame.mjs";
3
+ import { X_ROOM } from "../marks/axes.mjs";
4
+ import { endLines } from "../marks/end-labels.mjs";
5
+ // src/kinds/time-plan.ts
6
+ /** A chart narrower than this names its series in a legend: labels beside it would squeeze the plot. */
7
+ const NARROW = 400;
8
+ /** Whether names at the marks' ends have room: the chart is wide enough, and each has a line. */
9
+ function endsFit(count, header, env) {
10
+ const plot = plotBox(env, header, {
11
+ left: 0,
12
+ right: 0,
13
+ bottom: X_ROOM
14
+ });
15
+ return env.width >= NARROW && count <= endLines(plot.height);
16
+ }
17
+ /** Whether every series has a value at the last place, where it would be named. */
18
+ const reachEnd = (series) => series.every((s) => (s.values.at(-1) ?? null) !== null);
19
+ /**
20
+ * How a chart names its series when it was not told: at their marks' ends when every one has
21
+ * an end to be named at and a line of room there; else in a legend, which one series alone
22
+ * does not need, since the title names it.
23
+ */
24
+ function namingOf(asked, at) {
25
+ if (asked !== void 0) return asked;
26
+ if (at.atEnds && endsFit(at.named, at.header, at.env)) return "end";
27
+ return awayFromEnds(at.series);
28
+ }
29
+ /** How series are named when not at their ends: in a legend, which one series alone does not need. */
30
+ const awayFromEnds = (series) => series > 1 ? "legend" : "none";
31
+ /** The series that are named, by their place. */
32
+ const namedOf = (plan) => plan.named ?? plan.table.series.map((_s, i) => i);
33
+ /**
34
+ * The plan with names at the ends only when they fit there: a chart asked for them with no room
35
+ * (too narrow, or more series than lines beside the plot) names its series in a legend instead.
36
+ */
37
+ function fitted(plan, env) {
38
+ if (plan.naming !== "end" || endsFit(namedOf(plan).length, plan.header, env)) return plan;
39
+ return {
40
+ ...plan,
41
+ naming: awayFromEnds(plan.table.series.length)
42
+ };
43
+ }
44
+ /** The chart in words, from its plan and its buckets' names: what it is, what each series did, and what had no value. */
45
+ function describePlan(plan, titles) {
46
+ const { table } = plan;
47
+ return summary(openingOf(table, {
48
+ what: plan.what,
49
+ titles
50
+ }), [
51
+ coursesSaid(table, titles),
52
+ focusSaid(plan.focusLabels ?? []),
53
+ ...plan.also ?? [],
54
+ ...missingOf(table)
55
+ ]);
56
+ }
57
+ export { describePlan, fitted, namedOf, namingOf, reachEnd };
@@ -0,0 +1,56 @@
1
+ import { headerNodes } from "../layout/frame.mjs";
2
+ import { X_ROOM, labelsUnder } from "../marks/axes.mjs";
3
+ import { END_REACH } from "../marks/series-line.mjs";
4
+ import { timeScale } from "../scale/time.mjs";
5
+ import { timeTicks } from "../scale/time-ticks.mjs";
6
+ import { valuePlot } from "./value-plot.mjs";
7
+ // src/kinds/time-plot.ts
8
+ /** The room right of a plot with no names beside it: the dot at a line's end, and a pixel of air. */
9
+ const END_ROOM = Math.ceil(END_REACH) + 1;
10
+ /** The frame of a chart over time. */
11
+ function timePlot(table, env, rule) {
12
+ const measure = table.series[0]?.measure;
13
+ const { plot, axis, place, grid } = valuePlot(env, {
14
+ header: rule.header,
15
+ values: rule.values,
16
+ zero: rule.zero,
17
+ reads: measure,
18
+ margins: {
19
+ top: rule.top ?? 0,
20
+ right: rule.right ?? 0,
21
+ bottom: X_ROOM
22
+ },
23
+ ...rule.gutter === void 0 ? {} : { gutter: rule.gutter }
24
+ });
25
+ const time = timeScale(table.x, {
26
+ from: plot.x,
27
+ to: plot.x + plot.width
28
+ }, rule.bands);
29
+ const ticks = timeTicks(table.x, {
30
+ center: time.center,
31
+ min: 0,
32
+ max: env.width,
33
+ measure: env.measure,
34
+ ...env.locale === void 0 ? {} : { locale: env.locale }
35
+ });
36
+ const base = [
37
+ ...headerNodes(env, rule.header),
38
+ ...grid,
39
+ ...labelsUnder(ticks, plot)
40
+ ];
41
+ return {
42
+ buckets: table.x.buckets,
43
+ plot,
44
+ axis,
45
+ place,
46
+ time,
47
+ base
48
+ };
49
+ }
50
+ /** Whether a table has any value to draw: with none, a chart over time is its header alone. */
51
+ const anyValueIn = (table) => table.series.some((s) => s.values.some((v) => v !== null));
52
+ /** Every value of a table's series, the comparison period's too. */
53
+ function valuesOf(table) {
54
+ return table.series.flatMap((s) => [...s.values, ...s.previous ?? []].filter((v) => v !== null));
55
+ }
56
+ export { END_ROOM, anyValueIn, timePlot, valuesOf };
@@ -0,0 +1,56 @@
1
+ import { textAt } from "../data/format.mjs";
2
+ import { wordsOf } from "../data/words.mjs";
3
+ import { paintAt } from "../theme.mjs";
4
+ // src/kinds/time-stops.ts
5
+ /** What a stop says of a bucket the data covers only part of. */
6
+ const partOf = (partial, words) => partial === void 0 ? void 0 : partial === "start" ? words.partial : words.soFar;
7
+ /** What a stop says beside its bucket's name: that the data covers only part of it, then what the kind says of it. */
8
+ function noteOf(said) {
9
+ const notes = said.filter((one) => one !== void 0);
10
+ return notes.length === 0 ? {} : { note: notes.join(", ") };
11
+ }
12
+ /**
13
+ * Where a series' value is found at a bucket: where its own mark is, when the kind says where;
14
+ * else at the bucket's middle, at its height along a line or at the stop's top.
15
+ */
16
+ const foundAt = (series, index, at) => at.markAt?.(series, index) ?? {
17
+ x: at.center(index),
18
+ y: at.y?.(series, index) ?? at.plot.y
19
+ };
20
+ /** One stop per bucket, each with the series that have a value there. */
21
+ function timeStops(table, env, at) {
22
+ const words = wordsOf(env);
23
+ return table.x.buckets.map((bucket, i) => {
24
+ const x = at.center(i);
25
+ const span = at.spanAt?.(i);
26
+ const items = table.series.flatMap((series, s) => {
27
+ const value = textAt(series, i);
28
+ if (value === void 0) return [];
29
+ const before = series.previous?.[i] ?? null;
30
+ return [{
31
+ key: series.key,
32
+ label: series.label,
33
+ value,
34
+ color: paintAt(at.paints, s),
35
+ ...foundAt(series, i, at),
36
+ ...before === null ? {} : { aside: words.before(series.measure.text(before)) }
37
+ }];
38
+ });
39
+ return {
40
+ key: bucket.label,
41
+ x,
42
+ y: at.plot.y,
43
+ title: at.titles[i] ?? bucket.label,
44
+ items,
45
+ ...span === void 0 ? {} : { span },
46
+ ...noteOf([partOf(bucket.partial, words), at.noteAt?.(i)]),
47
+ ...at.band === void 0 ? {} : { band: {
48
+ x: x - at.band / 2,
49
+ y: at.plot.y,
50
+ width: at.band,
51
+ height: at.plot.height
52
+ } }
53
+ };
54
+ });
55
+ }
56
+ export { timeStops };
@@ -0,0 +1,33 @@
1
+ import { plotBox } from "../layout/frame.mjs";
2
+ import { gutterOf, valueGrid } from "../marks/axes.mjs";
3
+ import { placeOn, tickCount, valueAxis } from "../scale/value.mjs";
4
+ // src/kinds/value-plot.ts
5
+ /** The plot, its value axis, and the axis's grid. */
6
+ function valuePlot(env, rule) {
7
+ const tall = plotBox(env, rule.header, {
8
+ ...rule.margins,
9
+ left: 0
10
+ }).height;
11
+ const axis = valueAxis(rule.values, {
12
+ zero: rule.zero,
13
+ count: tickCount(tall),
14
+ reads: rule.reads
15
+ });
16
+ const left = Math.max(rule.gutter ?? 0, gutterOf(axis, rule.reads, env.measure));
17
+ const plot = plotBox(env, rule.header, {
18
+ ...rule.margins,
19
+ left
20
+ });
21
+ const place = placeOn(axis, plot.y + plot.height, plot.y);
22
+ return {
23
+ plot,
24
+ axis,
25
+ place,
26
+ grid: valueGrid(axis, {
27
+ plot,
28
+ place,
29
+ reads: rule.reads
30
+ })
31
+ };
32
+ }
33
+ export { valuePlot };
@@ -0,0 +1,7 @@
1
+ import { Named } from "../data/rows.mjs";
2
+ import { Value } from "../data/types.mjs";
3
+ /** A step of a waterfall: a total, or a change to the running total (the default). */
4
+ export type WaterfallStep = Named & {
5
+ value: Value;
6
+ kind?: "total" | "change";
7
+ };
@@ -0,0 +1,71 @@
1
+ import { drawable } from "../data/clean.mjs";
2
+ import { changeWritten, signAsWritten, signed } from "../data/format.mjs";
3
+ // src/kinds/waterfall-data.ts
4
+ /** The steps with every value that cannot be drawn taken as missing. */
5
+ const cleaned = (steps) => steps.map((s) => ({
6
+ ...s,
7
+ value: drawable(s.value)
8
+ }));
9
+ /** Each step with its leg, walking the running total from zero. */
10
+ function walked(steps) {
11
+ const rows = [];
12
+ for (const step of steps) {
13
+ const running = rows.at(-1)?.leg.to ?? 0;
14
+ const total = step.kind === "total";
15
+ const value = step.value;
16
+ const leg = value === null ? {
17
+ from: running,
18
+ to: running,
19
+ total,
20
+ change: 0,
21
+ known: false
22
+ } : total ? {
23
+ from: 0,
24
+ to: value,
25
+ total,
26
+ change: value,
27
+ known: true
28
+ } : {
29
+ from: running,
30
+ to: running + value,
31
+ total,
32
+ change: value,
33
+ known: true
34
+ };
35
+ rows.push({
36
+ ...step,
37
+ leg
38
+ });
39
+ }
40
+ return rows;
41
+ }
42
+ /**
43
+ * A change as the waterfall writes it, by the shared rule (`changeWritten`) over the running
44
+ * totals it runs between, which says how far it went and which way: this adds the sign,
45
+ * "+$12,400", "−$3,100", "+6 pts" (none when it reads as none: a refund of a third of a cent,
46
+ * written "$0", is no change, and nor is a change in points whose two running totals read
47
+ * alike), or, for a share with no points writer, writes its two values ("40% → 46%", `join`
48
+ * between them), never a percent: 40% to 46% is not "+6%". A change that is not a share is the
49
+ * measure's text of its size, and went the way its own sign reads as written, whatever the sum
50
+ * rounds to. Its text is always written, so it is a `Written` with a text.
51
+ */
52
+ function signedOrEnds(leg, says, join = " → ") {
53
+ const { measure, points } = says;
54
+ const written = changeWritten(leg, measure, {
55
+ points,
56
+ own: () => ({
57
+ text: measure.text(Math.abs(leg.change)),
58
+ sign: signAsWritten(leg.change, measure.text)
59
+ })
60
+ });
61
+ return {
62
+ text: written.text === void 0 ? `${measure.text(leg.from)}${join}${measure.text(leg.to)}` : signed(written.sign, written.text),
63
+ sign: written.sign
64
+ };
65
+ }
66
+ /** How a step's bar is labelled: a total as its value, a change as it is written; nothing for none. */
67
+ const labelOf = (leg, says) => {
68
+ if (!leg.known) return "";
69
+ return leg.total ? says.measure.text(leg.to) : signedOrEnds(leg, says).text;
70
+ };
71
+ export { cleaned, labelOf, signedOrEnds, walked };
@@ -0,0 +1,38 @@
1
+ import { lengthsOn } from "../scale/value.mjs";
2
+ import { keptRows, reachOf, rowFrame, rowPlot, slotsOf, slotted } from "./row-chart.mjs";
3
+ import { labelOf } from "./waterfall-data.mjs";
4
+ // src/kinds/waterfall-layout.ts
5
+ /**
6
+ * The rows drawn and the slot of the line that counts the rest: every row when all fit, else
7
+ * the first that fit less one, and a closing total kept under the line in place of a change.
8
+ */
9
+ const keptOf = (rows, shown) => slotted(rows, keptRows(rows, shown, (row) => row === rows.at(-1) && row.leg.total));
10
+ /** Where the rows go and which of them are drawn. */
11
+ function layoutOf(rows, options, env) {
12
+ const labelsOf = (shown) => keptOf(rows, shown).kept.map(({ row }) => row.label);
13
+ const frame = rowFrame(rows.map((row) => row.label), {
14
+ header: options,
15
+ labelsOf
16
+ }, env);
17
+ const ends = rows.flatMap(({ leg }) => leg.known ? [leg.from, leg.to] : []);
18
+ const wording = {
19
+ measure: options.measure,
20
+ points: options.points
21
+ };
22
+ const texts = rows.map((row) => labelOf(row.leg, wording));
23
+ const reach = reachOf(frame, texts, {
24
+ env,
25
+ bothSides: ends.some((v) => v < 0)
26
+ });
27
+ const slots = keptOf(rows, frame.shown);
28
+ return {
29
+ frame,
30
+ reach,
31
+ x: lengthsOn(ends, reach.from, reach.to),
32
+ ...slots,
33
+ drawn: ends.length > 0,
34
+ numbers: reach.fits,
35
+ plot: rowPlot(frame, reach, slotsOf(slots.kept))
36
+ };
37
+ }
38
+ export { layoutOf };
@@ -0,0 +1,82 @@
1
+ import { keyOf } from "../data/rows.mjs";
2
+ import { MUTED } from "../scene/paint.mjs";
3
+ import { signPaint } from "../theme.mjs";
4
+ import { rowBar, rowName, rowValue } from "./row-marks.mjs";
5
+ import { barThick } from "./row-chart.mjs";
6
+ import { labelOf, signedOrEnds } from "./waterfall-data.mjs";
7
+ // src/kinds/waterfall-marks.ts
8
+ /**
9
+ * A bar's colour: a total is neutral data, grey. A change is good, bad or grey for none by the
10
+ * measure, read off the way it went as written; the chart's own colour when the measure says no
11
+ * way is better. With no numbers written nothing on the page says good or bad, so a change is
12
+ * drawn neutral: grey when the measure has a better way, the chart's own colour when it has none.
13
+ */
14
+ function colorOf(row, at) {
15
+ if (row.leg.total) return MUTED;
16
+ const sign = at.numbers ? signedOrEnds(row.leg, at).sign : 0;
17
+ return signPaint(sign, at.measure, at.own);
18
+ }
19
+ /** One row: its name, and its bar and value when it has one. */
20
+ function rowNodes(row, slot, at) {
21
+ const { frame, x } = at;
22
+ const { leg } = row;
23
+ const name = rowName(row.label, {
24
+ frame,
25
+ slot,
26
+ env: at.env,
27
+ key: keyOf(row)
28
+ });
29
+ if (!leg.known) return [name];
30
+ const mid = frame.middle(slot);
31
+ const from = x(leg.from);
32
+ const to = x(leg.to);
33
+ const toRight = leg.total ? leg.to >= 0 : leg.change >= 0;
34
+ const value = {
35
+ left: Math.min(from, to),
36
+ right: Math.max(from, to),
37
+ toRight,
38
+ y: mid,
39
+ frame,
40
+ env: at.env,
41
+ floats: !leg.total,
42
+ zero: x(0)
43
+ };
44
+ const thick = barThick(frame.rowHeight);
45
+ return [
46
+ name,
47
+ rowBar({
48
+ from,
49
+ to,
50
+ mid,
51
+ thick,
52
+ fill: colorOf(row, at),
53
+ key: keyOf(row)
54
+ }),
55
+ ...at.numbers ? rowValue(labelOf(leg, at), value) : []
56
+ ];
57
+ }
58
+ /**
59
+ * The hairline from a bar's end down to the next row, at the running total between them: only
60
+ * between two rows drawn next to each other that both have a value, so none crosses the line
61
+ * that counts the rows left out, and none passes a step whose change is not known.
62
+ */
63
+ function joinNodes(kept, at) {
64
+ const { frame } = at;
65
+ const thick = barThick(frame.rowHeight);
66
+ return kept.flatMap(({ row, slot }, i) => {
67
+ const next = kept[i + 1];
68
+ if (next?.slot !== slot + 1 || !row.leg.known || !next.row.leg.known) return [];
69
+ const x = at.x(row.leg.to);
70
+ const mid = frame.middle(slot);
71
+ return [{
72
+ kind: "line",
73
+ part: "join",
74
+ x1: x,
75
+ x2: x,
76
+ y1: mid + thick / 2,
77
+ y2: mid + frame.rowHeight - thick / 2,
78
+ stroke: MUTED
79
+ }];
80
+ });
81
+ }
82
+ export { colorOf, joinNodes, rowNodes };