@d3plus/core 4.11.0 → 4.12.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 (287) hide show
  1. package/es/internal.js +15 -5
  2. package/es/src/charts/Alluvial/emit.js +2 -2
  3. package/es/src/charts/Alluvial/index.js +7 -1
  4. package/es/src/charts/Alluvial/titles.js +24 -4
  5. package/es/src/charts/ArcDiagram/emit.js +27 -13
  6. package/es/src/charts/ArcDiagram/events.js +6 -2
  7. package/es/src/charts/ArcDiagram/index.js +2 -0
  8. package/es/src/charts/BarChart/index.js +3 -10
  9. package/es/src/charts/Calendar/index.js +2 -0
  10. package/es/src/charts/Candlestick/index.js +4 -10
  11. package/es/src/charts/Gantt/applyLayout.js +2 -4
  12. package/es/src/charts/Geomap/flowEmit.js +11 -6
  13. package/es/src/charts/Hexbin/index.js +2 -0
  14. package/es/src/charts/Icicle/index.js +3 -1
  15. package/es/src/charts/Matrix/applyLayout.js +20 -9
  16. package/es/src/charts/Matrix/index.js +19 -1
  17. package/es/src/charts/Network/applyLayout.js +36 -5
  18. package/es/src/charts/Network/bundle.js +5 -4
  19. package/es/src/charts/Network/emit.js +39 -40
  20. package/es/src/charts/Network/graph.js +34 -5
  21. package/es/src/charts/Network/graphFluent.js +5 -3
  22. package/es/src/charts/Network/index.js +6 -1
  23. package/es/src/charts/Pack/applyLayout.js +16 -5
  24. package/es/src/charts/Pack/emit.js +15 -8
  25. package/es/src/charts/Pack/groupRows.js +61 -0
  26. package/es/src/charts/Pack/index.js +3 -0
  27. package/es/src/charts/Pack/neutralPaint.js +20 -0
  28. package/es/src/charts/Pack/nodeNames.js +35 -0
  29. package/es/src/charts/ParallelCoordinates/axes.js +22 -22
  30. package/es/src/charts/ParallelCoordinates/chrome.js +18 -0
  31. package/es/src/charts/ParallelCoordinates/index.js +3 -1
  32. package/es/src/charts/ParallelCoordinates/titles.js +17 -9
  33. package/es/src/charts/Pie/emit.js +9 -1
  34. package/es/src/charts/Pie/index.js +10 -0
  35. package/es/src/charts/Plot/areaEnter.js +68 -0
  36. package/es/src/charts/Plot/draw.js +26 -12
  37. package/es/src/charts/Plot/index.js +4 -10
  38. package/es/src/charts/Plot/lineMarkerKeys.js +19 -0
  39. package/es/src/charts/Plot/plotInit.js +6 -0
  40. package/es/src/charts/Plot/shapeLabelLegend.js +67 -0
  41. package/es/src/charts/Plot/sharedHover.js +2 -1
  42. package/es/src/charts/Plot/sharedTooltip.js +13 -3
  43. package/es/src/charts/PolarArea/index.js +2 -1
  44. package/es/src/charts/Priestley/applyLayout.js +11 -7
  45. package/es/src/charts/Priestley/index.js +0 -2
  46. package/es/src/charts/Priestley/timeAxis.js +11 -8
  47. package/es/src/charts/Pyramid/gutter.js +52 -16
  48. package/es/src/charts/Pyramid/index.js +55 -7
  49. package/es/src/charts/Pyramid/scene.js +4 -4
  50. package/es/src/charts/Radar/applyLayout.js +31 -33
  51. package/es/src/charts/Radar/axisDecorations.js +29 -17
  52. package/es/src/charts/Radar/curvedLabels.js +43 -2
  53. package/es/src/charts/Radar/emit.js +30 -15
  54. package/es/src/charts/Radar/index.js +41 -2
  55. package/es/src/charts/Radar/points.js +85 -0
  56. package/es/src/charts/RadialBar/emit.js +6 -1
  57. package/es/src/charts/RadialBar/index.js +10 -0
  58. package/es/src/charts/RadialMatrix/applyLayout.js +115 -31
  59. package/es/src/charts/RadialMatrix/index.js +15 -2
  60. package/es/src/charts/Rings/applyLayout.js +11 -150
  61. package/es/src/charts/Rings/emit.js +80 -40
  62. package/es/src/charts/Rings/index.js +27 -4
  63. package/es/src/charts/Rings/ringsCurves.js +156 -0
  64. package/es/src/charts/Rings/ringsParallel.js +20 -3
  65. package/es/src/charts/Rings/ringsPlacement.js +152 -0
  66. package/es/src/charts/Rings/ringsSizing.js +61 -38
  67. package/es/src/charts/Sankey/applyLayout.js +18 -4
  68. package/es/src/charts/Sankey/index.js +7 -1
  69. package/es/src/charts/Sunburst/emit.js +9 -1
  70. package/es/src/charts/Sunburst/index.js +13 -1
  71. package/es/src/charts/Tree/applyLayout.js +44 -14
  72. package/es/src/charts/Tree/emit.js +5 -5
  73. package/es/src/charts/Tree/index.js +10 -12
  74. package/es/src/charts/Tree/keys.js +33 -0
  75. package/es/src/charts/Tree/nodeLabel.js +15 -0
  76. package/es/src/charts/Treemap/emitGroupHeaders.js +3 -5
  77. package/es/src/charts/definition/makeChart.js +6 -2
  78. package/es/src/charts/drawSteps/minimap.js +4 -20
  79. package/es/src/charts/drawSteps/zoomActions.js +36 -0
  80. package/es/src/charts/drawSteps/zoomControls.js +31 -18
  81. package/es/src/charts/drawSteps/zoomControlsMarkup.js +23 -4
  82. package/es/src/charts/drawSteps/zoomDrag.js +188 -0
  83. package/es/src/charts/drawSteps/zoomFit.js +69 -0
  84. package/es/src/charts/events/click.legend.js +4 -2
  85. package/es/src/charts/events/click.shape.js +5 -3
  86. package/es/src/charts/events/mouseenter.js +6 -16
  87. package/es/src/charts/events/mouseleave.js +9 -2
  88. package/es/src/charts/events/mousemove.legend.js +28 -32
  89. package/es/src/charts/events/mousemove.shape.js +44 -44
  90. package/es/src/charts/features/axes.js +15 -4
  91. package/es/src/charts/features/axesFinal.js +7 -2
  92. package/es/src/charts/features/axesMeasure.js +26 -8
  93. package/es/src/charts/features/axisTooltip.js +138 -0
  94. package/es/src/charts/features/centerLabel.js +177 -0
  95. package/es/src/charts/features/colorScaleBivariate.js +83 -0
  96. package/es/src/charts/features/colorScaleBucket.js +18 -0
  97. package/es/src/charts/features/colorScaleHover.js +30 -5
  98. package/es/src/charts/features/colorScaleLimit.js +73 -0
  99. package/es/src/charts/features/colorScaleTooltip.js +77 -0
  100. package/es/src/charts/features/colorScaleTop.js +61 -0
  101. package/es/src/charts/features/curvedArrows.js +33 -0
  102. package/es/src/charts/features/depthKey.js +26 -0
  103. package/es/src/charts/features/edgeArrows.js +61 -2
  104. package/es/src/charts/features/featuresColorScale.js +57 -16
  105. package/es/src/charts/features/hoverTicks.js +41 -0
  106. package/es/src/charts/features/idleQueue.js +72 -0
  107. package/es/src/charts/features/linkInteraction.js +59 -7
  108. package/es/src/charts/features/networkMeasures.js +241 -0
  109. package/es/src/charts/features/nodeStats.js +309 -0
  110. package/es/src/charts/features/plotEndLabels.js +28 -7
  111. package/es/src/charts/features/plotPaint.js +9 -2
  112. package/es/src/charts/features/shapeEmit.js +7 -1
  113. package/es/src/charts/features/textHalo.js +3 -2
  114. package/es/src/charts/partition/chartFields.js +12 -3
  115. package/es/src/charts/partition/interaction.js +10 -5
  116. package/es/src/charts/pipeline/insetPlacement.js +8 -3
  117. package/es/src/charts/polar/chrome.js +81 -9
  118. package/es/src/charts/polar/config.js +4 -0
  119. package/es/src/charts/polar/wedgeLayout.js +2 -1
  120. package/es/src/charts/viz/Viz.js +24 -15
  121. package/es/src/charts/viz/VizBase.js +39 -4
  122. package/es/src/charts/viz/backgroundInk.js +10 -0
  123. package/es/src/charts/viz/emphasis.js +14 -0
  124. package/es/src/charts/viz/fillStroke.js +10 -0
  125. package/es/src/charts/viz/interactionOpacity.js +115 -32
  126. package/es/src/charts/viz/reportDrawError.js +15 -0
  127. package/es/src/charts/viz/setCursor.js +29 -0
  128. package/es/src/charts/viz/tooltipEnabled.js +38 -0
  129. package/es/src/charts/viz/userClick.js +34 -0
  130. package/es/src/charts/viz/vizDataPolling.js +0 -1
  131. package/es/src/charts/viz/vizDefaults.js +13 -34
  132. package/es/src/charts/viz/vizFields.js +6 -1
  133. package/es/src/charts/viz/vizRender.js +35 -5
  134. package/es/src/charts/viz/vizVisibility.js +12 -2
  135. package/es/src/components/Axis/Axis.js +29 -2
  136. package/es/src/components/Axis/axisBreak.js +29 -7
  137. package/es/src/components/Axis/axisDefaults.js +11 -0
  138. package/es/src/components/Axis/axisLabelKinds.js +36 -0
  139. package/es/src/components/Axis/axisLabelLineHeight.js +19 -0
  140. package/es/src/components/Axis/axisLabelRoom.js +37 -0
  141. package/es/src/components/Axis/axisLabelSize.js +171 -0
  142. package/es/src/components/Axis/axisLabelThinning.js +98 -4
  143. package/es/src/components/Axis/axisLayout.js +71 -46
  144. package/es/src/components/Axis/axisLayoutLabels.js +82 -140
  145. package/es/src/components/Axis/axisLayoutScale.js +9 -10
  146. package/es/src/components/Axis/axisLimit.js +27 -0
  147. package/es/src/components/Axis/axisMaxSize.js +39 -0
  148. package/es/src/components/Axis/axisRender.js +20 -8
  149. package/es/src/components/Axis/axisRounding.js +16 -1
  150. package/es/src/components/Axis/axisScene.js +11 -2
  151. package/es/src/components/Axis/axisTitle.js +53 -0
  152. package/es/src/components/Axis/axisTooltipTargets.js +128 -0
  153. package/es/src/components/ColorScale/ColorScale.js +62 -18
  154. package/es/src/components/ColorScale/bivariateRender.js +353 -0
  155. package/es/src/components/ColorScale/bivariateScale.js +150 -0
  156. package/es/src/components/ColorScale/colorScaleRender.js +32 -2
  157. package/es/src/components/ColorScale/colorScaleSwatchTooltips.js +77 -0
  158. package/es/src/components/Legend/Legend.js +10 -2
  159. package/es/src/components/Legend/legendCut.js +108 -0
  160. package/es/src/components/Legend/legendRender.js +38 -13
  161. package/es/src/components/TextBox.js +5 -2
  162. package/es/src/components/Timeline/timelineRender.js +2 -1
  163. package/es/src/components/textBoxScene.js +3 -0
  164. package/es/src/components/textEllipsis.js +7 -0
  165. package/es/src/components/tooltipDom.js +8 -5
  166. package/es/src/fluent.js +48 -0
  167. package/es/src/utils/BaseClass.js +7 -2
  168. package/es/src/utils/configValue.js +9 -0
  169. package/package.json +10 -10
  170. package/types/index.d.ts +1 -1
  171. package/types/internal.d.ts +22 -5
  172. package/types/src/charts/Alluvial/titles.d.ts +16 -3
  173. package/types/src/charts/ArcDiagram/emit.d.ts +3 -2
  174. package/types/src/charts/ArcDiagram/events.d.ts +2 -1
  175. package/types/src/charts/Geomap/flowEmit.d.ts +3 -2
  176. package/types/src/charts/Matrix/applyLayout.d.ts +4 -2
  177. package/types/src/charts/Network/applyLayout.d.ts +11 -0
  178. package/types/src/charts/Network/bundle.d.ts +3 -1
  179. package/types/src/charts/Network/graph.d.ts +12 -4
  180. package/types/src/charts/Pack/applyLayout.d.ts +2 -0
  181. package/types/src/charts/Pack/groupRows.d.ts +46 -0
  182. package/types/src/charts/Pack/index.d.ts +3 -0
  183. package/types/src/charts/Pack/neutralPaint.d.ts +14 -0
  184. package/types/src/charts/Pack/nodeNames.d.ts +23 -0
  185. package/types/src/charts/ParallelCoordinates/chrome.d.ts +12 -0
  186. package/types/src/charts/ParallelCoordinates/index.d.ts +1 -0
  187. package/types/src/charts/ParallelCoordinates/titles.d.ts +7 -2
  188. package/types/src/charts/Plot/areaEnter.d.ts +34 -0
  189. package/types/src/charts/Plot/index.d.ts +4 -10
  190. package/types/src/charts/Plot/lineMarkerKeys.d.ts +11 -0
  191. package/types/src/charts/Plot/shapeLabelLegend.d.ts +19 -0
  192. package/types/src/charts/Plot/sharedTooltip.d.ts +7 -1
  193. package/types/src/charts/Priestley/timeAxis.d.ts +7 -4
  194. package/types/src/charts/Pyramid/gutter.d.ts +28 -6
  195. package/types/src/charts/Pyramid/scene.d.ts +1 -1
  196. package/types/src/charts/Radar/applyLayout.d.ts +2 -3
  197. package/types/src/charts/Radar/axisDecorations.d.ts +5 -2
  198. package/types/src/charts/Radar/curvedLabels.d.ts +35 -0
  199. package/types/src/charts/Radar/emit.d.ts +5 -2
  200. package/types/src/charts/Radar/index.d.ts +7 -2
  201. package/types/src/charts/Radar/points.d.ts +50 -0
  202. package/types/src/charts/RadialMatrix/applyLayout.d.ts +6 -4
  203. package/types/src/charts/Rings/emit.d.ts +24 -2
  204. package/types/src/charts/Rings/index.d.ts +4 -2
  205. package/types/src/charts/Rings/ringsCurves.d.ts +50 -0
  206. package/types/src/charts/Rings/ringsGraph.d.ts +29 -5
  207. package/types/src/charts/Rings/ringsParallel.d.ts +4 -2
  208. package/types/src/charts/Rings/ringsPlacement.d.ts +47 -0
  209. package/types/src/charts/Rings/ringsSizing.d.ts +36 -9
  210. package/types/src/charts/Tree/applyLayout.d.ts +20 -0
  211. package/types/src/charts/Tree/keys.d.ts +25 -0
  212. package/types/src/charts/Tree/nodeLabel.d.ts +11 -0
  213. package/types/src/charts/definition/ChartDefinition.d.ts +13 -0
  214. package/types/src/charts/definition/makeChart.d.ts +2 -2
  215. package/types/src/charts/drawSteps/zoomActions.d.ts +30 -0
  216. package/types/src/charts/drawSteps/zoomControls.d.ts +15 -0
  217. package/types/src/charts/drawSteps/zoomControlsMarkup.d.ts +16 -1
  218. package/types/src/charts/drawSteps/zoomDrag.d.ts +71 -0
  219. package/types/src/charts/drawSteps/zoomFit.d.ts +30 -0
  220. package/types/src/charts/features/axisTooltip.d.ts +49 -0
  221. package/types/src/charts/features/centerLabel.d.ts +75 -0
  222. package/types/src/charts/features/colorScaleBivariate.d.ts +50 -0
  223. package/types/src/charts/features/colorScaleBucket.d.ts +10 -0
  224. package/types/src/charts/features/colorScaleHover.d.ts +13 -3
  225. package/types/src/charts/features/colorScaleLimit.d.ts +60 -0
  226. package/types/src/charts/features/colorScaleTooltip.d.ts +43 -0
  227. package/types/src/charts/features/colorScaleTop.d.ts +30 -0
  228. package/types/src/charts/features/curvedArrows.d.ts +14 -0
  229. package/types/src/charts/features/depthKey.d.ts +19 -0
  230. package/types/src/charts/features/edgeArrows.d.ts +29 -2
  231. package/types/src/charts/features/hoverTicks.d.ts +30 -0
  232. package/types/src/charts/features/idleQueue.d.ts +46 -0
  233. package/types/src/charts/features/linkInteraction.d.ts +13 -4
  234. package/types/src/charts/features/networkMeasures.d.ts +53 -0
  235. package/types/src/charts/features/nodeStats.d.ts +93 -0
  236. package/types/src/charts/features/plotEndLabels.d.ts +14 -1
  237. package/types/src/charts/features/textHalo.d.ts +4 -3
  238. package/types/src/charts/partition/chartFields.d.ts +6 -1
  239. package/types/src/charts/pipeline/insetPlacement.d.ts +6 -0
  240. package/types/src/charts/polar/chrome.d.ts +19 -6
  241. package/types/src/charts/viz/Viz.d.ts +10 -3
  242. package/types/src/charts/viz/VizBase.d.ts +31 -2
  243. package/types/src/charts/viz/backgroundInk.d.ts +8 -0
  244. package/types/src/charts/viz/emphasis.d.ts +17 -0
  245. package/types/src/charts/viz/fillStroke.d.ts +7 -0
  246. package/types/src/charts/viz/reportDrawError.d.ts +12 -0
  247. package/types/src/charts/viz/setCursor.d.ts +26 -0
  248. package/types/src/charts/viz/tooltipEnabled.d.ts +31 -0
  249. package/types/src/charts/viz/userClick.d.ts +35 -0
  250. package/types/src/charts/viz/vizFields.d.ts +5 -0
  251. package/types/src/charts/viz/vizTypes.d.ts +16 -0
  252. package/types/src/charts/viz/vizVisibility.d.ts +7 -0
  253. package/types/src/components/Axis/Axis.d.ts +33 -3
  254. package/types/src/components/Axis/axisBreak.d.ts +19 -3
  255. package/types/src/components/Axis/axisDefaults.d.ts +12 -0
  256. package/types/src/components/Axis/axisLabelKinds.d.ts +22 -0
  257. package/types/src/components/Axis/axisLabelLineHeight.d.ts +27 -0
  258. package/types/src/components/Axis/axisLabelRoom.d.ts +17 -0
  259. package/types/src/components/Axis/axisLabelSize.d.ts +82 -0
  260. package/types/src/components/Axis/axisLabelThinning.d.ts +38 -2
  261. package/types/src/components/Axis/axisLayout.d.ts +9 -2
  262. package/types/src/components/Axis/axisLayoutLabels.d.ts +28 -33
  263. package/types/src/components/Axis/axisLayoutScale.d.ts +3 -1
  264. package/types/src/components/Axis/axisLimit.d.ts +18 -0
  265. package/types/src/components/Axis/axisMaxSize.d.ts +48 -0
  266. package/types/src/components/Axis/axisRounding.d.ts +8 -0
  267. package/types/src/components/Axis/axisTitle.d.ts +30 -0
  268. package/types/src/components/Axis/axisTooltipTargets.d.ts +82 -0
  269. package/types/src/components/ColorScale/ColorScale.d.ts +21 -11
  270. package/types/src/components/ColorScale/bivariateRender.d.ts +53 -0
  271. package/types/src/components/ColorScale/bivariateScale.d.ts +92 -0
  272. package/types/src/components/ColorScale/colorScaleSwatchTooltips.d.ts +48 -0
  273. package/types/src/components/Legend/Legend.d.ts +5 -0
  274. package/types/src/components/Legend/legendCut.d.ts +31 -0
  275. package/types/src/components/Legend/legendRender.d.ts +6 -1
  276. package/types/src/components/TextBox.d.ts +4 -0
  277. package/types/src/components/textEllipsis.d.ts +6 -0
  278. package/types/src/fluent.d.ts +18 -0
  279. package/types/src/shapes/emitLabels.d.ts +1 -1
  280. package/types/src/utils/D3plusConfig.d.ts +485 -609
  281. package/types/src/utils/configValue.d.ts +8 -0
  282. package/types/src/utils/index.d.ts +1 -1
  283. package/types/umd-entry.d.ts +4 -0
  284. package/umd/d3plus-core.full.js +22930 -17936
  285. package/umd/d3plus-core.full.min.js +2 -2
  286. package/umd/d3plus-core.js +21240 -16404
  287. package/umd/d3plus-core.min.js +2 -2
