react-native-wagmi-charts 2.7.3 → 2.8.1

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 (357) hide show
  1. package/README.md +42 -15
  2. package/lib/commonjs/charts/candle/Candle.js +177 -93
  3. package/lib/commonjs/charts/candle/Candle.js.map +1 -1
  4. package/lib/commonjs/charts/candle/Candles.js +66 -43
  5. package/lib/commonjs/charts/candle/Candles.js.map +1 -1
  6. package/lib/commonjs/charts/candle/Chart.js +38 -28
  7. package/lib/commonjs/charts/candle/Chart.js.map +1 -1
  8. package/lib/commonjs/charts/candle/Context.js +74 -43
  9. package/lib/commonjs/charts/candle/Context.js.map +1 -1
  10. package/lib/commonjs/charts/candle/Crosshair.js +190 -81
  11. package/lib/commonjs/charts/candle/Crosshair.js.map +1 -1
  12. package/lib/commonjs/charts/candle/CrosshairTooltip.js +140 -61
  13. package/lib/commonjs/charts/candle/CrosshairTooltip.js.map +1 -1
  14. package/lib/commonjs/charts/candle/DatetimeText.js +19 -14
  15. package/lib/commonjs/charts/candle/DatetimeText.js.map +1 -1
  16. package/lib/commonjs/charts/candle/Line.js +73 -28
  17. package/lib/commonjs/charts/candle/Line.js.map +1 -1
  18. package/lib/commonjs/charts/candle/PriceText.js +19 -14
  19. package/lib/commonjs/charts/candle/PriceText.js.map +1 -1
  20. package/lib/commonjs/charts/candle/index.js +67 -64
  21. package/lib/commonjs/charts/candle/types.js +4 -4
  22. package/lib/commonjs/charts/candle/useCandleData.js +9 -12
  23. package/lib/commonjs/charts/candle/useCandlestickChart.js +10 -9
  24. package/lib/commonjs/charts/candle/useCandlestickChart.js.map +1 -1
  25. package/lib/commonjs/charts/candle/useDatetime.js +16 -18
  26. package/lib/commonjs/charts/candle/useDatetime.js.map +1 -1
  27. package/lib/commonjs/charts/candle/usePrice.js +21 -22
  28. package/lib/commonjs/charts/candle/usePrice.js.map +1 -1
  29. package/lib/commonjs/charts/candle/utils/getDomain.js +5 -8
  30. package/lib/commonjs/charts/candle/utils/getHeight.js +12 -11
  31. package/lib/commonjs/charts/candle/utils/getPrice.js +12 -11
  32. package/lib/commonjs/charts/candle/utils/getY.js +12 -11
  33. package/lib/commonjs/charts/candle/utils/index.js +16 -16
  34. package/lib/commonjs/charts/line/Axis.js +402 -0
  35. package/lib/commonjs/charts/line/Axis.js.map +1 -0
  36. package/lib/commonjs/charts/line/Chart.js +140 -69
  37. package/lib/commonjs/charts/line/Chart.js.map +1 -1
  38. package/lib/commonjs/charts/line/ChartPath.js +290 -90
  39. package/lib/commonjs/charts/line/ChartPath.js.map +1 -1
  40. package/lib/commonjs/charts/line/Context.js +98 -40
  41. package/lib/commonjs/charts/line/Context.js.map +1 -1
  42. package/lib/commonjs/charts/line/Cursor.js +129 -75
  43. package/lib/commonjs/charts/line/Cursor.js.map +1 -1
  44. package/lib/commonjs/charts/line/CursorCrosshair.js +151 -58
  45. package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
  46. package/lib/commonjs/charts/line/CursorLine.js +251 -45
  47. package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
  48. package/lib/commonjs/charts/line/Data.js +73 -35
  49. package/lib/commonjs/charts/line/Data.js.map +1 -1
  50. package/lib/commonjs/charts/line/DatetimeText.js +27 -14
  51. package/lib/commonjs/charts/line/DatetimeText.js.map +1 -1
  52. package/lib/commonjs/charts/line/Dot.js +150 -57
  53. package/lib/commonjs/charts/line/Dot.js.map +1 -1
  54. package/lib/commonjs/charts/line/Gradient.js +124 -54
  55. package/lib/commonjs/charts/line/Gradient.js.map +1 -1
  56. package/lib/commonjs/charts/line/Group.js +54 -24
  57. package/lib/commonjs/charts/line/Group.js.map +1 -1
  58. package/lib/commonjs/charts/line/Highlight.js +115 -47
  59. package/lib/commonjs/charts/line/Highlight.js.map +1 -1
  60. package/lib/commonjs/charts/line/HorizontalLine.js +92 -40
  61. package/lib/commonjs/charts/line/HorizontalLine.js.map +1 -1
  62. package/lib/commonjs/charts/line/HoverTrap/index.js +10 -7
  63. package/lib/commonjs/charts/line/HoverTrap/index.js.map +1 -1
  64. package/lib/commonjs/charts/line/HoverTrap/index.web.js +115 -86
  65. package/lib/commonjs/charts/line/HoverTrap/index.web.js.map +1 -1
  66. package/lib/commonjs/charts/line/LineChartPathContext.js +14 -11
  67. package/lib/commonjs/charts/line/LineChartPathContext.js.map +1 -1
  68. package/lib/commonjs/charts/line/Path.js +78 -39
  69. package/lib/commonjs/charts/line/Path.js.map +1 -1
  70. package/lib/commonjs/charts/line/PriceText.js +113 -14
  71. package/lib/commonjs/charts/line/PriceText.js.map +1 -1
  72. package/lib/commonjs/charts/line/Tooltip.js +236 -106
  73. package/lib/commonjs/charts/line/Tooltip.js.map +1 -1
  74. package/lib/commonjs/charts/line/index.js +75 -62
  75. package/lib/commonjs/charts/line/index.js.map +1 -1
  76. package/lib/commonjs/charts/line/types.js +4 -4
  77. package/lib/commonjs/charts/line/useAnimatedPath.js +28 -23
  78. package/lib/commonjs/charts/line/useAnimatedPath.js.map +1 -1
  79. package/lib/commonjs/charts/line/useCurrentY.js +17 -17
  80. package/lib/commonjs/charts/line/useDatetime.js +34 -33
  81. package/lib/commonjs/charts/line/useDatetime.js.map +1 -1
  82. package/lib/commonjs/charts/line/useLineChart.js +21 -17
  83. package/lib/commonjs/charts/line/useLineChart.js.map +1 -1
  84. package/lib/commonjs/charts/line/usePrice.js +30 -28
  85. package/lib/commonjs/charts/line/usePrice.js.map +1 -1
  86. package/lib/commonjs/charts/line/utils/getArea.js +48 -20
  87. package/lib/commonjs/charts/line/utils/getArea.js.map +1 -1
  88. package/lib/commonjs/charts/line/utils/getDomain.js +5 -7
  89. package/lib/commonjs/charts/line/utils/getPath.js +54 -20
  90. package/lib/commonjs/charts/line/utils/getPath.js.map +1 -1
  91. package/lib/commonjs/charts/line/utils/getXPositionForCurve.js +8 -5
  92. package/lib/commonjs/charts/line/utils/getXPositionForCurve.js.map +1 -1
  93. package/lib/commonjs/charts/line/utils/index.js +19 -19
  94. package/lib/commonjs/charts/line/utils/interpolatePath.js +102 -62
  95. package/lib/commonjs/charts/line/utils/interpolatePath.js.map +1 -1
  96. package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js +5 -5
  97. package/lib/commonjs/components/AnimatedText.js +66 -39
  98. package/lib/commonjs/components/AnimatedText.js.map +1 -1
  99. package/lib/commonjs/index.js +27 -16
  100. package/lib/commonjs/index.js.map +1 -1
  101. package/lib/commonjs/types.js +2 -0
  102. package/lib/commonjs/types.js.map +1 -0
  103. package/lib/commonjs/utils/formatDatetime.js +5 -9
  104. package/lib/commonjs/utils/formatPrice.js +13 -9
  105. package/lib/commonjs/utils/formatPrice.js.map +1 -1
  106. package/lib/commonjs/utils/index.js +13 -13
  107. package/lib/commonjs/utils/usePrevious.js +10 -9
  108. package/lib/commonjs/utils/usePrevious.js.map +1 -1
  109. package/lib/module/charts/candle/Candle.js +126 -76
  110. package/lib/module/charts/candle/Candle.js.map +1 -1
  111. package/lib/module/charts/candle/Candles.js +53 -34
  112. package/lib/module/charts/candle/Candles.js.map +1 -1
  113. package/lib/module/charts/candle/Chart.js +23 -20
  114. package/lib/module/charts/candle/Chart.js.map +1 -1
  115. package/lib/module/charts/candle/Context.js +53 -23
  116. package/lib/module/charts/candle/Context.js.map +1 -1
  117. package/lib/module/charts/candle/Crosshair.js +151 -69
  118. package/lib/module/charts/candle/Crosshair.js.map +1 -1
  119. package/lib/module/charts/candle/CrosshairTooltip.js +102 -52
  120. package/lib/module/charts/candle/CrosshairTooltip.js.map +1 -1
  121. package/lib/module/charts/candle/DatetimeText.js +5 -5
  122. package/lib/module/charts/candle/Line.js +37 -19
  123. package/lib/module/charts/candle/PriceText.js +5 -5
  124. package/lib/module/charts/candle/PriceText.js.map +1 -1
  125. package/lib/module/charts/candle/index.js +2 -2
  126. package/lib/module/charts/candle/types.js +1 -1
  127. package/lib/module/charts/candle/useCandleData.js +3 -7
  128. package/lib/module/charts/candle/useCandlestickChart.js +2 -2
  129. package/lib/module/charts/candle/useCandlestickChart.js.map +1 -1
  130. package/lib/module/charts/candle/useDatetime.js +10 -12
  131. package/lib/module/charts/candle/useDatetime.js.map +1 -1
  132. package/lib/module/charts/candle/usePrice.js +12 -14
  133. package/lib/module/charts/candle/usePrice.js.map +1 -1
  134. package/lib/module/charts/candle/utils/getDomain.js +2 -5
  135. package/lib/module/charts/candle/utils/getHeight.js +8 -7
  136. package/lib/module/charts/candle/utils/getPrice.js +2 -6
  137. package/lib/module/charts/candle/utils/getY.js +2 -6
  138. package/lib/module/charts/candle/utils/index.js +1 -1
  139. package/lib/module/charts/line/Axis.js +349 -0
  140. package/lib/module/charts/line/Axis.js.map +1 -0
  141. package/lib/module/charts/line/Chart.js +82 -46
  142. package/lib/module/charts/line/Chart.js.map +1 -1
  143. package/lib/module/charts/line/ChartPath.js +246 -77
  144. package/lib/module/charts/line/ChartPath.js.map +1 -1
  145. package/lib/module/charts/line/Context.js +65 -32
  146. package/lib/module/charts/line/Context.js.map +1 -1
  147. package/lib/module/charts/line/Cursor.js +86 -60
  148. package/lib/module/charts/line/Cursor.js.map +1 -1
  149. package/lib/module/charts/line/CursorCrosshair.js +118 -50
  150. package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
  151. package/lib/module/charts/line/CursorLine.js +210 -33
  152. package/lib/module/charts/line/CursorLine.js.map +1 -1
  153. package/lib/module/charts/line/Data.js +41 -28
  154. package/lib/module/charts/line/Data.js.map +1 -1
  155. package/lib/module/charts/line/DatetimeText.js +14 -6
  156. package/lib/module/charts/line/DatetimeText.js.map +1 -1
  157. package/lib/module/charts/line/Dot.js +95 -41
  158. package/lib/module/charts/line/Dot.js.map +1 -1
  159. package/lib/module/charts/line/Gradient.js +80 -42
  160. package/lib/module/charts/line/Gradient.js.map +1 -1
  161. package/lib/module/charts/line/Group.js +15 -14
  162. package/lib/module/charts/line/Highlight.js +62 -32
  163. package/lib/module/charts/line/Highlight.js.map +1 -1
  164. package/lib/module/charts/line/HorizontalLine.js +49 -27
  165. package/lib/module/charts/line/HorizontalLine.js.map +1 -1
  166. package/lib/module/charts/line/HoverTrap/index.js +3 -2
  167. package/lib/module/charts/line/HoverTrap/index.web.js +102 -76
  168. package/lib/module/charts/line/HoverTrap/index.web.js.map +1 -1
  169. package/lib/module/charts/line/LineChartPathContext.js +3 -3
  170. package/lib/module/charts/line/Path.js +34 -27
  171. package/lib/module/charts/line/Path.js.map +1 -1
  172. package/lib/module/charts/line/PriceText.js +80 -6
  173. package/lib/module/charts/line/PriceText.js.map +1 -1
  174. package/lib/module/charts/line/Tooltip.js +202 -94
  175. package/lib/module/charts/line/Tooltip.js.map +1 -1
  176. package/lib/module/charts/line/index.js +6 -3
  177. package/lib/module/charts/line/index.js.map +1 -1
  178. package/lib/module/charts/line/types.js +1 -1
  179. package/lib/module/charts/line/useAnimatedPath.js +22 -16
  180. package/lib/module/charts/line/useAnimatedPath.js.map +1 -1
  181. package/lib/module/charts/line/useCurrentY.js +4 -9
  182. package/lib/module/charts/line/useDatetime.js +28 -27
  183. package/lib/module/charts/line/useDatetime.js.map +1 -1
  184. package/lib/module/charts/line/useLineChart.js +11 -8
  185. package/lib/module/charts/line/useLineChart.js.map +1 -1
  186. package/lib/module/charts/line/usePrice.js +24 -22
  187. package/lib/module/charts/line/usePrice.js.map +1 -1
  188. package/lib/module/charts/line/utils/getArea.js +16 -11
  189. package/lib/module/charts/line/utils/getArea.js.map +1 -1
  190. package/lib/module/charts/line/utils/getDomain.js +2 -4
  191. package/lib/module/charts/line/utils/getPath.js +22 -11
  192. package/lib/module/charts/line/utils/getPath.js.map +1 -1
  193. package/lib/module/charts/line/utils/getXPositionForCurve.js +5 -2
  194. package/lib/module/charts/line/utils/getXPositionForCurve.js.map +1 -1
  195. package/lib/module/charts/line/utils/index.js +1 -1
  196. package/lib/module/charts/line/utils/interpolatePath.js +99 -59
  197. package/lib/module/charts/line/utils/interpolatePath.js.map +1 -1
  198. package/lib/module/charts/line/utils/lineChartDataPropToArray.js +2 -2
  199. package/lib/module/components/AnimatedText.js +24 -30
  200. package/lib/module/components/AnimatedText.js.map +1 -1
  201. package/lib/module/index.js +2 -1
  202. package/lib/module/index.js.map +1 -1
  203. package/lib/module/types.js +1 -0
  204. package/lib/module/types.js.map +1 -0
  205. package/lib/module/utils/formatDatetime.js +2 -6
  206. package/lib/module/utils/formatPrice.js +10 -6
  207. package/lib/module/utils/formatPrice.js.map +1 -1
  208. package/lib/module/utils/index.js +1 -1
  209. package/lib/module/utils/usePrevious.js +2 -2
  210. package/lib/module/utils/usePrevious.js.map +1 -1
  211. package/lib/typescript/src/charts/candle/Candle.d.ts +45 -31
  212. package/lib/typescript/src/charts/candle/Candle.d.ts.map +1 -1
  213. package/lib/typescript/src/charts/candle/Candles.d.ts +25 -14
  214. package/lib/typescript/src/charts/candle/Candles.d.ts.map +1 -1
  215. package/lib/typescript/src/charts/candle/Chart.d.ts +13 -8
  216. package/lib/typescript/src/charts/candle/Chart.d.ts.map +1 -1
  217. package/lib/typescript/src/charts/candle/Context.d.ts +15 -8
  218. package/lib/typescript/src/charts/candle/Context.d.ts.map +1 -1
  219. package/lib/typescript/src/charts/candle/Crosshair.d.ts +18 -10
  220. package/lib/typescript/src/charts/candle/Crosshair.d.ts.map +1 -1
  221. package/lib/typescript/src/charts/candle/CrosshairTooltip.d.ts +16 -9
  222. package/lib/typescript/src/charts/candle/CrosshairTooltip.d.ts.map +1 -1
  223. package/lib/typescript/src/charts/candle/DatetimeText.d.ts +16 -10
  224. package/lib/typescript/src/charts/candle/DatetimeText.d.ts.map +1 -1
  225. package/lib/typescript/src/charts/candle/Line.d.ts +10 -5
  226. package/lib/typescript/src/charts/candle/Line.d.ts.map +1 -1
  227. package/lib/typescript/src/charts/candle/PriceText.d.ts +15 -8
  228. package/lib/typescript/src/charts/candle/PriceText.d.ts.map +1 -1
  229. package/lib/typescript/src/charts/candle/index.d.ts +32 -14
  230. package/lib/typescript/src/charts/candle/index.d.ts.map +1 -1
  231. package/lib/typescript/src/charts/candle/types.d.ts +16 -19
  232. package/lib/typescript/src/charts/candle/types.d.ts.map +1 -1
  233. package/lib/typescript/src/charts/candle/useCandleData.d.ts +1 -1
  234. package/lib/typescript/src/charts/candle/useCandlestickChart.d.ts +1 -1
  235. package/lib/typescript/src/charts/candle/useDatetime.d.ts +14 -10
  236. package/lib/typescript/src/charts/candle/useDatetime.d.ts.map +1 -1
  237. package/lib/typescript/src/charts/candle/usePrice.d.ts +13 -8
  238. package/lib/typescript/src/charts/candle/usePrice.d.ts.map +1 -1
  239. package/lib/typescript/src/charts/candle/utils/getDomain.d.ts +1 -1
  240. package/lib/typescript/src/charts/candle/utils/getHeight.d.ts +9 -5
  241. package/lib/typescript/src/charts/candle/utils/getPrice.d.ts +9 -5
  242. package/lib/typescript/src/charts/candle/utils/getY.d.ts +9 -5
  243. package/lib/typescript/src/charts/candle/utils/index.d.ts +1 -1
  244. package/lib/typescript/src/charts/line/Axis.d.ts +33 -0
  245. package/lib/typescript/src/charts/line/Axis.d.ts.map +1 -0
  246. package/lib/typescript/src/charts/line/Chart.d.ts +33 -23
  247. package/lib/typescript/src/charts/line/Chart.d.ts.map +1 -1
  248. package/lib/typescript/src/charts/line/ChartPath.d.ts +29 -16
  249. package/lib/typescript/src/charts/line/ChartPath.d.ts.map +1 -1
  250. package/lib/typescript/src/charts/line/Context.d.ts +17 -10
  251. package/lib/typescript/src/charts/line/Context.d.ts.map +1 -1
  252. package/lib/typescript/src/charts/line/Cursor.d.ts +23 -13
  253. package/lib/typescript/src/charts/line/Cursor.d.ts.map +1 -1
  254. package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +24 -12
  255. package/lib/typescript/src/charts/line/CursorCrosshair.d.ts.map +1 -1
  256. package/lib/typescript/src/charts/line/CursorLine.d.ts +19 -8
  257. package/lib/typescript/src/charts/line/CursorLine.d.ts.map +1 -1
  258. package/lib/typescript/src/charts/line/Data.d.ts +17 -13
  259. package/lib/typescript/src/charts/line/DatetimeText.d.ts +15 -9
  260. package/lib/typescript/src/charts/line/DatetimeText.d.ts.map +1 -1
  261. package/lib/typescript/src/charts/line/Dot.d.ts +39 -26
  262. package/lib/typescript/src/charts/line/Dot.d.ts.map +1 -1
  263. package/lib/typescript/src/charts/line/Gradient.d.ts +9 -5
  264. package/lib/typescript/src/charts/line/Gradient.d.ts.map +1 -1
  265. package/lib/typescript/src/charts/line/Group.d.ts +6 -3
  266. package/lib/typescript/src/charts/line/Highlight.d.ts +17 -9
  267. package/lib/typescript/src/charts/line/Highlight.d.ts.map +1 -1
  268. package/lib/typescript/src/charts/line/HorizontalLine.d.ts +30 -26
  269. package/lib/typescript/src/charts/line/HorizontalLine.d.ts.map +1 -1
  270. package/lib/typescript/src/charts/line/HoverTrap/index.d.ts +1 -1
  271. package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts +2 -2
  272. package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts.map +1 -1
  273. package/lib/typescript/src/charts/line/LineChartPathContext.d.ts +4 -4
  274. package/lib/typescript/src/charts/line/Path.d.ts +28 -23
  275. package/lib/typescript/src/charts/line/Path.d.ts.map +1 -1
  276. package/lib/typescript/src/charts/line/PriceText.d.ts +29 -13
  277. package/lib/typescript/src/charts/line/PriceText.d.ts.map +1 -1
  278. package/lib/typescript/src/charts/line/Tooltip.d.ts +34 -22
  279. package/lib/typescript/src/charts/line/Tooltip.d.ts.map +1 -1
  280. package/lib/typescript/src/charts/line/index.d.ts +34 -20
  281. package/lib/typescript/src/charts/line/index.d.ts.map +1 -1
  282. package/lib/typescript/src/charts/line/types.d.ts +19 -18
  283. package/lib/typescript/src/charts/line/types.d.ts.map +1 -1
  284. package/lib/typescript/src/charts/line/useAnimatedPath.d.ts +10 -7
  285. package/lib/typescript/src/charts/line/useAnimatedPath.d.ts.map +1 -1
  286. package/lib/typescript/src/charts/line/useCurrentY.d.ts +2 -2
  287. package/lib/typescript/src/charts/line/useCurrentY.d.ts.map +1 -1
  288. package/lib/typescript/src/charts/line/useDatetime.d.ts +12 -8
  289. package/lib/typescript/src/charts/line/useDatetime.d.ts.map +1 -1
  290. package/lib/typescript/src/charts/line/useLineChart.d.ts +10 -10
  291. package/lib/typescript/src/charts/line/usePrice.d.ts +12 -8
  292. package/lib/typescript/src/charts/line/usePrice.d.ts.map +1 -1
  293. package/lib/typescript/src/charts/line/utils/getArea.d.ts +17 -9
  294. package/lib/typescript/src/charts/line/utils/getArea.d.ts.map +1 -1
  295. package/lib/typescript/src/charts/line/utils/getDomain.d.ts +1 -1
  296. package/lib/typescript/src/charts/line/utils/getPath.d.ts +21 -11
  297. package/lib/typescript/src/charts/line/utils/getPath.d.ts.map +1 -1
  298. package/lib/typescript/src/charts/line/utils/getXPositionForCurve.d.ts +1 -1
  299. package/lib/typescript/src/charts/line/utils/index.d.ts +1 -1
  300. package/lib/typescript/src/charts/line/utils/interpolatePath.d.ts +17 -5
  301. package/lib/typescript/src/charts/line/utils/lineChartDataPropToArray.d.ts +4 -2
  302. package/lib/typescript/src/components/AnimatedText.d.ts +7 -4
  303. package/lib/typescript/src/components/AnimatedText.d.ts.map +1 -1
  304. package/lib/typescript/src/index.d.ts +2 -1
  305. package/lib/typescript/src/index.d.ts.map +1 -1
  306. package/lib/typescript/src/types.d.ts +8 -0
  307. package/lib/typescript/src/types.d.ts.map +1 -0
  308. package/lib/typescript/src/utils/formatDatetime.d.ts +9 -5
  309. package/lib/typescript/src/utils/formatPrice.d.ts +9 -5
  310. package/lib/typescript/src/utils/formatPrice.d.ts.map +1 -1
  311. package/lib/typescript/src/utils/index.d.ts +1 -1
  312. package/lib/typescript/src/utils/usePrevious.d.ts +1 -1
  313. package/package.json +19 -43
  314. package/src/charts/candle/Candle.tsx +2 -17
  315. package/src/charts/candle/Candles.tsx +1 -3
  316. package/src/charts/candle/Chart.tsx +1 -1
  317. package/src/charts/candle/Context.tsx +30 -7
  318. package/src/charts/candle/Crosshair.tsx +20 -8
  319. package/src/charts/candle/CrosshairTooltip.tsx +3 -1
  320. package/src/charts/candle/DatetimeText.tsx +1 -1
  321. package/src/charts/candle/PriceText.tsx +2 -1
  322. package/src/charts/candle/types.ts +1 -7
  323. package/src/charts/candle/useCandlestickChart.ts +1 -1
  324. package/src/charts/candle/useDatetime.ts +3 -1
  325. package/src/charts/candle/usePrice.ts +5 -1
  326. package/src/charts/line/Axis.tsx +363 -0
  327. package/src/charts/line/Chart.tsx +10 -7
  328. package/src/charts/line/ChartPath.tsx +77 -18
  329. package/src/charts/line/Context.tsx +29 -18
  330. package/src/charts/line/Cursor.tsx +15 -11
  331. package/src/charts/line/CursorCrosshair.tsx +27 -8
  332. package/src/charts/line/CursorLine.tsx +177 -18
  333. package/src/charts/line/Data.tsx +6 -4
  334. package/src/charts/line/DatetimeText.tsx +12 -3
  335. package/src/charts/line/Dot.tsx +2 -2
  336. package/src/charts/line/Gradient.tsx +2 -5
  337. package/src/charts/line/Highlight.tsx +8 -4
  338. package/src/charts/line/HorizontalLine.tsx +2 -8
  339. package/src/charts/line/HoverTrap/index.web.tsx +93 -60
  340. package/src/charts/line/Path.tsx +10 -17
  341. package/src/charts/line/PriceText.tsx +74 -4
  342. package/src/charts/line/Tooltip.tsx +135 -69
  343. package/src/charts/line/index.ts +4 -1
  344. package/src/charts/line/types.ts +1 -2
  345. package/src/charts/line/useAnimatedPath.ts +1 -2
  346. package/src/charts/line/useDatetime.ts +13 -10
  347. package/src/charts/line/useLineChart.ts +1 -1
  348. package/src/charts/line/usePrice.ts +6 -4
  349. package/src/charts/line/utils/getArea.ts +12 -10
  350. package/src/charts/line/utils/getPath.ts +13 -10
  351. package/src/charts/line/utils/getXPositionForCurve.ts +1 -1
  352. package/src/charts/line/utils/interpolatePath.ts +2 -2
  353. package/src/components/AnimatedText.tsx +13 -20
  354. package/src/index.ts +1 -0
  355. package/src/types.ts +7 -0
  356. package/src/utils/formatPrice.ts +7 -7
  357. package/src/utils/usePrevious.ts +1 -1
