react-native-wagmi-charts 2.7.2 → 2.8.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.
- package/README.md +42 -15
- package/lib/commonjs/charts/candle/Candle.js +177 -93
- package/lib/commonjs/charts/candle/Candle.js.map +1 -1
- package/lib/commonjs/charts/candle/Candles.js +66 -43
- package/lib/commonjs/charts/candle/Candles.js.map +1 -1
- package/lib/commonjs/charts/candle/Chart.js +38 -28
- package/lib/commonjs/charts/candle/Chart.js.map +1 -1
- package/lib/commonjs/charts/candle/Context.js +74 -43
- package/lib/commonjs/charts/candle/Context.js.map +1 -1
- package/lib/commonjs/charts/candle/Crosshair.js +191 -81
- package/lib/commonjs/charts/candle/Crosshair.js.map +1 -1
- package/lib/commonjs/charts/candle/CrosshairTooltip.js +140 -61
- package/lib/commonjs/charts/candle/CrosshairTooltip.js.map +1 -1
- package/lib/commonjs/charts/candle/DatetimeText.js +19 -14
- package/lib/commonjs/charts/candle/DatetimeText.js.map +1 -1
- package/lib/commonjs/charts/candle/Line.js +73 -28
- package/lib/commonjs/charts/candle/Line.js.map +1 -1
- package/lib/commonjs/charts/candle/PriceText.js +19 -14
- package/lib/commonjs/charts/candle/PriceText.js.map +1 -1
- package/lib/commonjs/charts/candle/index.js +67 -64
- package/lib/commonjs/charts/candle/types.js +4 -4
- package/lib/commonjs/charts/candle/useCandleData.js +9 -12
- package/lib/commonjs/charts/candle/useCandlestickChart.js +10 -9
- package/lib/commonjs/charts/candle/useCandlestickChart.js.map +1 -1
- package/lib/commonjs/charts/candle/useDatetime.js +16 -18
- package/lib/commonjs/charts/candle/useDatetime.js.map +1 -1
- package/lib/commonjs/charts/candle/usePrice.js +21 -22
- package/lib/commonjs/charts/candle/usePrice.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/getDomain.js +5 -8
- package/lib/commonjs/charts/candle/utils/getHeight.js +12 -11
- package/lib/commonjs/charts/candle/utils/getPrice.js +12 -11
- package/lib/commonjs/charts/candle/utils/getY.js +12 -11
- package/lib/commonjs/charts/candle/utils/index.js +16 -16
- package/lib/commonjs/charts/line/Axis.js +402 -0
- package/lib/commonjs/charts/line/Axis.js.map +1 -0
- package/lib/commonjs/charts/line/Chart.js +140 -69
- package/lib/commonjs/charts/line/Chart.js.map +1 -1
- package/lib/commonjs/charts/line/ChartPath.js +290 -90
- package/lib/commonjs/charts/line/ChartPath.js.map +1 -1
- package/lib/commonjs/charts/line/Context.js +98 -40
- package/lib/commonjs/charts/line/Context.js.map +1 -1
- package/lib/commonjs/charts/line/Cursor.js +130 -75
- package/lib/commonjs/charts/line/Cursor.js.map +1 -1
- package/lib/commonjs/charts/line/CursorCrosshair.js +151 -58
- package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
- package/lib/commonjs/charts/line/CursorLine.js +251 -45
- package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
- package/lib/commonjs/charts/line/Data.js +73 -35
- package/lib/commonjs/charts/line/Data.js.map +1 -1
- package/lib/commonjs/charts/line/DatetimeText.js +27 -14
- package/lib/commonjs/charts/line/DatetimeText.js.map +1 -1
- package/lib/commonjs/charts/line/Dot.js +150 -57
- package/lib/commonjs/charts/line/Dot.js.map +1 -1
- package/lib/commonjs/charts/line/Gradient.js +124 -54
- package/lib/commonjs/charts/line/Gradient.js.map +1 -1
- package/lib/commonjs/charts/line/Group.js +54 -24
- package/lib/commonjs/charts/line/Group.js.map +1 -1
- package/lib/commonjs/charts/line/Highlight.js +115 -47
- package/lib/commonjs/charts/line/Highlight.js.map +1 -1
- package/lib/commonjs/charts/line/HorizontalLine.js +92 -40
- package/lib/commonjs/charts/line/HorizontalLine.js.map +1 -1
- package/lib/commonjs/charts/line/HoverTrap/index.js +10 -7
- package/lib/commonjs/charts/line/HoverTrap/index.js.map +1 -1
- package/lib/commonjs/charts/line/HoverTrap/index.web.js +115 -86
- package/lib/commonjs/charts/line/HoverTrap/index.web.js.map +1 -1
- package/lib/commonjs/charts/line/LineChartPathContext.js +14 -11
- package/lib/commonjs/charts/line/LineChartPathContext.js.map +1 -1
- package/lib/commonjs/charts/line/Path.js +78 -39
- package/lib/commonjs/charts/line/Path.js.map +1 -1
- package/lib/commonjs/charts/line/PriceText.js +113 -14
- package/lib/commonjs/charts/line/PriceText.js.map +1 -1
- package/lib/commonjs/charts/line/Tooltip.js +236 -106
- package/lib/commonjs/charts/line/Tooltip.js.map +1 -1
- package/lib/commonjs/charts/line/index.js +75 -62
- package/lib/commonjs/charts/line/index.js.map +1 -1
- package/lib/commonjs/charts/line/types.js +4 -4
- package/lib/commonjs/charts/line/useAnimatedPath.js +28 -23
- package/lib/commonjs/charts/line/useAnimatedPath.js.map +1 -1
- package/lib/commonjs/charts/line/useCurrentY.js +17 -17
- package/lib/commonjs/charts/line/useDatetime.js +34 -33
- package/lib/commonjs/charts/line/useDatetime.js.map +1 -1
- package/lib/commonjs/charts/line/useLineChart.js +21 -17
- package/lib/commonjs/charts/line/useLineChart.js.map +1 -1
- package/lib/commonjs/charts/line/usePrice.js +30 -28
- package/lib/commonjs/charts/line/usePrice.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getArea.js +48 -20
- package/lib/commonjs/charts/line/utils/getArea.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getDomain.js +5 -7
- package/lib/commonjs/charts/line/utils/getPath.js +54 -20
- package/lib/commonjs/charts/line/utils/getPath.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getXPositionForCurve.js +8 -5
- package/lib/commonjs/charts/line/utils/getXPositionForCurve.js.map +1 -1
- package/lib/commonjs/charts/line/utils/index.js +19 -19
- package/lib/commonjs/charts/line/utils/interpolatePath.js +102 -62
- package/lib/commonjs/charts/line/utils/interpolatePath.js.map +1 -1
- package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js +5 -5
- package/lib/commonjs/components/AnimatedText.js +66 -39
- package/lib/commonjs/components/AnimatedText.js.map +1 -1
- package/lib/commonjs/index.js +27 -16
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/formatDatetime.js +5 -9
- package/lib/commonjs/utils/formatPrice.js +13 -9
- package/lib/commonjs/utils/formatPrice.js.map +1 -1
- package/lib/commonjs/utils/index.js +13 -13
- package/lib/commonjs/utils/usePrevious.js +10 -9
- package/lib/commonjs/utils/usePrevious.js.map +1 -1
- package/lib/module/charts/candle/Candle.js +126 -76
- package/lib/module/charts/candle/Candle.js.map +1 -1
- package/lib/module/charts/candle/Candles.js +53 -34
- package/lib/module/charts/candle/Candles.js.map +1 -1
- package/lib/module/charts/candle/Chart.js +23 -20
- package/lib/module/charts/candle/Chart.js.map +1 -1
- package/lib/module/charts/candle/Context.js +53 -23
- package/lib/module/charts/candle/Context.js.map +1 -1
- package/lib/module/charts/candle/Crosshair.js +152 -69
- package/lib/module/charts/candle/Crosshair.js.map +1 -1
- package/lib/module/charts/candle/CrosshairTooltip.js +102 -52
- package/lib/module/charts/candle/CrosshairTooltip.js.map +1 -1
- package/lib/module/charts/candle/DatetimeText.js +5 -5
- package/lib/module/charts/candle/Line.js +37 -19
- package/lib/module/charts/candle/PriceText.js +5 -5
- package/lib/module/charts/candle/PriceText.js.map +1 -1
- package/lib/module/charts/candle/index.js +2 -2
- package/lib/module/charts/candle/types.js +1 -1
- package/lib/module/charts/candle/useCandleData.js +3 -7
- package/lib/module/charts/candle/useCandlestickChart.js +2 -2
- package/lib/module/charts/candle/useCandlestickChart.js.map +1 -1
- package/lib/module/charts/candle/useDatetime.js +10 -12
- package/lib/module/charts/candle/useDatetime.js.map +1 -1
- package/lib/module/charts/candle/usePrice.js +12 -14
- package/lib/module/charts/candle/usePrice.js.map +1 -1
- package/lib/module/charts/candle/utils/getDomain.js +2 -5
- package/lib/module/charts/candle/utils/getHeight.js +8 -7
- package/lib/module/charts/candle/utils/getPrice.js +2 -6
- package/lib/module/charts/candle/utils/getY.js +2 -6
- package/lib/module/charts/candle/utils/index.js +1 -1
- package/lib/module/charts/line/Axis.js +349 -0
- package/lib/module/charts/line/Axis.js.map +1 -0
- package/lib/module/charts/line/Chart.js +82 -46
- package/lib/module/charts/line/Chart.js.map +1 -1
- package/lib/module/charts/line/ChartPath.js +246 -77
- package/lib/module/charts/line/ChartPath.js.map +1 -1
- package/lib/module/charts/line/Context.js +65 -32
- package/lib/module/charts/line/Context.js.map +1 -1
- package/lib/module/charts/line/Cursor.js +87 -60
- package/lib/module/charts/line/Cursor.js.map +1 -1
- package/lib/module/charts/line/CursorCrosshair.js +118 -50
- package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
- package/lib/module/charts/line/CursorLine.js +210 -33
- package/lib/module/charts/line/CursorLine.js.map +1 -1
- package/lib/module/charts/line/Data.js +41 -28
- package/lib/module/charts/line/Data.js.map +1 -1
- package/lib/module/charts/line/DatetimeText.js +14 -6
- package/lib/module/charts/line/DatetimeText.js.map +1 -1
- package/lib/module/charts/line/Dot.js +95 -41
- package/lib/module/charts/line/Dot.js.map +1 -1
- package/lib/module/charts/line/Gradient.js +80 -42
- package/lib/module/charts/line/Gradient.js.map +1 -1
- package/lib/module/charts/line/Group.js +15 -14
- package/lib/module/charts/line/Highlight.js +62 -32
- package/lib/module/charts/line/Highlight.js.map +1 -1
- package/lib/module/charts/line/HorizontalLine.js +49 -27
- package/lib/module/charts/line/HorizontalLine.js.map +1 -1
- package/lib/module/charts/line/HoverTrap/index.js +3 -2
- package/lib/module/charts/line/HoverTrap/index.web.js +102 -76
- package/lib/module/charts/line/HoverTrap/index.web.js.map +1 -1
- package/lib/module/charts/line/LineChartPathContext.js +3 -3
- package/lib/module/charts/line/Path.js +34 -27
- package/lib/module/charts/line/Path.js.map +1 -1
- package/lib/module/charts/line/PriceText.js +80 -6
- package/lib/module/charts/line/PriceText.js.map +1 -1
- package/lib/module/charts/line/Tooltip.js +202 -94
- package/lib/module/charts/line/Tooltip.js.map +1 -1
- package/lib/module/charts/line/index.js +6 -3
- package/lib/module/charts/line/index.js.map +1 -1
- package/lib/module/charts/line/types.js +1 -1
- package/lib/module/charts/line/useAnimatedPath.js +22 -16
- package/lib/module/charts/line/useAnimatedPath.js.map +1 -1
- package/lib/module/charts/line/useCurrentY.js +4 -9
- package/lib/module/charts/line/useDatetime.js +28 -27
- package/lib/module/charts/line/useDatetime.js.map +1 -1
- package/lib/module/charts/line/useLineChart.js +11 -8
- package/lib/module/charts/line/useLineChart.js.map +1 -1
- package/lib/module/charts/line/usePrice.js +24 -22
- package/lib/module/charts/line/usePrice.js.map +1 -1
- package/lib/module/charts/line/utils/getArea.js +16 -11
- package/lib/module/charts/line/utils/getArea.js.map +1 -1
- package/lib/module/charts/line/utils/getDomain.js +2 -4
- package/lib/module/charts/line/utils/getPath.js +22 -11
- package/lib/module/charts/line/utils/getPath.js.map +1 -1
- package/lib/module/charts/line/utils/getXPositionForCurve.js +5 -2
- package/lib/module/charts/line/utils/getXPositionForCurve.js.map +1 -1
- package/lib/module/charts/line/utils/index.js +1 -1
- package/lib/module/charts/line/utils/interpolatePath.js +99 -59
- package/lib/module/charts/line/utils/interpolatePath.js.map +1 -1
- package/lib/module/charts/line/utils/lineChartDataPropToArray.js +2 -2
- package/lib/module/components/AnimatedText.js +24 -30
- package/lib/module/components/AnimatedText.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +1 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/formatDatetime.js +2 -6
- package/lib/module/utils/formatPrice.js +10 -6
- package/lib/module/utils/formatPrice.js.map +1 -1
- package/lib/module/utils/index.js +1 -1
- package/lib/module/utils/usePrevious.js +2 -2
- package/lib/module/utils/usePrevious.js.map +1 -1
- package/lib/typescript/src/charts/candle/Candle.d.ts +45 -31
- package/lib/typescript/src/charts/candle/Candle.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/Candles.d.ts +25 -14
- package/lib/typescript/src/charts/candle/Candles.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/Chart.d.ts +13 -8
- package/lib/typescript/src/charts/candle/Chart.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/Context.d.ts +15 -8
- package/lib/typescript/src/charts/candle/Context.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/Crosshair.d.ts +19 -10
- package/lib/typescript/src/charts/candle/Crosshair.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/CrosshairTooltip.d.ts +16 -9
- package/lib/typescript/src/charts/candle/CrosshairTooltip.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/DatetimeText.d.ts +17 -11
- package/lib/typescript/src/charts/candle/DatetimeText.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/Line.d.ts +10 -5
- package/lib/typescript/src/charts/candle/Line.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/PriceText.d.ts +16 -9
- package/lib/typescript/src/charts/candle/PriceText.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/index.d.ts +32 -14
- package/lib/typescript/src/charts/candle/index.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/types.d.ts +16 -19
- package/lib/typescript/src/charts/candle/types.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/useCandleData.d.ts +1 -1
- package/lib/typescript/src/charts/candle/useCandlestickChart.d.ts +1 -1
- package/lib/typescript/src/charts/candle/useDatetime.d.ts +14 -10
- package/lib/typescript/src/charts/candle/useDatetime.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/usePrice.d.ts +13 -8
- package/lib/typescript/src/charts/candle/usePrice.d.ts.map +1 -1
- package/lib/typescript/src/charts/candle/utils/getDomain.d.ts +1 -1
- package/lib/typescript/src/charts/candle/utils/getHeight.d.ts +9 -5
- package/lib/typescript/src/charts/candle/utils/getPrice.d.ts +9 -5
- package/lib/typescript/src/charts/candle/utils/getY.d.ts +9 -5
- package/lib/typescript/src/charts/candle/utils/index.d.ts +1 -1
- package/lib/typescript/src/charts/line/Axis.d.ts +33 -0
- package/lib/typescript/src/charts/line/Axis.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Chart.d.ts +33 -23
- package/lib/typescript/src/charts/line/Chart.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/ChartPath.d.ts +29 -16
- package/lib/typescript/src/charts/line/ChartPath.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Context.d.ts +17 -10
- package/lib/typescript/src/charts/line/Context.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Cursor.d.ts +23 -12
- package/lib/typescript/src/charts/line/Cursor.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +25 -13
- package/lib/typescript/src/charts/line/CursorCrosshair.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/CursorLine.d.ts +19 -8
- package/lib/typescript/src/charts/line/CursorLine.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Data.d.ts +17 -13
- package/lib/typescript/src/charts/line/DatetimeText.d.ts +16 -10
- package/lib/typescript/src/charts/line/DatetimeText.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Dot.d.ts +40 -27
- package/lib/typescript/src/charts/line/Dot.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Gradient.d.ts +11 -7
- package/lib/typescript/src/charts/line/Gradient.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Group.d.ts +6 -3
- package/lib/typescript/src/charts/line/Highlight.d.ts +19 -11
- package/lib/typescript/src/charts/line/Highlight.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/HorizontalLine.d.ts +30 -26
- package/lib/typescript/src/charts/line/HorizontalLine.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/HoverTrap/index.d.ts +1 -1
- package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts +2 -2
- package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/LineChartPathContext.d.ts +4 -4
- package/lib/typescript/src/charts/line/Path.d.ts +30 -25
- package/lib/typescript/src/charts/line/Path.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/PriceText.d.ts +30 -14
- package/lib/typescript/src/charts/line/PriceText.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Tooltip.d.ts +36 -24
- package/lib/typescript/src/charts/line/Tooltip.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/index.d.ts +34 -20
- package/lib/typescript/src/charts/line/index.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/types.d.ts +19 -18
- package/lib/typescript/src/charts/line/types.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/useAnimatedPath.d.ts +10 -7
- package/lib/typescript/src/charts/line/useAnimatedPath.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/useCurrentY.d.ts +2 -2
- package/lib/typescript/src/charts/line/useCurrentY.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/useDatetime.d.ts +12 -8
- package/lib/typescript/src/charts/line/useDatetime.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/useLineChart.d.ts +10 -10
- package/lib/typescript/src/charts/line/usePrice.d.ts +12 -8
- package/lib/typescript/src/charts/line/usePrice.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/utils/getArea.d.ts +17 -9
- package/lib/typescript/src/charts/line/utils/getArea.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/utils/getDomain.d.ts +1 -1
- package/lib/typescript/src/charts/line/utils/getPath.d.ts +21 -11
- package/lib/typescript/src/charts/line/utils/getPath.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/utils/getXPositionForCurve.d.ts +1 -1
- package/lib/typescript/src/charts/line/utils/index.d.ts +1 -1
- package/lib/typescript/src/charts/line/utils/interpolatePath.d.ts +17 -5
- package/lib/typescript/src/charts/line/utils/lineChartDataPropToArray.d.ts +4 -2
- package/lib/typescript/src/components/AnimatedText.d.ts +7 -4
- package/lib/typescript/src/components/AnimatedText.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +8 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/formatDatetime.d.ts +9 -5
- package/lib/typescript/src/utils/formatPrice.d.ts +9 -5
- package/lib/typescript/src/utils/formatPrice.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -1
- package/lib/typescript/src/utils/usePrevious.d.ts +1 -1
- package/package.json +19 -43
- package/src/charts/candle/Candle.tsx +2 -17
- package/src/charts/candle/Candles.tsx +1 -3
- package/src/charts/candle/Chart.tsx +1 -1
- package/src/charts/candle/Context.tsx +30 -7
- package/src/charts/candle/Crosshair.tsx +25 -10
- package/src/charts/candle/CrosshairTooltip.tsx +3 -1
- package/src/charts/candle/DatetimeText.tsx +3 -3
- package/src/charts/candle/PriceText.tsx +4 -3
- package/src/charts/candle/types.ts +1 -7
- package/src/charts/candle/useCandlestickChart.ts +1 -1
- package/src/charts/candle/useDatetime.ts +3 -1
- package/src/charts/candle/usePrice.ts +5 -1
- package/src/charts/line/Axis.tsx +363 -0
- package/src/charts/line/Chart.tsx +10 -7
- package/src/charts/line/ChartPath.tsx +77 -18
- package/src/charts/line/Context.tsx +29 -18
- package/src/charts/line/Cursor.tsx +18 -9
- package/src/charts/line/CursorCrosshair.tsx +29 -9
- package/src/charts/line/CursorLine.tsx +177 -18
- package/src/charts/line/Data.tsx +6 -4
- package/src/charts/line/DatetimeText.tsx +14 -5
- package/src/charts/line/Dot.tsx +5 -4
- package/src/charts/line/Gradient.tsx +4 -7
- package/src/charts/line/Highlight.tsx +10 -6
- package/src/charts/line/HorizontalLine.tsx +2 -8
- package/src/charts/line/HoverTrap/index.web.tsx +93 -60
- package/src/charts/line/Path.tsx +12 -19
- package/src/charts/line/PriceText.tsx +76 -6
- package/src/charts/line/Tooltip.tsx +131 -64
- package/src/charts/line/index.ts +4 -1
- package/src/charts/line/types.ts +1 -2
- package/src/charts/line/useAnimatedPath.ts +1 -2
- package/src/charts/line/useDatetime.ts +13 -10
- package/src/charts/line/useLineChart.ts +1 -1
- package/src/charts/line/usePrice.ts +6 -4
- package/src/charts/line/utils/getArea.ts +12 -10
- package/src/charts/line/utils/getPath.ts +13 -10
- package/src/charts/line/utils/getXPositionForCurve.ts +1 -1
- package/src/charts/line/utils/interpolatePath.ts +2 -2
- package/src/components/AnimatedText.tsx +13 -20
- package/src/index.ts +1 -0
- package/src/types.ts +7 -0
- package/src/utils/formatPrice.ts +7 -7
- package/src/utils/usePrevious.ts +1 -1
package/src/charts/line/Data.tsx
CHANGED
|
@@ -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 ${
|
|
80
|
-
|
|
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 ${
|
|
95
|
-
|
|
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.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { TextProps as RNTextProps } from 'react-native';
|
|
3
|
-
import type
|
|
4
|
-
|
|
3
|
+
import type { AnimatedProps } from 'react-native-reanimated';
|
|
4
|
+
import { useDerivedValue } from 'react-native-reanimated';
|
|
5
5
|
import { useLineChartDatetime } from './useDatetime';
|
|
6
|
-
import type { TFormatterFn } from '
|
|
6
|
+
import type { TFormatterFn } from '../../types';
|
|
7
7
|
import { AnimatedText } from '../../components/AnimatedText';
|
|
8
8
|
|
|
9
9
|
type LineChartDatetimeProps = {
|
|
@@ -11,7 +11,7 @@ type LineChartDatetimeProps = {
|
|
|
11
11
|
options?: Intl.DateTimeFormatOptions;
|
|
12
12
|
format?: TFormatterFn<number>;
|
|
13
13
|
variant?: 'formatted' | 'value';
|
|
14
|
-
style?:
|
|
14
|
+
style?: AnimatedProps<RNTextProps>['style'];
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
LineChartDatetimeText.displayName = 'LineChartDatetimeText';
|
|
@@ -24,5 +24,14 @@ export function LineChartDatetimeText({
|
|
|
24
24
|
style,
|
|
25
25
|
}: LineChartDatetimeProps) {
|
|
26
26
|
const datetime = useLineChartDatetime({ format, locale, options });
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
const text = useDerivedValue(() => {
|
|
29
|
+
const value = datetime[variant].value;
|
|
30
|
+
if (typeof value === 'number') {
|
|
31
|
+
return value === 0 || isNaN(value) ? '' : value.toString();
|
|
32
|
+
}
|
|
33
|
+
return value || '';
|
|
34
|
+
}, [datetime, variant]);
|
|
35
|
+
|
|
36
|
+
return <AnimatedText text={text} style={style} />;
|
|
28
37
|
}
|
package/src/charts/line/Dot.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import Animated, {
|
|
4
4
|
Easing,
|
|
@@ -7,6 +7,7 @@ import Animated, {
|
|
|
7
7
|
withRepeat,
|
|
8
8
|
withSequence,
|
|
9
9
|
withTiming,
|
|
10
|
+
AnimatedProps,
|
|
10
11
|
} from 'react-native-reanimated';
|
|
11
12
|
import { Circle, CircleProps } from 'react-native-svg';
|
|
12
13
|
|
|
@@ -19,8 +20,8 @@ import { useLineChart } from './useLineChart';
|
|
|
19
20
|
const AnimatedCircle = Animated.createAnimatedComponent(Circle);
|
|
20
21
|
|
|
21
22
|
export type LineChartDotProps = {
|
|
22
|
-
dotProps?:
|
|
23
|
-
outerDotProps?:
|
|
23
|
+
dotProps?: AnimatedProps<CircleProps>;
|
|
24
|
+
outerDotProps?: AnimatedProps<CircleProps>;
|
|
24
25
|
color?: string;
|
|
25
26
|
inactiveColor?: string;
|
|
26
27
|
showInactiveColor?: boolean;
|
|
@@ -92,7 +93,7 @@ export function LineChartDot({
|
|
|
92
93
|
);
|
|
93
94
|
|
|
94
95
|
const animatedOuterDotProps = useAnimatedProps(() => {
|
|
95
|
-
|
|
96
|
+
const defaultProps = {
|
|
96
97
|
cx: x.value,
|
|
97
98
|
cy: y.value,
|
|
98
99
|
opacity: 0.1,
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import Animated from 'react-native-reanimated';
|
|
2
|
+
import Animated, { AnimatedProps } from 'react-native-reanimated';
|
|
3
3
|
import { Defs, LinearGradient, Stop, Path, PathProps } from 'react-native-svg';
|
|
4
|
-
|
|
5
4
|
import { LineChartDimensionsContext } from './Chart';
|
|
6
5
|
import { LineChartPathContext } from './LineChartPathContext';
|
|
7
|
-
import useAnimatedPath from './useAnimatedPath';
|
|
6
|
+
import { useAnimatedPath } from './useAnimatedPath';
|
|
8
7
|
|
|
9
8
|
const AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
10
9
|
|
|
11
|
-
export type LineChartGradientProps =
|
|
10
|
+
export type LineChartGradientProps = AnimatedProps<PathProps> & {
|
|
12
11
|
color?: string;
|
|
13
12
|
children?: React.ReactNode;
|
|
14
13
|
};
|
|
@@ -25,7 +24,6 @@ export function LineChartGradient({
|
|
|
25
24
|
const { area } = React.useContext(LineChartDimensionsContext);
|
|
26
25
|
const { color: contextColor, isTransitionEnabled } =
|
|
27
26
|
React.useContext(LineChartPathContext);
|
|
28
|
-
|
|
29
27
|
const color = overrideColor || contextColor;
|
|
30
28
|
|
|
31
29
|
////////////////////////////////////////////////
|
|
@@ -52,8 +50,7 @@ export function LineChartGradient({
|
|
|
52
50
|
y1="0"
|
|
53
51
|
y2="100%"
|
|
54
52
|
>
|
|
55
|
-
{
|
|
56
|
-
{children}
|
|
53
|
+
{children as React.ReactElement[]}
|
|
57
54
|
</LinearGradient>
|
|
58
55
|
</Defs>
|
|
59
56
|
) : (
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import Animated from 'react-native-reanimated';
|
|
2
|
+
import Animated, { AnimatedProps } from 'react-native-reanimated';
|
|
3
3
|
import { ClipPath, Defs, G, Path, PathProps, Rect } from 'react-native-svg';
|
|
4
|
-
|
|
5
4
|
import { LineChartDimensionsContext } from './Chart';
|
|
6
5
|
import { LineChartPathContext } from './LineChartPathContext';
|
|
7
|
-
import useAnimatedPath from './useAnimatedPath';
|
|
6
|
+
import { useAnimatedPath } from './useAnimatedPath';
|
|
8
7
|
import { getXPositionForCurve } from './utils/getXPositionForCurve';
|
|
9
8
|
|
|
10
9
|
const AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
11
10
|
|
|
12
|
-
export type LineChartColorProps =
|
|
11
|
+
export type LineChartColorProps = AnimatedProps<PathProps> & {
|
|
13
12
|
color?: string;
|
|
14
13
|
from: number;
|
|
15
14
|
to: number;
|
|
@@ -45,13 +44,18 @@ export function LineChartHighlight({
|
|
|
45
44
|
|
|
46
45
|
////////////////////////////////////////////////
|
|
47
46
|
|
|
47
|
+
const clipId = React.useMemo(
|
|
48
|
+
() => `clip-${Math.random().toString(36).substring(2, 11)}`,
|
|
49
|
+
[]
|
|
50
|
+
);
|
|
51
|
+
|
|
48
52
|
const clipStart = getXPositionForCurve(parsedPath, from);
|
|
49
53
|
const clipEnd = getXPositionForCurve(parsedPath, to);
|
|
50
54
|
|
|
51
55
|
return (
|
|
52
56
|
<G>
|
|
53
57
|
<Defs>
|
|
54
|
-
<ClipPath id=
|
|
58
|
+
<ClipPath id={clipId}>
|
|
55
59
|
<Rect
|
|
56
60
|
x={clipStart}
|
|
57
61
|
y="0"
|
|
@@ -62,7 +66,7 @@ export function LineChartHighlight({
|
|
|
62
66
|
</ClipPath>
|
|
63
67
|
</Defs>
|
|
64
68
|
<AnimatedPath
|
|
65
|
-
clipPath=
|
|
69
|
+
clipPath={`url(#${clipId})`}
|
|
66
70
|
animatedProps={animatedProps}
|
|
67
71
|
fill="transparent"
|
|
68
72
|
stroke={isInactive ? inactiveColor || color : color}
|
|
@@ -23,15 +23,11 @@ type HorizontalLineProps = {
|
|
|
23
23
|
* This may be useful to customize the line's position based on the thickness of your cursor or chart path.
|
|
24
24
|
*
|
|
25
25
|
* ```tsx
|
|
26
|
-
* <LineChart.HorizontalLine
|
|
27
|
-
* at={{ index: 3 }}
|
|
28
|
-
* />
|
|
26
|
+
* <LineChart.HorizontalLine at={{ index: 3 }} />
|
|
29
27
|
*
|
|
30
28
|
* // or
|
|
31
29
|
*
|
|
32
|
-
* <LineChart.HorizontalLine
|
|
33
|
-
* at={{ value: 320.32}}
|
|
34
|
-
* />
|
|
30
|
+
* <LineChart.HorizontalLine at={{ value: 320.32 }} />
|
|
35
31
|
* ```
|
|
36
32
|
*/
|
|
37
33
|
at?:
|
|
@@ -78,9 +74,7 @@ export function LineChartHorizontalLine({
|
|
|
78
74
|
|
|
79
75
|
const offsetTop = yDomain.max - at.value;
|
|
80
76
|
const percentageOffsetTop = offsetTop / (yDomain.max - yDomain.min);
|
|
81
|
-
|
|
82
77
|
const heightBetweenGutters = height - gutter * 2;
|
|
83
|
-
|
|
84
78
|
const offsetTopPixels = gutter + percentageOffsetTop * heightBetweenGutters;
|
|
85
79
|
|
|
86
80
|
return withTiming(offsetTopPixels + offsetY);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { View, StyleSheet } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import { LineChartDimensionsContext } from '../Chart';
|
|
@@ -6,74 +6,116 @@ import { useLineChart } from '../useLineChart';
|
|
|
6
6
|
|
|
7
7
|
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Minimum time in milliseconds that must pass between touch events before a
|
|
11
|
+
* hover state is activated on web.
|
|
12
|
+
*/
|
|
13
|
+
const HOVER_THRESHOLD_MS = 1000;
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* (including for multi-modality devices) and considers "hover" to be enabled
|
|
20
|
-
* if a mouse movement occurs more than 1 second after the last touch event.
|
|
21
|
-
* This threshold is long enough to account for longer delays between the
|
|
22
|
-
* browser firing touch and mouse events on low-powered devices.
|
|
23
|
-
*/
|
|
24
|
-
const HOVER_THRESHOLD_MS = 1000;
|
|
25
|
-
let lastTouchTimestamp = 0;
|
|
15
|
+
/**
|
|
16
|
+
* Hover state manager for web platform. This singleton ensures global hover
|
|
17
|
+
* detection is properly initialized and cleaned up.
|
|
18
|
+
*/
|
|
19
|
+
class HoverStateManager {
|
|
20
|
+
private isEnabled = false;
|
|
21
|
+
private lastTouchTimestamp = 0;
|
|
22
|
+
private initialized = false;
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
|
|
24
|
+
constructor() {
|
|
25
|
+
if (canUseDOM) {
|
|
26
|
+
this.initialize();
|
|
30
27
|
}
|
|
31
|
-
isEnabled = true;
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
private initialize() {
|
|
31
|
+
if (this.initialized) return;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The following logic comes from the creator of react-native-web:
|
|
35
|
+
* https://gist.github.com/necolas/1c494e44e23eb7f8c5864a2fac66299a
|
|
36
|
+
* It's also used by MotiPressable's hover interactions:
|
|
37
|
+
* https://github.com/nandorojo/moti/blob/master/packages/interactions/src/pressable/hoverable.tsx
|
|
38
|
+
*
|
|
39
|
+
* Web browsers emulate mouse events (and hover states) after touch events.
|
|
40
|
+
* This code infers when the currently-in-use modality supports hover
|
|
41
|
+
* (including for multi-modality devices) and considers "hover" to be enabled
|
|
42
|
+
* if a mouse movement occurs more than 1 second after the last touch event.
|
|
43
|
+
* This threshold is long enough to account for longer delays between the
|
|
44
|
+
* browser firing touch and mouse events on low-powered devices.
|
|
45
|
+
*/
|
|
46
|
+
document.addEventListener('touchstart', this.disableHover, true);
|
|
47
|
+
document.addEventListener('touchmove', this.disableHover, true);
|
|
48
|
+
document.addEventListener('mousemove', this.enableHover, true);
|
|
49
|
+
this.initialized = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private enableHover = () => {
|
|
53
|
+
if (
|
|
54
|
+
this.isEnabled ||
|
|
55
|
+
Date.now() - this.lastTouchTimestamp < HOVER_THRESHOLD_MS
|
|
56
|
+
) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.isEnabled = true;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
private disableHover = () => {
|
|
63
|
+
this.lastTouchTimestamp = Date.now();
|
|
64
|
+
if (this.isEnabled) {
|
|
65
|
+
this.isEnabled = false;
|
|
38
66
|
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
public isHoverEnabled(): boolean {
|
|
70
|
+
return this.isEnabled;
|
|
39
71
|
}
|
|
40
72
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Cleanup method for removing event listeners. Note: In practice, this may
|
|
75
|
+
* never be called since these are app-level listeners, but it's provided for
|
|
76
|
+
* completeness and testing purposes.
|
|
77
|
+
*/
|
|
78
|
+
public cleanup() {
|
|
79
|
+
if (!this.initialized || !canUseDOM) return;
|
|
80
|
+
document.removeEventListener('touchstart', this.disableHover, true);
|
|
81
|
+
document.removeEventListener('touchmove', this.disableHover, true);
|
|
82
|
+
document.removeEventListener('mousemove', this.enableHover, true);
|
|
83
|
+
this.initialized = false;
|
|
84
|
+
}
|
|
44
85
|
}
|
|
45
86
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
87
|
+
// Singleton instance
|
|
88
|
+
const hoverStateManager = new HoverStateManager();
|
|
49
89
|
|
|
50
90
|
export const LineChartHoverTrap = () => {
|
|
51
91
|
const { width, parsedPath } = React.useContext(LineChartDimensionsContext);
|
|
52
92
|
const { currentX, currentIndex, isActive, data } = useLineChart();
|
|
53
93
|
|
|
54
94
|
const onMouseMove = React.useCallback(
|
|
55
|
-
(
|
|
56
|
-
if (isHoverEnabled()) {
|
|
57
|
-
if (parsedPath) {
|
|
58
|
-
const boundedX = Math.min(x, width);
|
|
59
|
-
isActive.value = true;
|
|
60
|
-
currentX.value = boundedX;
|
|
61
|
-
|
|
62
|
-
// on Web, we could drag the cursor to be negative, breaking it
|
|
63
|
-
// so we clamp the index at 0 to fix it
|
|
64
|
-
// https://github.com/coinjar/react-native-wagmi-charts/issues/24
|
|
65
|
-
const minIndex = 0;
|
|
66
|
-
const boundedIndex = Math.max(
|
|
67
|
-
minIndex,
|
|
68
|
-
Math.round(boundedX / width / (1 / (data ? data.length - 1 : 1)))
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
currentIndex.value = boundedIndex;
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
95
|
+
(e: React.MouseEvent<HTMLElement>) => {
|
|
96
|
+
if (!hoverStateManager.isHoverEnabled()) {
|
|
74
97
|
isActive.value = false;
|
|
75
98
|
currentIndex.value = -1;
|
|
99
|
+
return;
|
|
76
100
|
}
|
|
101
|
+
|
|
102
|
+
if (!parsedPath) return;
|
|
103
|
+
|
|
104
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
105
|
+
const boundedX = Math.min(e.clientX - rect.left, width);
|
|
106
|
+
isActive.value = true;
|
|
107
|
+
currentX.value = boundedX;
|
|
108
|
+
|
|
109
|
+
// on Web, we could drag the cursor to be negative, breaking it
|
|
110
|
+
// so we clamp the index at 0 to fix it
|
|
111
|
+
// https://github.com/coinjar/react-native-wagmi-charts/issues/24
|
|
112
|
+
const minIndex = 0;
|
|
113
|
+
const boundedIndex = Math.max(
|
|
114
|
+
minIndex,
|
|
115
|
+
Math.round(boundedX / width / (1 / (data ? data.length - 1 : 1)))
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
currentIndex.value = boundedIndex;
|
|
77
119
|
},
|
|
78
120
|
[currentIndex, currentX, data, isActive, parsedPath, width]
|
|
79
121
|
);
|
|
@@ -87,16 +129,7 @@ export const LineChartHoverTrap = () => {
|
|
|
87
129
|
<View
|
|
88
130
|
style={StyleSheet.absoluteFill}
|
|
89
131
|
// @ts-expect-error mouse move event
|
|
90
|
-
onMouseMove={
|
|
91
|
-
// eslint-disable-next-line no-undef
|
|
92
|
-
(e: React.MouseEvent<HTMLElement>) => {
|
|
93
|
-
let rect = e.currentTarget.getBoundingClientRect();
|
|
94
|
-
let x = e.clientX - rect.left; // x position within the element.
|
|
95
|
-
|
|
96
|
-
onMouseMove({ x });
|
|
97
|
-
},
|
|
98
|
-
[onMouseMove]
|
|
99
|
-
)}
|
|
132
|
+
onMouseMove={onMouseMove}
|
|
100
133
|
onMouseLeave={onMouseLeave}
|
|
101
134
|
/>
|
|
102
135
|
);
|
package/src/charts/line/Path.tsx
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import Animated from 'react-native-reanimated';
|
|
2
|
+
import Animated, { AnimatedProps } from 'react-native-reanimated';
|
|
3
3
|
import { Path, PathProps } from 'react-native-svg';
|
|
4
|
-
|
|
5
4
|
import { LineChartDimensionsContext } from './Chart';
|
|
6
5
|
import { LineChartPathContext } from './LineChartPathContext';
|
|
7
|
-
import useAnimatedPath from './useAnimatedPath';
|
|
6
|
+
import { useAnimatedPath } from './useAnimatedPath';
|
|
8
7
|
|
|
9
8
|
const AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
10
9
|
|
|
11
|
-
export type LineChartPathProps =
|
|
10
|
+
export type LineChartPathProps = AnimatedProps<PathProps> & {
|
|
12
11
|
color?: string;
|
|
13
12
|
inactiveColor?: string;
|
|
14
13
|
width?: number;
|
|
@@ -20,7 +19,7 @@ export type LineChartPathProps = Animated.AnimateProps<PathProps> & {
|
|
|
20
19
|
*
|
|
21
20
|
* While this use case is rare, it may be useful on web, where animations might not work as well.
|
|
22
21
|
*
|
|
23
|
-
|
|
22
|
+
***Example**
|
|
24
23
|
*
|
|
25
24
|
* ```tsx
|
|
26
25
|
* <LineChart.Path
|
|
@@ -43,25 +42,19 @@ export function LineChartPath({
|
|
|
43
42
|
const { isTransitionEnabled, isInactive } =
|
|
44
43
|
React.useContext(LineChartPathContext);
|
|
45
44
|
|
|
46
|
-
////////////////////////////////////////////////
|
|
47
|
-
|
|
48
45
|
const { animatedProps } = useAnimatedPath({
|
|
49
46
|
enabled: isTransitionEnabled,
|
|
50
47
|
path,
|
|
51
48
|
});
|
|
52
49
|
|
|
53
|
-
////////////////////////////////////////////////
|
|
54
|
-
|
|
55
50
|
return (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/>
|
|
65
|
-
</>
|
|
51
|
+
<AnimatedPath
|
|
52
|
+
animatedProps={animatedProps}
|
|
53
|
+
fill="transparent"
|
|
54
|
+
stroke={isInactive ? inactiveColor || color : color}
|
|
55
|
+
strokeOpacity={isInactive && !inactiveColor ? 0.2 : 1}
|
|
56
|
+
strokeWidth={strokeWidth}
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
66
59
|
);
|
|
67
60
|
}
|
|
@@ -1,21 +1,35 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import type
|
|
4
|
-
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Text, TextStyle } from 'react-native';
|
|
3
|
+
import type { TextProps as RNTextProps, StyleProp } from 'react-native';
|
|
4
|
+
import type { AnimatedProps } from 'react-native-reanimated';
|
|
5
|
+
import {
|
|
6
|
+
useDerivedValue,
|
|
7
|
+
useAnimatedReaction,
|
|
8
|
+
runOnJS,
|
|
9
|
+
} from 'react-native-reanimated';
|
|
5
10
|
import { useLineChartPrice } from './usePrice';
|
|
6
|
-
import
|
|
11
|
+
import { useLineChart } from './useLineChart';
|
|
12
|
+
import type { TFormatterFn } from '../../types';
|
|
7
13
|
import { AnimatedText } from '../../components/AnimatedText';
|
|
8
14
|
|
|
9
15
|
export type LineChartPriceTextProps = {
|
|
10
16
|
format?: TFormatterFn<string>;
|
|
11
17
|
precision?: number;
|
|
12
18
|
variant?: 'formatted' | 'value';
|
|
13
|
-
style?:
|
|
19
|
+
style?: AnimatedProps<RNTextProps>['style'];
|
|
14
20
|
/**
|
|
15
21
|
* By default, it will use the current active index from the chart.
|
|
16
22
|
* If this is set it will use the index provided.
|
|
17
23
|
*/
|
|
18
24
|
index?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Use optimized rendering for high-frequency updates (bypasses AnimatedText)
|
|
27
|
+
*/
|
|
28
|
+
useOptimizedRendering?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Function to determine text color based on the formatted value
|
|
31
|
+
*/
|
|
32
|
+
getTextColor?: (formattedValue: string) => string;
|
|
19
33
|
};
|
|
20
34
|
|
|
21
35
|
LineChartPriceText.displayName = 'LineChartPriceText';
|
|
@@ -26,7 +40,63 @@ export function LineChartPriceText({
|
|
|
26
40
|
variant = 'formatted',
|
|
27
41
|
style,
|
|
28
42
|
index,
|
|
43
|
+
useOptimizedRendering = false,
|
|
44
|
+
getTextColor,
|
|
29
45
|
}: LineChartPriceTextProps) {
|
|
30
46
|
const price = useLineChartPrice({ format, precision, index });
|
|
47
|
+
|
|
48
|
+
// If we have a custom format function and optimized rendering is enabled,
|
|
49
|
+
// use regular React state instead of AnimatedText
|
|
50
|
+
if (format && useOptimizedRendering) {
|
|
51
|
+
const { currentIndex, data } = useLineChart();
|
|
52
|
+
const [displayText, setDisplayText] = useState('');
|
|
53
|
+
const [textColor, setTextColor] = useState('#000000');
|
|
54
|
+
|
|
55
|
+
const updateText = (newText: string) => {
|
|
56
|
+
setDisplayText(newText);
|
|
57
|
+
// Update color if getTextColor function is provided
|
|
58
|
+
if (getTextColor) {
|
|
59
|
+
setTextColor(getTextColor(newText));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const textValue = useDerivedValue(() => {
|
|
64
|
+
if (!data) {
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
if (
|
|
68
|
+
(typeof currentIndex.value === 'undefined' ||
|
|
69
|
+
currentIndex.value === -1) &&
|
|
70
|
+
index == null
|
|
71
|
+
) {
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
let price = 0;
|
|
75
|
+
price =
|
|
76
|
+
data[Math.min(index ?? currentIndex.value, data.length - 1)]!.value;
|
|
77
|
+
const valueString = price.toFixed(precision).toString();
|
|
78
|
+
|
|
79
|
+
// Call format function directly in worklet
|
|
80
|
+
return format({ value: valueString, formatted: valueString });
|
|
81
|
+
}, [currentIndex, data, precision]);
|
|
82
|
+
|
|
83
|
+
// Use useAnimatedReaction to update React state with runOnJS
|
|
84
|
+
useAnimatedReaction(
|
|
85
|
+
() => textValue.value,
|
|
86
|
+
(current, previous) => {
|
|
87
|
+
if (current !== previous) {
|
|
88
|
+
runOnJS(updateText)(current);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
[textValue]
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// Merge the text color with the provided style
|
|
95
|
+
const dynamicStyle = [style, { color: textColor }] as StyleProp<TextStyle>;
|
|
96
|
+
|
|
97
|
+
return <Text style={dynamicStyle}>{displayText}</Text>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// For non-custom format, use the original approach
|
|
31
101
|
return <AnimatedText text={price[variant]} style={style} />;
|
|
32
102
|
}
|