basalt-ui 2.27.2 → 2.29.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 (343) hide show
  1. package/CHANGELOG.md +466 -307
  2. package/MIGRATING.md +358 -12
  3. package/agent/rules/basalt-batteries.md +1 -1
  4. package/agent/rules/basalt-mantine.md +1 -1
  5. package/agent/rules/basalt-tokens.md +2 -2
  6. package/agent/skills/basalt-app/SKILL.md +3 -3
  7. package/agent/skills/basalt-charts/SKILL.md +1 -1
  8. package/agent/skills/basalt-design/SKILL.md +12 -6
  9. package/agent/skills/basalt-design/references/catalogue.md +42 -36
  10. package/agent/skills/basalt-design/references/recipes.md +47 -0
  11. package/agent/skills/basalt-design/references/states.md +1 -1
  12. package/configs/oxlint-basalt.json +2 -1
  13. package/configs/oxlint-plugin.js +112 -3
  14. package/configs/oxlint-plugin.test.ts +99 -4
  15. package/configs/oxlint.json +1 -0
  16. package/dist/agent/chat/thread-message.d.ts +1 -160
  17. package/dist/agent/chat/thread-message.d.ts.map +1 -1
  18. package/dist/agent/chat/thread-message.js +7 -162
  19. package/dist/agent/chat/virtualize.d.ts +5 -5
  20. package/dist/charts/ChartCard.d.ts +14 -7
  21. package/dist/charts/ChartCard.d.ts.map +1 -1
  22. package/dist/charts/ChartCard.js +112 -23
  23. package/dist/charts/Lines.d.ts.map +1 -1
  24. package/dist/charts/Lines.js +11 -4
  25. package/dist/charts/Sparkline.d.ts +14 -2
  26. package/dist/charts/Sparkline.d.ts.map +1 -1
  27. package/dist/charts/Sparkline.js +155 -44
  28. package/dist/charts/chart-box.module.css +59 -2
  29. package/dist/charts/chart-box.module.css.d.ts +5 -0
  30. package/dist/charts/chart-card.module.css +28 -17
  31. package/dist/charts/chart-card.module.css.d.ts +3 -0
  32. package/dist/charts/compile.d.ts +1 -1
  33. package/dist/charts/compile.d.ts.map +1 -1
  34. package/dist/charts/compile.js +38 -27
  35. package/dist/charts/labels.d.ts +13 -3
  36. package/dist/charts/labels.d.ts.map +1 -1
  37. package/dist/charts/labels.js +131 -20
  38. package/dist/charts/legend.d.ts.map +1 -1
  39. package/dist/charts/legend.js +1 -1
  40. package/dist/charts/ref-label.d.ts +37 -8
  41. package/dist/charts/ref-label.d.ts.map +1 -1
  42. package/dist/charts/ref-label.js +55 -10
  43. package/dist/charts/sparkline.module.css +50 -0
  44. package/dist/charts/sparkline.module.css.d.ts +3 -0
  45. package/dist/charts/state.d.ts +4 -4
  46. package/dist/charts/state.d.ts.map +1 -1
  47. package/dist/charts/state.js +23 -5
  48. package/dist/cli/doctor-upgrade.d.ts +11 -0
  49. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  50. package/dist/cli/doctor-upgrade.js +54 -0
  51. package/dist/cli/doctor.d.ts.map +1 -1
  52. package/dist/cli/doctor.js +32 -0
  53. package/dist/cli/help.d.ts.map +1 -1
  54. package/dist/cli/help.js +8 -3
  55. package/dist/cli/index.d.ts +13 -13
  56. package/dist/cli/index.d.ts.map +1 -1
  57. package/dist/cli/index.js +36 -2
  58. package/dist/cli/init.d.ts +6 -0
  59. package/dist/cli/init.d.ts.map +1 -1
  60. package/dist/cli/init.js +118 -27
  61. package/dist/cli/router-wiring.d.ts +3 -0
  62. package/dist/cli/router-wiring.d.ts.map +1 -1
  63. package/dist/cli/router-wiring.js +2 -0
  64. package/dist/cli/shot/capture.d.ts +34 -2
  65. package/dist/cli/shot/capture.d.ts.map +1 -1
  66. package/dist/cli/shot/capture.js +95 -12
  67. package/dist/cli/shot/detect.d.ts +4 -1
  68. package/dist/cli/shot/detect.d.ts.map +1 -1
  69. package/dist/cli/shot/detect.js +38 -16
  70. package/dist/cli/shot/index.d.ts.map +1 -1
  71. package/dist/cli/shot/index.js +9 -2
  72. package/dist/cli/shot/measure.d.ts.map +1 -1
  73. package/dist/cli/shot/measure.js +11 -2
  74. package/dist/cli/shot/types.d.ts +4 -1
  75. package/dist/cli/shot/types.d.ts.map +1 -1
  76. package/dist/cli/sync.d.ts.map +1 -1
  77. package/dist/cli/sync.js +10 -2
  78. package/dist/common/could-not-load.d.ts +13 -0
  79. package/dist/common/could-not-load.d.ts.map +1 -0
  80. package/dist/common/could-not-load.js +14 -0
  81. package/dist/common/empty-copy.d.ts +16 -0
  82. package/dist/common/empty-copy.d.ts.map +1 -0
  83. package/dist/common/empty-copy.js +9 -0
  84. package/dist/common/index.d.ts +1 -0
  85. package/dist/common/index.d.ts.map +1 -1
  86. package/dist/common/index.js +3 -0
  87. package/dist/common/props.d.ts +20 -0
  88. package/dist/common/props.d.ts.map +1 -1
  89. package/dist/common/props.js +13 -1
  90. package/dist/common/retry-button.module.css +7 -3
  91. package/dist/common/virtual-rows.d.ts +196 -0
  92. package/dist/common/virtual-rows.d.ts.map +1 -0
  93. package/dist/common/virtual-rows.js +290 -0
  94. package/dist/controls/controls.module.css +33 -1
  95. package/dist/controls/controls.module.css.d.ts +2 -0
  96. package/dist/controls/enum-filter.d.ts.map +1 -1
  97. package/dist/controls/enum-filter.js +8 -2
  98. package/dist/controls/filter-pill.d.ts +27 -3
  99. package/dist/controls/filter-pill.d.ts.map +1 -1
  100. package/dist/controls/filter-pill.js +15 -4
  101. package/dist/controls/form-layout.d.ts +9 -3
  102. package/dist/controls/form-layout.d.ts.map +1 -1
  103. package/dist/controls/form-layout.js +74 -12
  104. package/dist/controls/form-layout.module.css +112 -7
  105. package/dist/controls/form-layout.module.css.d.ts +1 -0
  106. package/dist/controls/multi-select-filter.d.ts +2 -2
  107. package/dist/controls/multi-select-filter.d.ts.map +1 -1
  108. package/dist/controls/multi-select-filter.js +12 -6
  109. package/dist/controls/range-filter.d.ts +1 -1
  110. package/dist/controls/range-filter.d.ts.map +1 -1
  111. package/dist/controls/range-filter.js +8 -2
  112. package/dist/dashboard/bar-list.d.ts +5 -5
  113. package/dist/dashboard/bar-list.d.ts.map +1 -1
  114. package/dist/dashboard/bar-list.js +15 -8
  115. package/dist/dashboard/bar-list.module.css +21 -5
  116. package/dist/dashboard/board-nav.d.ts +22 -0
  117. package/dist/dashboard/board-nav.d.ts.map +1 -0
  118. package/dist/dashboard/board-nav.js +49 -0
  119. package/dist/dashboard/board.d.ts +52 -0
  120. package/dist/dashboard/board.d.ts.map +1 -0
  121. package/dist/dashboard/board.js +247 -0
  122. package/dist/dashboard/board.module.css +179 -0
  123. package/dist/dashboard/board.module.css.d.ts +28 -0
  124. package/dist/dashboard/empty-state.d.ts +6 -6
  125. package/dist/dashboard/empty-state.d.ts.map +1 -1
  126. package/dist/dashboard/empty-state.js +17 -8
  127. package/dist/dashboard/event-list-model.d.ts +54 -0
  128. package/dist/dashboard/event-list-model.d.ts.map +1 -0
  129. package/dist/dashboard/event-list-model.js +76 -0
  130. package/dist/dashboard/event-list-rows.d.ts +23 -0
  131. package/dist/dashboard/event-list-rows.d.ts.map +1 -0
  132. package/dist/dashboard/event-list-rows.js +89 -0
  133. package/dist/dashboard/event-list-scroll.d.ts +55 -0
  134. package/dist/dashboard/event-list-scroll.d.ts.map +1 -0
  135. package/dist/dashboard/event-list-scroll.js +216 -0
  136. package/dist/dashboard/event-list-skeleton.d.ts +10 -0
  137. package/dist/dashboard/event-list-skeleton.d.ts.map +1 -0
  138. package/dist/dashboard/event-list-skeleton.js +34 -0
  139. package/dist/dashboard/event-list.d.ts +65 -0
  140. package/dist/dashboard/event-list.d.ts.map +1 -0
  141. package/dist/dashboard/event-list.js +208 -0
  142. package/dist/dashboard/event-list.module.css +336 -0
  143. package/dist/dashboard/event-list.module.css.d.ts +34 -0
  144. package/dist/dashboard/index.d.ts +2 -0
  145. package/dist/dashboard/index.d.ts.map +1 -1
  146. package/dist/dashboard/index.js +4 -0
  147. package/dist/dashboard/meter-model.d.ts +6 -3
  148. package/dist/dashboard/meter-model.d.ts.map +1 -1
  149. package/dist/dashboard/meter-model.js +9 -4
  150. package/dist/dashboard/meter-parts.d.ts +3 -0
  151. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  152. package/dist/dashboard/meter-parts.js +36 -6
  153. package/dist/dashboard/meter.d.ts +3 -3
  154. package/dist/dashboard/meter.d.ts.map +1 -1
  155. package/dist/dashboard/meter.js +10 -2
  156. package/dist/dashboard/meter.module.css +20 -12
  157. package/dist/dashboard/meter.module.css.d.ts +0 -1
  158. package/dist/dashboard/page-summary.d.ts +3 -3
  159. package/dist/dashboard/page-summary.d.ts.map +1 -1
  160. package/dist/dashboard/page-summary.js +7 -2
  161. package/dist/dashboard/page-summary.module.css +5 -2
  162. package/dist/dashboard/query-state.d.ts +9 -8
  163. package/dist/dashboard/query-state.d.ts.map +1 -1
  164. package/dist/dashboard/query-state.js +29 -11
  165. package/dist/dashboard/section.d.ts +11 -3
  166. package/dist/dashboard/section.d.ts.map +1 -1
  167. package/dist/dashboard/section.js +34 -7
  168. package/dist/dashboard/settings-section.d.ts +8 -5
  169. package/dist/dashboard/settings-section.d.ts.map +1 -1
  170. package/dist/dashboard/settings-section.js +12 -8
  171. package/dist/dashboard/settings-section.module.css +25 -4
  172. package/dist/dashboard/settings-section.module.css.d.ts +1 -0
  173. package/dist/dashboard/stat-card-parts.d.ts +5 -1
  174. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  175. package/dist/dashboard/stat-card-parts.js +8 -3
  176. package/dist/dashboard/stat-card.d.ts +3 -3
  177. package/dist/dashboard/stat-card.d.ts.map +1 -1
  178. package/dist/dashboard/stat-card.js +47 -12
  179. package/dist/dashboard/stat-card.module.css +42 -7
  180. package/dist/dashboard/stat-card.module.css.d.ts +3 -0
  181. package/dist/dashboard/stat-group.d.ts +2 -2
  182. package/dist/dashboard/stat-group.d.ts.map +1 -1
  183. package/dist/dashboard/stat-group.js +10 -3
  184. package/dist/dashboard/stat-strip.d.ts +5 -4
  185. package/dist/dashboard/stat-strip.d.ts.map +1 -1
  186. package/dist/dashboard/stat-strip.js +41 -31
  187. package/dist/dashboard/stat-strip.module.css +8 -6
  188. package/dist/dashboard/visual-slot.d.ts +4 -0
  189. package/dist/dashboard/visual-slot.d.ts.map +1 -1
  190. package/dist/dashboard/visual-slot.js +2 -0
  191. package/dist/dashboard/widget-header.d.ts +6 -6
  192. package/dist/dashboard/widget-header.d.ts.map +1 -1
  193. package/dist/dashboard/widget-header.js +4 -2
  194. package/dist/dashboard/widget-header.module.css +12 -15
  195. package/dist/format/shared.d.ts.map +1 -1
  196. package/dist/format/shared.js +24 -1
  197. package/dist/guard/index.d.ts +1 -1
  198. package/dist/guard/index.d.ts.map +1 -1
  199. package/dist/guard/index.js +4 -1
  200. package/dist/index.d.ts +1 -1
  201. package/dist/index.d.ts.map +1 -1
  202. package/dist/index.js +4 -0
  203. package/dist/shell/app-main.module.css +18 -0
  204. package/dist/styles.css +69 -0
  205. package/dist/surfaces.d.ts +2 -2
  206. package/dist/surfaces.d.ts.map +1 -1
  207. package/dist/surfaces.js +8 -2
  208. package/dist/table/cell-kinds.d.ts +47 -0
  209. package/dist/table/cell-kinds.d.ts.map +1 -0
  210. package/dist/table/cell-kinds.js +180 -0
  211. package/dist/table/cell-kinds.module.css +55 -0
  212. package/dist/table/cell-kinds.module.css.d.ts +15 -0
  213. package/dist/table/data-table-fold.d.ts +155 -0
  214. package/dist/table/data-table-fold.d.ts.map +1 -0
  215. package/dist/table/data-table-fold.js +320 -0
  216. package/dist/table/data-table-state.d.ts +10 -3
  217. package/dist/table/data-table-state.d.ts.map +1 -1
  218. package/dist/table/data-table-state.js +11 -6
  219. package/dist/table/data-table.d.ts +13 -28
  220. package/dist/table/data-table.d.ts.map +1 -1
  221. package/dist/table/data-table.js +362 -255
  222. package/dist/table/data-table.module.css +282 -3
  223. package/dist/table/data-table.module.css.d.ts +16 -0
  224. package/dist/table/table-features.d.ts +34 -4
  225. package/dist/table/table-features.d.ts.map +1 -1
  226. package/dist/table/table-features.js +10 -0
  227. package/dist/theme/card-inset.module.css +35 -0
  228. package/dist/theme/controls.module.css +55 -2
  229. package/dist/theme/ctl-theme.d.ts.map +1 -1
  230. package/dist/theme/ctl-theme.js +5 -0
  231. package/dist/theme/index.d.ts.map +1 -1
  232. package/dist/theme/index.js +14 -10
  233. package/dist/tokens/core.d.ts +1 -0
  234. package/dist/tokens/core.d.ts.map +1 -1
  235. package/dist/tokens/core.js +1 -0
  236. package/dist/tokens/derive.js +1 -1
  237. package/dist/tokens/palette.d.ts +2 -1
  238. package/dist/tokens/palette.d.ts.map +1 -1
  239. package/llms.txt +295 -5
  240. package/package.json +1 -1
  241. package/src/agent/chat/thread-message.tsx +10 -403
  242. package/src/agent/chat/virtualize.ts +5 -5
  243. package/src/charts/ChartCard.tsx +175 -31
  244. package/src/charts/Lines.tsx +13 -4
  245. package/src/charts/Sparkline.tsx +213 -48
  246. package/src/charts/chart-box.module.css +59 -2
  247. package/src/charts/chart-box.module.css.d.ts +5 -0
  248. package/src/charts/chart-card.module.css +28 -17
  249. package/src/charts/chart-card.module.css.d.ts +3 -0
  250. package/src/charts/compile.ts +59 -33
  251. package/src/charts/labels.ts +175 -24
  252. package/src/charts/legend.tsx +3 -2
  253. package/src/charts/ref-label.ts +114 -18
  254. package/src/charts/sparkline.module.css +50 -0
  255. package/src/charts/sparkline.module.css.d.ts +3 -0
  256. package/src/charts/state.tsx +40 -10
  257. package/src/cli/doctor-upgrade.ts +75 -0
  258. package/src/cli/doctor.ts +36 -0
  259. package/src/cli/help.ts +16 -6
  260. package/src/cli/index.ts +73 -67
  261. package/src/cli/init.ts +157 -36
  262. package/src/cli/router-wiring.ts +2 -2
  263. package/src/cli/shot/capture.ts +138 -16
  264. package/src/cli/shot/detect.ts +46 -22
  265. package/src/cli/shot/index.ts +8 -2
  266. package/src/cli/shot/measure.ts +11 -2
  267. package/src/cli/shot/types.ts +4 -1
  268. package/src/cli/sync.ts +12 -2
  269. package/src/common/could-not-load.ts +22 -0
  270. package/src/common/empty-copy.ts +17 -0
  271. package/src/common/index.ts +1 -0
  272. package/src/common/props.ts +30 -0
  273. package/src/common/retry-button.module.css +7 -3
  274. package/src/common/virtual-rows.tsx +682 -0
  275. package/src/controls/controls.module.css +33 -1
  276. package/src/controls/controls.module.css.d.ts +2 -0
  277. package/src/controls/enum-filter.tsx +8 -2
  278. package/src/controls/filter-pill.tsx +80 -27
  279. package/src/controls/form-layout.module.css +112 -7
  280. package/src/controls/form-layout.module.css.d.ts +1 -0
  281. package/src/controls/form-layout.tsx +115 -22
  282. package/src/controls/multi-select-filter.tsx +22 -11
  283. package/src/controls/range-filter.tsx +9 -3
  284. package/src/dashboard/bar-list.module.css +21 -5
  285. package/src/dashboard/bar-list.tsx +53 -45
  286. package/src/dashboard/board-nav.ts +67 -0
  287. package/src/dashboard/board.module.css +179 -0
  288. package/src/dashboard/board.module.css.d.ts +28 -0
  289. package/src/dashboard/board.tsx +415 -0
  290. package/src/dashboard/empty-state.tsx +21 -11
  291. package/src/dashboard/event-list-model.ts +125 -0
  292. package/src/dashboard/event-list-rows.tsx +117 -0
  293. package/src/dashboard/event-list-scroll.ts +291 -0
  294. package/src/dashboard/event-list-skeleton.tsx +62 -0
  295. package/src/dashboard/event-list.module.css +336 -0
  296. package/src/dashboard/event-list.module.css.d.ts +34 -0
  297. package/src/dashboard/event-list.tsx +336 -0
  298. package/src/dashboard/index.ts +2 -0
  299. package/src/dashboard/meter-model.ts +16 -7
  300. package/src/dashboard/meter-parts.tsx +53 -14
  301. package/src/dashboard/meter.module.css +20 -12
  302. package/src/dashboard/meter.module.css.d.ts +0 -1
  303. package/src/dashboard/meter.tsx +36 -18
  304. package/src/dashboard/page-summary.module.css +5 -2
  305. package/src/dashboard/page-summary.tsx +13 -6
  306. package/src/dashboard/query-state.tsx +55 -30
  307. package/src/dashboard/section.tsx +83 -41
  308. package/src/dashboard/settings-section.module.css +25 -4
  309. package/src/dashboard/settings-section.module.css.d.ts +1 -0
  310. package/src/dashboard/settings-section.tsx +18 -8
  311. package/src/dashboard/stat-card-parts.tsx +20 -3
  312. package/src/dashboard/stat-card.module.css +42 -7
  313. package/src/dashboard/stat-card.module.css.d.ts +3 -0
  314. package/src/dashboard/stat-card.tsx +55 -13
  315. package/src/dashboard/stat-group.tsx +22 -14
  316. package/src/dashboard/stat-strip.module.css +8 -6
  317. package/src/dashboard/stat-strip.tsx +29 -20
  318. package/src/dashboard/visual-slot.ts +5 -0
  319. package/src/dashboard/widget-header.module.css +12 -15
  320. package/src/dashboard/widget-header.tsx +8 -5
  321. package/src/format/shared.ts +30 -1
  322. package/src/guard/index.ts +7 -1
  323. package/src/index.ts +4 -0
  324. package/src/shell/app-main.module.css +18 -0
  325. package/src/styles.css +69 -0
  326. package/src/surfaces.ts +7 -1
  327. package/src/table/cell-kinds.module.css +55 -0
  328. package/src/table/cell-kinds.module.css.d.ts +15 -0
  329. package/src/table/cell-kinds.tsx +263 -0
  330. package/src/table/data-table-fold.tsx +567 -0
  331. package/src/table/data-table-state.ts +24 -13
  332. package/src/table/data-table.module.css +282 -3
  333. package/src/table/data-table.module.css.d.ts +16 -0
  334. package/src/table/data-table.tsx +430 -362
  335. package/src/table/table-features.ts +44 -4
  336. package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -66
  337. package/src/theme/card-inset.module.css +35 -0
  338. package/src/theme/controls.module.css +55 -2
  339. package/src/theme/ctl-theme.tsx +8 -0
  340. package/src/theme/index.ts +12 -8
  341. package/src/tokens/core.ts +1 -0
  342. package/src/tokens/derive.ts +1 -1
  343. package/src/tokens/palette.ts +4 -1
