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
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
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,
|
|
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,
|
|
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
|
|
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
|
-
|
|
75
|
+
return () => {
|
|
76
|
+
isMounted.value = false;
|
|
77
|
+
};
|
|
69
78
|
}, []);
|
|
70
79
|
|
|
71
80
|
////////////////////////////////////////////////
|
|
72
81
|
|
|
73
|
-
const
|
|
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
|
-
|
|
128
|
-
|
|
141
|
+
BACKGROUND_COMPONENTS.includes(
|
|
142
|
+
(child as ReactElementWithDisplayName)?.type?.displayName || ''
|
|
143
|
+
)
|
|
129
144
|
);
|
|
130
145
|
foregroundChildren = iterableChildren.filter((child) =>
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
|
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 =
|
|
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 =
|
|
50
|
-
() =>
|
|
51
|
-
|
|
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
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import Animated, { runOnJS } from 'react-native-reanimated';
|
|
4
4
|
import {
|
|
@@ -22,8 +22,10 @@ export type LineChartCursorProps = {
|
|
|
22
22
|
snapToPoint?: boolean;
|
|
23
23
|
at?: number;
|
|
24
24
|
shouldCancelWhenOutside?: boolean;
|
|
25
|
+
minDurationMs?: number;
|
|
25
26
|
onActivated?: () => void;
|
|
26
27
|
onEnded?: () => void;
|
|
28
|
+
orientation?: 'horizontal' | 'vertical';
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
export const CursorContext = React.createContext({ type: '' });
|
|
@@ -36,6 +38,7 @@ export function LineChartCursor({
|
|
|
36
38
|
type,
|
|
37
39
|
at,
|
|
38
40
|
shouldCancelWhenOutside = false,
|
|
41
|
+
minDurationMs = 0,
|
|
39
42
|
onActivated,
|
|
40
43
|
onEnded,
|
|
41
44
|
}: LineChartCursorProps) {
|
|
@@ -73,11 +76,11 @@ export function LineChartCursor({
|
|
|
73
76
|
0
|
|
74
77
|
);
|
|
75
78
|
|
|
76
|
-
const
|
|
77
|
-
closestIndex > 0
|
|
78
|
-
? parsedPath.curves[closestPathCurve]
|
|
79
|
-
:
|
|
80
|
-
).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;
|
|
81
84
|
// Update values
|
|
82
85
|
currentIndex.value = closestIndex;
|
|
83
86
|
currentX.value = newXPosition;
|
|
@@ -114,7 +117,7 @@ export function LineChartCursor({
|
|
|
114
117
|
};
|
|
115
118
|
|
|
116
119
|
const longPressGesture = Gesture.LongPress()
|
|
117
|
-
.minDuration(0)
|
|
120
|
+
.minDuration(minDurationMs ?? 0)
|
|
118
121
|
.maxDistance(999999)
|
|
119
122
|
.shouldCancelWhenOutside(shouldCancelWhenOutside)
|
|
120
123
|
.onStart(
|
|
@@ -133,8 +136,14 @@ export function LineChartCursor({
|
|
|
133
136
|
)
|
|
134
137
|
.onTouchesMove((event) => {
|
|
135
138
|
'worklet';
|
|
136
|
-
if (
|
|
137
|
-
|
|
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);
|
|
138
147
|
updatePosition(xPosition);
|
|
139
148
|
}
|
|
140
149
|
})
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import
|
|
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,
|
|
6
|
+
AnimatedProps,
|
|
6
7
|
} from 'react-native-reanimated';
|
|
7
8
|
|
|
8
9
|
import { LineChartCursor, LineChartCursorProps } from './Cursor';
|
|
9
10
|
import { useLineChart } from './useLineChart';
|
|
10
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
|
+
|
|
11
19
|
type LineChartCursorCrosshairProps = Omit<
|
|
12
20
|
LineChartCursorProps,
|
|
13
21
|
'children' | 'type'
|
|
@@ -16,7 +24,7 @@ type LineChartCursorCrosshairProps = Omit<
|
|
|
16
24
|
color?: string;
|
|
17
25
|
size?: number;
|
|
18
26
|
outerSize?: number;
|
|
19
|
-
crosshairWrapperProps?:
|
|
27
|
+
crosshairWrapperProps?: AnimatedProps<ViewProps>;
|
|
20
28
|
crosshairProps?: ViewProps;
|
|
21
29
|
crosshairOuterProps?: ViewProps;
|
|
22
30
|
};
|
|
@@ -40,9 +48,10 @@ export function LineChartCursorCrosshair({
|
|
|
40
48
|
Platform.OS === 'ios'
|
|
41
49
|
);
|
|
42
50
|
React.useEffect(() => {
|
|
43
|
-
setTimeout(() => {
|
|
51
|
+
const timer = setTimeout(() => {
|
|
44
52
|
setEnableSpringAnimation(true);
|
|
45
|
-
},
|
|
53
|
+
}, ANDROID_SPRING_ANIMATION_DELAY_MS);
|
|
54
|
+
return () => clearTimeout(timer);
|
|
46
55
|
}, []);
|
|
47
56
|
|
|
48
57
|
const animatedCursorStyle = useAnimatedStyle(
|
|
@@ -54,6 +63,8 @@ export function LineChartCursorCrosshair({
|
|
|
54
63
|
scale: enableSpringAnimation
|
|
55
64
|
? withSpring(isActive.value ? 1 : 0, {
|
|
56
65
|
damping: 10,
|
|
66
|
+
stiffness: 100,
|
|
67
|
+
mass: 0.3,
|
|
57
68
|
})
|
|
58
69
|
: 0,
|
|
59
70
|
},
|
|
@@ -67,11 +78,10 @@ export function LineChartCursorCrosshair({
|
|
|
67
78
|
<Animated.View
|
|
68
79
|
{...crosshairWrapperProps}
|
|
69
80
|
style={[
|
|
81
|
+
styles.crosshairWrapper,
|
|
70
82
|
{
|
|
71
83
|
width: outerSize,
|
|
72
84
|
height: outerSize,
|
|
73
|
-
alignItems: 'center',
|
|
74
|
-
justifyContent: 'center',
|
|
75
85
|
},
|
|
76
86
|
animatedCursorStyle,
|
|
77
87
|
crosshairWrapperProps.style,
|
|
@@ -80,13 +90,12 @@ export function LineChartCursorCrosshair({
|
|
|
80
90
|
<View
|
|
81
91
|
{...crosshairOuterProps}
|
|
82
92
|
style={[
|
|
93
|
+
styles.crosshairOuter,
|
|
83
94
|
{
|
|
84
95
|
backgroundColor: color,
|
|
85
96
|
width: outerSize,
|
|
86
97
|
height: outerSize,
|
|
87
98
|
borderRadius: outerSize,
|
|
88
|
-
opacity: 0.1,
|
|
89
|
-
position: 'absolute',
|
|
90
99
|
},
|
|
91
100
|
crosshairOuterProps.style,
|
|
92
101
|
]}
|
|
@@ -108,3 +117,14 @@ export function LineChartCursorCrosshair({
|
|
|
108
117
|
</LineChartCursor>
|
|
109
118
|
);
|
|
110
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, {
|
|
4
|
-
|
|
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
|
|
25
|
-
const {
|
|
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
|
|
188
|
+
const lineAnimatedProps = useAnimatedProps(
|
|
28
189
|
() => ({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
190
|
+
x1: 0,
|
|
191
|
+
y1: 0,
|
|
192
|
+
x2: lineEndX.value,
|
|
193
|
+
y2: lineEndY.value,
|
|
32
194
|
}),
|
|
33
|
-
[
|
|
195
|
+
[lineEndX, lineEndY]
|
|
34
196
|
);
|
|
35
197
|
|
|
36
198
|
return (
|
|
37
199
|
<LineChartCursor {...cursorProps} type="line">
|
|
38
|
-
<Animated.View style={
|
|
200
|
+
<Animated.View style={containerStyle}>
|
|
39
201
|
<Svg style={styles.svg}>
|
|
40
|
-
<
|
|
41
|
-
|
|
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
|
});
|