@@ -10,6 +10,9 @@ import { ceilPow, fixFloat, floorPow, isNegative } from "./axisRounding.js";
10
10
  import { powTicks } from "./powTicks.js";
11
11
  import { timeDataInDomain } from "./timeValues.js";
12
12
  import { slantedLabelBox } from "./axisLabelAngle.js";
13
+ import { labelLineHeight } from "./axisLabelLineHeight.js";
14
+ import { configureTitle } from "./axisTitle.js";
15
+ import { axisLabelEllipsis } from "./axisDefaults.js";
13
16
  const maxTimezoneOffset = 1000 * 60 * 60 * 26;
14
17
  /**
15
18
  * Calculates ticks from a given scale (negative and/or positive)
@@ -154,7 +157,9 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
154
157
  const space = data ? data.space : 0;
155
158
  const fP = data ? data.fP : 0;
156
159
  const labelOffset = data && axis.schema.labelOffset ? data.offset ?? 0 : 0;
157
- const fitWidth = horizontal ? space : bounds.width - margin[axis._position.opposite] - hBuff - margin[axis.schema.orient] + p;
160
+ // A vertical axis's flat label is painted in the box it was measured
161
+ // in (see `fitLabelRoom`).
162
+ const fitWidth = horizontal ? space : data?.room ?? bounds.width - margin[axis._position.opposite] - hBuff - margin[axis.schema.orient] + p;
158
163
  // A `fixedSize` label space can be narrower than a label: widen that
159
164
  // label's box (outward, away from the axis line) instead of dropping it.
160
165
  const labelWidth = !horizontal && data && typeof axis.schema.fixedSize === "number" ? Math.max(fitWidth, Math.ceil(data.width) + p) : fitWidth;
@@ -169,6 +174,8 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
169
174
  },
170
175
  rotate: data ? data.rotate : false,
171
176
  angle: data ? data.angle : 0,
177
+ cut: !!data?.cut,
178
+ lineHeight: data?.lineHeight,
172
179
  size: labels.includes(d) || axis.schema.scale === "log" && Math.log10(Math.abs(d)) % 1 === 0 ? size : ticks.includes(d) ? Math.ceil(size / 2) : axis._scaleData.find((t)=>+t === d) ? Math.ceil(size / 4) : 0,
173
180
  text: !data?.truncated && labels.includes(d) ? tickFormat(d) : false,
174
181
  tick: ticks.includes(d),
@@ -198,7 +205,9 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
198
205
  // moves the body-div fallback above the compute-mode early-return
199
206
  // would silently leak one <div> per tick render.
200
207
  .renderMode("compute").select(null).data(tickData).duration(axis.schema.duration).labelConfig({
201
- ellipsis: (d)=>d && d.length ? `${d}...` : "",
208
+ ellipsis: axisLabelEllipsis,
209
+ // A label measured cut short mid-word (see `cutLabel`) is drawn so.
210
+ truncateWord: (d)=>!!(d.cut !== undefined ? d : d.data)?.cut,
202
211
  // Slanted labels wrap between words, as they were measured.
203
212
  ...axis._labelRotation && axis._labelSlant ? {
204
213
  split: wholeWordSplit
@@ -214,6 +223,11 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
214
223
  // v4 scene-only: tick shape stays compute-mode; toScene() composes ticks.
215
224
  // No `g.ticks` DOM wrapper needed in the detached compute.
216
225
  axis._tickShape.config(configPrep.bind(axis)(axis.schema.shapeConfig)).labelConfig({
226
+ // Each label is painted with the line height it was measured with.
227
+ lineHeight: (d, i)=>{
228
+ const datum = d.lineHeight !== undefined ? d : d.data;
229
+ return typeof datum?.lineHeight === "number" ? datum.lineHeight : labelLineHeight(axis.schema.shapeConfig, datum?.id, i);
230
+ },
217
231
  padding: 0
218
232
  }).render();
219
233
  }
@@ -229,11 +243,9 @@ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
229
243
  // Title TextBox runs in compute mode regardless. When there's no
230
244
  // parent group (standaloneCompute path above), skip the title's
231
245
  // DOM mount — its scene comes via toScene() anyway.
232
- axis._titleClass.renderMode("compute").data(axis.schema.title ? [
233
- {
234
- text: axis.schema.title
235
- }
236
- ] : []).duration(axis.schema.duration).height(margin[axis.schema.orient]).rotate(axis.schema.orient === "left" ? -90 : axis.schema.orient === "right" ? 90 : 0).select(!group ? null : elem("g.d3plus-Axis-title", {
246
+ axis._titleClass.renderMode("compute").duration(axis.schema.duration).select(!group ? null : elem("g.d3plus-Axis-title", {
237
247
  parent: group
238
- }).node()).text((d)=>d.text).verticalAlign("middle").width(range[range.length - 1] - range[0]).x(horizontal ? range[0] : axis.schema.orient === "left" ? bounds.x + margin.left / 2 - (range[range.length - 1] - range[0]) / 2 : bounds.x + bounds.width - margin.right / 2 - (range[range.length - 1] - range[0]) / 2).y(horizontal ? axis.schema.orient === "bottom" ? bounds.y + bounds.height - margin.bottom : bounds.y : range[0] + (range[range.length - 1] - range[0]) / 2 - margin[axis.schema.orient] / 2).config(configPrep.bind(axis)(axis.schema.titleConfig)).render();
248
+ }).node()).x(horizontal ? range[0] : axis.schema.orient === "left" ? bounds.x + margin.left / 2 - (range[range.length - 1] - range[0]) / 2 : bounds.x + bounds.width - margin.right / 2 - (range[range.length - 1] - range[0]) / 2).y(horizontal ? axis.schema.orient === "bottom" ? bounds.y + bounds.height - margin.bottom : bounds.y : range[0] + (range[range.length - 1] - range[0]) / 2 - margin[axis.schema.orient] / 2);
249
+ // Wrapped as it was measured (see `titleRoom`), in the room it claimed.
250
+ configureTitle(axis._titleClass, axis, range, margin[axis.schema.orient]).render();
239
251
  }
@@ -3,7 +3,7 @@
3
3
  widens or narrows a linear or log domain to "nice" values. Pure.
4
4
 
5
5
  @module
6
- */ import { max } from "d3-array";
6
+ */ import { extent, max } from "d3-array";
7
7
  /** Whether `d` is negative, counting -0. */ export const isNegative = (d)=>d < 0 || Object.is(d, -0);
