@d3plus/core 4.3.0 → 4.6.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 (335) hide show
  1. package/README.md +7406 -3676
  2. package/es/index.js +3 -3
  3. package/es/index.js.map +1 -1
  4. package/es/internal.js +13 -2
  5. package/es/internal.js.map +1 -1
  6. package/es/src/charts/AreaPlot/index.js +1 -2
  7. package/es/src/charts/AreaPlot/index.js.map +1 -1
  8. package/es/src/charts/BarChart/index.js +9 -3
  9. package/es/src/charts/BarChart/index.js.map +1 -1
  10. package/es/src/charts/BoxWhisker/index.js +6 -2
  11. package/es/src/charts/BoxWhisker/index.js.map +1 -1
  12. package/es/src/charts/BumpChart/index.js +1 -2
  13. package/es/src/charts/BumpChart/index.js.map +1 -1
  14. package/es/src/charts/Chord/applyLayout.js +205 -0
  15. package/es/src/charts/Chord/applyLayout.js.map +1 -0
  16. package/es/src/charts/Chord/emit.js +220 -0
  17. package/es/src/charts/Chord/emit.js.map +1 -0
  18. package/es/src/charts/Chord/index.js +249 -0
  19. package/es/src/charts/Chord/index.js.map +1 -0
  20. package/es/src/charts/Geomap/applyLayout.js +17 -10
  21. package/es/src/charts/Geomap/applyLayout.js.map +1 -1
  22. package/es/src/charts/Geomap/basemapTheme.js +78 -0
  23. package/es/src/charts/Geomap/basemapTheme.js.map +1 -0
  24. package/es/src/charts/Geomap/emit.js +18 -9
  25. package/es/src/charts/Geomap/emit.js.map +1 -1
  26. package/es/src/charts/Geomap/index.js +74 -105
  27. package/es/src/charts/Geomap/index.js.map +1 -1
  28. package/es/src/charts/Histogram/binData.js +225 -0
  29. package/es/src/charts/Histogram/binData.js.map +1 -0
  30. package/es/src/charts/Histogram/index.js +271 -0
  31. package/es/src/charts/Histogram/index.js.map +1 -0
  32. package/es/src/charts/LinePlot/index.js +1 -2
  33. package/es/src/charts/LinePlot/index.js.map +1 -1
  34. package/es/src/charts/Matrix/emit.js +6 -0
  35. package/es/src/charts/Matrix/emit.js.map +1 -1
  36. package/es/src/charts/Matrix/index.js +1 -2
  37. package/es/src/charts/Matrix/index.js.map +1 -1
  38. package/es/src/charts/Network/applyLayout.js +52 -4
  39. package/es/src/charts/Network/applyLayout.js.map +1 -1
  40. package/es/src/charts/Network/emit.js +61 -27
  41. package/es/src/charts/Network/emit.js.map +1 -1
  42. package/es/src/charts/Network/index.js +40 -55
  43. package/es/src/charts/Network/index.js.map +1 -1
  44. package/es/src/charts/Pack/emit.js +40 -2
  45. package/es/src/charts/Pack/emit.js.map +1 -1
  46. package/es/src/charts/Pack/index.js +14 -2
  47. package/es/src/charts/Pack/index.js.map +1 -1
  48. package/es/src/charts/Pie/applyLayout.js +20 -2
  49. package/es/src/charts/Pie/applyLayout.js.map +1 -1
  50. package/es/src/charts/Pie/emit.js +277 -32
  51. package/es/src/charts/Pie/emit.js.map +1 -1
  52. package/es/src/charts/Pie/index.js +47 -3
  53. package/es/src/charts/Pie/index.js.map +1 -1
  54. package/es/src/charts/Plot/discreteSpan.js +42 -0
  55. package/es/src/charts/Plot/discreteSpan.js.map +1 -0
  56. package/es/src/charts/Plot/draw.js +3 -1
  57. package/es/src/charts/Plot/draw.js.map +1 -1
  58. package/es/src/charts/Plot/index.js +152 -17
  59. package/es/src/charts/Plot/index.js.map +1 -1
  60. package/es/src/charts/Plot/pipeline.js +48 -22
  61. package/es/src/charts/Plot/pipeline.js.map +1 -1
  62. package/es/src/charts/Plot/pipelineDomains.js +84 -8
  63. package/es/src/charts/Plot/pipelineDomains.js.map +1 -1
  64. package/es/src/charts/Plot/plotZoom.js +278 -0
  65. package/es/src/charts/Plot/plotZoom.js.map +1 -0
  66. package/es/src/charts/Plot/shapeDefaults.js +3 -3
  67. package/es/src/charts/Plot/shapeDefaults.js.map +1 -1
  68. package/es/src/charts/Plot/sharedHover.js +431 -0
  69. package/es/src/charts/Plot/sharedHover.js.map +1 -0
  70. package/es/src/charts/Plot/sharedHoverScene.js +230 -0
  71. package/es/src/charts/Plot/sharedHoverScene.js.map +1 -0
  72. package/es/src/charts/Plot/sharedTooltip.js +163 -0
  73. package/es/src/charts/Plot/sharedTooltip.js.map +1 -0
  74. package/es/src/charts/Plot/stackShareLabels.js +137 -0
  75. package/es/src/charts/Plot/stackShareLabels.js.map +1 -0
  76. package/es/src/charts/Plot/stackShareTooltip.js +31 -0
  77. package/es/src/charts/Plot/stackShareTooltip.js.map +1 -0
  78. package/es/src/charts/Plot/trendLines.js +367 -0
  79. package/es/src/charts/Plot/trendLines.js.map +1 -0
  80. package/es/src/charts/Plot/trendScene.js +220 -0
  81. package/es/src/charts/Plot/trendScene.js.map +1 -0
  82. package/es/src/charts/Plot/trendTooltip.js +160 -0
  83. package/es/src/charts/Plot/trendTooltip.js.map +1 -0
  84. package/es/src/charts/Priestley/emit.js +36 -3
  85. package/es/src/charts/Priestley/emit.js.map +1 -1
  86. package/es/src/charts/Priestley/index.js +1 -2
  87. package/es/src/charts/Priestley/index.js.map +1 -1
  88. package/es/src/charts/Radar/emit.js +4 -1
  89. package/es/src/charts/Radar/emit.js.map +1 -1
  90. package/es/src/charts/Radar/index.js +16 -4
  91. package/es/src/charts/Radar/index.js.map +1 -1
  92. package/es/src/charts/RadialMatrix/emit.js +6 -0
  93. package/es/src/charts/RadialMatrix/emit.js.map +1 -1
  94. package/es/src/charts/RadialMatrix/index.js +18 -3
  95. package/es/src/charts/RadialMatrix/index.js.map +1 -1
  96. package/es/src/charts/Rings/applyLayout.js +72 -116
  97. package/es/src/charts/Rings/applyLayout.js.map +1 -1
  98. package/es/src/charts/Rings/emit.js +75 -10
  99. package/es/src/charts/Rings/emit.js.map +1 -1
  100. package/es/src/charts/Rings/index.js +24 -5
  101. package/es/src/charts/Rings/index.js.map +1 -1
  102. package/es/src/charts/Rings/ringsSizing.js +189 -0
  103. package/es/src/charts/Rings/ringsSizing.js.map +1 -0
  104. package/es/src/charts/Sankey/emit.js +55 -11
  105. package/es/src/charts/Sankey/emit.js.map +1 -1
  106. package/es/src/charts/Sankey/index.js +8 -2
  107. package/es/src/charts/Sankey/index.js.map +1 -1
  108. package/es/src/charts/StackedArea/index.js +9 -3
  109. package/es/src/charts/StackedArea/index.js.map +1 -1
  110. package/es/src/charts/Tree/emit.js +10 -4
  111. package/es/src/charts/Tree/emit.js.map +1 -1
  112. package/es/src/charts/Tree/index.js +6 -5
  113. package/es/src/charts/Tree/index.js.map +1 -1
  114. package/es/src/charts/Treemap/emit.js +56 -3
  115. package/es/src/charts/Treemap/emit.js.map +1 -1
  116. package/es/src/charts/Treemap/index.js +1 -2
  117. package/es/src/charts/Treemap/index.js.map +1 -1
  118. package/es/src/charts/definition/ChartDefinition.js.map +1 -1
  119. package/es/src/charts/definition/makeChart.js +8 -1
  120. package/es/src/charts/definition/makeChart.js.map +1 -1
  121. package/es/src/charts/drawSteps/backControl.js +85 -0
  122. package/es/src/charts/drawSteps/backControl.js.map +1 -0
  123. package/es/src/charts/drawSteps/bottomRightControls.js +193 -0
  124. package/es/src/charts/drawSteps/bottomRightControls.js.map +1 -0
  125. package/es/src/charts/drawSteps/bottomRightControlsMarkup.js +161 -0
  126. package/es/src/charts/drawSteps/bottomRightControlsMarkup.js.map +1 -0
  127. package/es/src/charts/drawSteps/controlButtonStyle.js +108 -0
  128. package/es/src/charts/drawSteps/controlButtonStyle.js.map +1 -0
  129. package/es/src/charts/drawSteps/minimap.js +395 -0
  130. package/es/src/charts/drawSteps/minimap.js.map +1 -0
  131. package/es/src/charts/drawSteps/minimapMarkup.js +147 -0
  132. package/es/src/charts/drawSteps/minimapMarkup.js.map +1 -0
  133. package/es/src/charts/drawSteps/searchControls.js +358 -0
  134. package/es/src/charts/drawSteps/searchControls.js.map +1 -0
  135. package/es/src/charts/drawSteps/searchControlsMarkup.js +430 -0
  136. package/es/src/charts/drawSteps/searchControlsMarkup.js.map +1 -0
  137. package/es/src/charts/drawSteps/tableView.js +173 -0
  138. package/es/src/charts/drawSteps/tableView.js.map +1 -0
  139. package/es/src/charts/drawSteps/tableViewControl.js +39 -0
  140. package/es/src/charts/drawSteps/tableViewControl.js.map +1 -0
  141. package/es/src/charts/drawSteps/tableViewMarkup.js +647 -0
  142. package/es/src/charts/drawSteps/tableViewMarkup.js.map +1 -0
  143. package/es/src/charts/drawSteps/topLeftControls.js +73 -0
  144. package/es/src/charts/drawSteps/topLeftControls.js.map +1 -0
  145. package/es/src/charts/drawSteps/topLeftControlsMarkup.js +227 -0
  146. package/es/src/charts/drawSteps/topLeftControlsMarkup.js.map +1 -0
  147. package/es/src/charts/drawSteps/zoomControls.js +317 -175
  148. package/es/src/charts/drawSteps/zoomControls.js.map +1 -1
  149. package/es/src/charts/drawSteps/zoomControlsMarkup.js +280 -0
  150. package/es/src/charts/drawSteps/zoomControlsMarkup.js.map +1 -0
  151. package/es/src/charts/events/click.shape.js +24 -1
  152. package/es/src/charts/events/click.shape.js.map +1 -1
  153. package/es/src/charts/events/mouseenter.js +3 -0
  154. package/es/src/charts/events/mouseenter.js.map +1 -1
  155. package/es/src/charts/events/mouseleave.js +3 -0
  156. package/es/src/charts/events/mouseleave.js.map +1 -1
  157. package/es/src/charts/events/mousemove.shape.js +2 -0
  158. package/es/src/charts/events/mousemove.shape.js.map +1 -1
  159. package/es/src/charts/features/attributionFeature.js +137 -0
  160. package/es/src/charts/features/attributionFeature.js.map +1 -0
  161. package/es/src/charts/features/axes.js +24 -9
  162. package/es/src/charts/features/axes.js.map +1 -1
  163. package/es/src/charts/features/chartGeometry.js +16 -2
  164. package/es/src/charts/features/chartGeometry.js.map +1 -1
  165. package/es/src/charts/features/edgeArrows.js +155 -0
  166. package/es/src/charts/features/edgeArrows.js.map +1 -0
  167. package/es/src/charts/features/emitHelpers.js +32 -0
  168. package/es/src/charts/features/emitHelpers.js.map +1 -1
  169. package/es/src/charts/features/ensureZoomDom.js +63 -12
  170. package/es/src/charts/features/ensureZoomDom.js.map +1 -1
  171. package/es/src/charts/features/features.js +89 -112
  172. package/es/src/charts/features/features.js.map +1 -1
  173. package/es/src/charts/features/featuresLegend.js +53 -17
  174. package/es/src/charts/features/featuresLegend.js.map +1 -1
  175. package/es/src/charts/features/plotPaint.js +81 -29
  176. package/es/src/charts/features/plotPaint.js.map +1 -1
  177. package/es/src/charts/features/shapeEmit.js +20 -2
  178. package/es/src/charts/features/shapeEmit.js.map +1 -1
  179. package/es/src/charts/features/zoomExtent.js +185 -0
  180. package/es/src/charts/features/zoomExtent.js.map +1 -0
  181. package/es/src/charts/helpers/tileAttributions.js +26 -0
  182. package/es/src/charts/helpers/tileAttributions.js.map +1 -1
  183. package/es/src/charts/index.js +2 -0
  184. package/es/src/charts/index.js.map +1 -1
  185. package/es/src/charts/pipeline/drillMorph.js +159 -0
  186. package/es/src/charts/pipeline/drillMorph.js.map +1 -0
  187. package/es/src/charts/pipeline/runChartDraw.js +35 -1
  188. package/es/src/charts/pipeline/runChartDraw.js.map +1 -1
  189. package/es/src/charts/pipeline/runVizPipeline.js +49 -15
  190. package/es/src/charts/pipeline/runVizPipeline.js.map +1 -1
  191. package/es/src/charts/pipeline/vizDrawPure.js +52 -6
  192. package/es/src/charts/pipeline/vizDrawPure.js.map +1 -1
  193. package/es/src/charts/viz/Viz.js +103 -59
  194. package/es/src/charts/viz/Viz.js.map +1 -1
  195. package/es/src/charts/viz/VizBase.js +186 -5
  196. package/es/src/charts/viz/VizBase.js.map +1 -1
  197. package/es/src/charts/viz/VizBaseConfig.js +41 -3
  198. package/es/src/charts/viz/VizBaseConfig.js.map +1 -1
  199. package/es/src/charts/viz/ordinalColor.js +2 -2
  200. package/es/src/charts/viz/ordinalColor.js.map +1 -1
  201. package/es/src/charts/viz/vizDefaults.js +270 -58
  202. package/es/src/charts/viz/vizDefaults.js.map +1 -1
  203. package/es/src/charts/viz/vizRender.js +54 -4
  204. package/es/src/charts/viz/vizRender.js.map +1 -1
  205. package/es/src/charts/viz/vizTypes.js.map +1 -1
  206. package/es/src/charts/viz/vizVisibility.js +145 -0
  207. package/es/src/charts/viz/vizVisibility.js.map +1 -0
  208. package/es/src/components/Axis/Axis.js +18 -9
  209. package/es/src/components/Axis/Axis.js.map +1 -1
  210. package/es/src/components/Axis/axisLayoutLabels.js +2 -1
  211. package/es/src/components/Axis/axisLayoutLabels.js.map +1 -1
  212. package/es/src/components/Axis/axisRender.js +5 -1
  213. package/es/src/components/Axis/axisRender.js.map +1 -1
  214. package/es/src/components/ColorScale/ColorScale.js +11 -11
  215. package/es/src/components/ColorScale/ColorScale.js.map +1 -1
  216. package/es/src/components/ColorScale/colorScaleScale.js +22 -10
  217. package/es/src/components/ColorScale/colorScaleScale.js.map +1 -1
  218. package/es/src/components/Legend/Legend.js +8 -5
  219. package/es/src/components/Legend/Legend.js.map +1 -1
  220. package/es/src/components/Legend/legendConfig.js +87 -21
  221. package/es/src/components/Legend/legendConfig.js.map +1 -1
  222. package/es/src/components/Legend/legendRender.js +29 -22
  223. package/es/src/components/Legend/legendRender.js.map +1 -1
  224. package/es/src/components/SizeLegend/SizeLegend.js +411 -0
  225. package/es/src/components/SizeLegend/SizeLegend.js.map +1 -0
  226. package/es/src/components/SizeLegend/sizeLegendLayout.js +285 -0
  227. package/es/src/components/SizeLegend/sizeLegendLayout.js.map +1 -0
  228. package/es/src/components/Timeline/timelineConfig.js +8 -4
  229. package/es/src/components/Timeline/timelineConfig.js.map +1 -1
  230. package/es/src/components/Timeline/timelineRender.js +1 -2
  231. package/es/src/components/Timeline/timelineRender.js.map +1 -1
  232. package/es/src/components/Tooltip.js +27 -7
  233. package/es/src/components/Tooltip.js.map +1 -1
  234. package/es/src/components/index.js +1 -0
  235. package/es/src/components/index.js.map +1 -1
  236. package/es/src/shapes/Box.js +4 -2
  237. package/es/src/shapes/Box.js.map +1 -1
  238. package/es/src/shapes/Shape.js +1 -1
  239. package/es/src/shapes/Shape.js.map +1 -1
  240. package/es/src/shapes/Whisker.js +3 -2
  241. package/es/src/shapes/Whisker.js.map +1 -1
  242. package/es/src/shapes/validateShapeConfig.js +141 -0
  243. package/es/src/shapes/validateShapeConfig.js.map +1 -0
  244. package/es/src/utils/BaseClass.js +134 -4
  245. package/es/src/utils/BaseClass.js.map +1 -1
  246. package/es/src/utils/D3plusConfig.js.map +1 -1
  247. package/es/src/utils/configDefault.js +17 -0
  248. package/es/src/utils/configDefault.js.map +1 -0
  249. package/es/src/utils/configPrep.js +2 -1
  250. package/es/src/utils/configPrep.js.map +1 -1
  251. package/es/src/utils/configWarnings.js +37 -0
  252. package/es/src/utils/configWarnings.js.map +1 -0
  253. package/es/src/utils/index.js +1 -0
  254. package/es/src/utils/index.js.map +1 -1
  255. package/package.json +13 -11
  256. package/types/index.d.ts +4 -4
  257. package/types/internal.d.ts +16 -2
  258. package/types/src/charts/BarChart/index.d.ts +2 -1
  259. package/types/src/charts/Chord/applyLayout.d.ts +43 -0
  260. package/types/src/charts/Chord/emit.d.ts +10 -0
  261. package/types/src/charts/Chord/index.d.ts +19 -0
  262. package/types/src/charts/Geomap/applyLayout.d.ts +9 -1
  263. package/types/src/charts/Geomap/basemapTheme.d.ts +35 -0
  264. package/types/src/charts/Histogram/binData.d.ts +37 -0
  265. package/types/src/charts/Histogram/index.d.ts +14 -0
  266. package/types/src/charts/Network/applyLayout.d.ts +8 -0
  267. package/types/src/charts/Plot/discreteSpan.d.ts +9 -0
  268. package/types/src/charts/Plot/index.d.ts +51 -3
  269. package/types/src/charts/Plot/pipeline.d.ts +14 -0
  270. package/types/src/charts/Plot/plotZoom.d.ts +65 -0
  271. package/types/src/charts/Plot/sharedHover.d.ts +79 -0
  272. package/types/src/charts/Plot/sharedHoverScene.d.ts +11 -0
  273. package/types/src/charts/Plot/sharedTooltip.d.ts +26 -0
  274. package/types/src/charts/Plot/stackShareLabels.d.ts +21 -0
  275. package/types/src/charts/Plot/stackShareTooltip.d.ts +9 -0
  276. package/types/src/charts/Plot/trendLines.d.ts +70 -0
  277. package/types/src/charts/Plot/trendScene.d.ts +18 -0
  278. package/types/src/charts/Plot/trendTooltip.d.ts +19 -0
  279. package/types/src/charts/Rings/applyLayout.d.ts +9 -0
  280. package/types/src/charts/Rings/ringsSizing.d.ts +49 -0
  281. package/types/src/charts/StackedArea/index.d.ts +2 -1
  282. package/types/src/charts/definition/ChartDefinition.d.ts +33 -1
  283. package/types/src/charts/definition/makeChart.d.ts +2 -1
  284. package/types/src/charts/drawSteps/backControl.d.ts +29 -0
  285. package/types/src/charts/drawSteps/bottomRightControls.d.ts +26 -0
  286. package/types/src/charts/drawSteps/bottomRightControlsMarkup.d.ts +108 -0
  287. package/types/src/charts/drawSteps/controlButtonStyle.d.ts +45 -0
  288. package/types/src/charts/drawSteps/minimap.d.ts +19 -0
  289. package/types/src/charts/drawSteps/minimapMarkup.d.ts +45 -0
  290. package/types/src/charts/drawSteps/searchControls.d.ts +3 -0
  291. package/types/src/charts/drawSteps/searchControlsMarkup.d.ts +111 -0
  292. package/types/src/charts/drawSteps/tableView.d.ts +23 -0
  293. package/types/src/charts/drawSteps/tableViewControl.d.ts +21 -0
  294. package/types/src/charts/drawSteps/tableViewMarkup.d.ts +119 -0
  295. package/types/src/charts/drawSteps/topLeftControls.d.ts +32 -0
  296. package/types/src/charts/drawSteps/topLeftControlsMarkup.d.ts +72 -0
  297. package/types/src/charts/drawSteps/zoomControls.d.ts +48 -8
  298. package/types/src/charts/drawSteps/zoomControlsMarkup.d.ts +138 -0
  299. package/types/src/charts/features/attributionFeature.d.ts +21 -0
  300. package/types/src/charts/features/axes.d.ts +1 -1
  301. package/types/src/charts/features/chartGeometry.d.ts +9 -3
  302. package/types/src/charts/features/edgeArrows.d.ts +92 -0
  303. package/types/src/charts/features/emitHelpers.d.ts +19 -0
  304. package/types/src/charts/features/ensureZoomDom.d.ts +6 -2
  305. package/types/src/charts/features/features.d.ts +32 -17
  306. package/types/src/charts/features/featuresLegend.d.ts +15 -0
  307. package/types/src/charts/features/plotPaint.d.ts +40 -2
  308. package/types/src/charts/features/zoomExtent.d.ts +25 -0
  309. package/types/src/charts/index.d.ts +2 -0
  310. package/types/src/charts/pipeline/drillMorph.d.ts +29 -0
  311. package/types/src/charts/pipeline/runVizPipeline.d.ts +14 -3
  312. package/types/src/charts/viz/Viz.d.ts +18 -1
  313. package/types/src/charts/viz/VizBase.d.ts +99 -4
  314. package/types/src/charts/viz/VizBaseConfig.d.ts +25 -3
  315. package/types/src/charts/viz/vizDefaults.d.ts +155 -0
  316. package/types/src/charts/viz/vizTypes.d.ts +204 -4
  317. package/types/src/charts/viz/vizVisibility.d.ts +34 -0
  318. package/types/src/components/Axis/Axis.d.ts +2 -0
  319. package/types/src/components/Legend/legendRender.d.ts +8 -2
  320. package/types/src/components/SizeLegend/SizeLegend.d.ts +107 -0
  321. package/types/src/components/SizeLegend/sizeLegendLayout.d.ts +101 -0
  322. package/types/src/components/Tooltip.d.ts +18 -3
  323. package/types/src/components/index.d.ts +1 -0
  324. package/types/src/shapes/validateShapeConfig.d.ts +10 -0
  325. package/types/src/utils/BaseClass.d.ts +15 -1
  326. package/types/src/utils/D3plusConfig.d.ts +200 -8
  327. package/types/src/utils/configDefault.d.ts +11 -0
  328. package/types/src/utils/configWarnings.d.ts +28 -0
  329. package/types/src/utils/index.d.ts +2 -1
  330. package/umd/d3plus-core.full.js +44507 -35766
  331. package/umd/d3plus-core.full.js.map +1 -1
  332. package/umd/d3plus-core.full.min.js +7073 -4410
  333. package/umd/d3plus-core.js +16718 -9634
  334. package/umd/d3plus-core.js.map +1 -1
  335. package/umd/d3plus-core.min.js +4615 -2322