@@ -1,5 +1,4 @@
1
- import * as React from 'react';
2
- // @ts-ignore
1
+ import React from 'react';
3
2
  import * as d3Shape from 'd3-shape';
4
3
 
5
4
  import { Dimensions, StyleSheet, View, ViewProps } from 'react-native';
@@ -53,6 +52,10 @@ export function LineChart({
53
52
  id,
54
53
  });
55
54
 
55
+ // Reserve space at the bottom for x-axis cursor labels
56
+ const X_AXIS_LABEL_RESERVED_HEIGHT = 40;
57
+ const chartDrawingHeight = height - X_AXIS_LABEL_RESERVED_HEIGHT;
58
+
56
59
  const pathWidth = React.useMemo(() => {
57
60
  let allowedWidth = width;
58
61
  if (data && xLength > data.length) {
@@ -66,7 +69,7 @@ export function LineChart({
66
69
  return getPath({
67
70
  data,
68
71
  width: pathWidth,
69
- height,
72
+ height: chartDrawingHeight,
70
73
  gutter: yGutter,
71
74
  shape,
72
75
  yDomain,
@@ -74,14 +77,14 @@ export function LineChart({
74
77
  });
75
78
  }
76
79
  return '';
77
- }, [data, pathWidth, height, yGutter, shape, yDomain, xDomain]);
80
+ }, [data, pathWidth, chartDrawingHeight, yGutter, shape, yDomain, xDomain]);
78
81
 
79
82
  const area = React.useMemo(() => {
80
83
  if (data && data.length > 0) {
81
84
  return getArea({
82
85
  data,
83
86
  width: pathWidth,
84
- height,
87
+ height: chartDrawingHeight,
85
88
  gutter: yGutter,
86
89
  shape,
87
90
  yDomain,
@@ -89,7 +92,7 @@ export function LineChart({
89
92
  });
90
93
  }
91
94
  return '';
92
- }, [data, pathWidth, height, yGutter, shape, yDomain, xDomain]);
95
+ }, [data, pathWidth, chartDrawingHeight, yGutter, shape, yDomain, xDomain]);
93
96
 
94
97
  const parsedPath = React.useMemo(() => parse(path), [path]);
95
98
  const pointWidth = React.useMemo(
@@ -107,7 +110,7 @@ export function LineChart({
107
110
  width,
108
111
  height,
109
112
  pathWidth,
110
- shape,
113
+ shape: shape as d3Shape.CurveFactory,
111
114
  }),
112
115
  [
113
116
  yGutter,
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
2
- import { StyleSheet, View } from 'react-native';
3
- import { Svg } from 'react-native-svg';
1
+ import React from 'react';
2
+ import { StyleSheet, View, Platform } from 'react-native';
3
+ import { Svg, Defs, ClipPath, Rect, G } from 'react-native-svg';
4
4
  import Animated, {
5
5
  useAnimatedProps,
6
6
  useSharedValue,
@@ -24,6 +24,13 @@ const BACKGROUND_COMPONENTS = [
24
24
  const FOREGROUND_COMPONENTS = ['LineChartHighlight', 'LineChartDot'];
25
25
 
26
26
  const AnimatedSVG = Animated.createAnimatedComponent(Svg);
27
+ const AnimatedRect = Animated.createAnimatedComponent(Rect);
28
+
29
+ type ReactElementWithDisplayName = React.ReactElement & {
30
+ type?: {
31
+ displayName?: string;
32
+ };
33
+ };
27
34
 
28
35
  type LineChartPathWrapperProps = {
29
36
  animationDuration?: number;
@@ -65,12 +72,19 @@ export function LineChartPathWrapper({
65
72
 
66
73
  React.useEffect(() => {
67
74
  isMounted.value = true;
68
- // eslint-disable-next-line react-hooks/exhaustive-deps
75
+ return () => {
76
+ isMounted.value = false;
77
+ };
69
78
  }, []);
70
79
 
71
80
  ////////////////////////////////////////////////
72
81
 
73
- const svgProps = useAnimatedProps(() => {
82
+ const clipId = React.useMemo(
83
+ () => `clip-foreground-${Math.random().toString(36).substring(2, 11)}`,
84
+ []
85
+ );
86
+
87
+ const clipProps = useAnimatedProps(() => {
74
88
  const shouldAnimateOnMount = animateOnMount === 'foreground';
75
89
  const inactiveWidth =
76
90
  !isMounted.value && shouldAnimateOnMount ? 0 : pathWidth;
@@ -124,12 +138,14 @@ export function LineChartPathWrapper({
124
138
  if (children) {
125
139
  const iterableChildren = flattenChildren(children);
126
140
  backgroundChildren = iterableChildren.filter((child) =>
127
- // @ts-ignore
128
- BACKGROUND_COMPONENTS.includes(child?.type?.displayName)
141
+ BACKGROUND_COMPONENTS.includes(
142
+ (child as ReactElementWithDisplayName)?.type?.displayName || ''
143
+ )
129
144
  );
130
145
  foregroundChildren = iterableChildren.filter((child) =>
131
- // @ts-ignore
132
- FOREGROUND_COMPONENTS.includes(child?.type?.displayName)
146
+ FOREGROUND_COMPONENTS.includes(
147
+ (child as ReactElementWithDisplayName)?.type?.displayName || ''
148
+ )
133
149
  );
134
150
  }
135
151
 
@@ -153,9 +169,7 @@ export function LineChartPathWrapper({
153
169
  {...pathProps}
154
170
  />
155
171
  </Svg>
156
- <Svg style={StyleSheet.absoluteFill}>
157
- {backgroundChildren}
158
- </Svg>
172
+ <Svg style={StyleSheet.absoluteFill}>{backgroundChildren}</Svg>
159
173
  </View>
160
174
  </LineChartPathContext.Provider>
161
175
  <LineChartPathContext.Provider
@@ -166,12 +180,57 @@ export function LineChartPathWrapper({
166
180
  }}
167
181
  >
168
182
  <View style={StyleSheet.absoluteFill}>
169
- <AnimatedSVG animatedProps={svgProps} height={height}>
170
- <LineChartPath color={color} width={strokeWidth} {...pathProps} />
171
- </AnimatedSVG>
172
- <AnimatedSVG animatedProps={svgProps} height={height} style={StyleSheet.absoluteFill}>
173
- {foregroundChildren}
174
- </AnimatedSVG>
183
+ {/* On web, animated SVG width doesn't work without
184
+ react-native-svg-web, but that library breaks chart data
185
+ transitions. Use ClipPath instead. On native, AnimatedSVG with
186
+ animated width works correctly. */}
187
+ {Platform.OS === 'web' ? (
188
+ <>
189
+ <Svg width={width} height={height}>
190
+ <Defs>
191
+ <ClipPath id={clipId}>
192
+ <AnimatedRect
193
+ x={0}
194
+ y={0}
195
+ animatedProps={clipProps}
196
+ height={height}
197
+ />
198
+ </ClipPath>
199
+ </Defs>
200
+ <G clipPath={`url(#${clipId})`}>
201
+ <LineChartPath
202
+ color={color}
203
+ width={strokeWidth}
204
+ {...pathProps}
205
+ />
206
+ </G>
207
+ </Svg>
208
+ <Svg
209
+ width={width}
210
+ height={height}
211
+ style={StyleSheet.absoluteFill}
212
+ >
213
+ <G clipPath={`url(#${clipId})`}>{foregroundChildren}</G>
214
+ </Svg>
215
+ </>
216
+ ) : (
217
+ <>
218
+ <AnimatedSVG animatedProps={clipProps} height={height}>
219
+ <LineChartPath
220
+ color={color}
221
+ width={strokeWidth}
222
+ {...pathProps}
223
+ />
224
+ </AnimatedSVG>
225
+ <AnimatedSVG
226
+ animatedProps={clipProps}
227
+ height={height}
228
+ style={StyleSheet.absoluteFill}
229
+ >
230
+ {foregroundChildren}
231
+ </AnimatedSVG>
232
+ </>
233
+ )}
175
234
  </View>
176
235
  </LineChartPathContext.Provider>
177
236
  </>
@@ -1,4 +1,5 @@
1
- import * as React from 'react';
1
+ import React, { createContext, useMemo } from 'react';
2
+
2
3
  import {
3
4
  runOnJS,
4
5
  useAnimatedReaction,
@@ -10,7 +11,7 @@ import { LineChartDataProvider } from './Data';
10
11
  import type { TLineChartContext, YRangeProp } from './types';
11
12
  import { getDomain, lineChartDataPropToArray } from './utils';
12
13
 
13
- export const LineChartContext = React.createContext<TLineChartContext>({
14
+ export const LineChartContext = createContext<TLineChartContext>({
14
15
  currentX: { value: -1 } as TLineChartContext['currentX'],
15
16
  currentIndex: { value: -1 } as TLineChartContext['currentIndex'],
16
17
  domain: [0, 0],
@@ -32,8 +33,6 @@ type LineChartProviderProps = {
32
33
  xDomain?: [number, number];
33
34
  };
34
35
 
35
- LineChartProvider.displayName = 'LineChartProvider';
36
-
37
36
  export function LineChartProvider({
38
37
  children,
39
38
  data = [],
@@ -46,27 +45,38 @@ export function LineChartProvider({
46
45
  const currentIndex = useSharedValue(-1);
47
46
  const isActive = useSharedValue(false);
48
47
 
49
- const domain = React.useMemo(
50
- () => getDomain(
51
- Array.isArray(data) ? data : Object.values(data)[0] as TLineChartData
52
- ),
48
+ const domain = useMemo(
49
+ () =>
50
+ getDomain(
51
+ Array.isArray(data) ? data : (Object.values(data)[0] as TLineChartData)
52
+ ),
53
+ [data]
54
+ );
55
+
56
+ const values = useMemo(
57
+ () => lineChartDataPropToArray(data).map(({ value }) => value),
53
58
  [data]
54
59
  );
55
60
 
56
- const contextValue = React.useMemo<TLineChartContext>(() => {
57
- const values = lineChartDataPropToArray(data).map(({ value }) => value);
58
- const domainRows =
59
- Array.isArray(data) ? data : Object.values(data)[0] as TLineChartData;
61
+ const yDomainValues = useMemo(
62
+ () => ({
63
+ min: yRange?.min ?? Math.min(...values),
64
+ max: yRange?.max ?? Math.max(...values),
65
+ }),
66
+ [values, yRange?.min, yRange?.max]
67
+ );
68
+
69
+ const contextValue = useMemo<TLineChartContext>(() => {
70
+ const domainRows = Array.isArray(data)
71
+ ? data
72
+ : (Object.values(data)[0] as TLineChartData);
60
73
 
61
74
  return {
62
75
  currentX,
63
76
  currentIndex,
64
77
  isActive,
65
78
  domain,
66
- yDomain: {
67
- min: yRange?.min ?? Math.min(...values),
68
- max: yRange?.max ?? Math.max(...values),
69
- },
79
+ yDomain: yDomainValues,
70
80
  xDomain,
71
81
  xLength: xLength ?? domainRows.length,
72
82
  };
@@ -76,8 +86,7 @@ export function LineChartProvider({
76
86
  data,
77
87
  domain,
78
88
  isActive,
79
- yRange?.max,
80
- yRange?.min,
89
+ yDomainValues,
81
90
  xLength,
82
91
  xDomain,
83
92
  ]);
@@ -100,3 +109,5 @@ export function LineChartProvider({
100
109
  </LineChartDataProvider>
101
110
  );
102
111
  }
112
+
113
+ LineChartProvider.displayName = 'LineChartProvider';
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
 
3
3
  import Animated, { runOnJS } from 'react-native-reanimated';
4
4
  import {
@@ -25,6 +25,7 @@ export type LineChartCursorProps = {
25
25
  minDurationMs?: number;
26
26
  onActivated?: () => void;
27
27
  onEnded?: () => void;
28
+ orientation?: 'horizontal' | 'vertical';
28
29
  };
29
30
 
30
31
  export const CursorContext = React.createContext({ type: '' });
@@ -75,11 +76,11 @@ export function LineChartCursor({
75
76
  0
76
77
  );
77
78
 
78
- const newXPosition = (
79
- closestIndex > 0
80
- ? parsedPath.curves[closestPathCurve]!.to
81
- : parsedPath.move
82
- ).x;
79
+ const curveSegment =
80
+ closestIndex > 0 && parsedPath.curves[closestPathCurve]
81
+ ? parsedPath.curves[closestPathCurve]
82
+ : null;
83
+ const newXPosition = (curveSegment ? curveSegment.to : parsedPath.move).x;
83
84
  // Update values
84
85
  currentIndex.value = closestIndex;
85
86
  currentX.value = newXPosition;
@@ -135,11 +136,14 @@ export function LineChartCursor({
135
136
  )
136
137
  .onTouchesMove((event) => {
137
138
  'worklet';
138
- if (parsedPath && isActive.value && event.allTouches.length > 0) {
139
- const xPosition = Math.max(
140
- 0,
141
- event.allTouches[0]!.x <= width ? event.allTouches[0]!.x : width
142
- );
139
+ if (
140
+ parsedPath &&
141
+ isActive.value &&
142
+ event.allTouches.length > 0 &&
143
+ event.allTouches[0]
144
+ ) {
145
+ const touchX = event.allTouches[0].x;
146
+ const xPosition = Math.max(0, touchX <= width ? touchX : width);
143
147
  updatePosition(xPosition);
144
148
  }
145
149
  })
@@ -1,5 +1,5 @@
1
- import * as React from 'react';
2
- import { Platform, View, ViewProps } from 'react-native';
1
+ import React from 'react';
2
+ import { Platform, View, ViewProps, StyleSheet } from 'react-native';
3
3
  import Animated, {
4
4
  useAnimatedStyle,
5
5
  withSpring,
@@ -9,6 +9,13 @@ import Animated, {
9
9
  import { LineChartCursor, LineChartCursorProps } from './Cursor';
10
10
  import { useLineChart } from './useLineChart';
11
11
 
12
+ /**
13
+ * Delay in milliseconds before enabling spring animations on Android. This
14
+ * prevents crashes that can occur when spring animations are enabled on initial
15
+ * render.
16
+ */
17
+ const ANDROID_SPRING_ANIMATION_DELAY_MS = 100;
18
+
12
19
  type LineChartCursorCrosshairProps = Omit<
13
20
  LineChartCursorProps,
14
21
  'children' | 'type'
@@ -41,9 +48,10 @@ export function LineChartCursorCrosshair({
41
48
  Platform.OS === 'ios'
42
49
  );
43
50
  React.useEffect(() => {
44
- setTimeout(() => {
51
+ const timer = setTimeout(() => {
45
52
  setEnableSpringAnimation(true);
46
- }, 100);
53
+ }, ANDROID_SPRING_ANIMATION_DELAY_MS);
54
+ return () => clearTimeout(timer);
47
55
  }, []);
48
56
 
49
57
  const animatedCursorStyle = useAnimatedStyle(
@@ -55,6 +63,8 @@ export function LineChartCursorCrosshair({
55
63
  scale: enableSpringAnimation
56
64
  ? withSpring(isActive.value ? 1 : 0, {
57
65
  damping: 10,
66
+ stiffness: 100,
67
+ mass: 0.3,
58
68
  })
59
69
  : 0,
60
70
  },
@@ -68,11 +78,10 @@ export function LineChartCursorCrosshair({
68
78
  <Animated.View
69
79
  {...crosshairWrapperProps}
70
80
  style={[
81
+ styles.crosshairWrapper,
71
82
  {
72
83
  width: outerSize,
73
84
  height: outerSize,
74
- alignItems: 'center',
75
- justifyContent: 'center',
76
85
  },
77
86
  animatedCursorStyle,
78
87
  crosshairWrapperProps.style,
@@ -81,13 +90,12 @@ export function LineChartCursorCrosshair({
81
90
  <View
82
91
  {...crosshairOuterProps}
83
92
  style={[
93
+ styles.crosshairOuter,
84
94
  {
85
95
  backgroundColor: color,
86
96
  width: outerSize,
87
97
  height: outerSize,
88
98
  borderRadius: outerSize,
89
- opacity: 0.1,
90
- position: 'absolute',
91
99
  },
92
100
  crosshairOuterProps.style,
93
101
  ]}
@@ -109,3 +117,14 @@ export function LineChartCursorCrosshair({
109
117
  </LineChartCursor>
110
118
  );
111
119
  }
120
+
121
+ const styles = StyleSheet.create({
122
+ crosshairWrapper: {
123
+ alignItems: 'center',
124
+ justifyContent: 'center',
125
+ },
126
+ crosshairOuter: {
127
+ opacity: 0.1,
128
+ position: 'absolute',
129
+ },
130
+ });
@@ -1,53 +1,213 @@
1
1
  import React from 'react';
2
- import { StyleSheet } from 'react-native';
3
- import Animated, { useAnimatedStyle } from 'react-native-reanimated';
4
- import Svg, { Line as SVGLine, LineProps } from 'react-native-svg';
2
+ import { StyleSheet, type TextStyle } from 'react-native';
3
+ import Animated, {
4
+ useAnimatedStyle,
5
+ useDerivedValue,
6
+ useAnimatedProps,
7
+ } from 'react-native-reanimated';
8
+ import Svg, { type LineProps, Line as SVGLine } from 'react-native-svg';
5
9
 
10
+ import type { TFormatterFn } from '../../types';
11
+ import { AnimatedText } from '../../components/AnimatedText';
6
12
  import { LineChartDimensionsContext } from './Chart';
7
- import { LineChartCursor, LineChartCursorProps } from './Cursor';
13
+ import { LineChartCursor, type LineChartCursorProps } from './Cursor';
14
+ import { useLineChartDatetime } from './useDatetime';
8
15
  import { useLineChart } from './useLineChart';
16
+ import { useLineChartPrice } from './usePrice';
9
17
 
10
18
  type LineChartCursorLineProps = {
11
19
  children?: React.ReactNode;
12
20
  color?: string;
13
21
  lineProps?: Partial<LineProps>;
22
+ format?: TFormatterFn<string | number>;
23
+ textStyle?: TextStyle;
14
24
  } & Omit<LineChartCursorProps, 'type' | 'children'>;
15
25
 
16
26
  LineChartCursorLine.displayName = 'LineChartCursorLine';
17
27
 
28
+ const TEXT_CONSTANTS = {
29
+ DEFAULT_COLOR: '#1A1E27',
30
+ DEFAULT_FONT_SIZE: 12,
31
+ CHAR_WIDTH_RATIO: 0.6,
32
+ MIN_WIDTH: 25,
33
+ MAX_WIDTH: 150,
34
+ INPUT_PADDING: 4,
35
+ } as const;
36
+
37
+ const SPACING = {
38
+ VERTICAL_TEXT_OFFSET: 40,
39
+ HORIZONTAL_TEXT_MARGIN: 8,
40
+ HORIZONTAL_RIGHT_MARGIN: 16,
41
+ BASE_LINE_GAP: 8,
42
+ X_AXIS_LABEL_RESERVED_HEIGHT: 40, // Reserved space at bottom for x-axis labels
43
+ } as const;
44
+
45
+ const AnimatedLine = Animated.createAnimatedComponent(SVGLine);
46
+
18
47
  export function LineChartCursorLine({
19
48
  children,
20
49
  color = 'gray',
21
50
  lineProps,
51
+ format,
52
+ textStyle,
22
53
  ...cursorProps
23
54
  }: LineChartCursorLineProps) {
24
- const { height } = React.useContext(LineChartDimensionsContext);
25
- const { currentX, isActive } = useLineChart();
55
+ const isHorizontal = cursorProps?.orientation === 'horizontal';
56
+ const { height, width } = React.useContext(LineChartDimensionsContext);
57
+ const { currentX, currentY, isActive } = useLineChart();
58
+
59
+ const price = useLineChartPrice({
60
+ format: isHorizontal ? (format as TFormatterFn<string>) : undefined,
61
+ precision: 2,
62
+ });
63
+
64
+ const datetime = useLineChartDatetime({
65
+ format: !isHorizontal ? (format as TFormatterFn<number>) : undefined,
66
+ });
67
+
68
+ const displayText = isHorizontal ? price.formatted : datetime.formatted;
69
+
70
+ const calculateTextWidth = (text: string, fontSize: number) => {
71
+ 'worklet';
72
+ const charWidth = fontSize * TEXT_CONSTANTS.CHAR_WIDTH_RATIO;
73
+ const calculatedWidth = text.length * charWidth;
74
+ return Math.max(
75
+ TEXT_CONSTANTS.MIN_WIDTH,
76
+ Math.min(TEXT_CONSTANTS.MAX_WIDTH, calculatedWidth)
77
+ );
78
+ };
79
+
80
+ const textWidth = useDerivedValue(() => {
81
+ const text = displayText.value;
82
+ if (!text) return TEXT_CONSTANTS.MIN_WIDTH;
83
+
84
+ const fontSize = textStyle?.fontSize || TEXT_CONSTANTS.DEFAULT_FONT_SIZE;
85
+ return calculateTextWidth(text, fontSize);
86
+ }, [displayText, textStyle?.fontSize]);
87
+
88
+ const lineEndX = useDerivedValue(() => {
89
+ if (!isHorizontal) return 0;
90
+
91
+ const fontSize = textStyle?.fontSize || TEXT_CONSTANTS.DEFAULT_FONT_SIZE;
92
+ const gap = Math.max(SPACING.BASE_LINE_GAP, fontSize * 0.5);
93
+
94
+ return (
95
+ width -
96
+ textWidth.value -
97
+ gap -
98
+ TEXT_CONSTANTS.INPUT_PADDING -
99
+ SPACING.HORIZONTAL_RIGHT_MARGIN
100
+ );
101
+ });
102
+
103
+ const lineEndY = useDerivedValue(() => {
104
+ if (isHorizontal) return 0;
105
+
106
+ // For vertical cursor, extend line to the chart area (excluding reserved label space)
107
+ return height - SPACING.X_AXIS_LABEL_RESERVED_HEIGHT;
108
+ });
109
+
110
+ const containerStyle = useAnimatedStyle(() => ({
111
+ opacity: isActive.value ? 1 : 0,
112
+ height: '100%',
113
+ transform: isHorizontal
114
+ ? [{ translateY: currentY.value }]
115
+ : [{ translateX: currentX.value }],
116
+ }));
117
+
118
+ const calculateFontSizeAdjustment = (fontSize: number) => {
119
+ 'worklet';
120
+ return Math.max(0.6, Math.min(0.8, 0.7 + (fontSize - 12) * 0.01));
121
+ };
122
+
123
+ const textPositionStyle = useAnimatedStyle(() => {
124
+ const fontSize = textStyle?.fontSize || TEXT_CONSTANTS.DEFAULT_FONT_SIZE;
125
+ const lineHeight = textStyle?.lineHeight || fontSize * 1.2;
126
+
127
+ const baseStyle = {
128
+ position: 'absolute' as const,
129
+ width: textWidth.value,
130
+ fontSize,
131
+ lineHeight,
132
+ color: textStyle?.color || TEXT_CONSTANTS.DEFAULT_COLOR,
133
+ ...textStyle,
134
+ };
135
+
136
+ if (isHorizontal) {
137
+ const fontSizeAdjustment = calculateFontSizeAdjustment(fontSize);
138
+ const textCenterOffset = -(lineHeight * fontSizeAdjustment);
139
+
140
+ return {
141
+ ...baseStyle,
142
+ left:
143
+ width -
144
+ textWidth.value -
145
+ SPACING.HORIZONTAL_RIGHT_MARGIN +
146
+ TEXT_CONSTANTS.INPUT_PADDING,
147
+ top: textCenterOffset,
148
+ textAlign: 'right' as const,
149
+ paddingLeft: 0,
150
+ paddingRight: 0,
151
+ };
152
+ }
153
+
154
+ // For vertical cursor (x-axis label)
155
+ const halfTextWidth = textWidth.value / 2;
156
+
157
+ // Since the container is already translated by currentX, we need to calculate
158
+ // the label position relative to the container's position
159
+ const containerX = currentX.value;
160
+
161
+ // Calculate where the label would be if centered
162
+ let labelLeft = -halfTextWidth;
163
+
164
+ // Check if label would overflow on the left
165
+ if (containerX + labelLeft < 0) {
166
+ labelLeft = -containerX;
167
+ }
168
+
169
+ // Check if label would overflow on the right
170
+ if (containerX + labelLeft + textWidth.value > width) {
171
+ labelLeft = width - containerX - textWidth.value;
172
+ }
173
+
174
+ // Position label in the reserved space at the bottom
175
+ const labelTop =
176
+ height -
177
+ SPACING.X_AXIS_LABEL_RESERVED_HEIGHT +
178
+ SPACING.HORIZONTAL_TEXT_MARGIN;
179
+
180
+ return {
181
+ ...baseStyle,
182
+ left: labelLeft,
183
+ top: labelTop,
184
+ textAlign: 'center' as const,
185
+ };
186
+ });
26
187
 
27
- const vertical = useAnimatedStyle(
188
+ const lineAnimatedProps = useAnimatedProps(
28
189
  () => ({
29
- opacity: isActive.value ? 1 : 0,
30
- height: '100%',
31
- transform: [{ translateX: currentX.value }],
190
+ x1: 0,
191
+ y1: 0,
192
+ x2: lineEndX.value,
193
+ y2: lineEndY.value,
32
194
  }),
33
- [currentX, isActive]
195
+ [lineEndX, lineEndY]
34
196
  );
35
197
 
36
198
  return (
37
199
  <LineChartCursor {...cursorProps} type="line">
38
- <Animated.View style={vertical}>
200
+ <Animated.View style={containerStyle}>
39
201
  <Svg style={styles.svg}>
40
- <SVGLine
41
- x1={0}
42
- y1={0}
43
- x2={0}
44
- y2={height}
202
+ <AnimatedLine
203
+ animatedProps={lineAnimatedProps}
45
204
  strokeWidth={2}
46
205
  stroke={color}
47
206
  strokeDasharray="3 3"
48
207
  {...lineProps}
49
208
  />
50
209
  </Svg>
210
+ <AnimatedText text={displayText} style={textPositionStyle} />
51
211
  </Animated.View>
52
212
  {children}
53
213
  </LineChartCursor>
@@ -57,7 +217,6 @@ export function LineChartCursorLine({
57
217
  const styles = StyleSheet.create({
58
218
  svg: {
59
219
  ...StyleSheet.absoluteFillObject,
60
- // height: 100% is required for <svg /> on web
61
220
  height: '100%',
62
221
  },
63
222
  });
@@ -76,8 +76,9 @@ function validateLineChartId(dataContext: LineChartDataContext, id?: string) {
76
76
  const joinedIds = otherIds.join(', ');
77
77
 
78
78
  const suggestion = otherIds.length
79
- ? `Did you mean to use ${singular ? 'this ID' : 'one of these IDs'
80
- }: ${joinedIds}`
79
+ ? `Did you mean to use ${
80
+ singular ? 'this ID' : 'one of these IDs'
81
+ }: ${joinedIds}`
81
82
  : `You didn't pass any IDs to your <LineChart.Provider />'s data prop. Did you mean to pass an array instead?`;
82
83
 
83
84
  console.warn(
@@ -91,8 +92,9 @@ ${suggestion}`
91
92
 
92
93
  const joinedIds = otherIds.join(', ');
93
94
  const suggestion = otherIds.length
94
- ? `Did you mean to use ${singular ? 'this ID' : 'one of these IDs'
95
- }: ${joinedIds}`
95
+ ? `Did you mean to use ${
96
+ singular ? 'this ID' : 'one of these IDs'
97
+ }: ${joinedIds}`
96
98
  : `You didn't pass any IDs to your <LineChart.Provider />'s data prop. Did you mean to pass an array instead?`;
97
99
 
98
100
  console.error(`[react-native-wagmi-charts] Missing data "id" prop on LineChart. You must pass an id prop to <LineChart /> when using a dictionary for your data.