@octanejs/visx 0.1.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 (767) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -0
  3. package/UPSTREAM.md +52 -0
  4. package/package.json +161 -0
  5. package/src/a11y/components/ChartA11yAnnouncer.tsrx +40 -0
  6. package/src/a11y/components/ChartA11yAnnouncer.tsrx.d.ts +14 -0
  7. package/src/a11y/components/ChartA11yDataTable.tsrx +40 -0
  8. package/src/a11y/components/ChartA11yDataTable.tsrx.d.ts +9 -0
  9. package/src/a11y/generators/ariaProps.ts +79 -0
  10. package/src/a11y/generators/dataTableHTML.ts +24 -0
  11. package/src/a11y/generators/description.ts +125 -0
  12. package/src/a11y/index.ts +35 -0
  13. package/src/a11y/keyboard/stateMachine.ts +231 -0
  14. package/src/a11y/react/index.ts +59 -0
  15. package/src/a11y/server.ts +29 -0
  16. package/src/a11y/types.ts +104 -0
  17. package/src/a11y/useChartA11y.tsrx +144 -0
  18. package/src/a11y/useChartA11y.tsrx.d.ts +27 -0
  19. package/src/a11y/useChartKeyboardNav.tsrx +234 -0
  20. package/src/a11y/useChartKeyboardNav.tsrx.d.ts +26 -0
  21. package/src/a11y/utils/data.ts +80 -0
  22. package/src/a11y/utils/format.ts +73 -0
  23. package/src/a11y/utils/table.ts +81 -0
  24. package/src/annotation/components/Annotation.tsrx +14 -0
  25. package/src/annotation/components/Annotation.tsrx.d.ts +8 -0
  26. package/src/annotation/components/CircleSubject.tsrx +37 -0
  27. package/src/annotation/components/CircleSubject.tsrx.d.ts +12 -0
  28. package/src/annotation/components/Connector.tsrx +75 -0
  29. package/src/annotation/components/Connector.tsrx.d.ts +14 -0
  30. package/src/annotation/components/EditableAnnotation.tsrx +179 -0
  31. package/src/annotation/components/EditableAnnotation.tsrx.d.ts +33 -0
  32. package/src/annotation/components/HtmlLabel.tsrx +93 -0
  33. package/src/annotation/components/HtmlLabel.tsrx.d.ts +10 -0
  34. package/src/annotation/components/Label.tsrx +249 -0
  35. package/src/annotation/components/Label.tsrx.d.ts +60 -0
  36. package/src/annotation/components/LabelAnchorLine.tsrx +32 -0
  37. package/src/annotation/components/LabelAnchorLine.tsrx.d.ts +12 -0
  38. package/src/annotation/components/LineSubject.tsrx +50 -0
  39. package/src/annotation/components/LineSubject.tsrx.d.ts +21 -0
  40. package/src/annotation/context/AnnotationContext.tsrx +6 -0
  41. package/src/annotation/context/AnnotationContext.tsrx.d.ts +4 -0
  42. package/src/annotation/index.ts +18 -0
  43. package/src/annotation/types/index.ts +10 -0
  44. package/src/axis/axis/Axis.tsrx +54 -0
  45. package/src/axis/axis/Axis.tsrx.d.ts +7 -0
  46. package/src/axis/axis/AxisBottom.tsrx +37 -0
  47. package/src/axis/axis/AxisBottom.tsrx.d.ts +10 -0
  48. package/src/axis/axis/AxisLeft.tsrx +37 -0
  49. package/src/axis/axis/AxisLeft.tsrx.d.ts +11 -0
  50. package/src/axis/axis/AxisRenderer.tsrx +102 -0
  51. package/src/axis/axis/AxisRenderer.tsrx.d.ts +3 -0
  52. package/src/axis/axis/AxisRight.tsrx +39 -0
  53. package/src/axis/axis/AxisRight.tsrx.d.ts +12 -0
  54. package/src/axis/axis/AxisTop.tsrx +38 -0
  55. package/src/axis/axis/AxisTop.tsrx.d.ts +11 -0
  56. package/src/axis/axis/Ticks.tsrx +56 -0
  57. package/src/axis/axis/Ticks.tsrx.d.ts +3 -0
  58. package/src/axis/constants/orientation.ts +12 -0
  59. package/src/axis/index.ts +10 -0
  60. package/src/axis/react/index.ts +5 -0
  61. package/src/axis/react/useAxis.tsrx +89 -0
  62. package/src/axis/react/useAxis.tsrx.d.ts +13 -0
  63. package/src/axis/types.ts +145 -0
  64. package/src/axis/utils/createPoint.ts +5 -0
  65. package/src/axis/utils/getAxisRangePaddingConfig.ts +11 -0
  66. package/src/axis/utils/getLabelTransform.ts +44 -0
  67. package/src/axis/utils/getTickFormatter.ts +19 -0
  68. package/src/axis/utils/getTickPosition.ts +28 -0
  69. package/src/bounds/enhancers/withBoundingRects.tsrx +59 -0
  70. package/src/bounds/enhancers/withBoundingRects.tsrx.d.ts +21 -0
  71. package/src/bounds/index.ts +6 -0
  72. package/src/brush/BaseBrush.tsrx +567 -0
  73. package/src/brush/BaseBrush.tsrx.d.ts +39 -0
  74. package/src/brush/Brush.tsrx +217 -0
  75. package/src/brush/Brush.tsrx.d.ts +56 -0
  76. package/src/brush/BrushCorner.tsrx +173 -0
  77. package/src/brush/BrushCorner.tsrx.d.ts +21 -0
  78. package/src/brush/BrushHandle.tsrx +222 -0
  79. package/src/brush/BrushHandle.tsrx.d.ts +33 -0
  80. package/src/brush/BrushOverlay.tsrx +18 -0
  81. package/src/brush/BrushOverlay.tsrx.d.ts +15 -0
  82. package/src/brush/BrushSelection.tsrx +181 -0
  83. package/src/brush/BrushSelection.tsrx.d.ts +27 -0
  84. package/src/brush/index.ts +9 -0
  85. package/src/brush/types.ts +62 -0
  86. package/src/brush/utils.ts +89 -0
  87. package/src/chart/config.ts +50 -0
  88. package/src/chart/domains.ts +47 -0
  89. package/src/chart/index.ts +33 -0
  90. package/src/chart/responsive.ts +3 -0
  91. package/src/chart/ticks.ts +90 -0
  92. package/src/chart/useChartDimensions.tsrx +74 -0
  93. package/src/chart/useChartDimensions.tsrx.d.ts +28 -0
  94. package/src/chord/Chord.tsrx +42 -0
  95. package/src/chord/Chord.tsrx.d.ts +22 -0
  96. package/src/chord/Ribbon.tsrx +63 -0
  97. package/src/chord/Ribbon.tsrx.d.ts +26 -0
  98. package/src/chord/index.ts +6 -0
  99. package/src/clip-path/clip-paths/CircleClipPath.tsrx +26 -0
  100. package/src/clip-path/clip-paths/CircleClipPath.tsrx.d.ts +14 -0
  101. package/src/clip-path/clip-paths/ClipPath.tsrx +21 -0
  102. package/src/clip-path/clip-paths/ClipPath.tsrx.d.ts +10 -0
  103. package/src/clip-path/clip-paths/RectClipPath.tsrx +28 -0
  104. package/src/clip-path/clip-paths/RectClipPath.tsrx.d.ts +15 -0
  105. package/src/clip-path/index.ts +4 -0
  106. package/src/curve/index.ts +21 -0
  107. package/src/delaunay/components/Polygon.tsrx +32 -0
  108. package/src/delaunay/components/Polygon.tsrx.d.ts +14 -0
  109. package/src/delaunay/delaunay.ts +17 -0
  110. package/src/delaunay/index.ts +4 -0
  111. package/src/delaunay/voronoi.ts +30 -0
  112. package/src/drag/Drag.tsrx +66 -0
  113. package/src/drag/Drag.tsrx.d.ts +17 -0
  114. package/src/drag/index.ts +13 -0
  115. package/src/drag/useDrag.tsrx +214 -0
  116. package/src/drag/useDrag.tsrx.d.ts +60 -0
  117. package/src/drag/util/clampNumber.ts +4 -0
  118. package/src/drag/util/getClosestPoint.ts +13 -0
  119. package/src/drag/util/raise.ts +8 -0
  120. package/src/drag/util/restrictPoint.ts +18 -0
  121. package/src/drag/util/useSamplesAlongPath.tsrx +26 -0
  122. package/src/drag/util/useSamplesAlongPath.tsrx.d.ts +3 -0
  123. package/src/drag/util/useStateWithCallback.tsrx +26 -0
  124. package/src/drag/util/useStateWithCallback.tsrx.d.ts +5 -0
  125. package/src/event/getXAndYFromEvent.ts +36 -0
  126. package/src/event/index.ts +3 -0
  127. package/src/event/localPoint.ts +18 -0
  128. package/src/event/localPointGeneric.ts +34 -0
  129. package/src/event/touchPoint.ts +2 -0
  130. package/src/event/typeGuards.ts +37 -0
  131. package/src/event/types.ts +13 -0
  132. package/src/external.d.ts +3 -0
  133. package/src/geo/graticule/Graticule.tsrx +97 -0
  134. package/src/geo/graticule/Graticule.tsrx.d.ts +52 -0
  135. package/src/geo/index.ts +13 -0
  136. package/src/geo/projections/Albers.tsrx +10 -0
  137. package/src/geo/projections/Albers.tsrx.d.ts +7 -0
  138. package/src/geo/projections/AlbersUsa.tsrx +10 -0
  139. package/src/geo/projections/AlbersUsa.tsrx.d.ts +7 -0
  140. package/src/geo/projections/CustomProjection.tsrx +10 -0
  141. package/src/geo/projections/CustomProjection.tsrx.d.ts +7 -0
  142. package/src/geo/projections/EqualEarth.tsrx +10 -0
  143. package/src/geo/projections/EqualEarth.tsrx.d.ts +7 -0
  144. package/src/geo/projections/Mercator.tsrx +10 -0
  145. package/src/geo/projections/Mercator.tsrx.d.ts +7 -0
  146. package/src/geo/projections/NaturalEarth.tsrx +10 -0
  147. package/src/geo/projections/NaturalEarth.tsrx.d.ts +7 -0
  148. package/src/geo/projections/Orthographic.tsrx +10 -0
  149. package/src/geo/projections/Orthographic.tsrx.d.ts +7 -0
  150. package/src/geo/projections/Projection.tsrx +201 -0
  151. package/src/geo/projections/Projection.tsrx.d.ts +86 -0
  152. package/src/geo/types.ts +14 -0
  153. package/src/glyph/glyphs/Glyph.tsrx +18 -0
  154. package/src/glyph/glyphs/Glyph.tsrx.d.ts +13 -0
  155. package/src/glyph/glyphs/GlyphCircle.tsrx +46 -0
  156. package/src/glyph/glyphs/GlyphCircle.tsrx.d.ts +18 -0
  157. package/src/glyph/glyphs/GlyphCross.tsrx +46 -0
  158. package/src/glyph/glyphs/GlyphCross.tsrx.d.ts +18 -0
  159. package/src/glyph/glyphs/GlyphDiamond.tsrx +46 -0
  160. package/src/glyph/glyphs/GlyphDiamond.tsrx.d.ts +18 -0
  161. package/src/glyph/glyphs/GlyphDot.tsrx +29 -0
  162. package/src/glyph/glyphs/GlyphDot.tsrx.d.ts +17 -0
  163. package/src/glyph/glyphs/GlyphSquare.tsrx +46 -0
  164. package/src/glyph/glyphs/GlyphSquare.tsrx.d.ts +18 -0
  165. package/src/glyph/glyphs/GlyphStar.tsrx +45 -0
  166. package/src/glyph/glyphs/GlyphStar.tsrx.d.ts +18 -0
  167. package/src/glyph/glyphs/GlyphTriangle.tsrx +46 -0
  168. package/src/glyph/glyphs/GlyphTriangle.tsrx.d.ts +18 -0
  169. package/src/glyph/glyphs/GlyphWye.tsrx +45 -0
  170. package/src/glyph/glyphs/GlyphWye.tsrx.d.ts +18 -0
  171. package/src/glyph/index.ts +20 -0
  172. package/src/gradient/gradients/GradientDarkgreenGreen.tsrx +13 -0
  173. package/src/gradient/gradients/GradientDarkgreenGreen.tsrx.d.ts +6 -0
  174. package/src/gradient/gradients/GradientLightgreenGreen.tsrx +13 -0
  175. package/src/gradient/gradients/GradientLightgreenGreen.tsrx.d.ts +6 -0
  176. package/src/gradient/gradients/GradientOrangeRed.tsrx +13 -0
  177. package/src/gradient/gradients/GradientOrangeRed.tsrx.d.ts +6 -0
  178. package/src/gradient/gradients/GradientPinkBlue.tsrx +13 -0
  179. package/src/gradient/gradients/GradientPinkBlue.tsrx.d.ts +6 -0
  180. package/src/gradient/gradients/GradientPinkRed.tsrx +13 -0
  181. package/src/gradient/gradients/GradientPinkRed.tsrx.d.ts +6 -0
  182. package/src/gradient/gradients/GradientPurpleOrange.tsrx +13 -0
  183. package/src/gradient/gradients/GradientPurpleOrange.tsrx.d.ts +6 -0
  184. package/src/gradient/gradients/GradientPurpleRed.tsrx +13 -0
  185. package/src/gradient/gradients/GradientPurpleRed.tsrx.d.ts +6 -0
  186. package/src/gradient/gradients/GradientPurpleTeal.tsrx +13 -0
  187. package/src/gradient/gradients/GradientPurpleTeal.tsrx.d.ts +6 -0
  188. package/src/gradient/gradients/GradientSteelPurple.tsrx +13 -0
  189. package/src/gradient/gradients/GradientSteelPurple.tsrx.d.ts +6 -0
  190. package/src/gradient/gradients/GradientTealBlue.tsrx +13 -0
  191. package/src/gradient/gradients/GradientTealBlue.tsrx.d.ts +6 -0
  192. package/src/gradient/gradients/LinearGradient.tsrx +85 -0
  193. package/src/gradient/gradients/LinearGradient.tsrx.d.ts +37 -0
  194. package/src/gradient/gradients/RadialGradient.tsrx +43 -0
  195. package/src/gradient/gradients/RadialGradient.tsrx.d.ts +5 -0
  196. package/src/gradient/index.ts +16 -0
  197. package/src/grid/grids/Grid.tsrx +86 -0
  198. package/src/grid/grids/Grid.tsrx.d.ts +30 -0
  199. package/src/grid/grids/GridAngle.tsrx +74 -0
  200. package/src/grid/grids/GridAngle.tsrx.d.ts +29 -0
  201. package/src/grid/grids/GridColumns.tsrx +76 -0
  202. package/src/grid/grids/GridColumns.tsrx.d.ts +18 -0
  203. package/src/grid/grids/GridPolar.tsrx +189 -0
  204. package/src/grid/grids/GridPolar.tsrx.d.ts +123 -0
  205. package/src/grid/grids/GridRadial.tsrx +92 -0
  206. package/src/grid/grids/GridRadial.tsrx.d.ts +44 -0
  207. package/src/grid/grids/GridRows.tsrx +76 -0
  208. package/src/grid/grids/GridRows.tsrx.d.ts +18 -0
  209. package/src/grid/index.ts +11 -0
  210. package/src/grid/types.ts +40 -0
  211. package/src/grid/utils/getScaleBandwidth.ts +5 -0
  212. package/src/grid/utils/polarToCartesian.ts +16 -0
  213. package/src/group/Group.tsrx +33 -0
  214. package/src/group/Group.tsrx.d.ts +16 -0
  215. package/src/group/index.ts +2 -0
  216. package/src/heatmap/heatmaps/HeatmapCircle.tsrx +109 -0
  217. package/src/heatmap/heatmaps/HeatmapCircle.tsrx.d.ts +44 -0
  218. package/src/heatmap/heatmaps/HeatmapRect.tsrx +121 -0
  219. package/src/heatmap/heatmaps/HeatmapRect.tsrx.d.ts +49 -0
  220. package/src/heatmap/index.ts +11 -0
  221. package/src/heatmap/types.ts +22 -0
  222. package/src/hierarchy/HierarchyDefaultLink.tsrx +19 -0
  223. package/src/hierarchy/HierarchyDefaultLink.tsrx.d.ts +13 -0
  224. package/src/hierarchy/HierarchyDefaultNode.tsrx +7 -0
  225. package/src/hierarchy/HierarchyDefaultNode.tsrx.d.ts +9 -0
  226. package/src/hierarchy/HierarchyDefaultRectNode.tsrx +7 -0
  227. package/src/hierarchy/HierarchyDefaultRectNode.tsrx.d.ts +10 -0
  228. package/src/hierarchy/hierarchies/Cluster.tsrx +81 -0
  229. package/src/hierarchy/hierarchies/Cluster.tsrx.d.ts +40 -0
  230. package/src/hierarchy/hierarchies/Pack.tsrx +69 -0
  231. package/src/hierarchy/hierarchies/Pack.tsrx.d.ts +35 -0
  232. package/src/hierarchy/hierarchies/Partition.tsrx +62 -0
  233. package/src/hierarchy/hierarchies/Partition.tsrx.d.ts +27 -0
  234. package/src/hierarchy/hierarchies/Tree.tsrx +82 -0
  235. package/src/hierarchy/hierarchies/Tree.tsrx.d.ts +43 -0
  236. package/src/hierarchy/hierarchies/Treemap.tsrx +97 -0
  237. package/src/hierarchy/hierarchies/Treemap.tsrx.d.ts +47 -0
  238. package/src/hierarchy/index.ts +26 -0
  239. package/src/hierarchy/types.ts +21 -0
  240. package/src/hierarchy/utils/setNumOrNumAccessor.ts +11 -0
  241. package/src/index.ts +74 -0
  242. package/src/internal/spring.tsrx +190 -0
  243. package/src/internal/spring.tsrx.d.ts +28 -0
  244. package/src/internal/useMeasure.tsrx +120 -0
  245. package/src/internal/useMeasure.tsrx.d.ts +22 -0
  246. package/src/kernel/accessors/normalizeAccessor.ts +59 -0
  247. package/src/kernel/domain/useDomain.tsrx +111 -0
  248. package/src/kernel/domain/useDomain.tsrx.d.ts +13 -0
  249. package/src/kernel/format/formatNumber.ts +8 -0
  250. package/src/kernel/ids/useStableId.tsrx +7 -0
  251. package/src/kernel/ids/useStableId.tsrx.d.ts +2 -0
  252. package/src/kernel/index.ts +25 -0
  253. package/src/kernel/memo/shallowEqual.ts +65 -0
  254. package/src/kernel/memo/useStructuralMemo.tsrx +18 -0
  255. package/src/kernel/memo/useStructuralMemo.tsrx.d.ts +3 -0
  256. package/src/kernel/path/createPath.ts +132 -0
  257. package/src/kernel/path/toPath2D.ts +41 -0
  258. package/src/kernel/refs/useLatestRef.tsrx +7 -0
  259. package/src/kernel/refs/useLatestRef.tsrx.d.ts +4 -0
  260. package/src/kernel/refs/useStableCallback.tsrx +13 -0
  261. package/src/kernel/refs/useStableCallback.tsrx.d.ts +2 -0
  262. package/src/kernel/warnings.ts +76 -0
  263. package/src/legend/index.ts +27 -0
  264. package/src/legend/legends/Legend/LegendItem.tsrx +35 -0
  265. package/src/legend/legends/Legend/LegendItem.tsrx.d.ts +16 -0
  266. package/src/legend/legends/Legend/LegendLabel.tsrx +39 -0
  267. package/src/legend/legends/Legend/LegendLabel.tsrx.d.ts +16 -0
  268. package/src/legend/legends/Legend/LegendShape.tsrx +64 -0
  269. package/src/legend/legends/Legend/LegendShape.tsrx.d.ts +25 -0
  270. package/src/legend/legends/Legend/index.tsrx +140 -0
  271. package/src/legend/legends/Legend/index.tsrx.d.ts +50 -0
  272. package/src/legend/legends/Linear.tsrx +23 -0
  273. package/src/legend/legends/Linear.tsrx.d.ts +11 -0
  274. package/src/legend/legends/Ordinal.tsrx +13 -0
  275. package/src/legend/legends/Ordinal.tsrx.d.ts +8 -0
  276. package/src/legend/legends/Quantile.tsrx +53 -0
  277. package/src/legend/legends/Quantile.tsrx.d.ts +12 -0
  278. package/src/legend/legends/Size.tsrx +37 -0
  279. package/src/legend/legends/Size.tsrx.d.ts +14 -0
  280. package/src/legend/legends/Threshold.tsrx +108 -0
  281. package/src/legend/legends/Threshold.tsrx.d.ts +23 -0
  282. package/src/legend/shapes/Circle.tsrx +27 -0
  283. package/src/legend/shapes/Circle.tsrx.d.ts +13 -0
  284. package/src/legend/shapes/Line.tsrx +33 -0
  285. package/src/legend/shapes/Line.tsrx.d.ts +13 -0
  286. package/src/legend/shapes/Rect.tsrx +23 -0
  287. package/src/legend/shapes/Rect.tsrx.d.ts +13 -0
  288. package/src/legend/types/index.ts +64 -0
  289. package/src/legend/util/defaultDomain.ts +21 -0
  290. package/src/legend/util/identity.ts +3 -0
  291. package/src/legend/util/labelTransformFactory.ts +18 -0
  292. package/src/legend/util/renderShape.ts +67 -0
  293. package/src/legend/util/valueOrIdentity.ts +12 -0
  294. package/src/marker/index.ts +9 -0
  295. package/src/marker/markers/Arrow.tsrx +30 -0
  296. package/src/marker/markers/Arrow.tsrx.d.ts +3 -0
  297. package/src/marker/markers/Circle.tsrx +26 -0
  298. package/src/marker/markers/Circle.tsrx.d.ts +3 -0
  299. package/src/marker/markers/Cross.tsrx +27 -0
  300. package/src/marker/markers/Cross.tsrx.d.ts +3 -0
  301. package/src/marker/markers/Line.tsrx +29 -0
  302. package/src/marker/markers/Line.tsrx.d.ts +3 -0
  303. package/src/marker/markers/Marker.tsrx +46 -0
  304. package/src/marker/markers/Marker.tsrx.d.ts +25 -0
  305. package/src/marker/markers/X.tsrx +6 -0
  306. package/src/marker/markers/X.tsrx.d.ts +3 -0
  307. package/src/mock-data/generators/genBin.ts +28 -0
  308. package/src/mock-data/generators/genBins.ts +27 -0
  309. package/src/mock-data/generators/genDateValue.ts +22 -0
  310. package/src/mock-data/generators/genPhyllotaxis.ts +27 -0
  311. package/src/mock-data/generators/genRandomNormalPoints.ts +32 -0
  312. package/src/mock-data/generators/genStats.ts +96 -0
  313. package/src/mock-data/generators/getSeededRandom.ts +9 -0
  314. package/src/mock-data/index.ts +40 -0
  315. package/src/mock-data/mocks/appleStock.ts +1289 -0
  316. package/src/mock-data/mocks/bitcoinPrice.ts +382 -0
  317. package/src/mock-data/mocks/browserUsage.ts +4053 -0
  318. package/src/mock-data/mocks/cityTemperature.ts +2207 -0
  319. package/src/mock-data/mocks/exoplanets.ts +5295 -0
  320. package/src/mock-data/mocks/groupDateValue.ts +22 -0
  321. package/src/mock-data/mocks/lesMiserables.ts +355 -0
  322. package/src/mock-data/mocks/letterFrequency.ts +35 -0
  323. package/src/mock-data/mocks/planets.ts +55 -0
  324. package/src/mock-data/mocks/shakespeare.ts +1870 -0
  325. package/src/network/DefaultLink.tsrx +16 -0
  326. package/src/network/DefaultLink.tsrx.d.ts +3 -0
  327. package/src/network/DefaultNode.tsrx +16 -0
  328. package/src/network/DefaultNode.tsrx.d.ts +9 -0
  329. package/src/network/Graph.tsrx +43 -0
  330. package/src/network/Graph.tsrx.d.ts +16 -0
  331. package/src/network/Links.tsrx +27 -0
  332. package/src/network/Links.tsrx.d.ts +12 -0
  333. package/src/network/Nodes.tsrx +41 -0
  334. package/src/network/Nodes.tsrx.d.ts +17 -0
  335. package/src/network/index.ts +11 -0
  336. package/src/network/types.ts +22 -0
  337. package/src/pattern/constants/index.ts +8 -0
  338. package/src/pattern/index.ts +16 -0
  339. package/src/pattern/patterns/Circles.tsrx +78 -0
  340. package/src/pattern/patterns/Circles.tsrx.d.ts +26 -0
  341. package/src/pattern/patterns/Hexagons.tsrx +63 -0
  342. package/src/pattern/patterns/Hexagons.tsrx.d.ts +26 -0
  343. package/src/pattern/patterns/Lines.tsrx +95 -0
  344. package/src/pattern/patterns/Lines.tsrx.d.ts +31 -0
  345. package/src/pattern/patterns/Path.tsrx +58 -0
  346. package/src/pattern/patterns/Path.tsrx.d.ts +28 -0
  347. package/src/pattern/patterns/Pattern.tsrx +25 -0
  348. package/src/pattern/patterns/Pattern.tsrx.d.ts +13 -0
  349. package/src/pattern/patterns/Waves.tsrx +69 -0
  350. package/src/pattern/patterns/Waves.tsrx.d.ts +26 -0
  351. package/src/point/Point.ts +20 -0
  352. package/src/point/index.ts +4 -0
  353. package/src/point/subtractPoints.ts +8 -0
  354. package/src/point/sumPoints.ts +8 -0
  355. package/src/react-spring/axis/AnimatedAxis.tsrx +28 -0
  356. package/src/react-spring/axis/AnimatedAxis.tsrx.d.ts +7 -0
  357. package/src/react-spring/axis/AnimatedTicks.tsrx +85 -0
  358. package/src/react-spring/axis/AnimatedTicks.tsrx.d.ts +6 -0
  359. package/src/react-spring/grid/AnimatedGridColumns.tsrx +38 -0
  360. package/src/react-spring/grid/AnimatedGridColumns.tsrx.d.ts +6 -0
  361. package/src/react-spring/grid/AnimatedGridLines.tsrx +47 -0
  362. package/src/react-spring/grid/AnimatedGridLines.tsrx.d.ts +10 -0
  363. package/src/react-spring/grid/AnimatedGridRows.tsrx +38 -0
  364. package/src/react-spring/grid/AnimatedGridRows.tsrx.d.ts +6 -0
  365. package/src/react-spring/index.ts +7 -0
  366. package/src/react-spring/spring-configs/useLineTransitionConfig.tsrx +102 -0
  367. package/src/react-spring/spring-configs/useLineTransitionConfig.tsrx.d.ts +50 -0
  368. package/src/react-spring/types/index.ts +1 -0
  369. package/src/responsive/components/ParentSize.tsrx +66 -0
  370. package/src/responsive/components/ParentSize.tsrx.d.ts +21 -0
  371. package/src/responsive/components/ScaleSVG.tsrx +44 -0
  372. package/src/responsive/components/ScaleSVG.tsrx.d.ts +19 -0
  373. package/src/responsive/enhancers/withParentSize.tsrx +101 -0
  374. package/src/responsive/enhancers/withParentSize.tsrx.d.ts +17 -0
  375. package/src/responsive/enhancers/withScreenSize.tsrx +64 -0
  376. package/src/responsive/enhancers/withScreenSize.tsrx.d.ts +17 -0
  377. package/src/responsive/hooks/useParentSize.tsrx +103 -0
  378. package/src/responsive/hooks/useParentSize.tsrx.d.ts +25 -0
  379. package/src/responsive/hooks/useScreenSize.tsrx +53 -0
  380. package/src/responsive/hooks/useScreenSize.tsrx.d.ts +12 -0
  381. package/src/responsive/index.ts +21 -0
  382. package/src/responsive/types/index.ts +36 -0
  383. package/src/responsive/utils/debounce.ts +59 -0
  384. package/src/sankey/Sankey.tsrx +157 -0
  385. package/src/sankey/Sankey.tsrx.d.ts +54 -0
  386. package/src/sankey/index.ts +20 -0
  387. package/src/sankey/types.ts +10 -0
  388. package/src/scale/createScale.ts +176 -0
  389. package/src/scale/index.ts +31 -0
  390. package/src/scale/operators/align.ts +16 -0
  391. package/src/scale/operators/base.ts +16 -0
  392. package/src/scale/operators/clamp.ts +16 -0
  393. package/src/scale/operators/constant.ts +16 -0
  394. package/src/scale/operators/domain.ts +25 -0
  395. package/src/scale/operators/exponent.ts +16 -0
  396. package/src/scale/operators/interpolate.ts +23 -0
  397. package/src/scale/operators/nice.ts +81 -0
  398. package/src/scale/operators/padding.ts +30 -0
  399. package/src/scale/operators/range.ts +22 -0
  400. package/src/scale/operators/reverse.ts +23 -0
  401. package/src/scale/operators/round.ts +32 -0
  402. package/src/scale/operators/scaleOperator.ts +86 -0
  403. package/src/scale/operators/unknown.ts +16 -0
  404. package/src/scale/operators/zero.ts +21 -0
  405. package/src/scale/react/index.ts +3 -0
  406. package/src/scale/react/useScale.tsrx +48 -0
  407. package/src/scale/react/useScale.tsrx.d.ts +20 -0
  408. package/src/scale/scales/band.ts +19 -0
  409. package/src/scale/scales/linear.ts +21 -0
  410. package/src/scale/scales/log.ts +21 -0
  411. package/src/scale/scales/ordinal.ts +13 -0
  412. package/src/scale/scales/point.ts +19 -0
  413. package/src/scale/scales/power.ts +22 -0
  414. package/src/scale/scales/quantile.ts +12 -0
  415. package/src/scale/scales/quantize.ts +18 -0
  416. package/src/scale/scales/radial.ts +19 -0
  417. package/src/scale/scales/squareRoot.ts +21 -0
  418. package/src/scale/scales/symlog.ts +21 -0
  419. package/src/scale/scales/threshold.ts +14 -0
  420. package/src/scale/scales/time.ts +20 -0
  421. package/src/scale/scales/utc.ts +20 -0
  422. package/src/scale/types/Base.ts +14 -0
  423. package/src/scale/types/BaseScaleConfig.ts +123 -0
  424. package/src/scale/types/Nice.ts +1 -0
  425. package/src/scale/types/Scale.ts +96 -0
  426. package/src/scale/types/ScaleConfig.ts +210 -0
  427. package/src/scale/types/ScaleInterpolate.ts +14 -0
  428. package/src/scale/updateScale.ts +163 -0
  429. package/src/scale/utils/coerceNumber.ts +10 -0
  430. package/src/scale/utils/createColorInterpolator.ts +43 -0
  431. package/src/scale/utils/getTicks.ts +25 -0
  432. package/src/scale/utils/inferScaleType.ts +60 -0
  433. package/src/scale/utils/isUtcScale.ts +16 -0
  434. package/src/scale/utils/scaleCanBeZeroed.ts +25 -0
  435. package/src/scale/utils/toString.ts +5 -0
  436. package/src/shape/index.ts +96 -0
  437. package/src/shape/react/index.ts +5 -0
  438. package/src/shape/react/usePie.tsrx +60 -0
  439. package/src/shape/react/usePie.tsrx.d.ts +20 -0
  440. package/src/shape/shapes/Arc.tsrx +60 -0
  441. package/src/shape/shapes/Arc.tsrx.d.ts +17 -0
  442. package/src/shape/shapes/Area.tsrx +32 -0
  443. package/src/shape/shapes/Area.tsrx.d.ts +4 -0
  444. package/src/shape/shapes/AreaClosed.tsrx +47 -0
  445. package/src/shape/shapes/AreaClosed.tsrx.d.ts +6 -0
  446. package/src/shape/shapes/AreaStack.tsrx +78 -0
  447. package/src/shape/shapes/AreaStack.tsrx.d.ts +7 -0
  448. package/src/shape/shapes/Bar.tsrx +18 -0
  449. package/src/shape/shapes/Bar.tsrx.d.ts +10 -0
  450. package/src/shape/shapes/BarGroup.tsrx +131 -0
  451. package/src/shape/shapes/BarGroup.tsrx.d.ts +57 -0
  452. package/src/shape/shapes/BarGroupHorizontal.tsrx +100 -0
  453. package/src/shape/shapes/BarGroupHorizontal.tsrx.d.ts +21 -0
  454. package/src/shape/shapes/BarRounded.tsrx +153 -0
  455. package/src/shape/shapes/BarRounded.tsrx.d.ts +44 -0
  456. package/src/shape/shapes/BarStack.tsrx +103 -0
  457. package/src/shape/shapes/BarStack.tsrx.d.ts +13 -0
  458. package/src/shape/shapes/BarStackHorizontal.tsrx +99 -0
  459. package/src/shape/shapes/BarStackHorizontal.tsrx.d.ts +13 -0
  460. package/src/shape/shapes/Circle.tsrx +18 -0
  461. package/src/shape/shapes/Circle.tsrx.d.ts +10 -0
  462. package/src/shape/shapes/Line.tsrx +43 -0
  463. package/src/shape/shapes/Line.tsrx.d.ts +21 -0
  464. package/src/shape/shapes/LinePath.tsrx +44 -0
  465. package/src/shape/shapes/LinePath.tsrx.d.ts +19 -0
  466. package/src/shape/shapes/LineRadial.tsrx +42 -0
  467. package/src/shape/shapes/LineRadial.tsrx.d.ts +12 -0
  468. package/src/shape/shapes/Pie.tsrx +87 -0
  469. package/src/shape/shapes/Pie.tsrx.d.ts +30 -0
  470. package/src/shape/shapes/Polygon.tsrx +85 -0
  471. package/src/shape/shapes/Polygon.tsrx.d.ts +37 -0
  472. package/src/shape/shapes/SplitLinePath.tsrx +86 -0
  473. package/src/shape/shapes/SplitLinePath.tsrx.d.ts +23 -0
  474. package/src/shape/shapes/Stack.tsrx +83 -0
  475. package/src/shape/shapes/Stack.tsrx.d.ts +25 -0
  476. package/src/shape/shapes/link/curve/LinkHorizontalCurve.tsrx +63 -0
  477. package/src/shape/shapes/link/curve/LinkHorizontalCurve.tsrx.d.ts +11 -0
  478. package/src/shape/shapes/link/curve/LinkRadialCurve.tsrx +72 -0
  479. package/src/shape/shapes/link/curve/LinkRadialCurve.tsrx.d.ts +9 -0
  480. package/src/shape/shapes/link/curve/LinkVerticalCurve.tsrx +62 -0
  481. package/src/shape/shapes/link/curve/LinkVerticalCurve.tsrx.d.ts +9 -0
  482. package/src/shape/shapes/link/diagonal/LinkHorizontal.tsrx +47 -0
  483. package/src/shape/shapes/link/diagonal/LinkHorizontal.tsrx.d.ts +7 -0
  484. package/src/shape/shapes/link/diagonal/LinkRadial.tsrx +49 -0
  485. package/src/shape/shapes/link/diagonal/LinkRadial.tsrx.d.ts +9 -0
  486. package/src/shape/shapes/link/diagonal/LinkVertical.tsrx +46 -0
  487. package/src/shape/shapes/link/diagonal/LinkVertical.tsrx.d.ts +6 -0
  488. package/src/shape/shapes/link/line/LinkHorizontalLine.tsrx +53 -0
  489. package/src/shape/shapes/link/line/LinkHorizontalLine.tsrx.d.ts +7 -0
  490. package/src/shape/shapes/link/line/LinkRadialLine.tsrx +58 -0
  491. package/src/shape/shapes/link/line/LinkRadialLine.tsrx.d.ts +5 -0
  492. package/src/shape/shapes/link/line/LinkVerticalLine.tsrx +53 -0
  493. package/src/shape/shapes/link/line/LinkVerticalLine.tsrx.d.ts +5 -0
  494. package/src/shape/shapes/link/step/LinkHorizontalStep.tsrx +59 -0
  495. package/src/shape/shapes/link/step/LinkHorizontalStep.tsrx.d.ts +12 -0
  496. package/src/shape/shapes/link/step/LinkRadialStep.tsrx +68 -0
  497. package/src/shape/shapes/link/step/LinkRadialStep.tsrx.d.ts +8 -0
  498. package/src/shape/shapes/link/step/LinkVerticalStep.tsrx +59 -0
  499. package/src/shape/shapes/link/step/LinkVerticalStep.tsrx.d.ts +10 -0
  500. package/src/shape/types/D3ShapeConfig.ts +91 -0
  501. package/src/shape/types/accessor.ts +9 -0
  502. package/src/shape/types/area.ts +14 -0
  503. package/src/shape/types/barGroup.ts +57 -0
  504. package/src/shape/types/barStack.ts +55 -0
  505. package/src/shape/types/base.ts +23 -0
  506. package/src/shape/types/index.ts +8 -0
  507. package/src/shape/types/link.ts +37 -0
  508. package/src/shape/types/stack.ts +15 -0
  509. package/src/shape/util/D3ShapeFactories.ts +125 -0
  510. package/src/shape/util/accessors.ts +25 -0
  511. package/src/shape/util/getBandwidth.ts +11 -0
  512. package/src/shape/util/getOrCreateMeasurementElement.ts +28 -0
  513. package/src/shape/util/getSplitLineSegments.ts +100 -0
  514. package/src/shape/util/setNumberOrNumberAccessor.ts +11 -0
  515. package/src/shape/util/stackOffset.ts +23 -0
  516. package/src/shape/util/stackOrder.ts +23 -0
  517. package/src/shape/util/trigonometry.ts +1 -0
  518. package/src/stats/BoxPlot.tsrx +257 -0
  519. package/src/stats/BoxPlot.tsrx.d.ts +51 -0
  520. package/src/stats/ViolinPlot.tsrx +78 -0
  521. package/src/stats/ViolinPlot.tsrx.d.ts +21 -0
  522. package/src/stats/index.ts +8 -0
  523. package/src/stats/types.ts +56 -0
  524. package/src/stats/util/computeStats.ts +71 -0
  525. package/src/text/Text.tsrx +43 -0
  526. package/src/text/Text.tsrx.d.ts +4 -0
  527. package/src/text/hooks/useText.tsrx +125 -0
  528. package/src/text/hooks/useText.tsrx.d.ts +7 -0
  529. package/src/text/index.ts +5 -0
  530. package/src/text/types.ts +54 -0
  531. package/src/text/util/getStringWidth.ts +38 -0
  532. package/src/text/util/memoize.ts +13 -0
  533. package/src/theme/compat/fromXYChartTheme.ts +132 -0
  534. package/src/theme/index.ts +14 -0
  535. package/src/theme/provider/ThemeScope.tsrx +58 -0
  536. package/src/theme/provider/ThemeScope.tsrx.d.ts +23 -0
  537. package/src/theme/provider/defineTheme.ts +67 -0
  538. package/src/theme/react/ThemeContext.tsrx +7 -0
  539. package/src/theme/react/ThemeContext.tsrx.d.ts +4 -0
  540. package/src/theme/react/ThemeProvider.tsrx +14 -0
  541. package/src/theme/react/ThemeProvider.tsrx.d.ts +4 -0
  542. package/src/theme/react/categoricalColor.ts +32 -0
  543. package/src/theme/react/index.ts +29 -0
  544. package/src/theme/react/useAxisStyle.tsrx +100 -0
  545. package/src/theme/react/useAxisStyle.tsrx.d.ts +23 -0
  546. package/src/theme/react/useCategoricalScale.tsrx +23 -0
  547. package/src/theme/react/useCategoricalScale.tsrx.d.ts +3 -0
  548. package/src/theme/react/useChartConfig.tsrx +108 -0
  549. package/src/theme/react/useChartConfig.tsrx.d.ts +15 -0
  550. package/src/theme/react/useColor.tsrx +18 -0
  551. package/src/theme/react/useColor.tsrx.d.ts +4 -0
  552. package/src/theme/react/useColorScale.tsrx +39 -0
  553. package/src/theme/react/useColorScale.tsrx.d.ts +7 -0
  554. package/src/theme/react/useGridStyle.tsrx +15 -0
  555. package/src/theme/react/useGridStyle.tsrx.d.ts +6 -0
  556. package/src/theme/react/useTheme.tsrx +7 -0
  557. package/src/theme/react/useTheme.tsrx.d.ts +3 -0
  558. package/src/theme/react/warn.ts +3 -0
  559. package/src/theme/runtime/createRuntimeTheme.ts +70 -0
  560. package/src/theme/runtime/resolveThemeInput.ts +19 -0
  561. package/src/theme/tokens/categorical.ts +18 -0
  562. package/src/theme/tokens/cssVar.ts +5 -0
  563. package/src/theme/tokens/dark.ts +51 -0
  564. package/src/theme/tokens/light.ts +62 -0
  565. package/src/theme/tokens/names.ts +49 -0
  566. package/src/theme/tokens/style.ts +45 -0
  567. package/src/theme/tokens/types.ts +118 -0
  568. package/src/theme/utils/warn.ts +5 -0
  569. package/src/threshold/Threshold.tsrx +112 -0
  570. package/src/threshold/Threshold.tsrx.d.ts +45 -0
  571. package/src/threshold/index.ts +2 -0
  572. package/src/tooltip/Portal.tsrx +27 -0
  573. package/src/tooltip/Portal.tsrx.d.ts +10 -0
  574. package/src/tooltip/context/TooltipPositionContext.tsrx +16 -0
  575. package/src/tooltip/context/TooltipPositionContext.tsrx.d.ts +11 -0
  576. package/src/tooltip/enhancers/withTooltip.tsrx +29 -0
  577. package/src/tooltip/enhancers/withTooltip.tsrx.d.ts +8 -0
  578. package/src/tooltip/floating/ChartTooltip.tsrx +95 -0
  579. package/src/tooltip/floating/ChartTooltip.tsrx.d.ts +29 -0
  580. package/src/tooltip/floating/ChartTooltipContent.tsrx +219 -0
  581. package/src/tooltip/floating/ChartTooltipContent.tsrx.d.ts +57 -0
  582. package/src/tooltip/floating/FloatingTooltip.tsrx +269 -0
  583. package/src/tooltip/floating/FloatingTooltip.tsrx.d.ts +20 -0
  584. package/src/tooltip/floating/anchors.ts +146 -0
  585. package/src/tooltip/floating/context.tsrx +29 -0
  586. package/src/tooltip/floating/context.tsrx.d.ts +9 -0
  587. package/src/tooltip/floating/index.ts +61 -0
  588. package/src/tooltip/floating/internalTypes.ts +125 -0
  589. package/src/tooltip/floating/middleware.ts +104 -0
  590. package/src/tooltip/floating/types.ts +198 -0
  591. package/src/tooltip/floating/useChartTooltip.tsrx +180 -0
  592. package/src/tooltip/floating/useChartTooltip.tsrx.d.ts +40 -0
  593. package/src/tooltip/floating/useFloatingTooltip.tsrx +301 -0
  594. package/src/tooltip/floating/useFloatingTooltip.tsrx.d.ts +3 -0
  595. package/src/tooltip/hooks/useTooltip.tsrx +67 -0
  596. package/src/tooltip/hooks/useTooltip.tsrx.d.ts +25 -0
  597. package/src/tooltip/hooks/useTooltipInPortal.tsrx +92 -0
  598. package/src/tooltip/hooks/useTooltipInPortal.tsrx.d.ts +34 -0
  599. package/src/tooltip/index.ts +20 -0
  600. package/src/tooltip/tooltips/Tooltip.tsrx +71 -0
  601. package/src/tooltip/tooltips/Tooltip.tsrx.d.ts +39 -0
  602. package/src/tooltip/tooltips/TooltipWithBounds.tsrx +82 -0
  603. package/src/tooltip/tooltips/TooltipWithBounds.tsrx.d.ts +9 -0
  604. package/src/voronoi/components/VoronoiPolygon.tsrx +32 -0
  605. package/src/voronoi/components/VoronoiPolygon.tsrx.d.ts +14 -0
  606. package/src/voronoi/index.ts +6 -0
  607. package/src/voronoi/react/index.ts +5 -0
  608. package/src/voronoi/react/useVoronoi.tsrx +30 -0
  609. package/src/voronoi/react/useVoronoi.tsrx.d.ts +10 -0
  610. package/src/voronoi/voronoi.ts +32 -0
  611. package/src/wordcloud/Wordcloud.tsrx +20 -0
  612. package/src/wordcloud/Wordcloud.tsrx.d.ts +7 -0
  613. package/src/wordcloud/d3-cloud.d.ts +1 -0
  614. package/src/wordcloud/index.ts +3 -0
  615. package/src/wordcloud/types.ts +154 -0
  616. package/src/wordcloud/useWordcloud.tsrx +277 -0
  617. package/src/wordcloud/useWordcloud.tsrx.d.ts +16 -0
  618. package/src/xychart/classes/DataRegistry.ts +53 -0
  619. package/src/xychart/components/Tooltip.tsrx +356 -0
  620. package/src/xychart/components/Tooltip.tsrx.d.ts +57 -0
  621. package/src/xychart/components/XYChart.tsrx +196 -0
  622. package/src/xychart/components/XYChart.tsrx.d.ts +47 -0
  623. package/src/xychart/components/annotation/AnimatedAnnotation.tsrx +72 -0
  624. package/src/xychart/components/annotation/AnimatedAnnotation.tsrx.d.ts +7 -0
  625. package/src/xychart/components/annotation/Annotation.tsrx +20 -0
  626. package/src/xychart/components/annotation/Annotation.tsrx.d.ts +7 -0
  627. package/src/xychart/components/annotation/AnnotationCircleSubject.tsrx +12 -0
  628. package/src/xychart/components/annotation/AnnotationCircleSubject.tsrx.d.ts +5 -0
  629. package/src/xychart/components/annotation/AnnotationConnector.tsrx +12 -0
  630. package/src/xychart/components/annotation/AnnotationConnector.tsrx.d.ts +5 -0
  631. package/src/xychart/components/annotation/AnnotationLabel.tsrx +29 -0
  632. package/src/xychart/components/annotation/AnnotationLabel.tsrx.d.ts +5 -0
  633. package/src/xychart/components/annotation/AnnotationLineSubject.tsrx +28 -0
  634. package/src/xychart/components/annotation/AnnotationLineSubject.tsrx.d.ts +9 -0
  635. package/src/xychart/components/annotation/private/BaseAnnotation.tsrx +86 -0
  636. package/src/xychart/components/annotation/private/BaseAnnotation.tsrx.d.ts +18 -0
  637. package/src/xychart/components/axis/AnimatedAxis.tsrx +15 -0
  638. package/src/xychart/components/axis/AnimatedAxis.tsrx.d.ts +9 -0
  639. package/src/xychart/components/axis/Axis.tsrx +11 -0
  640. package/src/xychart/components/axis/Axis.tsrx.d.ts +5 -0
  641. package/src/xychart/components/axis/BaseAxis.tsrx +94 -0
  642. package/src/xychart/components/axis/BaseAxis.tsrx.d.ts +15 -0
  643. package/src/xychart/components/grid/AnimatedGrid.tsrx +34 -0
  644. package/src/xychart/components/grid/AnimatedGrid.tsrx.d.ts +8 -0
  645. package/src/xychart/components/grid/BaseGrid.tsrx +49 -0
  646. package/src/xychart/components/grid/BaseGrid.tsrx.d.ts +16 -0
  647. package/src/xychart/components/grid/Grid.tsrx +9 -0
  648. package/src/xychart/components/grid/Grid.tsrx.d.ts +4 -0
  649. package/src/xychart/components/series/AnimatedAreaSeries.tsrx +8 -0
  650. package/src/xychart/components/series/AnimatedAreaSeries.tsrx.d.ts +4 -0
  651. package/src/xychart/components/series/AnimatedAreaStack.tsrx +8 -0
  652. package/src/xychart/components/series/AnimatedAreaStack.tsrx.d.ts +4 -0
  653. package/src/xychart/components/series/AnimatedBarGroup.tsrx +8 -0
  654. package/src/xychart/components/series/AnimatedBarGroup.tsrx.d.ts +4 -0
  655. package/src/xychart/components/series/AnimatedBarSeries.tsrx +15 -0
  656. package/src/xychart/components/series/AnimatedBarSeries.tsrx.d.ts +4 -0
  657. package/src/xychart/components/series/AnimatedBarStack.tsrx +8 -0
  658. package/src/xychart/components/series/AnimatedBarStack.tsrx.d.ts +4 -0
  659. package/src/xychart/components/series/AnimatedGlyphSeries.tsrx +28 -0
  660. package/src/xychart/components/series/AnimatedGlyphSeries.tsrx.d.ts +8 -0
  661. package/src/xychart/components/series/AnimatedLineSeries.tsrx +8 -0
  662. package/src/xychart/components/series/AnimatedLineSeries.tsrx.d.ts +4 -0
  663. package/src/xychart/components/series/AreaSeries.tsrx +7 -0
  664. package/src/xychart/components/series/AreaSeries.tsrx.d.ts +4 -0
  665. package/src/xychart/components/series/AreaStack.tsrx +7 -0
  666. package/src/xychart/components/series/AreaStack.tsrx.d.ts +4 -0
  667. package/src/xychart/components/series/BarGroup.tsrx +8 -0
  668. package/src/xychart/components/series/BarGroup.tsrx.d.ts +4 -0
  669. package/src/xychart/components/series/BarSeries.tsrx +13 -0
  670. package/src/xychart/components/series/BarSeries.tsrx.d.ts +5 -0
  671. package/src/xychart/components/series/BarStack.tsrx +8 -0
  672. package/src/xychart/components/series/BarStack.tsrx.d.ts +4 -0
  673. package/src/xychart/components/series/GlyphSeries.tsrx +38 -0
  674. package/src/xychart/components/series/GlyphSeries.tsrx.d.ts +8 -0
  675. package/src/xychart/components/series/LineSeries.tsrx +7 -0
  676. package/src/xychart/components/series/LineSeries.tsrx.d.ts +4 -0
  677. package/src/xychart/components/series/private/AnimatedBars.tsrx +151 -0
  678. package/src/xychart/components/series/private/AnimatedBars.tsrx.d.ts +5 -0
  679. package/src/xychart/components/series/private/AnimatedGlyphs.tsrx +108 -0
  680. package/src/xychart/components/series/private/AnimatedGlyphs.tsrx.d.ts +40 -0
  681. package/src/xychart/components/series/private/AnimatedPath.tsrx +47 -0
  682. package/src/xychart/components/series/private/AnimatedPath.tsrx.d.ts +4 -0
  683. package/src/xychart/components/series/private/Bars.tsrx +45 -0
  684. package/src/xychart/components/series/private/Bars.tsrx.d.ts +4 -0
  685. package/src/xychart/components/series/private/BaseAreaSeries.tsrx +187 -0
  686. package/src/xychart/components/series/private/BaseAreaSeries.tsrx.d.ts +20 -0
  687. package/src/xychart/components/series/private/BaseAreaStack.tsrx +259 -0
  688. package/src/xychart/components/series/private/BaseAreaStack.tsrx.d.ts +19 -0
  689. package/src/xychart/components/series/private/BaseBarGroup.tsrx +198 -0
  690. package/src/xychart/components/series/private/BaseBarGroup.tsrx.d.ts +15 -0
  691. package/src/xychart/components/series/private/BaseBarSeries.tsrx +154 -0
  692. package/src/xychart/components/series/private/BaseBarSeries.tsrx.d.ts +16 -0
  693. package/src/xychart/components/series/private/BaseBarStack.tsrx +192 -0
  694. package/src/xychart/components/series/private/BaseBarStack.tsrx.d.ts +14 -0
  695. package/src/xychart/components/series/private/BaseGlyphSeries.tsrx +107 -0
  696. package/src/xychart/components/series/private/BaseGlyphSeries.tsrx.d.ts +14 -0
  697. package/src/xychart/components/series/private/BaseLineSeries.tsrx +135 -0
  698. package/src/xychart/components/series/private/BaseLineSeries.tsrx.d.ts +14 -0
  699. package/src/xychart/components/series/private/defaultRenderGlyph.tsrx +29 -0
  700. package/src/xychart/components/series/private/defaultRenderGlyph.tsrx.d.ts +3 -0
  701. package/src/xychart/constants.ts +9 -0
  702. package/src/xychart/context/DataContext.tsrx +23 -0
  703. package/src/xychart/context/DataContext.tsrx.d.ts +11 -0
  704. package/src/xychart/context/EventEmitterContext.tsrx +6 -0
  705. package/src/xychart/context/EventEmitterContext.tsrx.d.ts +3 -0
  706. package/src/xychart/context/ThemeContext.tsrx +7 -0
  707. package/src/xychart/context/ThemeContext.tsrx.d.ts +4 -0
  708. package/src/xychart/context/TooltipContext.tsrx +7 -0
  709. package/src/xychart/context/TooltipContext.tsrx.d.ts +3 -0
  710. package/src/xychart/hooks/useDataRegistry.tsrx +41 -0
  711. package/src/xychart/hooks/useDataRegistry.tsrx.d.ts +5 -0
  712. package/src/xychart/hooks/useDimensions.tsrx +40 -0
  713. package/src/xychart/hooks/useDimensions.tsrx.d.ts +15 -0
  714. package/src/xychart/hooks/useEventEmitter.tsrx +62 -0
  715. package/src/xychart/hooks/useEventEmitter.tsrx.d.ts +24 -0
  716. package/src/xychart/hooks/useEventEmitters.tsrx +64 -0
  717. package/src/xychart/hooks/useEventEmitters.tsrx.d.ts +25 -0
  718. package/src/xychart/hooks/useEventHandlers.tsrx +162 -0
  719. package/src/xychart/hooks/useEventHandlers.tsrx.d.ts +31 -0
  720. package/src/xychart/hooks/useScales.tsrx +113 -0
  721. package/src/xychart/hooks/useScales.tsrx.d.ts +15 -0
  722. package/src/xychart/hooks/useSeriesEvents.tsrx +82 -0
  723. package/src/xychart/hooks/useSeriesEvents.tsrx.d.ts +18 -0
  724. package/src/xychart/hooks/useStackedData.tsrx +96 -0
  725. package/src/xychart/hooks/useStackedData.tsrx.d.ts +14 -0
  726. package/src/xychart/index.ts +56 -0
  727. package/src/xychart/providers/DataProvider.tsrx +141 -0
  728. package/src/xychart/providers/DataProvider.tsrx.d.ts +22 -0
  729. package/src/xychart/providers/EventEmitterProvider.tsrx +10 -0
  730. package/src/xychart/providers/EventEmitterProvider.tsrx.d.ts +6 -0
  731. package/src/xychart/providers/ThemeProvider.tsrx +13 -0
  732. package/src/xychart/providers/ThemeProvider.tsrx.d.ts +8 -0
  733. package/src/xychart/providers/TooltipProvider.tsrx +101 -0
  734. package/src/xychart/providers/TooltipProvider.tsrx.d.ts +10 -0
  735. package/src/xychart/theme/buildChartTheme.ts +178 -0
  736. package/src/xychart/theme/colors.ts +174 -0
  737. package/src/xychart/theme/themes/dark.ts +24 -0
  738. package/src/xychart/theme/themes/light.ts +16 -0
  739. package/src/xychart/typeguards/events.ts +12 -0
  740. package/src/xychart/typeguards/isValidNumber.ts +3 -0
  741. package/src/xychart/types/axis.ts +3 -0
  742. package/src/xychart/types/data.ts +57 -0
  743. package/src/xychart/types/event.ts +30 -0
  744. package/src/xychart/types/index.ts +6 -0
  745. package/src/xychart/types/series.ts +219 -0
  746. package/src/xychart/types/theme.ts +50 -0
  747. package/src/xychart/types/tooltip.ts +24 -0
  748. package/src/xychart/utils/cleanColorString.ts +4 -0
  749. package/src/xychart/utils/collectDataRegistryEntries.ts +50 -0
  750. package/src/xychart/utils/combineBarStackData.ts +51 -0
  751. package/src/xychart/utils/findNearestDatumSingleDimension.ts +64 -0
  752. package/src/xychart/utils/findNearestDatumX.ts +34 -0
  753. package/src/xychart/utils/findNearestDatumXY.ts +42 -0
  754. package/src/xychart/utils/findNearestDatumY.ts +34 -0
  755. package/src/xychart/utils/findNearestGroupDatum.ts +50 -0
  756. package/src/xychart/utils/findNearestStackDatum.ts +44 -0
  757. package/src/xychart/utils/getBarStackRegistryData.ts +49 -0
  758. package/src/xychart/utils/getChildrenAndGrandchildrenWithProps.ts +24 -0
  759. package/src/xychart/utils/getScaleBandwidth.ts +7 -0
  760. package/src/xychart/utils/getScaleBaseline.ts +24 -0
  761. package/src/xychart/utils/getScaledValueFactory.ts +21 -0
  762. package/src/xychart/utils/isDiscreteScale.ts +9 -0
  763. package/src/zoom/Zoom.tsrx +375 -0
  764. package/src/zoom/Zoom.tsrx.d.ts +62 -0
  765. package/src/zoom/index.ts +16 -0
  766. package/src/zoom/types.ts +120 -0
  767. package/src/zoom/util/matrix.ts +104 -0