8
8
  /** The power of ten at or below `|d|`, carrying `d`'s sign. */ export const floorPow = (d)=>Math.pow(10, Math.floor(Math.log10(Math.abs(d)))) * Math.pow(-1, isNegative(d) ? 1 : 0);
9
9
  /** The power of ten at or above `|d|`, carrying `d`'s sign. */ export const ceilPow = (d)=>Math.pow(10, Math.ceil(Math.log10(Math.abs(d)))) * Math.pow(-1, isNegative(d) ? 1 : 0);
@@ -77,3 +77,18 @@
77
77
  }
78
78
  return undefined;
79
79
  }
80
+ /**
81
+ The open end of an axis rounded "inside" that the value `d` labels, if
82
+ any: "min" when `d` is the lowest of the `values` the axis labels and
83
+ the `domain` reaches down to it, "max" when it is the highest and the
84
+ domain reaches up to it. A value beyond the domain has nothing past it,
85
+ so it is not open-ended.
86
+ */ export function openEnd(d, values, domain) {
87
+ const value = Number(d);
88
+ const [low, high] = extent(values, Number);
89
+ const [from, to] = extent(domain, Number);
90
+ if (low === undefined || from === undefined) return undefined;
91
+ if (value === low && from <= low) return "min";
92
+ if (value === high && to >= high) return "max";
93
+ return undefined;
94
+ }
@@ -2,6 +2,7 @@
2
2
  The axis's backend-agnostic scene: gridlines and the domain bar emitted
