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.
- 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 +190 -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 +129 -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 +151 -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 +86 -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 +18 -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 +16 -10
- 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 +15 -8
- 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 -13
- package/lib/typescript/src/charts/line/Cursor.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +24 -12
- 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 +15 -9
- package/lib/typescript/src/charts/line/DatetimeText.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Dot.d.ts +39 -26
- package/lib/typescript/src/charts/line/Dot.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Gradient.d.ts +9 -5
- 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 +17 -9
- 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 +28 -23
- package/lib/typescript/src/charts/line/Path.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/PriceText.d.ts +29 -13
- package/lib/typescript/src/charts/line/PriceText.d.ts.map +1 -1
- package/lib/typescript/src/charts/line/Tooltip.d.ts +34 -22
- 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 +20 -8
- package/src/charts/candle/CrosshairTooltip.tsx +3 -1
- package/src/charts/candle/DatetimeText.tsx +1 -1
- package/src/charts/candle/PriceText.tsx +2 -1
- 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 +15 -11
- package/src/charts/line/CursorCrosshair.tsx +27 -8
- package/src/charts/line/CursorLine.tsx +177 -18
- package/src/charts/line/Data.tsx +6 -4
- package/src/charts/line/DatetimeText.tsx +12 -3
- package/src/charts/line/Dot.tsx +2 -2
- package/src/charts/line/Gradient.tsx +2 -5
- package/src/charts/line/Highlight.tsx +8 -4
- package/src/charts/line/HorizontalLine.tsx +2 -8
- package/src/charts/line/HoverTrap/index.web.tsx +93 -60
- package/src/charts/line/Path.tsx +10 -17
- package/src/charts/line/PriceText.tsx +74 -4
- package/src/charts/line/Tooltip.tsx +135 -69
- 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 {
|
|
@@ -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
|
|
79
|
-
closestIndex > 0
|
|
80
|
-
? parsedPath.curves[closestPathCurve]
|
|
81
|
-
:
|
|
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 (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
|
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
|
-
},
|
|
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, {
|
|
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
|
});
|
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.
|