@@ -38,8 +38,9 @@ import { cursorBinding, followerOptions, quietWhileFollowing } from './cursor'
38
38
  import { cursorDots } from './marks'
39
39
  import { bucketTicks, strideEvery } from './ticks'
40
40
  import { MAIN_PANE, plotAccess, plotContext } from './plot-context'
41
- import { refLabelPosition } from './ref-label'
42
- import type { RefLabelPoint } from './ref-label'
41
+ import { claimedLabelBoxes } from './labels'
42
+ import { refLabelDy, refLabelPosition } from './ref-label'
43
+ import type { LabelBox, RefLabelPoint } from './ref-label'
43
44
  import type { PlotSizes } from './plot-context'
44
45
  import { resolveContainerClass } from '../tokens/size-classes'
45
46
  import { resolveYDomain, xScaleFor, xZoneFractions, yScaleFor } from './scales'
@@ -326,10 +327,15 @@ function wholeStepFormat<T>(
326
327
  /** A fixed domain's end this near the last round tick (as a share of the tick step) stays unlabelled. */
327
328
  const END_TICK_MIN_GAP = 0.4
328
329
 
330
+ /** A label without its digits (any script), separators and spaces: the unit or symbol text it carries. */
331
+ const labelShape = (label: string): string => label.replace(/[\p{Nd}.,\s]/gu, '')
332
+
329
333
  /**
330
- * The compact ladder's three ticks can stop short of a fixed domain's end (`[0, 25]` ticks `0 10 20`),
331
- * and a unit the formatter states on the top tick (`25 days`) goes with it. A fixed domain whose end
332
- * leaves at least {@link END_TICK_MIN_GAP} of a step above the last tick gets the end as a tick too.
334
+ * The compact ladder's few ticks can stop short of a fixed domain's end (`[0, 25]` ticks `0 10 20`).
335
+ * The end joins them only when it carries something the round ticks do not: a formatter that states
336
+ * the unit on the end alone (`25 days`) would lose it otherwise. A uniform formatter (`77 kg` beside
337
+ * `76 kg`) gains nothing from a tick off the step, so the end stays unlabelled and every label sits
338
+ * on an even step.
333
339
  */
334
340
  function withEndTick<T>(
335
341
  cfg: AxisConfig<T> | undefined,
@@ -339,11 +345,12 @@ function withEndTick<T>(
339
345
  if (!Array.isArray(cfg?.domain) || cfg.scale === 'log' || cfg.nice === true) return null
340
346
  const [lo, hi] = [Math.min(...axis.domain), Math.max(...axis.domain)]
341
347
  const round = scaleLinear().domain([lo, hi]).ticks(count)
342
- const last = round.at(-1)
343
- const next = round.at(1)
344
- const first = round.at(0)
345
- if (last === undefined || next === undefined || first === undefined || last >= hi) return null
346
- return hi - last >= (next - first) * END_TICK_MIN_GAP ? { values: [...round, hi] } : null
348
+ const [first, next, last] = [round.at(0), round.at(1), round.at(-1)]
349
+ if (first === undefined || next === undefined || last === undefined || last >= hi) return null
350
+ if (hi - last < (next - first) * END_TICK_MIN_GAP) return null
351
+ return labelShape(axis.format(hi)) === labelShape(axis.format(last))
352
+ ? null
353
+ : { values: [...round, hi] }
347
354
  }
348
355
 
349
356
  export function yGuide<T>(opts: {
@@ -787,8 +794,6 @@ function underlayMarks<T, X extends ChartX>(
787
794
  /** A band's bar spans this share of its half step (`paddingInner` 0.2 leaves 0.8 of the step). */
788
795
  const BAR_BODY = 0.8
789
796
  const REF_LABEL_DX = 6
790
- const REF_LABEL_DY_ABOVE = -5
791
- const REF_LABEL_DY_BELOW = 11
792
797
 
793
798
  /** What a reference line's caption needs to choose its spot: the plot in px and the data on its axis. */
794
799
  type RefLabelContext<T, X extends ChartX> = {
@@ -796,6 +801,8 @@ type RefLabelContext<T, X extends ChartX> = {
796
801
  plotHeight: number
797
802
  /** One polyline per visible series on the line's axis. */
798
803
  lines: (side: 'left' | 'right' | undefined) => readonly (readonly RefLabelPoint[])[]
804
+ /** The end labels placed on the left axis: a caption there keeps clear of them. */
805
+ claimed: readonly LabelBox[]
799
806
  axes: Axes<T>
800
807
  model: XScaleModel<X>
801
808
  }
@@ -818,6 +825,7 @@ const refLabelMark = <T, X extends ChartX>(
818
825
  label: r.label ?? '',
819
826
  fontSize: VX.text.micro,
820
827
  series: ctx.lines(r.axis),
828
+ claimed: startFirst ? [] : ctx.claimed,
821
829
  })
822
830
  const atStart = position.startsWith('start')
823
831
  return decorative(
@@ -832,7 +840,7 @@ const refLabelMark = <T, X extends ChartX>(
832
840
  fontSize: VX.text.micro,
833
841
  anchor: atStart ? 'start' : 'end',
834
842
  dx: atStart ? REF_LABEL_DX : -REF_LABEL_DX,
835
- dy: position.endsWith('above') ? REF_LABEL_DY_ABOVE : REF_LABEL_DY_BELOW,
843
+ dy: refLabelDy(position, VX.text.micro),
836
844
  }),
837
845
  )
838
846
  }
@@ -1027,6 +1035,8 @@ const stripAnchor = (
1027
1035
  }
1028
1036
  const STRIP_TOOLTIP_PLACEMENT = ['bottom', 'top'] as const
1029
1037
  const STRIP_TOOLTIP_OFFSET = 8
1038
+ /** Air between a strip tooltip opened below and the scene's bottom edge (under the tick labels), px. */
1039
+ const STRIP_TICK_AIR = 2
1030
1040
  /**
1031
1041
  * A slotted `Bars` (`tooltipBelow` and `bare`): a micro-visual whose tooltip is the one-line chip
1032
1042
  * (`chart-box.module.css`, `data-basalt-slot`) in the line the cell reserves above the plot. It
@@ -1041,7 +1051,7 @@ const slotAnchor = (
1041
1051
  return { x: (Math.min(...xs) + Math.max(...xs)) / 2, y: plot.y }
1042
1052
  }
1043
1053
  const SLOT_TOOLTIP_PLACEMENT = ['top'] as const
1044
- /** The plot's focus ring (`svg.ts-chart:focus-visible`, `chart-box.module.css`) is a 2px outline at a 0.125rem offset, and the chip keeps 1px of air above it. Mirrors that CSS ring at `--mantine-scale` 1; the chip's `block-size` in the same file is the reserve less this. */
1054
+ /** The plot's focus ring (`svg.ts-chart:focus-visible`, `chart-box.module.css`) is a 2px outline at a 0.125rem offset, and the chip keeps 1px of air above it. Mirrors that CSS ring at `--mantine-scale` 1; the chip's `block-size` in the same file is the reserve less this. A chart's ring is inset (W49) but a Sparkline's stays outer, and the chip is sized to the Sparkline's reserve. */
1045
1055
  const SLOT_RING_CLEARANCE = 2 + 2 + 1
1046
1056
 
1047
1057
  /** A tooltip's chrome (title row, padding) and each series row, px: the guess the bar anchor reserves. */
@@ -1081,6 +1091,8 @@ const barAnchor =
1081
1091
  const TIP_CARD = '[data-basalt-chart-card], [data-strip-cell], .mantine-Card-root'
1082
1092
  /** Air between a card-clamped tooltip and the card's edge, px. */
1083
1093
  const TIP_CARD_AIR = 4
1094
+ /** Air between the plot's left edge and a tooltip, so the first point's cursor dot stays visible, px. */
1095
+ const TIP_DOT_AIR = 10
1084
1096
  /** A card narrower than this keeps the engine's width and horizontal placement (a ~120px strip
1085
1097
  * cell would squeeze a tooltip to its 6rem label floor); the vertical rule applies to every card. */
1086
1098
  const TIP_CARD_ROOMY = 192
@@ -1092,7 +1104,7 @@ const TIP_CARD_ROOMY = 192
1092
1104
  * `top`, so each write is followed by a settle inside the card (`settleInCard`).
1093
1105
  */
1094
1106
  /** What a card clamp does: `card` a chart tooltip (both axes, the card's width), `slot` a slotted
1095
- * `Bars` chip (flush above its plot), `strip` a `BandStrip`'s (sideways only, as before Wave 39). */
1107
+ * `Bars` chip (flush above its plot), `strip` a `BandStrip`'s (sideways, and below the x tick labels when it opens under the strip). */
1096
1108
  type TipMode = 'card' | 'slot' | 'strip'
1097
1109
 
1098
1110
  const cardPortal = (mode: TipMode): ChartTooltipPortalExtension => ({
@@ -1150,10 +1162,13 @@ export function settleInCard(
1150
1162
  y: surface.top + (p.y / sceneH) * surface.height,
1151
1163
  })
1152
1164
  if (mode === 'strip') {
1153
- // A `BandStrip`: sideways only, as before; the engine's width and vertical placement stand.
1165
+ // A `BandStrip`: sideways, and clear of the tick labels below; the engine's width stands.
1154
1166
  if (w0 + 2 * TIP_CARD_AIR <= card.width)
1155
1167
  left = Math.min(Math.max(left, card.left + TIP_CARD_AIR), card.right - w0 - TIP_CARD_AIR)
1156
1168
  if (Math.abs(left - Number.parseFloat(tip.style.left)) > 0.5) tip.style.left = `${left}px`
1169
+ // Opening below the strip, it starts under the scene (the x tick labels sit in its bottom margin).
1170
+ const clear = surface.bottom + STRIP_TICK_AIR
1171
+ if (tip.dataset['placement'] === 'bottom' && top < clear) tip.style.top = `${clear}px`
1157
1172
  return
1158
1173
  }
1159
1174
  const roomy = card.width >= TIP_CARD_ROOMY
@@ -1177,6 +1192,14 @@ export function settleInCard(
1177
1192
  const [w, h] = [tip.offsetWidth, tip.offsetHeight]
1178
1193
  const anchor = toClient(ctx.anchor)
1179
1194
  const gap = Math.max(0, Number.isFinite(ctx.offset) ? (ctx.offset ?? 10) : 10)
1195
+ // The plot's rect: the axis tick labels sit in the margins around it, so a card tooltip stays inside
1196
+ // it when it fits (a first-point tooltip would otherwise cover the y ticks and an x tick).
1197
+ const margin = ctx.scene.margin ?? { top: 0, right: 0, bottom: 0, left: 0 }
1198
+ const plotTL = toClient({ x: margin.left, y: margin.top })
1199
+ const plotBR = toClient({ x: sceneW - margin.right, y: sceneH - margin.bottom })
1200
+ // Per axis: a tooltip taller than a short plot still keeps its left edge clear of the y tick labels.
1201
+ const fenceX = !slot && plotBR.x - plotTL.x >= w + TIP_DOT_AIR
1202
+ const fenceY = !slot && plotBR.y - plotTL.y >= h
1180
1203
  const maxTop = card.bottom - TIP_CARD_AIR - h
1181
1204
  // The card's header (title and facts) is off-limits while the plot area below it can hold the tooltip.
1182
1205
  const headerBottom = slot
@@ -1203,6 +1226,9 @@ export function settleInCard(
1203
1226
  if (roomy) left = anchor.x - w / 2
1204
1227
  }
1205
1228
  if (!slot) top = maxTop < minTop ? minTop : Math.min(Math.max(top, minTop), maxTop)
1229
+ if (fenceY) top = Math.min(Math.max(top, plotTL.y), plotBR.y - h)
1230
+ // The left bound also clears the focused point's dot, drawn on the plot's edge at the first point.
1231
+ if (fenceX) left = Math.min(Math.max(left, plotTL.x + TIP_DOT_AIR), plotBR.x - w)
1206
1232
  if (grown || w + 2 * TIP_CARD_AIR <= card.width)
1207
1233
  left = Math.min(
1208
1234
  Math.max(left, card.left + TIP_CARD_AIR),
@@ -1337,24 +1363,23 @@ export function compileCartesian<T, X extends ChartX>(
1337
1363
  const cls = resolveContainerClass(width)
1338
1364
  const axes = axesAt(cls)
1339
1365
  const access = plotAccess(definition, input.plot, MAIN_PANE)
1340
- const kindMarks = input.marks(
1341
- plotContext(
1342
- {
1343
- rows,
1344
- visible,
1345
- highlighted: input.highlighted ?? null,
1346
- containerClass: cls,
1347
- width,
1348
- height,
1349
- data: input.data,
1350
- xFraction: model.fraction,
1351
- y2: axes.right ? 'y2' : undefined,
1352
- yDomain: axes.left.domain,
1353
- y2Domain: axes.right?.domain,
1354
- },
1355
- access,
1356
- ),
1366
+ const plot = plotContext(
1367
+ {
1368
+ rows,
1369
+ visible,
1370
+ highlighted: input.highlighted ?? null,
1371
+ containerClass: cls,
1372
+ width,
1373
+ height,
1374
+ data: input.data,
1375
+ xFraction: model.fraction,
1376
+ y2: axes.right ? 'y2' : undefined,
1377
+ yDomain: axes.left.domain,
1378
+ y2Domain: axes.right?.domain,
1379
+ },
1380
+ access,
1357
1381
  )
1382
+ const kindMarks = input.marks(plot)
1358
1383
  const under = underlayMarks(input, model, axes)
1359
1384
  const over = refLineMarks(input, axes, () => {
1360
1385
  // Reading the plot size recompiles once on the measured area; the frame stands in before it.
@@ -1364,6 +1389,7 @@ export function compileCartesian<T, X extends ChartX>(
1364
1389
  plotWidth: size?.width ?? width,
1365
1390
  plotHeight: size?.height ?? height,
1366
1391
  lines: linesOn,
1392
+ claimed: claimedLabelBoxes(plot),
1367
1393
  axes,
1368
1394
  model,
1369
1395
  }
@@ -5,12 +5,14 @@
5
5
  import { decorative } from '@tanstack/charts/mark/decorative'
6
6
  import { text } from '@tanstack/charts/text'
7
7
  import { VX } from '../tokens'
8
+ import { yRangeWithin } from './ref-label'
9
+ import type { LabelBox, RefLabelPoint } from './ref-label'
8
10
  import { rowX } from './types'
9
11
  import type { ChartMarks, ChartSeries, ChartX, PlotContext, PlotRow } from './types'
10
12
 
11
13
  const MAX_END_LABELS = 3
12
- /** Two end labels closer than this (px, vertically) are pushed apart to it. */
13
- const END_LABEL_MIN_GAP = 13
14
+ /** Two end labels closer than this (px, vertically) are pushed apart to it: one label line (11px at 1.35) plus two pixels of air. */
15
+ const END_LABEL_MIN_GAP = 17
14
16
  const END_LABEL_DX = 6
15
17
  /**
16
18
  * A glyph's advance as a share of the font size, for the room check. 0.85 covers proportional
@@ -24,6 +26,16 @@ const END_LABEL_FLIP_DY = -9
24
26
  const END_LABEL_FLIP_DY_BELOW = 13
25
27
  /** The room a label's centre keeps from the plot's top and bottom edge, px: half its line. */
26
28
  const END_LABEL_EDGE = 7
29
+ /** A glyph's advance as a share of the font size, for a label's drawn box (the room check's {@link END_LABEL_GLYPH_EM} errs wide). */
30
+ const BOX_GLYPH_EM = 0.68
31
+ /** A label's ink is this share of its font size tall, centred on its text's y. */
32
+ const BOX_INK = 0.75
33
+ /** Air a label keeps from any line, px, and the margin a claimed box carries for a caption. */
34
+ const LINE_AIR = 4.5
35
+ /** What a label across a reference rule from its own line costs in {@link place}'s air score, px. */
36
+ const CROSSED_PENALTY = 100
37
+ /** The most flipped labels whose two sides are all tried (2 ** n assignments). */
38
+ const MAX_SIDE_SEARCH = 5
27
39
 
28
40
  export type EndLabelAnchor = 'start' | 'end'
29
41
  /** Which side of its line a flipped label sits: away from the line's last segment. */
@@ -56,8 +68,20 @@ export type EndLabel<T, X extends ChartX> = {
56
68
  anchor: EndLabelAnchor
57
69
  /** Only a flipped label (left of its point) can meet its own line; it takes the clear side. */
58
70
  side: EndLabelSide
59
- /** A vertical shift in px (negative is up) that keeps this label clear of its neighbours. */
71
+ /** A vertical shift in px (negative is up) that keeps this label clear of its neighbours and the lines. */
60
72
  nudge: number
73
+ /** The room the drawn label takes, for a reference caption to keep clear of. */
74
+ box: LabelBox
75
+ }
76
+
77
+ const claimedBoxes = new WeakMap<object, readonly LabelBox[]>()
78
+ /** Records the boxes the end labels of `plot` take (once per plot, by `Lines`). */
79
+ export function claimLabelBoxes(plot: object, boxes: readonly LabelBox[]): void {
80
+ claimedBoxes.set(plot, boxes)
81
+ }
82
+ /** The boxes {@link claimLabelBoxes} recorded for `plot`: what a reference caption avoids. */
83
+ export function claimedLabelBoxes(plot: object): readonly LabelBox[] {
84
+ return claimedBoxes.get(plot) ?? []
61
85
  }
62
86
 
63
87
  type LastPoint<T, X extends ChartX> = {
@@ -72,16 +96,21 @@ type LastPoint<T, X extends ChartX> = {
72
96
  /**
73
97
  * Pushes labels apart: `ys` are the labels' heights in px from the plot's bottom, returned as the
74
98
  * shift each needs (positive is up) so no two sit closer than {@link END_LABEL_MIN_GAP} and the
75
- * lowest and the topmost stay {@link END_LABEL_EDGE} inside the plot. Order is kept.
99
+ * lowest and the topmost stay {@link END_LABEL_EDGE} inside the plot; a stack too tall for the plot
100
+ * shrinks its gap to fit. Order is kept.
76
101
  */
77
102
  export function spreadLabels(ys: readonly number[], plotHeight: number): number[] {
78
103
  const order = ys.map((y, i) => i).toSorted((a, b) => (ys[a] as number) - (ys[b] as number))
79
104
  const placed = new Map<number, number>()
105
+ // A stack taller than the plot closes its gaps evenly rather than leave the plot.
106
+ const room = Math.max(plotHeight - 2 * END_LABEL_EDGE, 0)
107
+ const gap =
108
+ ys.length > 1 ? Math.min(END_LABEL_MIN_GAP, room / (ys.length - 1)) : END_LABEL_MIN_GAP
80
109
  let floor = END_LABEL_EDGE
81
110
  for (const i of order) {
82
111
  const at = Math.max(ys[i] as number, floor)
83
112
  placed.set(i, at)
84
- floor = at + END_LABEL_MIN_GAP
113
+ floor = at + gap
85
114
  }
86
115
  // Pushed past the top: slide the whole stack back down, then re-sweep from the top.
87
116
  const top = plotHeight - END_LABEL_EDGE
@@ -89,7 +118,7 @@ export function spreadLabels(ys: readonly number[], plotHeight: number): number[
89
118
  for (const i of order.toReversed()) {
90
119
  const at = Math.min(placed.get(i) as number, ceiling, top)
91
120
  placed.set(i, at)
92
- ceiling = at - END_LABEL_MIN_GAP
121
+ ceiling = at - gap
93
122
  }
94
123
  return ys.map((y, i) => (placed.get(i) as number) - y)
95
124
  }
@@ -105,6 +134,8 @@ export function endLabelPlan<T, X extends ChartX>(
105
134
  plot: PlotContext<T, X>,
106
135
  lines: readonly ChartSeries<T>[],
107
136
  naming: LinesNaming = 'auto',
137
+ /** The values of the reference lines on the left axis: rules a label must not sit on. */
138
+ rules: readonly number[] = [],
108
139
  ): EndLabel<T, X>[] {
109
140
  if (naming === 'legend' || plot.y2 !== undefined || lines.length === 0) return []
110
141
  if (naming === 'auto' && (plot.containerClass !== 'wide' || lines.length > MAX_END_LABELS))
@@ -119,30 +150,150 @@ export function endLabelPlan<T, X extends ChartX>(
119
150
  })
120
151
  // No `y2` here (returned above), so every label reads the left domain.
121
152
  const [lo, hi] = plot.yDomain
122
- const placed = last.map(({ series, fraction, y, prev }) => {
123
- const anchor = endLabelAnchor({
153
+ const anchors = last.map(({ series, fraction }) =>
154
+ endLabelAnchor({
124
155
  fraction,
125
156
  plotWidth: plot.plotWidth,
126
157
  label: series.label,
127
158
  fontSize: VX.text.micro,
128
- })
129
- // A line falling into its end point comes from above: the label drops below it.
130
- const side = prev !== null && prev > y ? ('below' as const) : ('above' as const)
131
- // The label's centre, px from the plot's bottom, with its flip: what the spread keeps apart.
132
- const centre = ((y - lo) / (hi - lo || 1)) * plot.plotHeight - endLabelOffset(anchor, side).dy
133
- return { anchor, side, centre }
159
+ }),
160
+ )
161
+ // Flipped labels (left of their point) sit over their own line. A line falling into its end
162
+ // comes from above, so its label drops below; a rising line's rises above. Several flipped lines
163
+ // that move the same way would all take the same side and stack in the gap between them, so they
164
+ // wrap the lines instead: falling, the lowest below and the rest above; rising, the mirror.
165
+ const falls = last.map(({ y, prev }) => prev !== null && prev > y)
166
+ const flipped = last.flatMap((_, i) => (anchors[i] === 'end' ? [i] : []))
167
+ const lineY = (i: number): number => (last[i] as (typeof last)[number]).y
168
+ const sameWay =
169
+ flipped.length > 1 && flipped.every((i) => falls[i] === falls[flipped[0] as number])
170
+ const wrapped = sameWay ? flipped.toSorted((a, b) => lineY(a) - lineY(b)) : []
171
+ // The one that keeps the far side: the lowest when falling, the highest when rising.
172
+ const outlier = falls[flipped[0] as number] ? wrapped[0] : wrapped.at(-1)
173
+ const preferred = last.map((_, i): EndLabelSide => {
174
+ const fall = falls[i] as boolean
175
+ return sameWay && anchors[i] === 'end'
176
+ ? (i === outlier) === fall
177
+ ? 'below'
178
+ : 'above'
179
+ : fall
180
+ ? 'below'
181
+ : 'above'
182
+ })
183
+ const toPx = (y: number): number => ((y - lo) / (hi - lo || 1)) * plot.plotHeight
184
+ const nominal = (i: number, side: EndLabelSide): number =>
185
+ toPx(lineY(i)) - endLabelOffset(anchors[i] as EndLabelAnchor, side).dy
186
+ const half = (VX.text.micro * BOX_INK) / 2
187
+ const plotW = Math.max(plot.plotWidth, 1)
188
+ const spans = last.map(({ series, fraction }, i) => {
189
+ const room = (END_LABEL_DX + series.label.length * VX.text.micro * BOX_GLYPH_EM) / plotW
190
+ const edge = END_LABEL_DX / plotW
191
+ return anchors[i] === 'end'
192
+ ? ([fraction - room, fraction - edge] as const)
193
+ : ([fraction + edge, fraction + room] as const)
134
194
  })
135
- const shifts = spreadLabels(
136
- placed.map((p) => p.centre),
137
- plot.plotHeight,
195
+ // Every line a label could sit on, as polylines in px from the plot's bottom: each visible
196
+ // series and each reference rule. Only the stretch under the labels matters.
197
+ const from = Math.min(...spans.map(([x0]) => x0))
198
+ const obstacles: RefLabelPoint[][] = [
199
+ ...plot.visible.map((s) => {
200
+ const pts: RefLabelPoint[] = []
201
+ let before: RefLabelPoint | undefined
202
+ for (const r of plot.rows(s.key)) {
203
+ const fx = r.y === null ? null : plot.xFraction(r.x)
204
+ if (fx === null || r.y === null) continue
205
+ const pt = { fx, y: toPx(r.y) }
206
+ if (fx < from) before = pt
207
+ else {
208
+ if (before !== undefined) pts.push(before)
209
+ before = undefined
210
+ pts.push(pt)
211
+ }
212
+ }
213
+ if (before !== undefined) pts.push(before)
214
+ return pts
215
+ }),
216
+ ...rules.map((v) => [
217
+ { fx: 0, y: toPx(v) },
218
+ { fx: 1, y: toPx(v) },
219
+ ]),
220
+ ]
221
+ /** Per label, the line ranges (px) its x-window runs into: fixed, so computed once. */
222
+ const windowRanges = spans.map(([x0, x1]) =>
223
+ obstacles.flatMap((pts) => {
224
+ const range = yRangeWithin(pts, x0, x1)
225
+ return range === null ? [] : [range]
226
+ }),
138
227
  )
139
- return last.map(({ series, row }, i) => ({
140
- series,
141
- row,
142
- anchor: (placed[i] as (typeof placed)[number]).anchor,
143
- side: (placed[i] as (typeof placed)[number]).side,
144
- nudge: 0 - (shifts[i] as number),
145
- }))
228
+ const ranges = (i: number): readonly [number, number][] => windowRanges[i] as [number, number][]
229
+ /** Where the centre goes to clear the lines on `side` of `start`, stepping past each one it meets. */
230
+ const cleared = (i: number, side: EndLabelSide, start: number): number => {
231
+ const blockers = ranges(i)
232
+ let c = start
233
+ for (let n = 0; n <= blockers.length; n++) {
234
+ const hit = blockers.find(([a, b]) => b + LINE_AIR > c - half && a - LINE_AIR < c + half)
235
+ if (hit === undefined) break
236
+ c = side === 'above' ? hit[1] + LINE_AIR + half : hit[0] - LINE_AIR - half
237
+ }
238
+ return c
239
+ }
240
+ const airOf = (i: number, c: number): number =>
241
+ Math.min(
242
+ Number.POSITIVE_INFINITY,
243
+ ...ranges(i).map(([a, b]) => Math.max(a - (c + half), c - half - b)),
244
+ )
245
+ const place = (sides: readonly EndLabelSide[]) => {
246
+ const start = last.map((_, i) =>
247
+ cleared(i, sides[i] as EndLabelSide, nominal(i, sides[i] as EndLabelSide)),
248
+ )
249
+ const shifts = spreadLabels(start, plot.plotHeight)
250
+ const centres = start.map((c, i) => c + (shifts[i] as number))
251
+ // A label across a reference rule from its own line's end reads as the rule's label: worse
252
+ // than any amount of lost air.
253
+ const crossed = centres.filter((c, i) => {
254
+ const end = toPx(lineY(i))
255
+ return rules.some(
256
+ (v) => (toPx(v) - c) * (toPx(v) - end) < 0 && (c - end) * (toPx(v) - end) > 0,
257
+ )
258
+ }).length
259
+ const score =
260
+ centres.reduce((sum, c, i) => sum + Math.min(airOf(i, c), LINE_AIR), 0) -
261
+ CROSSED_PENALTY * crossed
262
+ return { sides, centres, score }
263
+ }
264
+ // Each flipped label may take either side: the assignment that keeps most air from the lines
265
+ // wins, the preferred one on a tie. Level labels (right of
266
+ // their point) keep theirs.
267
+ const options = flipped.length <= MAX_SIDE_SEARCH ? flipped.length : 0
268
+ let best = place(preferred)
269
+ for (let mask = 1; mask < 1 << options; mask++) {
270
+ const sides = preferred.map((side, i): EndLabelSide => {
271
+ const at = flipped.indexOf(i)
272
+ return at >= 0 && (mask >> at) & 1 ? (side === 'above' ? 'below' : 'above') : side
273
+ })
274
+ const trial = place(sides)
275
+ if (trial.score > best.score + 0.01) best = trial
276
+ }
277
+ return last.map(({ series, row }, i) => {
278
+ const side = best.sides[i] as EndLabelSide
279
+ const centre = best.centres[i] as number
280
+ const [x0, x1] = spans[i] as readonly [number, number]
281
+ const perPx = (hi - lo) / (plot.plotHeight || 1)
282
+ // Two pixels of margin each way: the caption keeps its own gap from the claimed box.
283
+ return {
284
+ series,
285
+ row,
286
+ anchor: anchors[i] as EndLabelAnchor,
287
+ side,
288
+ nudge: nominal(i, side) - centre,
289
+ box: {
290
+ fx0: x0 - 2 / plotW,
291
+ fx1: x1 + 2 / plotW,
292
+ y0: lo + (centre - half - 2) * perPx,
293
+ y1: lo + (centre + half + 2) * perPx,
294
+ },
295
+ }
296
+ })
146
297
  }
147
298
 
148
299
  /** The offset of a label from its point: right of it, level; or left of it, above or below. */
@@ -115,7 +115,7 @@ export type SignedSeries<T> = ChartSeries<T> & { colorNegative?: string | undefi
115
115
 
116
116
  type SwatchStyle = Pick<
117
117
  SignedSeries<never>,
118
- 'color' | 'colorNegative' | 'mark' | 'dash' | 'strokeOpacity' | 'fillOpacity'
118
+ 'color' | 'colorNegative' | 'mark' | 'dash' | 'strokeOpacity' | 'fillOpacity' | 'role'
119
119
  >
120
120
 
121
121
  /** A swatch fill: the series colour, or a hard-stop split for a sign-coloured bar. */
@@ -149,7 +149,8 @@ function LineSwatch({ s, compact }: { s: SwatchStyle; compact: boolean }): React
149
149
  y1={4}
150
150
  y2={4}
151
151
  stroke={s.color}
152
- strokeWidth={2}
152
+ // A reference line is drawn as a 1px rule (`refLineMarks`), a series from 2px: the key keeps that difference.
153
+ strokeWidth={s.role === 'reference' ? 1 : 2}
153
154
  strokeLinecap={s.dash === 'dashed' ? 'butt' : 'round'}
154
155
  strokeOpacity={s.strokeOpacity ?? 1}
155
156
  {...(s.dash === 'dashed' && { strokeDasharray: dash })}