3
3
  natively, composed with the tick Shape's and title TextBox's scenes.
4
4
  */ import { axisBarNodes } from "./axisBreak.js";
5
+ import { stampTickTooltips, stampTitleTooltip, tickRank } from "./axisTooltipTargets.js";
5
6
  /**
6
7
  Converts an attribute-style config (e.g. gridConfig, barConfig) into a Paint.
7
8
  @private
@@ -151,13 +152,21 @@
151
152
  const lbl = axis._tickShape._labelClass;
152
153
  if (lbl && typeof lbl.toScene === "function" && lbl._data && lbl._data.length) {
153
154
  const lblScene = lbl.toScene();
154
- if (lblScene && Array.isArray(lblScene.children)) children.push(...lblScene.children);
155
+ if (lblScene && Array.isArray(lblScene.children)) {
156
+ const labels = lblScene.children;
157
+ stampTickTooltips(labels, axis.schema.tickTooltip, tickRank(axis));
158
+ children.push(...labels);
159
+ }
155
160
  }
156
161
  }
157
162
  const bar = barLinePoints(axis);
158
163
  if (bar) children.push(...axisBarNodes(axis, bar.points, (cfg)=>configToPaint(axis, cfg)));
159
164
  if (axis._titleClass && typeof axis._titleClass.toScene === "function" && axis._titleClass._data && axis._titleClass._data.length) {
160
- children.push(axis._titleClass.toScene());
165
+ const title = axis._titleClass.toScene();
166
+ stampTitleTooltip([
167
+ title
168
+ ], axis.schema.title, axis.schema.titleTooltip);
169
+ children.push(title);
161
170
  }
162
171
  // The axis was placed inside a container the caller positioned (e.g. Plot's
163
172
  // xGroup); preserve that placement on the scene root.
@@ -0,0 +1,53 @@
1
+ /**
2
+ The axis title, configured once for both the measure and the paint, so
3
+ the title claims exactly the room it draws.
4
+ */ import { fontExists, parseSides, textWidth } from "@d3plus/dom";
5
+ import { softHyphen } from "@d3plus/text";
6
+ import TextBox from "../TextBox.js";
7
+ import { configPrep } from "../../utils/index.js";
8
+ /**
9
+ Whether the first word of `box`'s text is wider than its line on its
10
+ own, as the wrap measures it. The wrap can't place such a word on any
11
+ line, so the box would draw nothing.
12
+ */ export function firstWordOverflows(box, d, i) {
13
+ const text = box.schema.text(d, i);
14
+ if (text === undefined) return false;
15
+ const [first] = box.schema.split(`${text}`.trim(), i);
16
+ if (!first) return false;
17
+ // A syllable ending in a soft hyphen is drawn with a hyphen at a break.
18
+ const word = first.endsWith(softHyphen) ? `${first.slice(0, -1)}-` : first;
19
+ const padding = parseSides(box.schema.padding(d, i));
20
+ const width = textWidth(word, {
21
+ "font-family": fontExists(box.schema.fontFamily(d, i)),
22
+ "font-size": box.schema.fontSize(d, i),
23
+ "font-weight": box.schema.fontWeight(d, i)
24
+ });
25
+ return width > box.schema.width(d, i) - padding.left - padding.right;
26
+ }
27
+ /**
28
+ Configures `box` as the axis title wrapped across `range`, in a box
29
+ `height` tall: its text, width, rotation, and `titleConfig`. A first
30
+ word too wide for the axis is cut mid-word with the ellipsis
31
+ (`truncateWord`), so the title still draws; any other title cut short
32
+ ends at a word break. A `truncateWord` in `titleConfig` overrides both.
33
+ A title left out (see `measureAxis` in `axisLimit.ts`) has no data, so
34
+ draws nothing.
35
+ */ export function configureTitle(box, axis, range, height) {
36
+ const { orient } = axis.schema;
37
+ return box.data(axis.schema.title && !axis._dropTitle ? [
38
+ {
39
+ text: axis.schema.title
40
+ }
41
+ ] : []).height(height).rotate(orient === "left" ? -90 : orient === "right" ? 90 : 0).text((d)=>d.text).verticalAlign("middle").width(range[range.length - 1] - range[0]).truncateWord((d, i)=>firstWordOverflows(box, d, i)).config(configPrep.bind(axis)(axis.schema.titleConfig));
42
+ }
43
+ /**
44
+ The room the axis title claims on the axis's side: its lines as the
45
+ title TextBox wraps them across `range`, within `height`, to the whole
46
+ pixel, plus the axis's padding. A title that draws nothing claims no
47
+ room.
48
+ */ export function titleRoom(axis, range, height) {
49
+ const box = configureTitle(new TextBox().renderMode("compute"), axis, range, height);
50
+ const [datum] = box._textData();
51
+ if (!datum?.lines.some((line)=>line)) return 0;
52
+ return Math.ceil(datum.lines.length * datum.lH) + axis.schema.padding;
53
+ }
@@ -0,0 +1,128 @@
1
+ /**
2
+ What an axis's title and tick labels carry for a chart's axis tooltips
3
+ (see `charts/features/axisTooltip.ts`): each label's scene nodes are
4
+ stamped with the label's value, its whole text, whether it is drawn cut
5
+ short, and the axis's `titleTooltip` or `tickTooltip`. A label no tooltip
6
+ could show for is left unstamped.
7
+ */ /**
8
+ The axis label a scene node was stamped as, if any.
9
+ @param node A picked scene node.
10
+ */ export function axisTooltipTarget(node) {
11
+ return node?.axisTooltip;
12
+ }
13
+ /** `text` without its whitespace, which a wrap moves between lines. */ const solid = (text)=>text.replace(/\s+/g, "");
14
+ /**
15
+ Whether a text node draws less than `text`: its layout cut it short (see
16
+ `TextNode.truncated`) and its lines don't spell the whole text.
17
+ @param node A label's scene node.
18
+ @param text The label's whole text.
19
+ */ export function labelCut(node, text) {
20
+ if (node.type !== "text" || !node.truncated) return false;
21
+ return solid(node.lines.map((line)=>line.text).join("")) !== solid(text);
22
+ }
23
+ /**
24
+ Whether a label with `option` for its tooltip option could show one.
25
+ @param option An axis's `titleTooltip` or `tickTooltip`.
26
+ @param truncated Whether the label is drawn cut short.
27
+ */ export const canShow = (option, truncated)=>option !== false && (truncated || option !== undefined && option !== null);
28
+ /** Every node of a scene subtree, depth-first. */ function flatten(nodes) {
29
+ return nodes.flatMap((node)=>[
30
+ node,
31
+ ...flatten(node.children ?? [])
32
+ ]);
33
+ }
34
+ /** The tick config a label node's datum wraps, if the node is a tick label. */ function tickOf(node) {
35
+ const tick = node.datum?.data;
36
+ return tick && typeof tick === "object" && "tick" in tick && "id" in tick ? tick : undefined;
37
+ }
38
+ /** The scales whose domain lists categories. */ const CATEGORICAL = [
39
+ "band",
40
+ "ordinal",
41
+ "point"
42
+ ];
43
+ /** A category as a map key: a date by its time. */ const category = (value)=>value instanceof Date ? +value : value;
44
+ /**
45
+ Where a tick's value falls along an axis's domain, counted from the
46
+ domain's start: the lowest value of a value or time axis, the first
47
+ category of a categorical one (its last when the axis holds its domain
48
+ end first). Neither `reverse` nor a descending domain moves a value's
49
+ place.
50
+ @param axis A laid-out axis.
51
+ */ export function tickRank(axis) {
52
+ if (!CATEGORICAL.includes(`${axis.schema.scale}`)) return (value)=>Number(value);
53
+ const domain = axis._givenDomain().slice();
54
+ if (axis._domainEndFirst) domain.reverse();
55
+ const places = new Map(domain.map((d, i)=>[
56
+ category(d),
57
+ i
58
+ ]));
59
+ return (value)=>places.get(category(value)) ?? domain.length;
60
+ }
61
+ /**
62
+ Stamps an axis's tick label nodes (each label's text, and its hitbox when
63
+ it has one) with their tooltip target.
64
+ @param nodes The tick labels' scene nodes.
65
+ @param option The axis's `tickTooltip`.
66
+ @param rank Each tick value's place along the axis (see `tickRank`):
67
+ labels are indexed in that order, or in the order of `nodes` without it.
68
+ */ export function stampTickTooltips(nodes, option, rank) {
69
+ if (option === false) return;
70
+ const all = flatten(nodes);
71
+ const targets = new Map();
72
+ for (const node of all){
73
+ const tick = tickOf(node);
74
+ if (node.type !== "text" || !tick || targets.has(node.datum)) continue;
75
+ const text = `${tick.text}`;
76
+ targets.set(node.datum, {
77
+ part: "tick",
78
+ value: tick.id,
79
+ index: 0,
80
+ text,
81
+ truncated: labelCut(node, text),
82
+ option
83
+ });
84
+ }
85
+ const ordered = Array.from(targets.values());
86
+ if (rank) ordered.sort((a, b)=>rank(a.value) - rank(b.value));
87
+ ordered.forEach((target, index)=>target.index = index);
88
+ for (const node of all){
89
+ const target = targets.get(node.datum);
90
+ if (target && canShow(option, target.truncated)) node.axisTooltip = target;
91
+ }
92
+ }
93
+ /**
94
+ Stamps an axis's title nodes with their tooltip target.
95
+ @param nodes The title's scene nodes.
96
+ @param title The axis's title.
97
+ @param option The axis's `titleTooltip`.
98
+ */ export function stampTitleTooltip(nodes, title, option) {
99
+ if (option === false) return;
100
+ const all = flatten(nodes);
101
+ const text = `${title}`;
102
+ const truncated = all.some((node)=>labelCut(node, text));
103
+ if (!canShow(option, truncated)) return;
104
+ const target = {
105
+ part: "title",
106
+ value: title,
107
+ index: 0,
108
+ text,
109
+ truncated,
110
+ option
111
+ };
112
+ for (const node of all)if (node.datum !== undefined) node.axisTooltip = target;
113
+ }
114
+ /**
115
+ An axis's scene as chrome under a chart's marks: every node takes the
116
+ "axis" interaction group, and each one that draws leaves hit-testing
117
+ unless it is stamped with a tooltip target, so the pointer reaches the
118
+ axis only on a label with a tooltip to show.
119
+ @param node An axis's scene, or a node in it.
120
+ */ export function inertAxis(node) {
121
+ const next = {
122
+ ...node,
123
+ interactionGroup: "axis"
124
+ };
125
+ if (next.type === "group") next.children = next.children.map(inertAxis);
126
+ else if (!next.axisTooltip) next.interactive = false;
127
+ return next;
128
+ }
@@ -9,18 +9,42 @@ import { accessor, BaseClass, paintComponentScene } from "../../utils/index.js";
9
9
  import { installFluent, mergeConfigBag, resolvesReset } from "../../fluent.js";