@@ -48,31 +48,83 @@ function _unsupported_iterable_to_array(o, minLen) {
48
48
  if (n === "Map" || n === "Set") return Array.from(n);
49
49
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
50
50
  }
51
- import { zoomTransform } from "d3-zoom";
51
+ import { select } from "d3-selection";
52
+ import { zoomIdentity, zoomTransform } from "d3-zoom";
52
53
  import { attrize } from "@d3plus/dom";
53
54
  import { chartBounds } from "../features/chartGeometry.js";
55
+ import { ensureZoomDom } from "../features/ensureZoomDom.js";
56
+ import { autoZoomMax } from "../features/zoomExtent.js";
57
+ import { isBrushing, mountCustomIcons, paintZoomButton, setBrushing, showsZoomControls, syncBrushButton, ZOOM_PANEL_STYLE, zoomControlsHtml } from "./zoomControlsMarkup.js";
58
+ import { refreshBottomRightPanel } from "./bottomRightControlsMarkup.js";
54
59
  /**
55
- Brush mode is per-chart, not global. Previously a module-level
56
- `let brushing = false` was shared across all chart instances on the
57
- page — toggling brush on chart A silently flipped chart B's state.
58
- Now lives on `viz._brushing` and is read/written via helpers.
59
- */ function isBrushing(viz) {
60
- return Boolean(viz._brushing);
61
- }
62
- function setBrushing(viz, value) {
63
- viz._brushing = value;
64
- }
65
- /**
66
- Apply a plain key/value style object to a real DOM element. v4 uses
67
- HtmlOverlay nodes for the zoom-control buttons, so the d3-selection
68
- `stylize` helper isn't reachable from the scene-graph escape hook.
69
- */ function applyStyleObj(el, styles) {
70
- if (!styles) return;
71
- for(var k in styles){
72
- var v = styles[k];
73
- if (v === undefined || v === null || v === false) continue;
74
- el.style[k] = String(v);
75
- }
60
+ Builds the four zoom-control buttons as an `htmlOverlay` scene-node
61
+ panel, pinned to the top-right corner of the whole chart (not the
62
+ margin-inset chart area) — top-positioned features leave room for it via
63
+ `zoomControlsBox`. Clicks ride the declarative `events` map (the
64
+ renderer delegates them from the host element, so they survive DOM
65
+ churn); hover can't be delegated (mouseenter/mouseleave don't bubble), so
66
+ `onUpdate` binds it per button. `onUpdate` (not `onMount`) because the
67
+ html isn't a fixed constant — it bakes in `zoomControlClassName`, the
68
+ locale's translated `aria-label`s, and the brush state, so those
69
+ changes swap in fresh button nodes on the next draw. The
70
+ `data-zoom-bound` guard styles, binds, and mounts each node's custom
71
+ icon (`zoomControlIcons`, if set) exactly once.
72
+ @private
73
+ */ function buildZoomControlPanel(viz) {
74
+ return {
75
+ type: "htmlOverlay",
76
+ key: "viz-zoom-controls",
77
+ x: 0,
78
+ y: 0,
79
+ width: viz.schema.width,
80
+ style: ZOOM_PANEL_STYLE,
81
+ className: "d3plus-zoom-control",
82
+ html: zoomControlsHtml(viz),
83
+ events: {
84
+ ".zoom-in": {
85
+ click: function click() {
86
+ return zoomMath.bind(viz)(viz.schema.zoomFactor);
87
+ }
88
+ },
89
+ ".zoom-out": {
90
+ click: function click() {
91
+ return zoomMath.bind(viz)(1 / viz.schema.zoomFactor);
92
+ }
93
+ },
94
+ ".zoom-reset": {
95
+ click: function click() {
96
+ return zoomMath.bind(viz)(0);
97
+ }
98
+ },
99
+ ".zoom-brush": {
100
+ click: function click(e) {
101
+ // Delegated dispatch: `e.currentTarget` is the host wrapper, so
102
+ // resolve the actual button from the event target.
103
+ var btn = e.target.closest(".zoom-brush");
104
+ if (!btn) return;
105
+ var willBrush = !isBrushing(viz);
106
+ btn.classList.toggle("active", willBrush);
107
+ btn.setAttribute("aria-pressed", String(willBrush));
108
+ paintZoomButton(viz, btn, btn.matches(":hover"));
109
+ zoomEvents.bind(viz)(willBrush);
110
+ }
111
+ }
112
+ },
113
+ onUpdate: function onUpdate(host) {
114
+ host.querySelectorAll(".zoom-control").forEach(function(btn) {
115
+ if (btn.dataset.zoomBound) return;
116
+ btn.dataset.zoomBound = "1";
117
+ paintZoomButton(viz, btn);
118
+ btn.addEventListener("mouseenter", function() {
119
+ return paintZoomButton(viz, btn, true);
120
+ });
121
+ btn.addEventListener("mouseleave", function() {
122
+ return paintZoomButton(viz, btn);
123
+ });
124
+ mountCustomIcons(viz, btn);
125
+ });
126
+ }
127
+ };
76
128
  }
