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,113 @@
1
+ import { X_ROOM } from "../marks/axes.mjs";
2
+ import { widestReach } from "../marks/dot.mjs";
3
+ import { legend, underHeader } from "../marks/legend.mjs";
4
+ import { placeOn, ticksAcross, valueAxis } from "../scale/value.mjs";
5
+ import { MUTED } from "../scene/paint.mjs";
6
+ import { anyValue, nowText } from "./dumbbell-data.mjs";
7
+ import { hasRoom, reachOf, rowFrame, rowPlot } from "./row-chart.mjs";
8
+ const DOT_REACH = widestReach(5);
9
+ /** The numbers a choice writes: each value now with its arrow, and each value then. */
10
+ function textsOf(rows, written, says) {
11
+ const now = rows.flatMap((r) => r.to === null ? [] : [nowText(r, r.to, says)]);
12
+ const then = rows.flatMap((r) => r.from === null ? [] : [says.measure.text(r.from)]);
13
+ return {
14
+ both: [...now, ...then],
15
+ to: now,
16
+ none: []
17
+ }[written];
18
+ }
19
+ /**
20
+ * Where the dots may go, and which numbers are written: both when they have the room they ask
21
+ * for each side of the plot, else the value now alone when it has, else none. `reachOf` keeps
22
+ * the plot its least width whatever the numbers ask, and gives back the room of numbers that
23
+ * do not fit, so the reach of numbers now with no room is the reach of none.
24
+ */
25
+ function reachFor(rows, frame, at) {
26
+ const { env } = at;
27
+ const reachWith = (written) => reachOf(frame, textsOf(rows, written, at.says), {
28
+ env,
29
+ bothSides: true
30
+ });
31
+ const both = reachWith("both");
32
+ if (both.fits) return {
33
+ written: "both",
34
+ reach: both
35
+ };
36
+ const now = reachWith("to");
37
+ return {
38
+ written: now.fits ? "to" : "none",
39
+ reach: now
40
+ };
41
+ }
42
+ /**
43
+ * The key over the rows: a ring for then and a dot for now. It is grey on purpose: it explains
44
+ * the two shapes, not a colour, since the rows are coloured by their change. Do not colour it.
45
+ */
46
+ function keyOver(options, env) {
47
+ const items = [{
48
+ key: "from",
49
+ label: options.fromLabel,
50
+ color: MUTED,
51
+ shape: "ring"
52
+ }, {
53
+ key: "to",
54
+ label: options.toLabel,
55
+ color: MUTED,
56
+ shape: "dot"
57
+ }];
58
+ return legend(items, {
59
+ ...underHeader(options, env),
60
+ measure: env.measure
61
+ });
62
+ }
63
+ /** Where the rows go under a key of this height, and where a value sits along a row. */
64
+ function arranged(rows, options, at) {
65
+ const { env } = at;
66
+ const above = at.legend?.height ?? 0;
67
+ const labels = rows.map((r) => r.label);
68
+ const frame = rowFrame(labels, {
69
+ header: options,
70
+ above,
71
+ below: X_ROOM
72
+ }, env);
73
+ const { written, reach } = reachFor(rows, frame, {
74
+ says: options,
75
+ env
76
+ });
77
+ const values = rows.flatMap((r) => [r.from, r.to].filter((v) => v !== null));
78
+ const from = reach.from + DOT_REACH;
79
+ const to = reach.to - DOT_REACH;
80
+ const axis = valueAxis(values, {
81
+ zero: "near",
82
+ count: ticksAcross(to - from),
83
+ reads: options.measure
84
+ });
85
+ const x = placeOn(axis, from, to);
86
+ const plot = rowPlot(frame, reach, frame.shown);
87
+ const moreY = plot.y + plot.height + X_ROOM + frame.rowHeight / 2;
88
+ const kept = rows.slice(0, frame.shown);
89
+ const zero = axis.min <= 0 && axis.max >= 0 ? x(0) : void 0;
90
+ const drawn = anyValue(rows);
91
+ return {
92
+ frame,
93
+ reach,
94
+ written,
95
+ axis,
96
+ x,
97
+ plot,
98
+ legend: at.legend,
99
+ kept,
100
+ drawn,
101
+ zero,
102
+ moreY
103
+ };
104
+ }
105
+ /** Where the rows go, with the key over them when it leaves room for a row, else without it. */
106
+ function layoutOf(rows, options, env) {
107
+ const keyed = arranged(rows, options, {
108
+ env,
109
+ legend: keyOver(options, env)
110
+ });
111
+ return hasRoom(keyed.frame, keyed.reach, true) ? keyed : arranged(rows, options, { env });
112
+ }
113
+ export { DOT_REACH, layoutOf };
@@ -0,0 +1,119 @@
1
+ import { keyOf } from "../data/rows.mjs";
2
+ import { zeroLine } from "../marks/axes.mjs";
3
+ import { dot } from "../marks/dot.mjs";
4
+ import { xGrid } from "../marks/x-axis.mjs";
5
+ import { MARK, TEXT, signPaint } from "../theme.mjs";
6
+ import { changeAsWritten, nowText } from "./dumbbell-data.mjs";
7
+ import { DOT_REACH } from "./dumbbell-layout.mjs";
8
+ import { rowName, rowValue } from "./row-marks.mjs";
9
+ // src/kinds/dumbbell-marks.ts
10
+ /**
11
+ * How thick the link between two dots is: the change itself, so heavier than a line, and still
12
+ * thinner than the dots so both ends read.
13
+ */
14
+ const LINK = 4;
15
+ /** Which way a row's value now is written from its dot: away from where it was. */
16
+ const rises = (row) => row.from === null || row.to === null || row.to >= row.from;
17
+ /** Where a number beside a dot at `x` may go: past the dot's ring, and never across zero. */
18
+ const besideDot = (x, y, at) => ({
19
+ left: x - DOT_REACH,
20
+ right: x + DOT_REACH,
21
+ y,
22
+ frame: at.frame,
23
+ env: at.env,
24
+ ...at.zero === void 0 ? {} : { zero: at.zero }
25
+ });
26
+ /** The value now with its arrow, past its dot on the side away from where it was. */
27
+ function nowNumber(row, y, at) {
28
+ if (row.to === null || at.written === "none") return [];
29
+ return rowValue(nowText(row, row.to, at), {
30
+ ...besideDot(at.x(row.to), y, at),
31
+ toRight: rises(row)
32
+ });
33
+ }
34
+ /** The value then, quieter, past its dot on its own far side. */
35
+ function thenNumber(row, y, at) {
36
+ if (row.from === null || at.written !== "both") return [];
37
+ return rowValue(at.measure.text(row.from), {
38
+ ...besideDot(at.x(row.from), y, at),
39
+ toRight: !rises(row) || row.to === null,
40
+ text: TEXT.tick
41
+ });
42
+ }
43
+ /**
44
+ * A row's colour: its change where the arrow beside the value now says it too, else no change,
45
+ * so not where that number has no room or no arrow. Whether the number has room does not hang
46
+ * on its row's height, so it is asked at any.
47
+ */
48
+ function colorOf(row, at) {
49
+ const arrowed = nowNumber(row, 0, at).length > 0;
50
+ return signPaint(arrowed ? changeAsWritten(row, at).sign : 0, at.measure, at.own);
51
+ }
52
+ /** The link between the two dots, when the row has both. */
53
+ function link(row, at) {
54
+ if (row.from === null || row.to === null) return [];
55
+ return [{
56
+ kind: "line",
57
+ part: "link",
58
+ key: keyOf(row),
59
+ x1: at.x(row.from),
60
+ x2: at.x(row.to),
61
+ y1: at.y,
62
+ y2: at.y,
63
+ stroke: at.paint,
64
+ strokeWidth: LINK,
65
+ opacity: MARK.faint
66
+ }];
67
+ }
68
+ /** A row: its name, the link, both dots and their numbers on their outer sides. */
69
+ function rowNodes(row, slot, at) {
70
+ const y = at.frame.middle(slot);
71
+ const key = keyOf(row);
72
+ const paint = colorOf(row, at);
73
+ const end = (value, hollow) => value === null ? [] : [dot({
74
+ x: at.x(value),
75
+ y,
76
+ r: 5,
77
+ color: paint,
78
+ hollow,
79
+ part: hollow ? "from" : "to",
80
+ key
81
+ })];
82
+ return [
83
+ rowName(row.label, {
84
+ frame: at.frame,
85
+ slot,
86
+ env: at.env,
87
+ key
88
+ }),
89
+ ...link(row, {
90
+ y,
91
+ paint,
92
+ x: at.x
93
+ }),
94
+ ...end(row.from, true),
95
+ ...end(row.to, false),
96
+ ...nowNumber(row, y, at),
97
+ ...thenNumber(row, y, at)
98
+ ];
99
+ }
100
+ /**
101
+ * The axis under the rows: an upright hairline at each tick, the numbers that fit under them, and
102
+ * the zero line when the axis holds zero.
103
+ */
104
+ function axisNodes(layout, at) {
105
+ const { plot, x, axis, frame } = layout;
106
+ return [...xGrid(axis, {
107
+ plot,
108
+ place: x,
109
+ reads: at.measure,
110
+ measure: at.env.measure,
111
+ min: frame.left,
112
+ max: at.env.width
113
+ }), ...zeroLine(axis, {
114
+ plot,
115
+ place: x,
116
+ upright: true
117
+ })];
118
+ }
119
+ export { axisNodes, colorOf, rowNodes };
@@ -0,0 +1,7 @@
1
+ import { Says } from "./dumbbell-data.mjs";
2
+ /** What the words of a dumbbell are made from: its measure, its points, and the names of its two ends. */
3
+ export type Wording = Says & {
4
+ /** What the hollow dot is ("Last year") and what the filled dot is ("This year"). */
5
+ fromLabel: string;
6
+ toLabel: string;
7
+ };
@@ -0,0 +1,94 @@
1
+ import { signed, topAsWritten } from "../data/format.mjs";
2
+ import { keyOf, rankable } from "../data/rows.mjs";
3
+ import { noValue, shownOf, summary, worthSaid } from "../describe.mjs";
4
+ import { changeAsWritten, missingEnds } from "./dumbbell-data.mjs";
5
+ import { colorOf } from "./dumbbell-marks.mjs";
6
+ import { rowStop } from "./row-marks.mjs";
7
+ // src/kinds/dumbbell-words.ts
8
+ /**
9
+ * A row's change as it is written: "+4 pts" or "−4 pts", signed the way the row went, and no
10
+ * sign where it reads as no change; nothing when an end is missing or the change is not
11
+ * written in points.
12
+ */
13
+ function signedPoints(row, says) {
14
+ const { text, sign } = changeAsWritten(row, says);
15
+ return text === void 0 ? void 0 : signed(sign, text);
16
+ }
17
+ /** Beside the value now: the change, when it is written. */
18
+ function asideOf(row, wording) {
19
+ const aside = signedPoints(row, wording);
20
+ return aside === void 0 ? void 0 : { aside };
21
+ }
22
+ /**
23
+ * What a pointer finds on a row: an item for the value then, keyed `from`, and one for the value
24
+ * now, keyed `to`, each when its end has a value; the change in points beside the value now.
25
+ */
26
+ function stopOf(row, slot, at) {
27
+ const { frame, env, wording } = at;
28
+ const color = colorOf(row, at);
29
+ const y = frame.middle(slot);
30
+ const item = (key, label, value) => value === null ? [] : [{
31
+ key,
32
+ label,
33
+ value: wording.measure.text(value),
34
+ color,
35
+ x: at.x(value),
36
+ y
37
+ }];
38
+ const now = item("to", wording.toLabel, row.to).map((it) => ({
39
+ ...it,
40
+ ...asideOf(row, wording)
41
+ }));
42
+ const items = [...item("from", wording.fromLabel, row.from), ...now];
43
+ return rowStop(row.label, {
44
+ frame,
45
+ slot,
46
+ key: keyOf(row),
47
+ items,
48
+ nodes: at.nodes,
49
+ env
50
+ });
51
+ }
52
+ /**
53
+ * The row that moved furthest either way, by its change as written, among two rows or more with
54
+ * both their ends, Other aside; none when the two furthest read alike. Only a row whose move
55
+ * its own numbers show: one that reads as unchanged moved not at all.
56
+ */
57
+ function movedMost(rows, says) {
58
+ const whole = rankable(rows).flatMap((row) => row.from === null || row.to === null ? [] : [{
59
+ row,
60
+ from: row.from,
61
+ to: row.to
62
+ }]);
63
+ return topAsWritten(whole, (m) => Math.abs(m.to - m.from), says.measure.text, (m) => changeAsWritten(m.row, says).sign !== 0);
64
+ }
65
+ /**
66
+ * "Moved most: Fell, 90% to 60% (−30 pts), which is worse": whether it is better or worse said
67
+ * as its colour says it; nothing when no row moved as written.
68
+ */
69
+ function movedMostText(rows, wording) {
70
+ const { measure } = wording;
71
+ const most = movedMost(rows, wording);
72
+ if (most === void 0) return void 0;
73
+ const change = signedPoints(most.row, wording);
74
+ const points = change === void 0 ? "" : ` (${change})`;
75
+ const worth = worthSaid(changeAsWritten(most.row, wording).sign, measure);
76
+ return `Moved most: ${most.row.label}, ${measure.text(most.from)} to ${measure.text(most.to)}${points}${worth}`;
77
+ }
78
+ /**
79
+ * What a dumbbell shows: of what, now read against then, how many rows it was given and drew, what
80
+ * moved most, how many rows have no value at all, and how many lack one end.
81
+ */
82
+ function describeDumbbell(rows, at) {
83
+ const missing = missingEnds(rows);
84
+ return summary([
85
+ `Dumbbell chart of ${at.measure.label}`,
86
+ `${at.toLabel} against ${at.fromLabel}`,
87
+ shownOf(rows.length, at.shown, "row")
88
+ ], [
89
+ movedMostText(rows, at),
90
+ noValue(missing.both, "row"),
91
+ noValue(missing.one, "row with an end missing", "rows with an end missing")
92
+ ]);
93
+ }
94
+ export { describeDumbbell, stopOf };
@@ -0,0 +1,14 @@
1
+ import { Env, Header } from "../data/types.mjs";
2
+ import { Scene } from "../scene/types.mjs";
3
+ import { DumbbellRow, DumbbellSort } from "./dumbbell-data.mjs";
4
+ import { Wording } from "./dumbbell-words.mjs";
5
+ /** A dumbbell's words (its measure, the names of its two ends, its points), and how it is drawn. */
6
+ export type DumbbellOptions = Header & Wording & {
7
+ /** By the value now, largest first (the default), by the change, or in the order given. */
8
+ sort?: DumbbellSort;
9
+ /** The palette place of the chart's own colour, every row's when the measure has no better way. */
10
+ slot?: number;
11
+ };
12
+ /** Each thing's value then and now, as a dot and a dot joined by the change. */
13
+ export declare function dumbbellChart(rows: readonly DumbbellRow[], options: DumbbellOptions, env: Env): Scene;
14
+ export type { DumbbellRow, DumbbellSort };
@@ -0,0 +1,67 @@
1
+ import { bare, headerNodes } from "../layout/frame.mjs";
2
+ import { seriesPaint } from "../theme.mjs";
3
+ import { rowsMore } from "./row-marks.mjs";
4
+ import { cleaned, ordered } from "./dumbbell-data.mjs";
5
+ import { layoutOf } from "./dumbbell-layout.mjs";
6
+ import { axisNodes, rowNodes } from "./dumbbell-marks.mjs";
7
+ import { describeDumbbell, stopOf } from "./dumbbell-words.mjs";
8
+ import { hasRoom } from "./row-chart.mjs";
9
+ // src/kinds/dumbbell.ts
10
+ /** Each thing's value then and now, as a dot and a dot joined by the change. */
11
+ function dumbbellChart(rows, options, env) {
12
+ const all = ordered(cleaned(rows), options.sort ?? "value");
13
+ const layout = layoutOf(all, options, env);
14
+ const { frame, plot, x, kept, zero } = layout;
15
+ const roomy = hasRoom(frame, layout.reach, layout.drawn);
16
+ const summary = describeDumbbell(all, {
17
+ ...options,
18
+ shown: roomy ? kept.length : 0
19
+ });
20
+ if (!roomy) return bare(env, options, summary);
21
+ const { measure, points } = options;
22
+ const own = seriesPaint(options.slot ?? 0);
23
+ const at = {
24
+ frame,
25
+ x,
26
+ zero,
27
+ measure,
28
+ points,
29
+ written: layout.written,
30
+ own,
31
+ env
32
+ };
33
+ const placed = kept.map((row, slot) => ({
34
+ row,
35
+ slot,
36
+ nodes: rowNodes(row, slot, at)
37
+ }));
38
+ return {
39
+ width: env.width,
40
+ height: env.height,
41
+ plot,
42
+ summary,
43
+ nodes: [
44
+ ...headerNodes(env, options),
45
+ ...layout.legend?.nodes ?? [],
46
+ ...axisNodes(layout, {
47
+ measure,
48
+ env
49
+ }),
50
+ ...placed.flatMap(({ nodes }) => nodes),
51
+ ...rowsMore(all.length - placed.length, {
52
+ frame,
53
+ env,
54
+ y: layout.moreY
55
+ })
56
+ ],
57
+ hover: {
58
+ snap: "y",
59
+ stops: placed.map(({ row, slot, nodes }) => stopOf(row, slot, {
60
+ ...at,
61
+ nodes,
62
+ wording: options
63
+ }))
64
+ }
65
+ };
66
+ }
67
+ export { dumbbellChart };
@@ -0,0 +1,11 @@
1
+ import { Named } from "../data/rows.mjs";
2
+ import { Value } from "../data/types.mjs";
3
+ /** A step of a funnel: how many reached it. */
4
+ export type FunnelStep = Named & {
5
+ value: Value;
6
+ /**
7
+ * The value as the host writes it, when it has its own text for it (an exact amount keeps
8
+ * every digit a float would lose); the measure's text when left out.
9
+ */
10
+ text?: string;
11
+ };
@@ -0,0 +1,70 @@
1
+ import { drawable } from "../data/clean.mjs";
2
+ import { orderAsWritten, percentText, said, topAsWritten } from "../data/format.mjs";
3
+ // src/kinds/funnel-data.ts
4
+ /** A step's value as it is written: the host's own text for it, else the measure's. */
5
+ const stepText = (step, measure) => said(step.text) ?? (step.value === null ? "" : measure.text(step.value));
6
+ /**
7
+ * A share as a funnel writes it. A share that is not nothing is never written as nothing: three
8
+ * of a million who went on are "<0.1%", not "0%", which would say that no one did.
9
+ */
10
+ function sharePercent(locale) {
11
+ const percent = percentText(locale);
12
+ const least = `<${percent(.001)}`;
13
+ return (share) => share > 0 && percent(share) === percent(0) ? least : percent(share);
14
+ }
15
+ /**
16
+ * The steps as they can be drawn. A value that is not finite is missing. So is a negative one:
17
+ * a count of people cannot be below zero, so it is a fault upstream, not a number to draw or say.
18
+ */
19
+ const cleaned = (steps) => steps.map((step) => {
20
+ const value = drawable(step.value);
21
+ return {
22
+ ...step,
23
+ value: value !== null && value >= 0 ? value : null
24
+ };
25
+ });
26
+ /**
27
+ * A share of a whole, null when either is missing or the whole is not above zero, and when a
28
+ * whole too small for a float makes the share too large for one.
29
+ */
30
+ function ratio(part, whole) {
31
+ if (part === null || whole === void 0 || whole === null || whole <= 0) return null;
32
+ const quotient = part / whole;
33
+ return quotient === 0 && part > 0 ? Number.MIN_VALUE : drawable(quotient);
34
+ }
35
+ /**
36
+ * The step that lost the most: the lowest rate, when it is written below 100% and the step's
37
+ * value reads below the step's before it. A step is a drop only when fewer went on than came in
38
+ * as its numbers read, so a funnel that only grew, lost too few to show, or whose steps read
39
+ * alike ($0.004 then $0.002, each "$0") has none. It is marked only when every rate is known: a
40
+ * rate not known could be the lower, and one rate alone is not the largest of anything. Two
41
+ * lowest rates that read alike mark none: a reader could not tell which lost more.
42
+ */
43
+ function leakOf(values, rate, at) {
44
+ const { measure, percent } = at;
45
+ if (rate.slice(1).includes(null)) return null;
46
+ const known = rate.flatMap((r, i) => r === null ? [] : [{
47
+ r,
48
+ i
49
+ }]);
50
+ const fell = (i) => orderAsWritten(values[i] ?? NaN, values[i - 1] ?? NaN, measure.text) < 0;
51
+ return topAsWritten(known, ({ r }) => -r, (turned) => percent(-turned), ({ r, i }) => orderAsWritten(r, 1, percent) < 0 && fell(i))?.i ?? null;
52
+ }
53
+ /**
54
+ * The flow through steps given as values in order, its drops judged as the numbers read by the
55
+ * funnel's words (its measure and its percent writer).
56
+ */
57
+ function flowOf(values, at) {
58
+ const first = values[0] ?? null;
59
+ const before = values.map((_v, i) => i === 0 ? null : values[i - 1] ?? null);
60
+ const rate = values.map((v, i) => ratio(v, before[i]));
61
+ return {
62
+ before,
63
+ share: values.map((v) => ratio(v, first)),
64
+ rate,
65
+ leak: leakOf(values, rate, at)
66
+ };
67
+ }
68
+ /** Which way a rate went, as its percent reads: down when fewer went on, none at 100%. */
69
+ const rateWay = (rate, percent) => orderAsWritten(rate, 1, percent);
70
+ export { cleaned, flowOf, rateWay, sharePercent, stepText };
@@ -0,0 +1,32 @@
1
+ import { lengthsOn } from "../scale/value.mjs";
2
+ import { LINE } from "../theme.mjs";
3
+ import { stepText } from "./funnel-data.mjs";
4
+ import { ROW, barThick, reachOf, rowFrame, rowPlot } from "./row-chart.mjs";
5
+ // src/kinds/funnel-layout.ts
6
+ /** The room between two bars that hold the share that went on between them: a line of small words. */
7
+ const TALKING = LINE.tick;
8
+ /** Where the steps go and which of them are drawn. */
9
+ function layoutOf(steps, options, env) {
10
+ const values = steps.flatMap((s) => s.value === null ? [] : [s.value]);
11
+ const most = ROW.most + TALKING - ROW.between;
12
+ const frame = rowFrame(steps.map((s) => s.label), {
13
+ header: options,
14
+ most
15
+ }, env);
16
+ const written = steps.filter((s) => s.value !== null).map((s) => stepText(s, options.measure));
17
+ const reach = reachOf(frame, written, { env });
18
+ const talks = barThick(frame.rowHeight, TALKING) >= barThick(ROW.least);
19
+ const kept = steps.slice(0, frame.shown);
20
+ return {
21
+ frame,
22
+ reach,
23
+ x: lengthsOn(values, reach.from, reach.to),
24
+ thick: barThick(frame.rowHeight, talks ? TALKING : ROW.between),
25
+ talks,
26
+ kept,
27
+ drawn: values.length > 0,
28
+ numbers: reach.fits,
29
+ plot: rowPlot(frame, reach, kept.length)
30
+ };
31
+ }
32
+ export { layoutOf };