@@ -0,0 +1,277 @@
1
+ import { useMemo } from 'octane';
2
+ import getStringWidth from '../text/util/getStringWidth';
3
+ import type { BaseDatum, CloudWord, WordcloudConfig } from './types';
4
+
5
+ const DEGREES_TO_RADIANS = Math.PI / 180;
6
+ const HASH_RANGE = 0x1_0000_0000;
7
+
8
+ export type WordBounds = {
9
+ left: number;
10
+ right: number;
11
+ top: number;
12
+ bottom: number;
13
+ };
14
+
15
+ type ResolvedWord<Datum extends BaseDatum> = Datum & Required<
16
+ Pick<CloudWord, 'font' | 'padding' | 'rotate' | 'size' | 'style' | 'text' | 'weight'>
17
+ > & { sourceIndex: number };
18
+
19
+ function valueAt<Datum, Value>(
20
+ value: Value | ((datum: Datum, index: number) => Value) | undefined,
21
+ datum: Datum,
22
+ index: number,
23
+ fallback: Value,
24
+ ): Value {
25
+ if (typeof value === 'function') return (value as (datum: Datum, index: number) => Value)(
26
+ datum,
27
+ index,
28
+ );
29
+ return value ?? fallback;
30
+ }
31
+
32
+ function textHash(text: string): number {
33
+ let hash = 2166136261;
34
+ for (const character of text) hash = Math.imul(hash ^ character.charCodeAt(0), 16777619);
35
+ return hash >>> 0;
36
+ }
37
+
38
+ function deterministicRandom(text: string, index: number, salt: string): number {
39
+ return textHash(`${text}\0${index}\0${salt}`) / HASH_RANGE;
40
+ }
41
+
42
+ function numericFontWeight(weight: string | number): string | number {
43
+ if (weight === 'bold' || weight === 'bolder') return 700;
44
+ if (weight === 'lighter') return 300;
45
+ return weight;
46
+ }
47
+
48
+ /**
49
+ * Estimates the axis-aligned rectangle occupied by a laid-out word. The same
50
+ * browser-independent metric is used for collision checks during SSR and the
51
+ * first client render.
52
+ */
53
+ export function getEstimatedWordBounds(
54
+ word: Pick<CloudWord, 'padding' | 'rotate' | 'size' | 'style' | 'text' | 'weight' | 'x' | 'y'>,
55
+ ): WordBounds {
56
+ const size = Math.max(0, Number(word.size) || 0);
57
+ const padding = Math.max(0, Number(word.padding) || 0);
58
+ const text = word.text ?? '';
59
+ const measuredWidth = getStringWidth(text, {
60
+ fontSize: size,
61
+ fontWeight: numericFontWeight(word.weight ?? 'normal'),
62
+ }) ?? text.length * size * 0.56;
63
+ const italicFactor = /italic|oblique/i.test(String(word.style ?? '')) ? 1.08 : 1;
64
+ const glyphWidth = measuredWidth * italicFactor + padding * 2;
65
+ const glyphHeight = size * 1.2 + padding * 2;
66
+ const angle = (Number(word.rotate) || 0) * DEGREES_TO_RADIANS;
67
+ const sin = Math.abs(Math.sin(angle));
68
+ const cos = Math.abs(Math.cos(angle));
69
+ const rotatedWidth = glyphWidth * cos + glyphHeight * sin;
70
+ const rotatedHeight = glyphWidth * sin + glyphHeight * cos;
71
+ const x = Number(word.x) || 0;
72
+ const y = Number(word.y) || 0;
73
+
74
+ return {
75
+ left: x - rotatedWidth / 2,
76
+ right: x + rotatedWidth / 2,
77
+ top: y - rotatedHeight / 2,
78
+ bottom: y + rotatedHeight / 2,
79
+ };
80
+ }
81
+
82
+ function boundsOverlap(a: WordBounds, b: WordBounds): boolean {
83
+ return a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
84
+ }
85
+
86
+ function isInsideLayout(bounds: WordBounds, width: number, height: number): boolean {
87
+ const halfWidth = width / 2;
88
+ const halfHeight = height / 2;
89
+ return bounds.left >= -halfWidth && bounds.right <= halfWidth &&
90
+ bounds.top >= -halfHeight &&
91
+ bounds.bottom <= halfHeight;
92
+ }
93
+
94
+ function archimedeanSpiral([width, height]: [number, number]) {
95
+ const aspectRatio = width / height;
96
+ return (input: number): [number, number] => {
97
+ const t = input * 0.1;
98
+ return [aspectRatio * t * Math.cos(t), t * Math.sin(t)];
99
+ };
100
+ }
101
+
102
+ function rectangularSpiral([width, height]: [number, number]) {
103
+ const dy = 4;
104
+ const dx = dy * width / height;
105
+ let x = 0;
106
+ let y = 0;
107
+
108
+ return (t: number): [number, number] => {
109
+ const sign = t < 0 ? -1 : 1;
110
+ switch ((Math.sqrt(1 + 4 * sign * t) - sign) & 3) {
111
+ case 0:
112
+ x += dx;
113
+ break;
114
+ case 1:
115
+ y += dy;
116
+ break;
117
+ case 2:
118
+ x -= dx;
119
+ break;
120
+ default:
121
+ y -= dy;
122
+ }
123
+ return [x, y];
124
+ };
125
+ }
126
+
127
+ function cellsForBounds(bounds: WordBounds, cellSize: number): string[] {
128
+ const minX = Math.floor(bounds.left / cellSize);
129
+ const maxX = Math.floor(bounds.right / cellSize);
130
+ const minY = Math.floor(bounds.top / cellSize);
131
+ const maxY = Math.floor(bounds.bottom / cellSize);
132
+ const cells: string[] = [];
133
+ for (let x = minX; x <= maxX; x += 1) {
134
+ for (let y = minY; y <= maxY; y += 1) cells.push(`${x},${y}`);
135
+ }
136
+ return cells;
137
+ }
138
+
139
+ function collides(
140
+ bounds: WordBounds,
141
+ grid: Map<string, WordBounds[]>,
142
+ cellSize: number,
143
+ ): boolean {
144
+ const candidates = new Set<WordBounds>();
145
+ for (const cell of cellsForBounds(bounds, cellSize)) {
146
+ for (const placed of grid.get(cell) ?? []) candidates.add(placed);
147
+ }
148
+ return [...candidates].some((placed) => boundsOverlap(bounds, placed));
149
+ }
150
+
151
+ function addToGrid(bounds: WordBounds, grid: Map<string, WordBounds[]>, cellSize: number): void {
152
+ for (const cell of cellsForBounds(bounds, cellSize)) {
153
+ const entries = grid.get(cell);
154
+ if (entries) entries.push(bounds);
155
+ else grid.set(cell, [bounds]);
156
+ }
157
+ }
158
+
159
+ export function layoutWordcloud<Datum extends BaseDatum>({
160
+ width,
161
+ height,
162
+ font,
163
+ fontSize,
164
+ fontStyle,
165
+ fontWeight,
166
+ padding,
167
+ random,
168
+ rotate,
169
+ spiral,
170
+ words,
171
+ }: WordcloudConfig<Datum>): CloudWord[] {
172
+ if (width <= 0 || height <= 0) return [];
173
+
174
+ const resolvedWords = words.map((datum, index): ResolvedWord<Datum> => {
175
+ const text = datum.text;
176
+ const fallbackSize = Math.sqrt(Number((datum as Datum & { value?: number }).value ?? 100));
177
+ const rawSize = Number(valueAt(fontSize, datum, index, fallbackSize));
178
+ const size = Number.isFinite(rawSize) ? Math.max(0, Math.trunc(rawSize)) : 0;
179
+ const resolvedRotate = rotate === undefined
180
+ ? random
181
+ ? Math.floor(random() * 6 - 3) * 30
182
+ : (textHash(text) % 6 - 3) * 30
183
+ : valueAt(rotate, datum, index, 0);
184
+
185
+ return {
186
+ ...datum,
187
+ sourceIndex: index,
188
+ text,
189
+ font: valueAt(font, datum, index, 'serif'),
190
+ padding: Math.max(0, Number(valueAt(padding, datum, index, 1)) || 0),
191
+ size,
192
+ style: valueAt(fontStyle, datum, index, 'normal'),
193
+ weight: valueAt(fontWeight, datum, index, 'normal'),
194
+ rotate: Number.isFinite(Number(resolvedRotate)) ? Number(resolvedRotate) : 0,
195
+ };
196
+ }).sort((a, b) => b.size - a.size || a.sourceIndex - b.sourceIndex);
197
+
198
+ const placedWords: CloudWord[] = [];
199
+ const grid = new Map<string, WordBounds[]>();
200
+ const cellSize = Math.max(
201
+ 8,
202
+ Math.min(64, Math.sqrt(width * height / Math.max(1, words.length))),
203
+ );
204
+ const maxDelta = Math.hypot(width, height);
205
+ const maxSteps = Math.max(2048, Math.ceil(maxDelta * 24));
206
+
207
+ for (const resolvedWord of resolvedWords) {
208
+ if (!resolvedWord.text || resolvedWord.size <= 0) continue;
209
+ const randomX = random
210
+ ? random()
211
+ : deterministicRandom(resolvedWord.text, resolvedWord.sourceIndex, 'x');
212
+ const randomY = random
213
+ ? random()
214
+ : deterministicRandom(resolvedWord.text, resolvedWord.sourceIndex, 'y');
215
+ const directionRandom = random
216
+ ? random()
217
+ : deterministicRandom(resolvedWord.text, resolvedWord.sourceIndex, 'direction');
218
+ const startX = Math.floor(width * (randomX + 0.5) / 2) - width / 2;
219
+ const startY = Math.floor(height * (randomY + 0.5) / 2) - height / 2;
220
+ const direction = directionRandom < 0.5 ? 1 : -1;
221
+ const spiralForWord =
222
+ typeof spiral === 'function'
223
+ ? spiral([width, height])
224
+ : spiral === 'rectangular'
225
+ ? rectangularSpiral([width, height])
226
+ : archimedeanSpiral([width, height]);
227
+
228
+ for (let step = 0; step < maxSteps; step += 1) {
229
+ const point = spiralForWord(step * direction);
230
+ if (!point || !Number.isFinite(point[0]) || !Number.isFinite(point[1])) break;
231
+ const candidate: CloudWord = {
232
+ ...resolvedWord,
233
+ x: startX + Math.trunc(point[0]),
234
+ y: startY + Math.trunc(point[1]),
235
+ };
236
+ delete (candidate as CloudWord & { sourceIndex?: number }).sourceIndex;
237
+ const bounds = getEstimatedWordBounds(candidate);
238
+ if (!isInsideLayout(bounds, width, height) || collides(bounds, grid, cellSize)) continue;
239
+
240
+ placedWords.push(candidate);
241
+ addToGrid(bounds, grid, cellSize);
242
+ break;
243
+ }
244
+ }
245
+
246
+ return placedWords;
247
+ }
248
+
249
+ export default function useWordcloud<Datum extends BaseDatum>(config: WordcloudConfig<Datum>) {
250
+ const {
251
+ width,
252
+ height,
253
+ font,
254
+ fontSize,
255
+ fontStyle,
256
+ fontWeight,
257
+ padding,
258
+ random,
259
+ rotate,
260
+ spiral,
261
+ words,
262
+ } = config;
263
+
264
+ return useMemo(() => layoutWordcloud(config), [
265
+ width,
266
+ height,
267
+ font,
268
+ fontSize,
269
+ fontStyle,
270
+ fontWeight,
271
+ padding,
272
+ random,
273
+ rotate,
274
+ spiral,
275
+ words,
276
+ ]);
277
+ }
@@ -0,0 +1,16 @@
1
+ // Generated by scripts/generate-tsrx-types.mjs.
2
+ import type { BaseDatum, CloudWord, WordcloudConfig } from './types';
3
+ export type WordBounds = {
4
+ left: number;
5
+ right: number;
6
+ top: number;
7
+ bottom: number;
8
+ };
9
+ /**
10
+ * Estimates the axis-aligned rectangle occupied by a laid-out word. The same
11
+ * browser-independent metric is used for collision checks during SSR and the
12
+ * first client render.
13
+ */
14
+ export declare function getEstimatedWordBounds(word: Pick<CloudWord, 'padding' | 'rotate' | 'size' | 'style' | 'text' | 'weight' | 'x' | 'y'>): WordBounds;
15
+ export declare function layoutWordcloud<Datum extends BaseDatum>({ width, height, font, fontSize, fontStyle, fontWeight, padding, random, rotate, spiral, words, }: WordcloudConfig<Datum>): CloudWord[];
16
+ export default function useWordcloud<Datum extends BaseDatum>(config: WordcloudConfig<Datum>): CloudWord[];
@@ -0,0 +1,53 @@
1
+ import type { AxisScale } from '@octanejs/visx/axis';
2
+ import type { DataRegistryEntry } from '../types/data';
3
+
4
+ /** A class for holding data entries */
5
+ export default class DataRegistry<
6
+ XScale extends AxisScale,
7
+ YScale extends AxisScale,
8
+ Datum extends object,
9
+ > {
10
+ private registry: { [key: string]: DataRegistryEntry<XScale, YScale, Datum> } = {};
11
+
12
+ private registryKeys: string[] = [];
13
+
14
+ /** Add one or more entries to the registry. */
15
+ public registerData(
16
+ entryOrEntries:
17
+ | DataRegistryEntry<XScale, YScale, Datum>
18
+ | DataRegistryEntry<XScale, YScale, Datum>[],
19
+ ) {
20
+ const entries = Array.isArray(entryOrEntries) ? entryOrEntries : [entryOrEntries];
21
+ entries.forEach((currEntry) => {
22
+ this.registry[currEntry.key] = currEntry;
23
+ this.registryKeys = Object.keys(this.registry);
24
+ });
25
+ }
26
+
27
+ /** Remove one or more entries to the registry. */
28
+ public unregisterData(keyOrKeys: string | string[]) {
29
+ const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];
30
+ keys.forEach((currKey) => {
31
+ delete this.registry[currKey];
32
+ this.registryKeys = Object.keys(this.registry);
33
+ });
34
+ }
35
+
36
+ /** Returns all data registry entries. This value is not constant between calls. */
37
+ public entries() {
38
+ return Object.values(this.registry);
39
+ }
40
+
41
+ /** Returns a specific entity from the registry, if it exists. */
42
+ public get(key: string) {
43
+ return this.registry[key];
44
+ }
45
+
46
+ /**
47
+ * Returns the current registry keys.
48
+ * This value is constant between calls if the keys themselves have not changed.
49
+ */
50
+ public keys() {
51
+ return this.registryKeys;
52
+ }
53
+ }
@@ -0,0 +1,356 @@
1
+ import { useCallback, useContext, useEffect, useRef } from 'octane';
2
+ import type { CSSProperties, SVGProps, ReactNode } from 'react';
3
+ import { useTooltipInPortal, defaultStyles } from '@octanejs/visx/tooltip';
4
+ import type {
5
+ TooltipProps as BaseTooltipProps,
6
+ UseTooltipPortalOptions,
7
+ } from '@octanejs/visx/tooltip';
8
+ import type { PickD3Scale } from '@octanejs/visx/scale';
9
+
10
+ import TooltipContext from '../context/TooltipContext.tsrx';
11
+ import DataContext from '../context/DataContext.tsrx';
12
+ import getScaleBandwidth from '../utils/getScaleBandwidth';
13
+ import isValidNumber from '../typeguards/isValidNumber';
14
+ import type { GlyphProps as RenderGlyphProps, TooltipContextType } from '../types';
15
+
16
+ /** fontSize + lineHeight from default styles break precise location of crosshair, etc. */
17
+ const TOOLTIP_NO_STYLE: CSSProperties = {
18
+ position: 'absolute',
19
+ pointerEvents: 'none',
20
+ fontSize: 0,
21
+ lineHeight: 0,
22
+ };
23
+
24
+ export type RenderTooltipParams<Datum extends object> = TooltipContextType<Datum> & {
25
+ colorScale?: PickD3Scale<'ordinal', string, string>;
26
+ };
27
+
28
+ export interface RenderTooltipGlyphProps<Datum extends object> extends RenderGlyphProps<Datum> {
29
+ glyphStyle?: SVGProps<SVGCircleElement>;
30
+ isNearestDatum: boolean;
31
+ }
32
+
33
+ export type TooltipProps<Datum extends object> = {
34
+ /**
35
+ * When TooltipContext.tooltipOpen=true, this function is invoked and if the
36
+ * return value is non-null, its content is rendered inside the tooltip container.
37
+ * Content will be rendered in an HTML parent.
38
+ */
39
+ /**
40
+ * When TooltipContext.tooltipOpen=true, this function is invoked and if the
41
+ * return value is non-null, its content is rendered inside the tooltip container.
42
+ * Content will be rendered in an HTML parent.
43
+ */
44
+ renderTooltip: (params: RenderTooltipParams<Datum>) => ReactNode;
45
+ /** Function which handles rendering glyphs. */
46
+ renderGlyph?: (params: RenderTooltipGlyphProps<Datum>) => ReactNode;
47
+ /** Whether to snap tooltip + crosshair x-coord to the nearest Datum x-coord instead of the event x-coord. */
48
+ snapTooltipToDatumX?: boolean;
49
+ /** Whether to snap tooltip + crosshair y-coord to the nearest Datum y-coord instead of the event y-coord. */
50
+ snapTooltipToDatumY?: boolean;
51
+ /** Whether to show a vertical line at tooltip position. */
52
+ showVerticalCrosshair?: boolean;
53
+ /** Whether to show a horizontal line at tooltip position. */
54
+ showHorizontalCrosshair?: boolean;
55
+ /** Whether to show a glyph at the tooltip position for the (single) nearest Datum. */
56
+ showDatumGlyph?: boolean;
57
+ /** Whether to show a glyph for the nearest Datum in each series. */
58
+ showSeriesGlyphs?: boolean;
59
+ /** Optional styles for the vertical crosshair, if visible. */
60
+ verticalCrosshairStyle?: SVGProps<SVGLineElement>;
61
+ /** Optional styles for the vertical crosshair, if visible. */
62
+ horizontalCrosshairStyle?: SVGProps<SVGLineElement>;
63
+ /** Optional styles for the point, if visible. */
64
+ glyphStyle?: SVGProps<SVGCircleElement>;
65
+ /**
66
+ * Tooltip depends on ResizeObserver, which may be polyfilled globally,
67
+ * passed to XYChart, or injected into this component.
68
+ */
69
+ resizeObserverPolyfill?: UseTooltipPortalOptions['polyfill'];
70
+ } & Omit<BaseTooltipProps, 'left' | 'top' | 'children'> & Pick<UseTooltipPortalOptions, 'debounce' | 'detectBounds' | 'scroll' | 'zIndex'>;
71
+
72
+ const INVISIBLE_STYLES: CSSProperties = {
73
+ position: 'absolute',
74
+ left: 0,
75
+ top: 0,
76
+ opacity: 0,
77
+ width: 0,
78
+ height: 0,
79
+ pointerEvents: 'none',
80
+ };
81
+
82
+ function DefaultGlyph<Datum extends object>({
83
+ x,
84
+ y,
85
+ size,
86
+ color,
87
+ glyphStyle,
88
+ }: Omit<RenderTooltipGlyphProps<Datum>, 'key'>) {
89
+ const { theme } = useContext(DataContext) || {};
90
+
91
+ return <circle
92
+ cx={x}
93
+ cy={y}
94
+ r={size}
95
+ fill={color}
96
+ stroke={theme?.backgroundColor}
97
+ strokeWidth={1.5}
98
+ paintOrder="fill"
99
+ {...glyphStyle}
100
+ />;
101
+ }
102
+
103
+ function defaultRenderGlyph<Datum extends object>({
104
+ key,
105
+ ...props
106
+ }: RenderTooltipGlyphProps<Datum>) {
107
+ return <DefaultGlyph {...props} />;
108
+ }
109
+
110
+ function TooltipInner<Datum extends object>({
111
+ debounce,
112
+ detectBounds,
113
+ horizontalCrosshairStyle,
114
+ glyphStyle,
115
+ renderTooltip,
116
+ renderGlyph = defaultRenderGlyph,
117
+ resizeObserverPolyfill: resizeObserverPolyfillProp,
118
+ scroll = true,
119
+ showDatumGlyph = false,
120
+ showHorizontalCrosshair = false,
121
+ showSeriesGlyphs = false,
122
+ showVerticalCrosshair = false,
123
+ snapTooltipToDatumX = false,
124
+ snapTooltipToDatumY = false,
125
+ verticalCrosshairStyle,
126
+ zIndex,
127
+ ...tooltipProps
128
+ }: TooltipProps<Datum>) {
129
+ const {
130
+ colorScale,
131
+ theme,
132
+ innerHeight,
133
+ innerWidth,
134
+ margin,
135
+ xScale,
136
+ yScale,
137
+ dataRegistry,
138
+ resizeObserverPolyfill,
139
+ } = useContext(DataContext) || {};
140
+ const tooltipContext = useContext(TooltipContext) as TooltipContextType<Datum>;
141
+ const { containerRef, TooltipInPortal, forceRefreshBounds } = useTooltipInPortal({
142
+ debounce,
143
+ detectBounds,
144
+ polyfill: resizeObserverPolyfill || resizeObserverPolyfillProp,
145
+ scroll,
146
+ zIndex,
147
+ });
148
+
149
+ // To correctly position itself in a Portal, the tooltip must know its container bounds
150
+ // this is done by rendering an invisible node whose ref can be used to find its parentElement
151
+ const setContainerRef = useCallback((ownRef: HTMLElement | SVGElement | null) => {
152
+ containerRef(ownRef?.parentElement ?? null);
153
+ }, [containerRef]);
154
+
155
+ const tooltipContent =
156
+ tooltipContext?.tooltipOpen ? renderTooltip({ ...tooltipContext, colorScale }) : null;
157
+
158
+ const showTooltip = tooltipContext?.tooltipOpen && tooltipContent != null;
159
+
160
+ // useTooltipInPortal is powered by react-use-measure and will update portal positions upon
161
+ // resize and page scroll. however it **cannot** detect when a chart container moves on a
162
+ // page due to animation or drag-and-drop, etc.
163
+ // therefore we force refresh the bounds any time we transition from a hidden tooltip to
164
+ // one that is visible.
165
+ const lastShowTooltip = useRef(false);
166
+ useEffect(() => {
167
+ if (showTooltip && !lastShowTooltip.current) {
168
+ forceRefreshBounds();
169
+ }
170
+ lastShowTooltip.current = showTooltip;
171
+ }, [showTooltip, forceRefreshBounds]);
172
+
173
+ let tooltipLeft = tooltipContext?.tooltipLeft;
174
+ let tooltipTop = tooltipContext?.tooltipTop;
175
+
176
+ const xScaleBandwidth =
177
+ xScale ? getScaleBandwidth(xScale) : 0;
178
+ const yScaleBandwidth =
179
+ yScale ? getScaleBandwidth(yScale) : 0;
180
+
181
+ const getDatumLeftTop = useCallback((key: string, datum: Datum) => {
182
+ const entry = dataRegistry?.get(key);
183
+ const xAccessor = entry?.xAccessor;
184
+ const yAccessor = entry?.yAccessor;
185
+ const left =
186
+ xScale && xAccessor ? Number(xScale(xAccessor(datum))) + xScaleBandwidth / 2 : undefined;
187
+ const top =
188
+ yScale && yAccessor ? Number(yScale(yAccessor(datum))) + yScaleBandwidth / 2 : undefined;
189
+ return { left, top };
190
+ }, [dataRegistry, xScaleBandwidth, yScaleBandwidth, xScale, yScale]);
191
+
192
+ const nearestDatum = tooltipContext?.tooltipData?.nearestDatum;
193
+ const nearestDatumKey = nearestDatum?.key ?? '';
194
+
195
+ // snap x- or y-coord to the actual data point (not event coordinates)
196
+ if (showTooltip && nearestDatum && (snapTooltipToDatumX || snapTooltipToDatumY)) {
197
+ const { left, top } = getDatumLeftTop(nearestDatumKey, nearestDatum.datum);
198
+ tooltipLeft = snapTooltipToDatumX && isValidNumber(left) ? left : tooltipLeft;
199
+ tooltipTop = snapTooltipToDatumY && isValidNumber(top) ? top : tooltipTop;
200
+ }
201
+
202
+ // collect positions + styles for glyphs; glyphs always snap to Datum, not event coords
203
+ const glyphProps: RenderTooltipGlyphProps<Datum>[] = [];
204
+
205
+ if (showTooltip && (showDatumGlyph || showSeriesGlyphs)) {
206
+ const size = Number(glyphStyle?.radius ?? 4);
207
+
208
+ if (showSeriesGlyphs) {
209
+ Object.values(tooltipContext?.tooltipData?.datumByKey ?? {}).forEach(({
210
+ key,
211
+ datum,
212
+ index,
213
+ }) => {
214
+ const color = colorScale?.(key) ?? theme?.htmlLabel?.color ?? '#222';
215
+ const { left, top } = getDatumLeftTop(key, datum);
216
+
217
+ // don't show glyphs if coords are unavailable
218
+ if (!isValidNumber(left) || !isValidNumber(top)) return;
219
+
220
+ glyphProps.push({
221
+ key,
222
+ color,
223
+ datum,
224
+ index,
225
+ size,
226
+ x: left,
227
+ y: top,
228
+ glyphStyle,
229
+ isNearestDatum: nearestDatum ? nearestDatum.key === key : false,
230
+ });
231
+ });
232
+ } else if (nearestDatum) {
233
+ const { left, top } = getDatumLeftTop(nearestDatumKey, nearestDatum.datum);
234
+ // don't show glyphs if coords are unavailable
235
+ if (isValidNumber(left) && isValidNumber(top)) {
236
+ const color =
237
+ (nearestDatumKey && colorScale?.(nearestDatumKey)) ??
238
+ // @ts-expect-error
239
+ null ??
240
+ theme?.gridStyles?.stroke ??
241
+ theme?.htmlLabel?.color ??
242
+ '#222';
243
+ glyphProps.push({
244
+ key: nearestDatumKey,
245
+ color,
246
+ datum: nearestDatum.datum,
247
+ index: nearestDatum.index,
248
+ size,
249
+ x: left,
250
+ y: top,
251
+ glyphStyle,
252
+ isNearestDatum: true,
253
+ });
254
+ }
255
+ }
256
+ }
257
+
258
+ return <>
259
+ <svg ref={setContainerRef} style={INVISIBLE_STYLES} />
260
+ {showTooltip &&
261
+ <>
262
+ {/** To correctly position crosshair / glyphs in a Portal, we leverage the logic in TooltipInPortal */}
263
+ {showVerticalCrosshair &&
264
+ <TooltipInPortal
265
+ className="visx-crosshair visx-crosshair-vertical"
266
+ left={tooltipLeft}
267
+ top={margin?.top}
268
+ offsetLeft={0}
269
+ offsetTop={0}
270
+ detectBounds={false}
271
+ style={TOOLTIP_NO_STYLE}
272
+ >
273
+ <svg width="1" height={innerHeight} overflow="visible">
274
+ <line
275
+ x1={0}
276
+ x2={0}
277
+ y1={0}
278
+ y2={innerHeight}
279
+ strokeWidth={1.5}
280
+ stroke={theme?.gridStyles?.stroke ?? theme?.htmlLabel?.color ?? '#222'}
281
+ {...verticalCrosshairStyle}
282
+ />
283
+ </svg>
284
+ </TooltipInPortal>}
285
+ {showHorizontalCrosshair &&
286
+ <TooltipInPortal
287
+ className="visx-crosshair visx-crosshair-horizontal"
288
+ left={margin?.left}
289
+ top={tooltipTop}
290
+ offsetLeft={0}
291
+ offsetTop={0}
292
+ detectBounds={false}
293
+ style={TOOLTIP_NO_STYLE}
294
+ >
295
+ <svg width={innerWidth} height="1" overflow="visible">
296
+ <line
297
+ x1={0}
298
+ x2={innerWidth}
299
+ y1={0}
300
+ y2={0}
301
+ strokeWidth={1.5}
302
+ stroke={theme?.gridStyles?.stroke ?? theme?.htmlLabel?.color ?? '#222'}
303
+ {...horizontalCrosshairStyle}
304
+ />
305
+ </svg>
306
+ </TooltipInPortal>}
307
+ {glyphProps.map(
308
+ ({
309
+ key,
310
+ x,
311
+ y,
312
+ ...props
313
+ }) => // We render glyps in a portal so that they can overflow the container if necessary
314
+ <TooltipInPortal
315
+ key={key}
316
+ className="visx-tooltip-glyph"
317
+ left={x}
318
+ top={y}
319
+ offsetLeft={0}
320
+ offsetTop={0}
321
+ detectBounds={false}
322
+ style={TOOLTIP_NO_STYLE}
323
+ >
324
+ <svg overflow="visible">{renderGlyph({ key, x: 0, y: 0, ...props })}</svg>
325
+ </TooltipInPortal>,
326
+ )}
327
+ <TooltipInPortal
328
+ left={tooltipLeft}
329
+ top={tooltipTop}
330
+ style={{
331
+ ...defaultStyles,
332
+ background: theme?.backgroundColor ?? 'white',
333
+ boxShadow: `0 1px 2px ${
334
+ theme?.htmlLabel?.color ? `${theme.htmlLabel.color}55` : '#22222255'
335
+ }`,
336
+ ...theme?.htmlLabel,
337
+ }}
338
+ {...tooltipProps}
339
+ >{tooltipContent}</TooltipInPortal>
340
+ </>}
341
+ </>;
342
+ }
343
+
344
+ /**
345
+ * This is a wrapper component which bails early if tooltip is not visible.
346
+ * If scroll detection is enabled in UseTooltipPortalOptions, this avoids re-rendering
347
+ * the component on every scroll. If many charts with Tooltips are rendered on a page,
348
+ * this also avoids creating many resize observers / hitting browser limits.
349
+ */
350
+ export default function Tooltip<Datum extends object>(props: TooltipProps<Datum>) {
351
+ const tooltipContext = useContext(TooltipContext) as TooltipContextType<Datum>;
352
+
353
+ if (!tooltipContext?.tooltipOpen) return null;
354
+
355
+ return <TooltipInner {...props} />;
356
+ }