77
129
  /**
78
130
  @name zoomFeature
@@ -90,115 +142,57 @@ function setBrushing(viz, value) {
90
142
  the SVG element directly via `viz._container.call(zoomBehavior)`.
91
143
  2. Returns the four control buttons (in/out/reset/brush) as an
92
144
  `htmlOverlay` scene-node panel; `runVizPipeline` appends it to
93
- `viz._featurePanels`. `onMount` is
94
- the scene's interactive-HTML escape hook: it wires the click/hover
95
- handlers + applies the user's zoomControl style configs. `onMount`
96
- fires ONCE per host element (after innerHTML is written, so the
97
- `.zoom-in` / `.zoom-out` querySelectors below resolve), not per
98
- draw — the html string is constant, so listeners attached here
99
- survive every subsequent draw (renderers only rewrite innerHTML
100
- when it differs from the current value).
145
+ `viz._featurePanels`. `onUpdate` is the scene's interactive-HTML
146
+ escape hook: it wires the hover handlers + applies the user's
147
+ zoomControl style configs, once per button DOM node (guarded by a
148
+ `data-zoom-bound` marker). Click handling instead rides the
149
+ declarative `events` map, which the renderer delegates from the
150
+ host element, so it survives DOM churn with no extra bookkeeping.
151
+ `onUpdate` (rather than `onMount`) matters because the html string
152
+ below isn't a fixed constant — it bakes in `zoomControlClassName`,
153
+ the active locale's translated `aria-label`s, and the current brush
154
+ state, so a `.locale(...)` or `.zoomControlClassName(...)` call
155
+ replaces the button nodes on the next draw. Renderers only rewrite
156
+ `innerHTML` when the string actually differs from the last-written
157
+ value, so the common case (nothing changed) is a cheap no-op.
101
158
  */ export var zoomFeature = {
102
159
  name: "zoom",
103
160
  layout: function layout(param) {
104
161
  var viz = param.viz;
162
+ if (!viz.schema.zoom) resetZoom(viz);
163
+ else ensureZoomSurface(viz);
105
164
  if (!viz._container || !viz._zoomGroup) return {
106
165
  panel: null,
107
166
  margin: {}
108
167
  };
109
168
  var bounds = chartBounds(viz);
110
- var height = viz._zoomHeight || bounds.height, that = viz, width = viz._zoomWidth || bounds.width;
111
- viz._zoomBehavior.extent([
169
+ var height = viz._zoomHeight || bounds.height, width = viz._zoomWidth || bounds.width;
170
+ // The zoom behavior works in the coordinate space of the element it's
171
+ // bound to — the outer <svg> (or the <canvas>, which shares its origin) —
172
+ // so the extent is the chart area's rect in that space, not a
173
+ // margin-relative [0, 0] → [width, height]. `Viz.toScene` applies the
174
+ // resulting transform above each chart's own positioning transform.
175
+ var _viz__margin = viz._margin, left = _viz__margin.left, top = _viz__margin.top;
176
+ var area = [
112
177
  [
113
- 0,
114
- 0
178
+ left,
179
+ top
115
180
  ],
116
181
  [
117
- width,
118
- height
182
+ left + width,
183
+ top + height
119
184
  ]
120
- ]).scaleExtent([
185
+ ];
186
+ viz._zoomBehavior.filter(function(event) {
187
+ return zoomGestureFilter(viz, event);
188
+ }).wheelDelta(wheelDelta).extent(area).scaleExtent([
121
189
  1,
122
- viz.schema.zoomMax
123
- ]).translateExtent([
124
- [
125
- 0,
126
- 0
127
- ],
128
- [
129
- width,
130
- height
131
- ]
132
- ]).on("zoom", function(event) {
190
+ zoomMax(viz, width, height)
191
+ ]).translateExtent(area).on("zoom", function(event) {
133
192
  return zoomed.bind(viz)(event.transform);
134
193
  });
135
194
  viz._zoomToBounds = zoomToBounds.bind(viz);
136
- var panel = null;
137
- if (viz.schema.zoom) {
138
- panel = {
139
- type: "htmlOverlay",
140
- key: "viz-zoom-controls",
141
- x: viz._margin.left,
142
- y: viz._margin.top,
143
- className: "d3plus-zoom-control",
144
- html: '<div class="zoom-control zoom-in">&#65291;</div>' + '<div class="zoom-control zoom-out">&#65293;</div>' + '<div class="zoom-control zoom-reset">&#8634;</div>' + '<div class="zoom-control zoom-brush">&#164;</div>',
145
- // Declarative click wiring — clicks bubble, so the renderer's
146
- // delegated dispatcher can route them by selector. The four
147
- // handlers below are the single source of truth for what each
148
- // zoom button does. Hover styles can't be delegated (mouseenter
149
- // / mouseleave don't bubble), so they live in onMount below as
150
- // a per-button binding.
151
- events: {
152
- ".zoom-in": {
153
- click: function click() {
154
- return zoomMath.bind(that)(that.schema.zoomFactor);
155
- }
156
- },
157
- ".zoom-out": {
158
- click: function click() {
159
- return zoomMath.bind(that)(1 / that.schema.zoomFactor);
160
- }
161
- },
162
- ".zoom-reset": {
163
- click: function click() {
164
- return zoomMath.bind(that)(0);
165
- }
166
- },
167
- ".zoom-brush": {
168
- click: function click(e) {
169
- // The overlay dispatches clicks via delegation, so `e.currentTarget`
170
- // is the host wrapper that encloses all four buttons — not the
171
- // clicked button. Styling/toggling the wrapper would paint the
172
- // active background around the whole control stack and offset it by
173
- // the base margin/border. Resolve the actual button from the event
174
- // target, the same way the dispatcher matches (`target.closest`).
175
- var btn = e.target.closest(".zoom-brush");
176
- if (!btn) return;
177
- var willBrush = !isBrushing(that);
178
- var isActive = btn.classList.toggle("active", willBrush);
179
- applyStyleObj(btn, isActive ? that.schema.zoomControlStyleActive || {} : that.schema.zoomControlStyle || {});
180
- zoomEvents.bind(that)(willBrush);
181
- }
182
- }
183
- },
184
- // onMount fires AFTER innerHTML is written so the querySelectorAll
185
- // matches. Applies base styles + binds non-delegable hover events
186
- // per button (mouseenter/mouseleave don't bubble through
187
- // delegated event listeners).
188
- onMount: function onMount(host) {
189
- var buttons = host.querySelectorAll(".zoom-control");
190
- buttons.forEach(function(btn) {
191
- applyStyleObj(btn, that.schema.zoomControlStyle || {});
192
- btn.addEventListener("mouseenter", function() {
193
- applyStyleObj(btn, that.schema.zoomControlStyleHover || {});
194
- });
195
- btn.addEventListener("mouseleave", function() {
196
- applyStyleObj(btn, btn.classList.contains("active") ? that.schema.zoomControlStyleActive || {} : that.schema.zoomControlStyle || {});
197
- });
198
- });
199
- }
200
- };
201
- }
195
+ var panel = showsZoomControls(viz) ? buildZoomControlPanel(viz) : null;
202
196
  viz._zoomBrush.extent([
203
197
  [
204
198
  0,
@@ -211,18 +205,111 @@ function setBrushing(viz, value) {
211
205
  ]).filter(function(event) {
212
206
  return !event.button && event.detail < 2;
213
207
  }).handleSize(viz.schema.zoomBrushHandleSize).on("start", brushStart.bind(viz)).on("brush", brushBrush.bind(viz)).on("end", brushEnd.bind(viz));
214
- var brushGroup = viz._container.selectAll("g.brush").data([
208
+ // The brush mounts in the outer <svg> above the painted scene (see
209
+ // `Viz._drawSceneToTarget`), not inside `_container` beneath it, so the
210
+ // selection box stays visible over the shapes while dragging. It's
211
+ // offset to the chart area, so selections come out chart-area-relative.
212
+ var brushGroup = viz._select.selectAll(":scope > g.d3plus-zoom-brush").data([
215
213
  0
216
214
  ]);
217
- viz._brushGroup = brushGroup.enter().append("g").attr("class", "brush").merge(brushGroup).call(viz._zoomBrush);
218
- zoomEvents.bind(viz)();
219
- if (viz._renderTiles) viz._renderTiles(zoomTransform((viz._zoomEventTarget || viz._container).node()), 0);
215
+ viz._brushGroup = brushGroup.enter().append("g").attr("class", "d3plus-zoom-brush").merge(brushGroup).attr("transform", "translate(".concat(left, ", ").concat(top, ")")).call(viz._zoomBrush);
216
+ zoomEvents.bind(viz)(isBrushing(viz));
217
+ if (viz._renderTiles) viz._renderTiles(tileZoomTransform(viz), 0);
220
218
  return {
221
219
  panel: panel,
222
220
  margin: {}
223
221
  };
224
222
  }
225
223
  };
224
+ /**
225
+ The maximum zoom scale: an explicit `zoomMax`, or — when unset — the scale
226
+ at which the chart's smallest shape fills the chart area.
227
+ @private
228
+ */ function zoomMax(viz, width, height) {
229
+ var _ref;
230
+ var _viz__chartTransform;
231
+ if (typeof viz.schema.zoomMax === "number") return viz.schema.zoomMax;
232
+ return autoZoomMax(viz._zoomShapes || viz._chartScene || [], width, height, viz.schema.zoomPadding, (_ref = (_viz__chartTransform = viz._chartTransform) === null || _viz__chartTransform === void 0 ? void 0 : _viz__chartTransform.scale) !== null && _ref !== void 0 ? _ref : 1);
233
+ }
234
+ /**
235
+ Mounts the DOM a zoomable chart needs: the `_container` <svg> hosting the
236
+ zoom brush (every chart but Network/Geomap, which mount their own
237
+ variants in `_draw`), and, on the SVG backend, points d3-zoom at the outer
238
+ <svg>. The scene paints into that same outer <svg>, so it receives wheel/
239
+ drag/dblclick both over painted shapes and over empty background. (The
240
+ Canvas backend binds the <canvas> instead — see `bindCanvasZoom`.)
241
+ @private
242
+ */ function ensureZoomSurface(viz) {
243
+ if (!viz._select) return;
244
+ if (!viz._ssr && (!viz._container || viz._container.classed("d3plus-zoom"))) {
245
+ var _chartBounds = chartBounds(viz), width = _chartBounds.width, height = _chartBounds.height;
246
+ ensureZoomDom(viz, {
247
+ kind: "generic",
248
+ width: width,
249
+ height: height,
250
+ duration: viz.schema.duration
251
+ });
252
+ }
253
+ if (viz._renderer !== "canvas") retargetZoom(viz, viz._select);
254
+ }
255
+ /**
256
+ Moves the d3-zoom listeners onto a new element, clearing them from the
257
+ previous target (and from `_container`, the default target) so a single
258
+ gesture is never zoomed twice.
259
+ @private
260
+ */ function retargetZoom(viz, target) {
261
+ var prev = viz._zoomEventTarget;
262
+ if (prev && prev.node() === target.node()) return;
263
+ if (prev) prev.on(".zoom", null);
264
+ if (viz._container) viz._container.on(".zoom", null);
265
+ viz._zoomEventTarget = target;
266
+ }
267
+ /**
268
+ Canvas backend: once the scene is painted (so the <canvas> exists), bind
269
+ d3-zoom to it. The compute <svg> overlaying the canvas is transparent to
270
+ pointer events there, so the canvas is the sole interaction surface —
271
+ CanvasRenderer's pick drives tooltips and d3-zoom drives pan/zoom on the
272
+ same element. Called after every canvas paint; a no-op once bound.
273
+ */ export function bindCanvasZoom(viz) {
274
+ if (!viz.schema.zoom || viz._ssr || !viz._zoomBehavior || !viz._brushGroup) return;
275
+ var renderer = viz._sceneRenderer;
276
+ var canvasNode = renderer && typeof renderer.toCanvas === "function" ? renderer.toCanvas() : null;
277
+ if (!canvasNode || viz._zoomEventTarget && viz._zoomEventTarget.node() === canvasNode) return;
278
+ retargetZoom(viz, select(canvasNode));
279
+ zoomEvents.bind(viz)(isBrushing(viz));
280
+ }
281
+ /**
282
+ Routes pointer events between the chart surface and the zoom brush.
283
+ While brush mode is on, the outer <svg> goes transparent to pointer
284
+ events and only the brush group opts back in, so a drag anywhere over the
285
+ chart (shapes included) reaches the brush rather than a shape. On the
286
+ Canvas backend the compute <svg> stays transparent otherwise, so the
287
+ <canvas> beneath is the interaction surface.
288
+ */ export function applyZoomPointerEvents(viz) {
289
+ var canvas = viz._renderer === "canvas";
290
+ var brushing = isBrushing(viz);
291
+ if (viz._select) viz._select.style("pointer-events", canvas || brushing ? "none" : null);
292
+ if (viz._container) viz._container.style("pointer-events", canvas ? "none" : null);
293
+ if (viz._brushGroup) viz._brushGroup.style("pointer-events", brushing ? "all" : null);
294
+ }
295
+ /**
296
+ The current zoom transform re-expressed for content inside `_container`,
297
+ which sits at the chart's margin offset rather than at the surface origin
298
+ the zoom behavior measures from (Geomap's imperative tile layer).
299
+ */ export function tileZoomTransform(viz) {
300
+ var t = zoomTransform((viz._zoomEventTarget || viz._container).node());
301
+ var _viz__margin = viz._margin, left = _viz__margin.left, top = _viz__margin.top;
302
+ return zoomIdentity.translate(t.x + (t.k - 1) * left, t.y + (t.k - 1) * top).scale(t.k);
303
+ }
304
+ /**
305
+ Drops any zoom left over from before `zoom` was turned off, so the chart
306
+ renders at its natural scale and a later re-enable starts from identity.
307
+ @private
308
+ */ function resetZoom(viz) {
309
+ viz._zoomTransform = undefined;
310
+ var tgt = viz._zoomEventTarget || viz._container;
311
+ if (tgt && tgt.node()) tgt.property("__zoom", zoomIdentity);
312
+ }
226
313
  /**
227
314
  @name zoomEvents
228
315
  Handles adding/removing zoom event listeners.
@@ -232,6 +319,7 @@ function setBrushing(viz, value) {
232
319
  setBrushing(this, brush);
233
320
  if (brush) this._brushGroup.style("display", "inline");
234
321
  else this._brushGroup.style("display", "none");
322
+ applyZoomPointerEvents(this);
235
323
  // The element d3-zoom binds its pointer listeners to. Defaults to the compute
236
324
  // `<svg>` container; on the Canvas backend it's the <canvas> (see
237
325
  // `bindCanvasZoom`), because the canvas is the interaction surface there —
@@ -243,6 +331,7 @@ function setBrushing(viz, value) {
243
331
  if (!this.schema.zoomScroll) {
244
332
  tgt.on("wheel.zoom", null);
245
333
  }
334
+ applyTouchAction(this);
246
335
  if (!this.schema.zoomPan) {
247
336
  tgt.on("mousedown.zoom mousemove.zoom", null).on("touchstart.zoom touchmove.zoom touchend.zoom touchcancel.zoom", null);
248
337
  }
@@ -250,6 +339,51 @@ function setBrushing(viz, value) {
250
339
  tgt.on(".zoom", null);
251
340
  }
252
341
  }
342
+ /** Whether the chart is currently zoomed in (or panned) from its natural view. */ function isZoomedIn(viz) {
343
+ var tgt = viz._zoomEventTarget || viz._container;
344
+ return Boolean(tgt && tgt.node() && zoomTransform(tgt.node()).k > 1);
345
+ }
346
+ /**
347
+ Which gestures d3-zoom acts on. With `zoomScroll: "modifier"` (the default
348
+ for charts embedded in a scrolling page), a chart doesn't capture the
349
+ page's own scrolling: a plain wheel scrolls the page and only Ctrl/⌘ +
350
+ wheel zooms (a trackpad pinch arrives as a Ctrl + wheel, so it zooms
351
+ too), and a one-finger touch scrolls the page while a two-finger pinch
352
+ zooms — until the chart is zoomed in, when one finger pans it. d3-zoom
353
+ registers every current touch when a gesture starts, so skipping the
354
+ first finger still gives a full pinch. Everything else follows d3-zoom's
355
+ default filter (no Ctrl + drag, primary button only).
356
+ @private
357
+ */ function zoomGestureFilter(viz, event) {
358
+ var _ref;
359
+ var _event_touches;
360
+ var modifier = viz.schema.zoomScroll === "modifier";
361
+ if (event.type === "wheel") return !modifier || event.ctrlKey || event.metaKey;
362
+ if (event.type === "touchstart" && modifier) return ((_ref = (_event_touches = event.touches) === null || _event_touches === void 0 ? void 0 : _event_touches.length) !== null && _ref !== void 0 ? _ref : 0) > 1 || isZoomedIn(viz);
363
+ return !event.ctrlKey && !event.button;
364
+ }
365
+ /**
366
+ d3-zoom's wheel-to-zoom rate, except that its 10× boost for Ctrl + wheel
367
+ only applies to a trackpad pinch (which browsers report as Ctrl + wheel
368
+ with small deltas). Now that Ctrl + wheel is how a mouse zooms a chart, a
369
+ mouse notch (~100px) held with Ctrl would otherwise jump 4× per notch.
370
+ @private
371
+ */ function wheelDelta(event) {
372
+ var pinch = event.ctrlKey && event.deltaMode === 0 && Math.abs(event.deltaY) < 50;
373
+ return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (pinch ? 10 : 1);
374
+ }
375
+ /**
376
+ Lets the browser keep one-finger page scrolling over a chart while
377
+ `zoomScroll` is "modifier" and the chart is at its natural view (a
378
+ pinch still reaches d3-zoom), and hands every touch to the chart once
379
+ it's zoomed in so one finger pans it.
380
+ @private
381
+ */ function applyTouchAction(viz) {
382
+ var tgt = viz._zoomEventTarget || viz._container;
383
+ if (!tgt) return;
384
+ var modifier = viz.schema.zoomScroll === "modifier" && viz.schema.zoomPan;
385
+ tgt.style("touch-action", modifier ? isZoomedIn(viz) ? "none" : "pan-x pan-y" : null);
386
+ }
253
387
  /**
254
388
  @name zoomed
255
389
  Handles events dispatched from this._zoomBehavior
@@ -268,14 +402,22 @@ function setBrushing(viz, value) {
268
402
  // what users see.
269
403
  var t = transform;
270
404
  if (t && (typeof t === "undefined" ? "undefined" : _type_of(t)) === "object" && "k" in t) {
271
- var _t_x, _t_y, _t_k;
405
+ var _t_k, _t_x, _t_y;
272
406
  // Nullish-coalesce rather than `||` so a legitimate zero (a deliberate
273
407
  // collapse-to-zero scale, or pan transform at origin) doesn't get
274
408
  // silently rewritten to the default.
275
- this._zoomTransform = {
409
+ var state = {
410
+ k: (_t_k = t.k) !== null && _t_k !== void 0 ? _t_k : 1,
276
411
  x: (_t_x = t.x) !== null && _t_x !== void 0 ? _t_x : 0,
277
- y: (_t_y = t.y) !== null && _t_y !== void 0 ? _t_y : 0,
278
- scale: (_t_k = t.k) !== null && _t_k !== void 0 ? _t_k : 1
412
+ y: (_t_y = t.y) !== null && _t_y !== void 0 ? _t_y : 0
413
+ };
414
+ // A chart can zoom its own way (Plot rescales its axes); otherwise the
415
+ // transform scales the rendered picture via `Viz.toScene`.
416
+ if (this._zoomRescale && this._zoomRescale(state, duration)) this._zoomTransform = undefined;
417
+ else this._zoomTransform = {
418
+ x: state.x,
419
+ y: state.y,
420
+ scale: state.k
279
421
  };
280
422
  } else if (t === false) {
281
423
  this._zoomTransform = undefined;
@@ -287,10 +429,13 @@ function setBrushing(viz, value) {
287
429
  // a 600 ms transition per event, causing visible lag + setTimeout
288
430
  // accumulation. Programmatic zooms (zoomMath, zoomToBounds) pass an
289
431
  // explicit duration when they want animation.
432
+ // The size legend relabels for the zoom (see `zoomSizeLegendScale`).
433
+ refreshBottomRightPanel(this);
290
434
  if (this._drawSceneToTarget && this._sceneRenderer) {
291
435
  this._drawSceneToTarget(duration);
292
436
  }
293
- if (this._renderTiles) this._renderTiles(zoomTransform((this._zoomEventTarget || this._container).node()), duration);
437
+ applyTouchAction(this);
438
+ if (this._renderTiles) this._renderTiles(tileZoomTransform(this), duration);
294
439
  }
295
440
  /**
296
441
  @name zoomMath
@@ -299,64 +444,48 @@ function setBrushing(viz, value) {
299
444
  */ function zoomMath() {
300
445
  var factor = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
301
446
  if (!this._container) return;
302
- var center = this._zoomBehavior.extent().bind(document)()[1].map(function(d) {
303
- return d / 2;
304
- }), scaleExtent = this._zoomBehavior.scaleExtent(), t = zoomTransform((this._zoomEventTarget || this._container).node());
305
- if (!factor) {
306
- t.k = scaleExtent[0];
307
- t.x = 0;
308
- t.y = 0;
309
- } else {
310
- var translate0 = [
311
- (center[0] - t.x) / t.k,
312
- (center[1] - t.y) / t.k
313
- ];
314
- t.k = Math.min(scaleExtent[1], t.k * factor);
315
- if (t.k <= scaleExtent[0]) {
316
- t.k = scaleExtent[0];
317
- t.x = 0;
318
- t.y = 0;
319
- } else {
320
- t.x += center[0] - (translate0[0] * t.k + t.x);
321
- t.y += center[1] - (translate0[1] * t.k + t.y);
322
- }
323
- }
324
- zoomed.bind(this)(t, this.schema.duration);
447
+ var _this__zoomBehavior_extent_bind = _sliced_to_array(this._zoomBehavior.extent().bind(document)(), 2), _this__zoomBehavior_extent_bind_ = _sliced_to_array(_this__zoomBehavior_extent_bind[0], 2), x0 = _this__zoomBehavior_extent_bind_[0], y0 = _this__zoomBehavior_extent_bind_[1], _this__zoomBehavior_extent_bind_1 = _sliced_to_array(_this__zoomBehavior_extent_bind[1], 2), x1 = _this__zoomBehavior_extent_bind_1[0], y1 = _this__zoomBehavior_extent_bind_1[1], cx = (x0 + x1) / 2, cy = (y0 + y1) / 2, t = zoomTransform((this._zoomEventTarget || this._container).node());
448
+ if (!factor) return zoomTo(this, 1, 0, 0);
449
+ // Scale about the chart area's center: keep the content point currently at
450
+ // the center fixed on screen.
451
+ var k = t.k * factor;
452
+ zoomTo(this, k, cx - (cx - t.x) / t.k * k, cy - (cy - t.y) / t.k * k);
453
+ }
454
+ /**
455
+ Applies a programmatic zoom: clamps the scale to `scaleExtent` and the
456
+ translate to `translateExtent` (the constraint d3-zoom enforces for
457
+ pointer gestures), records it as the bound element's zoom state so the
458
+ next wheel/drag continues from here, and paints it.
459
+
460
+ Exported so `minimap.ts`'s drag-to-pan and Cmd/Ctrl+scroll-to-zoom can
461
+ reuse the same scale/translate clamping instead of reimplementing it.
462
+ */ export function zoomTo(viz, scale, x, y) {
463
+ var duration = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : viz.schema.duration;
464
+ var _viz__zoomBehavior_scaleExtent = _sliced_to_array(viz._zoomBehavior.scaleExtent(), 2), kMin = _viz__zoomBehavior_scaleExtent[0], kMax = _viz__zoomBehavior_scaleExtent[1], _viz__zoomBehavior_translateExtent = _sliced_to_array(viz._zoomBehavior.translateExtent(), 2), _viz__zoomBehavior_translateExtent_ = _sliced_to_array(_viz__zoomBehavior_translateExtent[0], 2), x0 = _viz__zoomBehavior_translateExtent_[0], y0 = _viz__zoomBehavior_translateExtent_[1], _viz__zoomBehavior_translateExtent_1 = _sliced_to_array(_viz__zoomBehavior_translateExtent[1], 2), x1 = _viz__zoomBehavior_translateExtent_1[0], y1 = _viz__zoomBehavior_translateExtent_1[1], k = Math.max(kMin, Math.min(kMax, scale));
465
+ // Content must still cover the whole area: its left edge (x0·k + tx) can't
466
+ // move right of x0, nor its right edge (x1·k + tx) left of x1.
467
+ var tx = Math.max(x1 * (1 - k), Math.min(x0 * (1 - k), x)), ty = Math.max(y1 * (1 - k), Math.min(y0 * (1 - k), y));
468
+ // A fresh transform, never a mutation of `zoomTransform(node)`'s result —
469
+ // for an element d3-zoom hasn't stored state on yet, that's d3's shared
470
+ // `zoomIdentity` constant.
471
+ var t = zoomIdentity.translate(tx, ty).scale(k);
472
+ (viz._zoomEventTarget || viz._container).property("__zoom", t);
473
+ zoomed.bind(viz)(t, duration);
325
474
  }
326
475
  /**
327
476
  @name zoomToBounds
328
- Zooms to given bounds.
477
+ Zooms so the given on-screen bounds (surface pixels, as currently
478
+ displayed) fill the chart area, less `zoomPadding`. `null` resets.
329
479
  @param bounds
330
480
  @private
331
481
  */ function zoomToBounds(bounds) {
332
482
  var duration = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : this.schema.duration;
333
- var scaleExtent = this._zoomBehavior.scaleExtent(), t = zoomTransform((this._zoomEventTarget || this._container).node());
334
- if (bounds) {
335
- var _this__zoomBehavior_translateExtent_ = _sliced_to_array(this._zoomBehavior.translateExtent()[1], 2), width = _this__zoomBehavior_translateExtent_[0], height = _this__zoomBehavior_translateExtent_[1], dx = bounds[1][0] - bounds[0][0], dy = bounds[1][1] - bounds[0][1];
336
- var k = Math.min(scaleExtent[1], 1 / Math.max(dx / width, dy / height));
337
- var xMod, yMod;
338
- if (dx / dy < width / height) {
339
- k *= (height - this.schema.zoomPadding * 2) / height;
340
- xMod = (width - dx * k) / 2 / k;
341
- yMod = this.schema.zoomPadding / k;
342
- } else {
343
- k *= (width - this.schema.zoomPadding * 2) / width;
344
- yMod = (height - dy * k) / 2 / k;
345
- xMod = this.schema.zoomPadding / k;
346
- }
347
- t.x = (t.x - bounds[0][0] + xMod) * (t.k * k / t.k);
348
- t.y = (t.y - bounds[0][1] + yMod) * (t.k * k / t.k);
349
- t.k *= k;
350
- if (t.x > 0) t.x = 0;
351
- else if (t.x < width * -t.k + width) t.x = width * -t.k + width;
352
- if (t.y > 0) t.y = 0;
353
- else if (t.y < height * -t.k + height) t.y = height * -t.k + height;
354
- } else {
355
- t.k = scaleExtent[0];
356
- t.x = 0;
357
- t.y = 0;
358
- }
359
- zoomed.bind(this)(t, duration);
483
+ if (!bounds) return zoomTo(this, 1, 0, 0, duration);
484
+ var _this__zoomBehavior_translateExtent = _sliced_to_array(this._zoomBehavior.translateExtent(), 2), _this__zoomBehavior_translateExtent_ = _sliced_to_array(_this__zoomBehavior_translateExtent[0], 2), x0 = _this__zoomBehavior_translateExtent_[0], y0 = _this__zoomBehavior_translateExtent_[1], _this__zoomBehavior_translateExtent_1 = _sliced_to_array(_this__zoomBehavior_translateExtent[1], 2), x1 = _this__zoomBehavior_translateExtent_1[0], y1 = _this__zoomBehavior_translateExtent_1[1], pad = this.schema.zoomPadding, t = zoomTransform((this._zoomEventTarget || this._container).node()), // Un-apply the current transform: bounds → unzoomed surface space.
485
+ bx0 = (bounds[0][0] - t.x) / t.k, by0 = (bounds[0][1] - t.y) / t.k, bx1 = (bounds[1][0] - t.x) / t.k, by1 = (bounds[1][1] - t.y) / t.k;
486
+ var k = Math.min((x1 - x0 - pad * 2) / (bx1 - bx0), (y1 - y0 - pad * 2) / (by1 - by0));
487
+ // Center the bounds in the chart area.
488
+ zoomTo(this, k, (x0 + x1) / 2 - k * (bx0 + bx1) / 2, (y0 + y1) / 2 - k * (by0 + by1) / 2, duration);
360
489
  }
361
490
  /**
362
491
  Triggered on brush "brush".
@@ -370,7 +499,20 @@ function setBrushing(viz, value) {
370
499
  */ function brushEnd(event) {
371
500
  if (!event.selection) return; // Only transition after input.
372
501
  this._brushGroup.call(this._zoomBrush.move, null);
373
- zoomToBounds.bind(this)(event.selection);
502
+ // A selection is a one-shot zoom: leave brush mode so the chart takes
503
+ // pointer events (hover, pan, wheel) again.
504
+ zoomEvents.bind(this)(false);
505
+ syncBrushButton(this);
506
+ // The brush group is offset by the chart margin; shift its selection into
507
+ // the surface space `zoomToBounds` expects.
508
+ var _this__margin = this._margin, left = _this__margin.left, top = _this__margin.top;
509
+ zoomToBounds.bind(this)(event.selection.map(function(param) {
510
+ var _param = _sliced_to_array(param, 2), x = _param[0], y = _param[1];
511
+ return [
512
+ x + left,
513
+ y + top
514
+ ];
515
+ }));
374
516
  }
375
517
  /**
376
518
  Triggered on brush "start".