10
10
  import { inkText } from "../../utils/themeInk.js";
11
11
  import Legend from "../Legend/Legend.js";
12
+ import { inertAxis } from "../Axis/axisTooltipTargets.js";
12
13
  import { formatYear, isYearLike } from "../Axis/yearValues.js";
13
14
  import { bucketBounds, labelValue } from "./bucketBounds.js";
14
15
  import { computeColorScale } from "./colorScaleScale.js";
15
16
  import { renderGradient, renderLegendVariant } from "./colorScaleRender.js";
16
17
  import { isBucketScale } from "./colorScaleType.js";
17
18
  import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
19
+ import { swatchTooltips } from "./colorScaleSwatchTooltips.js";
20
+ import { renderBivariate } from "./bivariateRender.js";
18
21
  /** ColorScale's fluent accessor schema. Config storage lives on `this.schema.<key>`. */ const colorScaleSchema = [
19
22
  {
20
23
  key: "align",
21
24
  coerce: "identity",
22
25
  default: "middle"
23
26
  },
27
+ // A bivariate scale reads a pair of values from each row and draws its
28
+ // grid of colors as a diamond key (see bivariateRender.ts).
29
+ {
30
+ key: "bivariate",
31
+ coerce: "identity",
32
+ default: false
33
+ },
34
+ {
35
+ key: "bivariateBuckets",
36
+ coerce: "identity",
37
+ default: 3
38
+ },
39
+ // No default grid: an unset one paints Stevens' blue–red scheme.
40
+ {
41
+ key: "bivariateColors",
42
+ coerce: "identity"
43
+ },
44
+ {
45
+ key: "bivariateLabels",
46
+ coerce: "identity"
47
+ },
24
48
  {
25
49
  key: "buckets",
26
50
  coerce: "identity",
@@ -158,7 +182,10 @@ import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
158
182
  _rectClass;
159
183
  /** The scale the last render built, with a `scale` function resolved. */ _scaleType = "linear";
160
184
  /** Where the color bar sits, set when the bar variant renders (see colorScaleHoverMark). */ _barGeometry;
161
- /** The value marked on the scale, set with `hover()`. */ _hoverValue;
185
+ /** The value marked on the scale, set with `hover()`: a pair of values on a bivariate scale. */ _hoverValue;
186
+ /** The names a chart gives a bivariate scale's two variables (its field names), under `bivariateLabels`. */ _bivariateFields;
187
+ /** The bivariate key's nodes, laid out by the last render. */ _bivariateNodes;
188
+ /** Each swatch's legend row, with its bucket, set when the swatch variant renders. */ _swatchBuckets = new Map();
162
189
  /** Smooth-gradient fill token (`gradient:<json>`), set by renderGradientStops. */ _gradientFill;
163
190
  // Standalone scene renderer (used when rendered on its own, not inside a
164
191
  // Viz). Reused across re-renders by paintComponentScene().
@@ -191,6 +218,8 @@ import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
191
218
  fontSize: 12
192
219
  };
193
220
  this._legendClass = new Legend();
221
+ // Swatch labels that don't fit whole are cut short, not left out.
222
+ this._legendClass._cutLabels = true;
194
223
  this.schema.legendConfig = {
195
224
  shapeConfig: {
196
225
  stroke: ()=>this.schema.colorDefaults.dark,
@@ -222,8 +251,10 @@ import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
222
251
  this._group = elem("g.d3plus-ColorScale", {
223
252
  parent: this._select
224
253
  });
225
- const compute = computeColorScale(this);
226
- const gradient = this.schema.bucketAxis || !isBucketScale(compute.scale);
254
+ const bivariate = Boolean(this.schema.bivariate);
255
+ this._bivariateNodes = bivariate ? renderBivariate(this).nodes : undefined;
256
+ const compute = bivariate ? undefined : computeColorScale(this);
257
+ const gradient = !bivariate && (this.schema.bucketAxis || !isBucketScale(compute.scale));
227
258
  const t = transition().duration(this.schema.duration);
228
259
  const groupParams = {
229
260
  enter: {
@@ -245,7 +276,7 @@ import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
245
276
  condition: gradient
246
277
  }, groupParams));
247
278
  const legendGroup = elem("g.d3plus-ColorScale-legend", Object.assign({
248
- condition: !gradient
279
+ condition: !gradient && !bivariate
249
280
  }, groupParams));
250
281
  const groups = {
251
282
  labelGroup,
@@ -254,8 +285,10 @@ import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
254
285
  groupParams,
255
286
  gradient
256
287
  };
257
- if (gradient) renderGradient(this, compute, groups);
258
- else renderLegendVariant(this, compute, groups);
288
+ if (compute) {
289
+ if (gradient) renderGradient(this, compute, groups);
290
+ else renderLegendVariant(this, compute, groups);
291
+ }
259
292
  // Standalone render: paint the scene into the user's `_select`. Inside a
260
293
  // Viz the color scale runs in compute mode and the Viz composes its
261
294
  // toScene().
@@ -266,10 +299,13 @@ import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
266
299
  /**
267
300
  Produces a backend-agnostic scene graph for this ColorScale with no DOM
268
301
  dependency. The discrete variant (jenks/buckets/quantile) delegates to the
269
- internal Legend's toScene(); the gradient variant composes the Rect, Axis,
270
- and label TextBox scenes. The scaleGroup's translate (set by the chart's
271
- colorScale feature on `g.d3plus-viz-colorScale`) is read off `_select` so
272
- the content lands at its on-screen position.
302
+ internal Legend's toScene(), its title and swatch labels taking the axis
303
+ tooltips (see `swatchTooltips`); the gradient variant composes the Rect,
304
+ Axis, and label TextBox scenes, all as chrome (see `inertAxis`): only an
305
+ axis label with a tooltip takes the pointer. The scaleGroup's
306
+ translate (set by the chart's colorScale feature on
307
+ `g.d3plus-viz-colorScale`) is read off `_select` so the content lands at
308
+ its on-screen position.
273
309
 
274
310
  A smooth (non-bucketed) gradient paints its Rect with a `gradient:<json>`
275
311
  fill token (see renderGradientStops); the backend materializes it into a
@@ -278,18 +314,26 @@ import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
278
314
  */ toScene() {
279
315
  const children = [];
280
316
  const gradient = this.schema.bucketAxis || !isBucketScale(this._scaleType);
281
- const pushScene = (cls)=>{
317
+ const pushScene = (cls, finish = (scene)=>scene)=>{
282
318
  if (cls && typeof cls.toScene === "function") {
283
319
  const s = cls.toScene();
284
- if (s) children.push(s);
320
+ if (s) children.push(finish(s));
285
321
  }
286
322
  };
287
- if (gradient) {
288
- pushScene(this._rectClass);
289
- pushScene(this._axisClass);
290
- pushScene(this._labelClass);
323
+ if (this._bivariateNodes) {
324
+ children.push(...this._bivariateNodes);
325
+ } else if (gradient) {
326
+ pushScene(this._rectClass, inertAxis);
327
+ pushScene(this._axisClass, inertAxis);
328
+ pushScene(this._labelClass, inertAxis);
291
329
  } else {
292
- pushScene(this._legendClass);
330
+ pushScene(this._legendClass, (scene)=>swatchTooltips(scene, {
331
+ title: this._legendClass.schema.title,
332
+ titleDatum: this._legendClass._titleClass.data()[0],
333
+ titleTooltip: this.schema.axisConfig.titleTooltip,
334
+ tickTooltip: this.schema.axisConfig.tickTooltip,
335
+ buckets: this._swatchBuckets
336
+ }));
293
337
  }
294
338
  // Preserve the placement of the scaleGroup the chart's colorScale feature
295
339
  // positioned (translate on `g.d3plus-viz-colorScale`).
@@ -313,7 +357,7 @@ import { addHoverMark, hoverMarkDefaults } from "./colorScaleHoverMark.js";
313
357
  } : {},
314
358
  children
315
359
  };
316
- addHoverMark(this, group);
360
+ if (!this._bivariateNodes) addHoverMark(this, group);
317
361
  return group;
318
362
  }
319
363
  axisConfig(_) {