@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
@@ -13,7 +13,8 @@
13
13
  `ribbonArrow`.
14
14
 
15
15
  @module
16
- */ import { cubicPoint } from "./linkLabelGeometry.js";
16
+ */ import { STROKE_EMPHASIS } from "../viz/emphasis.js";
17
+ import { cubicPoint } from "./linkLabelGeometry.js";
17
18
  /** Normalize an `arrows` config value for one edge into `{source, target}` flags. */ export function arrowEnds(arrows, d, i) {
18
19
  const v = typeof arrows === "function" ? arrows(d, i) : arrows;
19
20
  if (v === true || v === "target") return {
@@ -84,6 +85,60 @@ const round = (n)=>Math.round(n * 100) / 100;
84
85
  const sw = Number.isFinite(strokeWidth) ? Math.max(0, strokeWidth) : 0;
85
86
  return Math.min(s, Math.max(s / 2, sw / 1.2));
86
87
  }
88
+ /**
89
+ An `arrowSize` config for an edge drawn `scale` times wider, as hover
90
+ and active emphasis draw it: a size you set grows with the stroke, and
91
+ the default follows the wider stroke on its own (see `defaultArrowSize`).
92
+ */ export function scaledArrowSize(arrowSize, scale) {
93
+ if (scale === 1) return arrowSize;
94
+ if (typeof arrowSize === "number") return arrowSize * scale;
95
+ if (typeof arrowSize === "function") return (d, i)=>{
96
+ const v = arrowSize(d, i);
97
+ return typeof v === "number" ? v * scale : v;
98
+ };
99
+ return arrowSize;
100
+ }
101
+ /**
102
+ An edge's stroke width `scale` times wider, as hover and active emphasis
103
+ draw it (a 0 or unset width counting as 1, the way they do).
104
+ */ export function scaledStrokeWidth(strokeWidth, scale) {
105
+ if (scale === 1) return strokeWidth;
106
+ const sw = typeof strokeWidth === "number" && strokeWidth ? strokeWidth : 1;
107
+ return sw * scale;
108
+ }
109
+ /**
110
+ An edge's visible stroke and arrowheads as `draw` draws them at their
111
+ own stroke width, carrying the geometry hover and active emphasis widen
112
+ them to: each arrowhead grows with the wider stroke and darkens with it,
113
+ and the stroke ends back inside it, so neither pokes past the other.
114
+ @param draw Draws the edge at `scale` times its stroke width (see
115
+ `scaledStrokeWidth` and `scaledArrowSize`).
116
+ */ export function emphasizedArrowEdge(draw) {
117
+ const rest = draw(1);
118
+ if (!rest.arrows.length) return rest;
119
+ const hover = draw(STROKE_EMPHASIS.hover.width);
120
+ const active = draw(STROKE_EMPHASIS.active.width);
121
+ const pathD = (node)=>node?.type === "path" ? node.d : undefined;
122
+ return {
123
+ d: rest.d,
124
+ arrows: rest.arrows.map((arrow, k)=>arrow.type === "path" ? {
125
+ ...arrow,
126
+ emphasis: {
127
+ ...arrow.emphasis,
128
+ d: {
129
+ hover: pathD(hover.arrows[k]),
130
+ active: pathD(active.arrows[k])
131
+ }
132
+ }
133
+ } : arrow),
134
+ emphasis: {
135
+ d: {
136
+ hover: hover.d,
137
+ active: active.d
138
+ }
139
+ }
140
+ };
141
+ }
87
142
  /** Resolves an edge's `arrows`/`arrowSize` into its arrowhead ends, size, and stroke trims. */ export function edgeArrowTrims(opts) {
88
143
  const ends = arrowEnds(opts.arrows, opts.datum, opts.i);
89
144
  const sw = typeof opts.strokeWidth === "number" ? opts.strokeWidth : 1;
@@ -259,12 +314,16 @@ const round = (n)=>Math.round(n * 100) / 100;
259
314
  /**
260
315
  Build one arrowhead scene node. `interactive: false` so the edge path owns
261
316
  hit-testing, and the same `datum` as its edge so the hover-dim pass keeps the
262
- arrow paired with its edge.
317
+ arrow paired with its edge. Emphasis darkens its fill with its edge's
318
+ stroke rather than outlining it.
263
319
  */ export function arrowNode(opts) {
264
320
  return {
265
321
  type: "path",
266
322
  key: opts.key,
267
323
  d: arrowPathD(opts.x, opts.y, opts.angle, opts.size),
324
+ emphasis: {
325
+ fill: true
326
+ },
268
327
  datum: opts.datum,
269
328
  interactive: false,
270
329
  paint: {
@@ -13,8 +13,12 @@ import { insetFrame, insetOrient, isInsetPending } from "./insetState.js";
13
13
  import { facetKey } from "../facet/facetData.js";
14
14
  import { colorScaleBucketRows } from "./colorScaleBucket.js";
15
15
  import { colorScaleValue, linkColorScaleRows } from "./colorScaleValue.js";
16
+ import { bivariateFieldNames, bivariateSpec } from "./colorScaleBivariate.js";
17
+ import { axisRoom, configSize, isWide, sideFrame, swatchFrame } from "./colorScaleLimit.js";
18
+ import { paintTopColorScale } from "./colorScaleTop.js";
16
19
  import { resolveAccessor, shapeConfigFor } from "./emitHelpers.js";
17
20
  import { effectiveDuration } from "../viz/reducedMotion.js";
21
+ import { resetKeys } from "../../fluent.js";
18
22
  /**
19
23
  The colorScale's data: the chart's data rolled up per time/id (and per
20
24
  small-multiples panel, the values the panels color by), keeping rows with
@@ -36,6 +40,13 @@ import { effectiveDuration } from "../viz/reducedMotion.js";
36
40
  return c !== undefined && c !== null;
37
41
  });
38
42
  }
43
+ /** The config a ColorScale merges each render's into, rather than replaces. */ const CONFIG_BAGS = [
44
+ "axisConfig",
45
+ "labelConfig",
46
+ "legendConfig",
47
+ "rectConfig"
48
+ ];
49
+ /** The `colorScaleConfig` keys each chart's ColorScale was last given. */ const configKeys = new WeakMap();
39
50
  /** The paint a bucket swatch takes from the chart's shapes: all but its fill. */ const SWATCH_STYLES = [
40
51
  "fillOpacity",
41
52
  "opacity",
@@ -73,7 +84,9 @@ import { effectiveDuration } from "../viz/reducedMotion.js";
73
84
  /**
74
85
  Configures and lays out the chart's `_colorScaleClass` into `frame`. It
75
86
  always runs in compute mode: Viz.toScene composes its scene, so the
76
- colorScale never paints a DOM copy of its own.
87
+ colorScale never paints a DOM copy of its own. The frame sets the
88
+ scale's width and height over the chart's `colorScaleConfig`, which
89
+ sizes the frame instead.
77
90
  */ function paintColorScale(viz, frame, show) {
78
91
  const transform = {
79
92
  opacity: frame.orient ? 1 : 0,
@@ -90,11 +103,26 @@ import { effectiveDuration } from "../viz/reducedMotion.js";
90
103
  }).node();
91
104
  const value = colorScaleValue(viz);
92
105
  if (!value) return;
93
- viz._colorScaleClass.renderMode("compute").align(frame.align).duration(effectiveDuration(viz)).data(colorScaleData(viz)).height(frame.height).locale(viz.schema.locale).orient(frame.orient).select(scaleGroup).value(value).width(frame.width).legendConfig({
106
+ const cs = viz._colorScaleClass;
107
+ // Each render starts from the ColorScale's defaults, so config the chart's
108
+ // colorScaleConfig gave it before and no longer gives it is dropped.
109
+ const config = viz.schema.colorScaleConfig;
110
+ cs.config(resetKeys(cs, [
111
+ ...CONFIG_BAGS,
112
+ ...configKeys.get(cs) ?? []
113
+ ]));
114
+ configKeys.set(cs, Object.keys(config));
115
+ const { limit } = frame;
116
+ const bivariate = bivariateSpec(viz);
117
+ cs._bivariateFields = bivariate ? bivariateFieldNames(viz, bivariate) : undefined;
118
+ cs.renderMode("compute").bivariate(Boolean(bivariate)).align(frame.align).duration(effectiveDuration(viz)).data(colorScaleData(viz)).locale(viz.schema.locale).orient(frame.orient).select(scaleGroup).value(value).legendConfig({
94
119
  shapeConfig: bucketSwatchConfig(viz)
95
120
  })// Links colored by number are thin lines: keep the ramp's low end
96
121
  // visible against a light background.
97
- .ordinalRamp(linkColorScaleRows(viz).length > 0).config(viz.schema.colorScaleConfig).hover(false).render();
122
+ .ordinalRamp(linkColorScaleRows(viz).length > 0)// Read as the axis is laid out, once the chart's own config is applied.
123
+ .axisConfig({
124
+ maxSize: limit === undefined ? undefined : ()=>axisRoom(limit, cs.size(), cs.padding())
125
+ }).config(config).width(frame.width).height(frame.height).hover(false).render();
98
126
  }
99
127
  /** The colorScale's sanitized position side (false when hidden). */ function colorScalePosition(viz) {
100
128
  return sanitizePosition(viz.schema.colorScalePosition.bind(viz)(resolveSpec(viz)), viz);
@@ -108,17 +136,18 @@ import { effectiveDuration } from "../viz/reducedMotion.js";
108
136
  const show = Boolean(colorScaleValue(viz)) && colorScalePosition(viz) !== false && !viz.schema.colorScaleConfig.select;
109
137
  const frame = insetFrame(orient, area);
110
138
  const maxSize = viz.schema.colorScaleMaxSize;
139
+ const config = viz.schema.colorScaleConfig;
111
140
  paintColorScale(viz, {
112
141
  x: 0,
113
142
  y: 0,
114
- width: orient === "row" ? min([
143
+ width: configSize(config, "width") ?? (orient === "row" ? min([
115
144
  maxSize,
116
145
  frame.width
117
- ]) : frame.width,
118
- height: orient === "column" ? min([
146
+ ]) : frame.width),
147
+ height: configSize(config, "height") ?? (orient === "column" ? min([
119
148
  maxSize,
120
149
  frame.height
121
- ]) : frame.height,
150
+ ]) : frame.height),
122
151
  orient: orient === "column" ? "right" : "bottom",
123
152
  align: "start"
124
153
  }, show);
@@ -156,10 +185,7 @@ import { effectiveDuration } from "../viz/reducedMotion.js";
156
185
  };
157
186
  }
158
187
  const position = colorScalePosition(viz);
159
- const wide = [
160
- "top",
161
- "bottom"
162
- ].includes(position);
188
+ const wide = isWide(position);
163
189
  const showColorScale = colorScaleValue(viz) && position;
164
190
  const padding = viz.schema.colorScalePadding(viz) ? viz._padding : {
165
191
  top: 0,
@@ -172,17 +198,23 @@ import { effectiveDuration } from "../viz/reducedMotion.js";
172
198
  // Share the bottom band with the bottom-right corner panel (size legend):
173
199
  // a bottom colorScale fits beside it, a side one ends above it.
174
200
  const corner = bottomRightClearance(viz, position, layoutMargin.bottom + padding.bottom, layoutMargin.right + padding.right);
201
+ // The `width` or `height` a chart's colorScaleConfig sets is the scale's
202
+ // length along its side, in place of colorScaleMaxSize, and its limit
203
+ // across it.
204
+ const config = viz.schema.colorScaleConfig;
205
+ const setWidth = configSize(config, "width");
206
+ const setHeight = configSize(config, "height");
175
207
  const availableWidth = viz.schema.width - (layoutMargin.left + layoutMargin.right + padding.left + padding.right) - corner.inset;
176
208
  const width = wide ? min([
177
- viz.schema.colorScaleMaxSize,
209
+ setWidth ?? viz.schema.colorScaleMaxSize,
178
210
  availableWidth
179
211
  ]) : viz.schema.width - (layoutMargin.left + layoutMargin.right);
180
212
  const availableHeight = viz.schema.height - (layoutMargin.bottom + layoutMargin.top + padding.bottom + padding.top) - drop - corner.drop;
181
213
  const height = !wide ? min([
182
- viz.schema.colorScaleMaxSize,
214
+ setHeight ?? viz.schema.colorScaleMaxSize,
183
215
  availableHeight
184
216
  ]) : viz.schema.height - (layoutMargin.bottom + layoutMargin.top);
185
- paintColorScale(viz, {
217
+ const frame = sideFrame({
186
218
  x: wide ? layoutMargin.left + padding.left + (availableWidth - width) / 2 : layoutMargin.left,
187
219
  y: wide ? layoutMargin.top : layoutMargin.top + padding.top + drop + (availableHeight - height) / 2,
188
220
  width,
@@ -194,7 +226,16 @@ import { effectiveDuration } from "../viz/reducedMotion.js";
194
226
  right: "end",
195
227
  top: "start"
196
228
  }[position] || "bottom"
197
- }, Boolean(showColorScale));
229
+ }, wide ? setHeight : setWidth);
230
+ const placed = showColorScale && !viz.schema.colorScaleConfig.select;
231
+ const paint = (at)=>{
232
+ paintColorScale(viz, at, Boolean(showColorScale));
233
+ // A Legend lays the swatches out within its own width and height.
234
+ const swatches = placed ? swatchFrame(viz._colorScaleClass, at) : undefined;
235
+ if (swatches) paintColorScale(viz, swatches, true);
236
+ };
237
+ // A scale at the top keeps clear of the corner control panels.
238
+ const topDrop = placed && position === "top" ? paintTopColorScale(viz, frame, height, paint) : (paint(frame), 0);
198
239
  const margin = {};
199
240
  if (showColorScale) {
200
241
  const scaleBounds = viz._colorScaleClass.outerBounds();
@@ -204,7 +245,7 @@ import { effectiveDuration } from "../viz/reducedMotion.js";
204
245
  // colorScale's claim when the legend is hidden. The colorScale
205
246
  // class is the source of truth.
206
247
  const csPadding = typeof viz._colorScaleClass.padding === "function" ? viz._colorScaleClass.padding() : viz._legendClass.padding();
207
- if (wide) margin[position] = scaleBounds.height + csPadding * 2;
248
+ if (wide) margin[position] = topDrop + scaleBounds.height + csPadding * 2;
208
249
  else margin[position] = scaleBounds.width + csPadding * 2;
209
250
  }
210
251
  }
@@ -0,0 +1,41 @@
1
+ /**
2
+ Discrete axis ticks that follow the hover: each tick label is stamped
3
+ with the value it stands for (see `hoverMatch`), so while marks are
4
+ hovered the labels of their buckets stay at full opacity and the rest dim
5
+ with the other marks. Continuous axes show a hover badge instead (see
6
+ `Plot/axisHover.ts`).
7
+ */ /** Whether an Axis draws discrete buckets (a band, ordinal, or point scale). */ export const discreteAxis = (axis)=>[
8
+ "band",
9
+ "ordinal",
10
+ "point"
11
+ ].includes(`${axis?.schema?.scale}`);
12
+ /**
13
+ Stamps every tick label in an axis scene with `hoverMatch`: the tick's
14
+ value, matched against `field` on the hovered marks' data.
15
+ @param node The axis scene (or any subtree of it).
16
+ @param field The datum key a mark keeps the axis value under.
17
+ */ export function tagHoverTicks(node, field) {
18
+ const tick = node.datum?.data;
19
+ if (node.type === "text" && tick && "tick" in tick && "id" in tick) node.hoverMatch = {
20
+ field,
21
+ value: tick.id
22
+ };
23
+ const kids = node.children;
24
+ if (kids) for (const child of kids)tagHoverTicks(child, field);
25
+ }
26
+ /**
27
+ The values under `field` in a datum or any datum it wraps (the first one
28
+ that has it), as strings; an array value gives each of its items.
29
+ */ export function datumValues(datum, field) {
30
+ let d = datum;
31
+ while(d && typeof d === "object"){
32
+ if (Object.prototype.hasOwnProperty.call(d, field)) {
33
+ const v = d[field];
34
+ return (Array.isArray(v) ? v : [
35
+ v
36
+ ]).map(String);
37
+ }
38
+ d = d.data;
39
+ }
40
+ return [];
41
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ Work spread over the browser's idle time: jobs run in short turns from
3
+ `requestIdleCallback` (or `setTimeout` where it is missing), so no turn
4
+ keeps the main thread busy for long.
5
+ */ /** What `requestIdleCallback` hands its callback. */ /** The longest a turn runs, in milliseconds, however long the browser stays idle. */ export const IDLE_BUDGET = 12;
6
+ /** The longest a job waits for an idle moment before it runs anyway, in milliseconds. */ const IDLE_TIMEOUT = 2000;
7
+ /** Calls `fn` at the next idle moment, or soon after when the browser has no idle callbacks. */ export function requestIdle(fn) {
8
+ const ric = globalThis.requestIdleCallback;
9
+ if (typeof ric === "function") ric(fn, {
10
+ timeout: IDLE_TIMEOUT
11
+ });
12
+ else setTimeout(()=>fn(undefined), 1);
13
+ }
14
+ const now = ()=>typeof performance !== "undefined" ? performance.now() : Date.now();
15
+ /**
16
+ Jobs keyed by name, run one after another in idle turns. Callbacks
17
+ passed to `beforeNext` run at the start of the next turn, before any job.
18
+ */ export class IdleQueue {
19
+ jobs = new Map();
20
+ before = [];
21
+ waiting = false;
22
+ /** How many jobs are waiting or running. */ get size() {
23
+ return this.jobs.size;
24
+ }
25
+ /** Whether a job named `key` is waiting or running. */ has(key) {
26
+ return this.jobs.has(key);
27
+ }
28
+ /** Queues `job` under `key`, unless a job of that name is already queued. */ add(key, job) {
29
+ if (this.jobs.has(key)) return;
30
+ this.jobs.set(key, job);
31
+ this.wake();
32
+ }
33
+ /** Cancels every job whose name isn't in `keys`. */ keep(keys) {
34
+ for (const key of [
35
+ ...this.jobs.keys()
36
+ ])if (!keys.has(key)) this.jobs.delete(key);
37
+ }
38
+ /** Cancels every job and every `beforeNext` callback. */ clear() {
39
+ this.jobs.clear();
40
+ this.before.length = 0;
41
+ }
42
+ /** Runs `fn` at the start of the next idle turn. */ beforeNext(fn) {
43
+ this.before.push(fn);
44
+ this.wake();
45
+ }
46
+ wake() {
47
+ if (this.waiting) return;
48
+ this.waiting = true;
49
+ requestIdle((deadline)=>this.turn(deadline));
50
+ }
51
+ /** One idle turn: the `beforeNext` callbacks, then jobs until the turn's time is up. */ turn(deadline) {
52
+ this.waiting = false;
53
+ const start = now();
54
+ const budget = Math.min(IDLE_BUDGET, deadline ? deadline.timeRemaining() : IDLE_BUDGET);
55
+ for (const fn of this.before.splice(0))fn();
56
+ for (const [key, job] of this.jobs){
57
+ const left = budget - (now() - start);
58
+ if (job.step(left) && this.jobs.get(key) === job) this.jobs.delete(key);
59
+ if (now() - start >= budget) break;
60
+ }
61
+ if (this.jobs.size || this.before.length) this.wake();
62
+ }
63
+ }
64
+ const queues = new WeakMap();
65
+ /** The idle queue of `owner` (a chart), made on first use. */ export function idleQueue(owner) {
66
+ let queue = queues.get(owner);
67
+ if (!queue) queues.set(owner, queue = new IdleQueue());
68
+ return queue;
69
+ }
70
+ /** Cancels the idle work of `owner` (a chart), if it has any. */ export function cancelIdleWork(owner) {
71
+ queues.get(owner)?.clear();
72
+ }
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  Link interaction shared by the node-link charts (Network, Rings, Sankey,
3
3
  ArcDiagram): the datum each link is drawn with, its tooltip and spoken
4
- label, what hovering a link or a node highlights, and the connections a
4
+ label, what hovering a link, a node, or a legend entry highlights, and
5
+ the connections a
5
6
  node's tooltip lists.
6
7
 
7
8
  A link's datum is its row from `links`, with `source` and `target`
@@ -13,6 +14,8 @@
13
14
  own fields.
14
15
  */ import { rtl } from "@d3plus/dom";
15
16
  import { formatAbbreviate } from "@d3plus/format";
17
+ import { colorCategory } from "./legendCategory.js";
18
+ import { nodeStatRows, scheduleNodeStats } from "./nodeStats.js";
16
19
  const metas = new WeakMap();
17
20
  const nodeEntries = new WeakMap();
18
21
  /** What the chart recorded for a link datum, if `d` is one. */ export function linkMeta(d) {
@@ -90,6 +93,7 @@ const nodeEntries = new WeakMap();
90
93
  graph
91
94
  });
92
95
  viz.ctx.linkGraph = graph;
96
+ scheduleNodeStats(viz, graph, ()=>statLinks(graph), ()=>refreshNodeTooltip(viz));
93
97
  return graph;
94
98
  }
95
99
  /**
@@ -198,6 +202,21 @@ const nodeEntries = new WeakMap();
198
202
  return id !== undefined && ids.has(`${id}`);
199
203
  };
200
204
  }
205
+ /**
206
+ What hovering a legend entry highlights: the nodes it stands for (one, or
207
+ every member of a merged entry, such as a cluster) and the links between
208
+ them. A row matches when every id it holds is one of the entry's, so the
209
+ entry matches itself.
210
+ */ export function legendHighlight(viz, d, i) {
211
+ const idsOf = (h, hi)=>[].concat(viz._id(h, hi)).map((id)=>`${id}`);
212
+ const ids = new Set(idsOf(d, i));
213
+ return (h, hi)=>{
214
+ const m = linkMeta(h);
215
+ if (m) return ids.has(m.source.id) && ids.has(m.target.id);
216
+ const own = idsOf(h, hi);
217
+ return own.length > 0 && own.every((id)=>ids.has(id));
218
+ };
219
+ }
201
220
  /**
202
221
  A node's links in `graph`, the other end of each, and its direction,
203
222
  strongest first. A link from the node to itself is `loop`, with the node
@@ -254,10 +273,31 @@ const nodeEntries = new WeakMap();
254
273
  return graph.sized ? 3 : 0;
255
274
  }
256
275
  /** The arrow a node's tooltip marks a link from the node to itself with. */ export const LOOP_ARROW = "↻";
276
+ /** A graph's links as the node measures read them (see `nodeStatRows`). */ function statLinks(graph) {
277
+ return graph.links.map((datum)=>{
278
+ const meta = linkMeta(datum);
279
+ return {
280
+ source: meta.source.id,
281
+ target: meta.target.id,
282
+ index: meta.index,
283
+ value: meta.value,
284
+ datum
285
+ };
286
+ });
287
+ }
257
288
  /**
258
- A node's tooltip rows: its number of connections, then its strongest
259
- links ("→ Target" or "← Source", or "↻ Node" for a link to itself, with
260
- the link's value when the links differ in value), up to
289
+ Renders the chart's tooltip again while it shows one of its nodes, so
290
+ measures that became ready since it opened fill in.
291
+ */ function refreshNodeTooltip(viz) {
292
+ const tooltip = viz._tooltipClass;
293
+ const shown = tooltip?.data();
294
+ if (Array.isArray(shown) && shown.some((d)=>linkNodeOf(viz, d))) tooltip.render();
295
+ }
296
+ /**
297
+ A node's tooltip rows: its number of connections (left out when its
298
+ degree takes its place) and the network measures `nodeTooltipStats`
299
+ lists (see `nodeStatRows`), then its strongest links ("→ Target" or "← Source", or "↻ Node" for a link to
300
+ itself, with the link's value when the links differ in value), up to
261
301
  `nodeTooltipLinkLimit`. The arrows mirror right to left (see
262
302
  `linkArrows`).
263
303
  */ export function nodeConnectionRows(viz, d) {
@@ -265,11 +305,13 @@ const nodeEntries = new WeakMap();
265
305
  if (!entry) return [];
266
306
  const { graph, id } = entry;
267
307
  const connections = nodeConnections(graph, id);
268
- const rows = [
308
+ const stats = nodeStatRows(viz, graph, id, ()=>statLinks(graph), ()=>refreshNodeTooltip(viz));
309
+ const rows = stats.degree ? stats.rows : [
269
310
  [
270
311
  viz.schema.translate("Connections"),
271
312
  `${connections.length}`
272
- ]
313
+ ],
314
+ ...stats.rows
273
315
  ];
274
316
  const [forward, back] = linkArrows(viz);
275
317
  for (const c of connections.slice(0, nodeTooltipLinkLimit(viz, graph))){
@@ -281,13 +323,23 @@ const nodeEntries = new WeakMap();
281
323
  }
282
324
  return rows;
283
325
  }
326
+ /**
327
+ The color category a row merging several nodes stands for (a cluster's
328
+ name, or a legend entry's color value), so a legend entry's tooltip
329
+ reads as the entry does instead of listing every node.
330
+ */ function mergedCategory(viz, d, i) {
331
+ const ids = viz._id?.(d, i);
332
+ if (!Array.isArray(ids) || ids.length < 2) return undefined;
333
+ const color = viz.schema.color;
334
+ return typeof color === "function" ? colorCategory(color(d, i)) : undefined;
335
+ }
284
336
  /**
285
337
  The node-link charts' default `tooltipConfig`: a link is titled
286
338
  "Source → Target" and lists its value and fields; a node is titled by its
287
339
  label and lists its connections.
288
340
  */ export function linkTooltipConfig(viz) {
289
341
  return {
290
- title: (d, i)=>isLinkDatum(d) ? linkTooltipTitle(viz, d) : viz._drawLabel(d, typeof d.i === "number" ? d.i : i),
342
+ title: (d, i)=>isLinkDatum(d) ? linkTooltipTitle(viz, d) : mergedCategory(viz, d, i) ?? viz._drawLabel(d, typeof d.i === "number" ? d.i : i),
291
343
  tbody: (d)=>isLinkDatum(d) ? linkTooltipRows(viz, d) : nodeConnectionRows(viz, d)
292
344
  };
293
345
  }