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,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
runOnJS,
|
|
4
|
+
SharedValue,
|
|
5
|
+
useAnimatedReaction,
|
|
6
|
+
useSharedValue,
|
|
7
|
+
} from 'react-native-reanimated';
|
|
3
8
|
|
|
4
9
|
import type { TContext, TData, TDomain } from './types';
|
|
5
10
|
import { getDomain } from './utils';
|
|
@@ -7,6 +12,7 @@ import { getDomain } from './utils';
|
|
|
7
12
|
export const CandlestickChartContext = React.createContext<TContext>({
|
|
8
13
|
currentX: { value: -1 } as SharedValue<number>,
|
|
9
14
|
currentY: { value: -1 } as SharedValue<number>,
|
|
15
|
+
currentIndex: { value: -1 } as SharedValue<number>,
|
|
10
16
|
data: [],
|
|
11
17
|
height: 0,
|
|
12
18
|
width: 0,
|
|
@@ -19,28 +25,33 @@ export const CandlestickChartContext = React.createContext<TContext>({
|
|
|
19
25
|
type CandlestickChartProviderProps = {
|
|
20
26
|
children: React.ReactNode;
|
|
21
27
|
data: TData;
|
|
22
|
-
width?: number;
|
|
23
|
-
height?: number;
|
|
24
28
|
valueRangeY?: TDomain;
|
|
29
|
+
onCurrentIndexChange?: (x: number) => void;
|
|
25
30
|
};
|
|
26
31
|
|
|
27
32
|
export function CandlestickChartProvider({
|
|
28
33
|
children,
|
|
29
34
|
data = [],
|
|
30
35
|
valueRangeY,
|
|
36
|
+
onCurrentIndexChange,
|
|
31
37
|
}: CandlestickChartProviderProps) {
|
|
32
38
|
const [width, setWidth] = React.useState(0);
|
|
33
39
|
const [height, setHeight] = React.useState(0);
|
|
34
40
|
const currentX = useSharedValue(-1);
|
|
35
41
|
const currentY = useSharedValue(-1);
|
|
36
|
-
const
|
|
42
|
+
const currentIndex = useSharedValue(-1);
|
|
43
|
+
const domain = React.useMemo(
|
|
44
|
+
() => valueRangeY ?? getDomain(data),
|
|
45
|
+
[data, valueRangeY]
|
|
46
|
+
);
|
|
37
47
|
|
|
38
|
-
const step = React.useMemo(() => width / data.length, [data.length, width])
|
|
48
|
+
const step = React.useMemo(() => width / data.length, [data.length, width]);
|
|
39
49
|
|
|
40
50
|
const contextValue = React.useMemo(
|
|
41
51
|
() => ({
|
|
42
52
|
currentX,
|
|
43
53
|
currentY,
|
|
54
|
+
currentIndex,
|
|
44
55
|
data,
|
|
45
56
|
width,
|
|
46
57
|
height,
|
|
@@ -49,7 +60,17 @@ export function CandlestickChartProvider({
|
|
|
49
60
|
setWidth,
|
|
50
61
|
setHeight,
|
|
51
62
|
}),
|
|
52
|
-
[currentX, currentY, data, domain, height, step, width]
|
|
63
|
+
[currentIndex, currentX, currentY, data, domain, height, step, width]
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
useAnimatedReaction(
|
|
67
|
+
() => currentIndex.value,
|
|
68
|
+
(x, prevX) => {
|
|
69
|
+
if (x !== prevX && onCurrentIndexChange) {
|
|
70
|
+
runOnJS(onCurrentIndexChange)(x);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
[currentIndex]
|
|
53
74
|
);
|
|
54
75
|
|
|
55
76
|
return (
|
|
@@ -58,3 +79,5 @@ export function CandlestickChartProvider({
|
|
|
58
79
|
</CandlestickChartContext.Provider>
|
|
59
80
|
);
|
|
60
81
|
}
|
|
82
|
+
|
|
83
|
+
CandlestickChartProvider.displayName = 'CandlestickChartProvider';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { StyleSheet, ViewProps } from 'react-native';
|
|
3
3
|
import {
|
|
4
4
|
Gesture,
|
|
@@ -20,6 +20,12 @@ import { CandlestickChartLine, CandlestickChartLineProps } from './Line';
|
|
|
20
20
|
import { useCandlestickChart } from './useCandlestickChart';
|
|
21
21
|
import { CandlestickChartCrosshairTooltipContext } from './CrosshairTooltip';
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Threshold in pixels from the left edge of the chart. When the cursor is
|
|
25
|
+
* within this distance, the tooltip will be positioned on the right side.
|
|
26
|
+
*/
|
|
27
|
+
const TOOLTIP_POSITION_THRESHOLD = 100;
|
|
28
|
+
|
|
23
29
|
type CandlestickChartCrosshairProps = {
|
|
24
30
|
color?: string;
|
|
25
31
|
children?: React.ReactNode;
|
|
@@ -40,26 +46,25 @@ export function CandlestickChartCrosshair({
|
|
|
40
46
|
minDurationMs = 0,
|
|
41
47
|
}: CandlestickChartCrosshairProps) {
|
|
42
48
|
const { width, height } = React.useContext(CandlestickChartDimensionsContext);
|
|
43
|
-
const { currentX, currentY, step } = useCandlestickChart();
|
|
44
|
-
|
|
49
|
+
const { currentX, currentY, currentIndex, step } = useCandlestickChart();
|
|
45
50
|
const tooltipPosition = useSharedValue<'left' | 'right'>('left');
|
|
46
|
-
|
|
47
51
|
const opacity = useSharedValue(0);
|
|
48
52
|
|
|
49
53
|
const updatePosition = (x: number, y: number) => {
|
|
50
54
|
'worklet';
|
|
51
55
|
const boundedX = x <= width - 1 ? x : width - 1;
|
|
52
|
-
if (boundedX <
|
|
56
|
+
if (boundedX < TOOLTIP_POSITION_THRESHOLD) {
|
|
53
57
|
tooltipPosition.value = 'right';
|
|
54
58
|
} else {
|
|
55
59
|
tooltipPosition.value = 'left';
|
|
56
60
|
}
|
|
57
61
|
currentY.value = clamp(y, 0, height);
|
|
58
62
|
currentX.value = boundedX - (boundedX % step) + step / 2;
|
|
63
|
+
currentIndex.value = Math.floor(boundedX / step);
|
|
59
64
|
};
|
|
60
65
|
|
|
61
66
|
const longPressGesture = Gesture.LongPress()
|
|
62
|
-
.minDuration(minDurationMs
|
|
67
|
+
.minDuration(minDurationMs)
|
|
63
68
|
.maxDistance(999999)
|
|
64
69
|
.onStart(
|
|
65
70
|
(event: GestureStateChangeEvent<LongPressGestureHandlerEventPayload>) => {
|
|
@@ -70,8 +75,12 @@ export function CandlestickChartCrosshair({
|
|
|
70
75
|
)
|
|
71
76
|
.onTouchesMove((event) => {
|
|
72
77
|
'worklet';
|
|
73
|
-
if (
|
|
74
|
-
|
|
78
|
+
if (
|
|
79
|
+
opacity.value === 1 &&
|
|
80
|
+
event.allTouches.length > 0 &&
|
|
81
|
+
event.allTouches[0]
|
|
82
|
+
) {
|
|
83
|
+
updatePosition(event.allTouches[0].x, event.allTouches[0].y);
|
|
75
84
|
}
|
|
76
85
|
})
|
|
77
86
|
.onEnd(() => {
|
|
@@ -79,7 +88,9 @@ export function CandlestickChartCrosshair({
|
|
|
79
88
|
opacity.value = 0;
|
|
80
89
|
currentY.value = -1;
|
|
81
90
|
currentX.value = -1;
|
|
91
|
+
currentIndex.value = -1;
|
|
82
92
|
});
|
|
93
|
+
|
|
83
94
|
const horizontal = useAnimatedStyle(
|
|
84
95
|
() => ({
|
|
85
96
|
opacity: opacity.value,
|
|
@@ -87,6 +98,7 @@ export function CandlestickChartCrosshair({
|
|
|
87
98
|
}),
|
|
88
99
|
[opacity, currentY]
|
|
89
100
|
);
|
|
101
|
+
|
|
90
102
|
const vertical = useAnimatedStyle(
|
|
91
103
|
() => ({
|
|
92
104
|
opacity: opacity.value,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import type {
|
|
3
3
|
LayoutChangeEvent,
|
|
4
4
|
StyleProp,
|
|
@@ -83,6 +83,7 @@ export function CandlestickChartCrosshairTooltip({
|
|
|
83
83
|
}),
|
|
84
84
|
[]
|
|
85
85
|
);
|
|
86
|
+
|
|
86
87
|
const leftTooltip = useAnimatedStyle(
|
|
87
88
|
() => ({
|
|
88
89
|
left: xGutter,
|
|
@@ -91,6 +92,7 @@ export function CandlestickChartCrosshairTooltip({
|
|
|
91
92
|
}),
|
|
92
93
|
[elementHeight, position, topOffset, xGutter]
|
|
93
94
|
);
|
|
95
|
+
|
|
94
96
|
const rightTooltip = useAnimatedStyle(
|
|
95
97
|
() => ({
|
|
96
98
|
left: width - elementWidth.value - xGutter,
|
|
@@ -3,7 +3,7 @@ import type { TextProps as RNTextProps } from 'react-native';
|
|
|
3
3
|
import type { AnimatedProps } from 'react-native-reanimated';
|
|
4
4
|
|
|
5
5
|
import { useCandlestickChartDatetime } 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 CandlestickChartPriceTextProps = {
|
|
@@ -2,7 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import type { TextProps as RNTextProps } from 'react-native';
|
|
3
3
|
import type { AnimatedProps } from 'react-native-reanimated';
|
|
4
4
|
|
|
5
|
-
import type { TFormatterFn
|
|
5
|
+
import type { TFormatterFn } from '../../types';
|
|
6
|
+
import type { TPriceType } from './types';
|
|
6
7
|
import { useCandlestickChartPrice } from './usePrice';
|
|
7
8
|
import { AnimatedText } from '../../components/AnimatedText';
|
|
8
9
|
|
|
@@ -13,6 +13,7 @@ export type TDomain = [min: number, max: number];
|
|
|
13
13
|
export type TContext = {
|
|
14
14
|
currentX: SharedValue<number>;
|
|
15
15
|
currentY: SharedValue<number>;
|
|
16
|
+
currentIndex: SharedValue<number>;
|
|
16
17
|
data: TData;
|
|
17
18
|
width: number;
|
|
18
19
|
height: number;
|
|
@@ -22,10 +23,3 @@ export type TContext = {
|
|
|
22
23
|
setHeight: React.Dispatch<React.SetStateAction<number>>;
|
|
23
24
|
};
|
|
24
25
|
export type TPriceType = 'crosshair' | 'open' | 'close' | 'low' | 'high';
|
|
25
|
-
export type TFormatterFn<T> = ({
|
|
26
|
-
value,
|
|
27
|
-
formatted,
|
|
28
|
-
}: {
|
|
29
|
-
value: T;
|
|
30
|
-
formatted: string;
|
|
31
|
-
}) => string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useDerivedValue } from 'react-native-reanimated';
|
|
2
2
|
|
|
3
3
|
import { formatDatetime } from '../../utils';
|
|
4
|
-
import type { TFormatterFn } from '
|
|
4
|
+
import type { TFormatterFn } from '../../types';
|
|
5
5
|
import { useCandleData } from './useCandleData';
|
|
6
6
|
import type { SharedValue } from 'react-native-reanimated';
|
|
7
7
|
|
|
@@ -30,11 +30,13 @@ export function useCandlestickChartDatetime({
|
|
|
30
30
|
|
|
31
31
|
const formatted = useDerivedValue(() => {
|
|
32
32
|
if (timestamp.value === -1) return '';
|
|
33
|
+
|
|
33
34
|
const formattedDatetime = formatDatetime({
|
|
34
35
|
value: timestamp.value,
|
|
35
36
|
locale,
|
|
36
37
|
options,
|
|
37
38
|
});
|
|
39
|
+
|
|
38
40
|
return format
|
|
39
41
|
? format({ value: timestamp.value, formatted: formattedDatetime })
|
|
40
42
|
: formattedDatetime;
|
|
@@ -3,7 +3,8 @@ import { useDerivedValue } from 'react-native-reanimated';
|
|
|
3
3
|
import { formatPrice } from '../../utils';
|
|
4
4
|
import { useCandlestickChart } from './useCandlestickChart';
|
|
5
5
|
import { getPrice } from './utils';
|
|
6
|
-
import type { TFormatterFn
|
|
6
|
+
import type { TFormatterFn } from '../../types';
|
|
7
|
+
import type { TPriceType } from './types';
|
|
7
8
|
import { useCandleData } from './useCandleData';
|
|
8
9
|
import type { SharedValue } from 'react-native-reanimated';
|
|
9
10
|
|
|
@@ -24,6 +25,7 @@ export function useCandlestickChartPrice({
|
|
|
24
25
|
|
|
25
26
|
const float = useDerivedValue(() => {
|
|
26
27
|
let price = 0;
|
|
28
|
+
|
|
27
29
|
if (type === 'crosshair') {
|
|
28
30
|
price = getPrice({
|
|
29
31
|
y: currentY.value,
|
|
@@ -33,9 +35,11 @@ export function useCandlestickChartPrice({
|
|
|
33
35
|
} else {
|
|
34
36
|
price = candle.value[type];
|
|
35
37
|
}
|
|
38
|
+
|
|
36
39
|
if (price === -1) return '';
|
|
37
40
|
return price.toFixed(precision).toString();
|
|
38
41
|
}, [currentY, domain, height, candle, type, precision]);
|
|
42
|
+
|
|
39
43
|
const formatted = useDerivedValue(() => {
|
|
40
44
|
if (!float.value) return '';
|
|
41
45
|
const formattedPrice = formatPrice({ value: float.value });
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ViewProps,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
Text,
|
|
6
|
+
TextStyle,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import { Line, Svg } from 'react-native-svg';
|
|
10
|
+
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
|
|
11
|
+
import { LineChartDimensionsContext } from './Chart';
|
|
12
|
+
import { useLineChart } from './useLineChart';
|
|
13
|
+
|
|
14
|
+
export type LineChartAxisPosition = 'left' | 'right' | 'top' | 'bottom';
|
|
15
|
+
export type LineChartAxisOrientation = 'horizontal' | 'vertical';
|
|
16
|
+
|
|
17
|
+
export type LineChartAxisProps = ViewProps & {
|
|
18
|
+
position: LineChartAxisPosition;
|
|
19
|
+
orientation: LineChartAxisOrientation;
|
|
20
|
+
color?: string;
|
|
21
|
+
strokeWidth?: number;
|
|
22
|
+
tickCount?: number;
|
|
23
|
+
domain?: [number, number];
|
|
24
|
+
hideOnInteraction?: boolean;
|
|
25
|
+
format?: (value: number | string) => string | number;
|
|
26
|
+
textStyle?: TextStyle;
|
|
27
|
+
labelPadding?: number; // Padding to prevent labels from going off-screen
|
|
28
|
+
labelWidth?: number; // Width allocated for labels
|
|
29
|
+
containerStyle?: ViewStyle; // Custom container style
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const LineChartAxis = ({
|
|
33
|
+
position,
|
|
34
|
+
orientation,
|
|
35
|
+
color = '#666',
|
|
36
|
+
strokeWidth,
|
|
37
|
+
tickCount = 5,
|
|
38
|
+
domain = [0, 100],
|
|
39
|
+
hideOnInteraction = false,
|
|
40
|
+
format = (value) => value,
|
|
41
|
+
textStyle,
|
|
42
|
+
labelPadding = 3,
|
|
43
|
+
containerStyle,
|
|
44
|
+
...props
|
|
45
|
+
}: LineChartAxisProps) => {
|
|
46
|
+
const { width, height } = React.useContext(LineChartDimensionsContext);
|
|
47
|
+
const { isActive } = useLineChart();
|
|
48
|
+
|
|
49
|
+
// Reserve space at the bottom for x-axis cursor labels
|
|
50
|
+
const X_AXIS_LABEL_RESERVED_HEIGHT = 40;
|
|
51
|
+
// For vertical axes, don't extend into the reserved cursor label space
|
|
52
|
+
const effectiveHeight =
|
|
53
|
+
orientation === 'vertical' ? height - X_AXIS_LABEL_RESERVED_HEIGHT : height;
|
|
54
|
+
|
|
55
|
+
const padding = {
|
|
56
|
+
left: 5,
|
|
57
|
+
right: 5,
|
|
58
|
+
top: 20,
|
|
59
|
+
bottom: 20,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
63
|
+
return {
|
|
64
|
+
opacity: hideOnInteraction && isActive.value ? 0 : 1,
|
|
65
|
+
};
|
|
66
|
+
}, [hideOnInteraction, isActive]);
|
|
67
|
+
|
|
68
|
+
const renderTicks = () => {
|
|
69
|
+
const [min, max] = domain;
|
|
70
|
+
const ticks = [];
|
|
71
|
+
const labels = [];
|
|
72
|
+
const tickLength = 5;
|
|
73
|
+
const labelOffset = 8;
|
|
74
|
+
|
|
75
|
+
// Calculate maximum label width needed dynamically
|
|
76
|
+
let maxLabelWidth = 0;
|
|
77
|
+
const fontSize = textStyle?.fontSize || 10;
|
|
78
|
+
const charWidth = fontSize * 0.6; // Dynamic character width based on font size
|
|
79
|
+
|
|
80
|
+
for (let i = 0; i <= tickCount; i++) {
|
|
81
|
+
const value = min + (max - min) * (i / tickCount);
|
|
82
|
+
const formattedValue = String(format(value));
|
|
83
|
+
// Dynamic width calculation based on actual font size
|
|
84
|
+
const estimatedWidth = formattedValue.length * charWidth;
|
|
85
|
+
maxLabelWidth = Math.max(maxLabelWidth, estimatedWidth);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Dynamic width allocation - ensure we don't exceed available space
|
|
89
|
+
const maxAllowableWidth =
|
|
90
|
+
position === 'left' || position === 'right'
|
|
91
|
+
? Math.max(width * 0.3, 60) // Allow up to 30% of chart width for y-axis labels, minimum 60px
|
|
92
|
+
: width * 0.9; // For horizontal labels, use most of the width
|
|
93
|
+
|
|
94
|
+
const dynamicLabelWidth = Math.min(
|
|
95
|
+
Math.max(maxLabelWidth + 16, 40), // Minimum 40px, add 16px padding
|
|
96
|
+
maxAllowableWidth // Don't exceed the calculated max
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
for (let i = 0; i <= tickCount; i++) {
|
|
100
|
+
const value = min + (max - min) * (i / tickCount);
|
|
101
|
+
const tickPosition = i / tickCount;
|
|
102
|
+
|
|
103
|
+
if (orientation === 'vertical') {
|
|
104
|
+
// Add padding to prevent labels from going off-screen
|
|
105
|
+
const topPadding = labelPadding;
|
|
106
|
+
const bottomPadding = labelPadding;
|
|
107
|
+
|
|
108
|
+
// Calculate y position with padding to keep labels on screen
|
|
109
|
+
const availableHeight = effectiveHeight - topPadding - bottomPadding;
|
|
110
|
+
const y = topPadding + availableHeight * (1 - tickPosition);
|
|
111
|
+
const x = position === 'left' ? padding.left : width - padding.right;
|
|
112
|
+
|
|
113
|
+
if (strokeWidth) {
|
|
114
|
+
ticks.push(
|
|
115
|
+
<Line
|
|
116
|
+
key={`tick-${i}`}
|
|
117
|
+
x1={x}
|
|
118
|
+
y1={y}
|
|
119
|
+
x2={position === 'left' ? x - tickLength : x + tickLength}
|
|
120
|
+
y2={y}
|
|
121
|
+
stroke={color}
|
|
122
|
+
strokeWidth={strokeWidth}
|
|
123
|
+
/>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
labels.push(
|
|
128
|
+
<Animated.View
|
|
129
|
+
key={`label-${i}`}
|
|
130
|
+
style={[
|
|
131
|
+
styles.verticalLabel,
|
|
132
|
+
{
|
|
133
|
+
width: dynamicLabelWidth, // Use calculated width
|
|
134
|
+
left:
|
|
135
|
+
position === 'left'
|
|
136
|
+
? Math.max(0, x - labelOffset - dynamicLabelWidth) // Keep labels within left boundary
|
|
137
|
+
: Math.min(width - dynamicLabelWidth - 5, x + labelOffset), // Keep labels within right boundary with 5px margin
|
|
138
|
+
top: y - 10, // Center the label vertically on the tick mark
|
|
139
|
+
},
|
|
140
|
+
position === 'left' ? styles.alignEnd : styles.alignStart,
|
|
141
|
+
]}
|
|
142
|
+
>
|
|
143
|
+
<Text
|
|
144
|
+
numberOfLines={1}
|
|
145
|
+
ellipsizeMode="tail"
|
|
146
|
+
style={[
|
|
147
|
+
styles.labelText,
|
|
148
|
+
{ color: color },
|
|
149
|
+
position === 'left' ? styles.textRight : styles.textLeft,
|
|
150
|
+
textStyle,
|
|
151
|
+
]}
|
|
152
|
+
adjustsFontSizeToFit={true}
|
|
153
|
+
minimumFontScale={0.7}
|
|
154
|
+
>
|
|
155
|
+
{String(format(value))}
|
|
156
|
+
</Text>
|
|
157
|
+
</Animated.View>
|
|
158
|
+
);
|
|
159
|
+
} else {
|
|
160
|
+
const x = width * tickPosition;
|
|
161
|
+
const y = position === 'top' ? 15 : height - padding.bottom;
|
|
162
|
+
|
|
163
|
+
if (strokeWidth) {
|
|
164
|
+
ticks.push(
|
|
165
|
+
<Line
|
|
166
|
+
key={`tick-${i}`}
|
|
167
|
+
x1={x}
|
|
168
|
+
y1={y}
|
|
169
|
+
x2={x}
|
|
170
|
+
y2={position === 'top' ? y - tickLength : height - 15}
|
|
171
|
+
stroke={color}
|
|
172
|
+
strokeWidth={strokeWidth}
|
|
173
|
+
/>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const alignmentStyle =
|
|
178
|
+
i === 0
|
|
179
|
+
? styles.alignStart
|
|
180
|
+
: i === tickCount
|
|
181
|
+
? styles.alignEnd
|
|
182
|
+
: styles.alignCenter;
|
|
183
|
+
const textAlignStyle =
|
|
184
|
+
i === 0
|
|
185
|
+
? styles.textLeft
|
|
186
|
+
: i === tickCount
|
|
187
|
+
? styles.textRight
|
|
188
|
+
: styles.textCenter;
|
|
189
|
+
|
|
190
|
+
labels.push(
|
|
191
|
+
<Animated.View
|
|
192
|
+
key={`label-${i}`}
|
|
193
|
+
style={[
|
|
194
|
+
styles.horizontalLabel,
|
|
195
|
+
{
|
|
196
|
+
width: dynamicLabelWidth, // Use dynamic width for horizontal labels too
|
|
197
|
+
left: Math.max(
|
|
198
|
+
0,
|
|
199
|
+
Math.min(
|
|
200
|
+
width - dynamicLabelWidth,
|
|
201
|
+
i === 0
|
|
202
|
+
? x + labelOffset
|
|
203
|
+
: i === tickCount
|
|
204
|
+
? x - dynamicLabelWidth - labelOffset
|
|
205
|
+
: x - dynamicLabelWidth / 2
|
|
206
|
+
)
|
|
207
|
+
),
|
|
208
|
+
top:
|
|
209
|
+
position === 'top'
|
|
210
|
+
? Math.max(0, y - labelOffset - 15)
|
|
211
|
+
: Math.max(0, height - 35),
|
|
212
|
+
},
|
|
213
|
+
alignmentStyle,
|
|
214
|
+
]}
|
|
215
|
+
>
|
|
216
|
+
<Text
|
|
217
|
+
numberOfLines={1}
|
|
218
|
+
ellipsizeMode="tail"
|
|
219
|
+
style={[
|
|
220
|
+
styles.labelText,
|
|
221
|
+
{ color: color },
|
|
222
|
+
textAlignStyle,
|
|
223
|
+
textStyle,
|
|
224
|
+
]}
|
|
225
|
+
adjustsFontSizeToFit={true}
|
|
226
|
+
minimumFontScale={0.7}
|
|
227
|
+
>
|
|
228
|
+
{String(format(value))}
|
|
229
|
+
</Text>
|
|
230
|
+
</Animated.View>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return { ticks, labels };
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const renderAxis = () => {
|
|
239
|
+
const { ticks, labels } = renderTicks();
|
|
240
|
+
|
|
241
|
+
let axisLine = null;
|
|
242
|
+
|
|
243
|
+
if (strokeWidth) {
|
|
244
|
+
switch (position) {
|
|
245
|
+
case 'left':
|
|
246
|
+
axisLine = (
|
|
247
|
+
<Line
|
|
248
|
+
x1={padding.left}
|
|
249
|
+
y1={0}
|
|
250
|
+
x2={padding.left}
|
|
251
|
+
y2={effectiveHeight}
|
|
252
|
+
stroke={color}
|
|
253
|
+
strokeWidth={strokeWidth}
|
|
254
|
+
/>
|
|
255
|
+
);
|
|
256
|
+
break;
|
|
257
|
+
case 'right':
|
|
258
|
+
axisLine = (
|
|
259
|
+
<Line
|
|
260
|
+
x1={width - padding.right}
|
|
261
|
+
y1={0}
|
|
262
|
+
x2={width - padding.right}
|
|
263
|
+
y2={effectiveHeight}
|
|
264
|
+
stroke={color}
|
|
265
|
+
strokeWidth={strokeWidth}
|
|
266
|
+
/>
|
|
267
|
+
);
|
|
268
|
+
break;
|
|
269
|
+
case 'top':
|
|
270
|
+
axisLine = (
|
|
271
|
+
<Line
|
|
272
|
+
x1={0}
|
|
273
|
+
y1={20}
|
|
274
|
+
x2={width}
|
|
275
|
+
y2={20}
|
|
276
|
+
stroke={color}
|
|
277
|
+
strokeWidth={strokeWidth}
|
|
278
|
+
/>
|
|
279
|
+
);
|
|
280
|
+
break;
|
|
281
|
+
case 'bottom':
|
|
282
|
+
axisLine = (
|
|
283
|
+
<Line
|
|
284
|
+
x1={0}
|
|
285
|
+
y1={height - 20}
|
|
286
|
+
x2={width}
|
|
287
|
+
y2={height - 20}
|
|
288
|
+
stroke={color}
|
|
289
|
+
strokeWidth={strokeWidth}
|
|
290
|
+
/>
|
|
291
|
+
);
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return { axisLine, ticks, labels };
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const { axisLine, ticks, labels } = renderAxis();
|
|
300
|
+
|
|
301
|
+
return (
|
|
302
|
+
<Animated.View
|
|
303
|
+
style={[styles.container, containerStyle, props.style, animatedStyle]}
|
|
304
|
+
>
|
|
305
|
+
<Svg width={width} height={height} style={StyleSheet.absoluteFill}>
|
|
306
|
+
{axisLine}
|
|
307
|
+
{ticks}
|
|
308
|
+
</Svg>
|
|
309
|
+
<Animated.View style={[StyleSheet.absoluteFill, styles.labelsContainer]}>
|
|
310
|
+
{labels}
|
|
311
|
+
</Animated.View>
|
|
312
|
+
</Animated.View>
|
|
313
|
+
);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const styles = StyleSheet.create({
|
|
317
|
+
container: {
|
|
318
|
+
position: 'absolute',
|
|
319
|
+
top: 0,
|
|
320
|
+
left: 0,
|
|
321
|
+
right: 0,
|
|
322
|
+
bottom: 0,
|
|
323
|
+
pointerEvents: 'none',
|
|
324
|
+
},
|
|
325
|
+
verticalLabel: {
|
|
326
|
+
position: 'absolute',
|
|
327
|
+
minHeight: 20,
|
|
328
|
+
zIndex: 1000,
|
|
329
|
+
overflow: 'visible',
|
|
330
|
+
justifyContent: 'center',
|
|
331
|
+
},
|
|
332
|
+
horizontalLabel: {
|
|
333
|
+
position: 'absolute',
|
|
334
|
+
minHeight: 20,
|
|
335
|
+
zIndex: 1000,
|
|
336
|
+
overflow: 'hidden',
|
|
337
|
+
justifyContent: 'center',
|
|
338
|
+
},
|
|
339
|
+
labelText: {
|
|
340
|
+
fontSize: 10,
|
|
341
|
+
},
|
|
342
|
+
labelsContainer: {
|
|
343
|
+
zIndex: 1000,
|
|
344
|
+
},
|
|
345
|
+
alignStart: {
|
|
346
|
+
alignItems: 'flex-start',
|
|
347
|
+
},
|
|
348
|
+
alignEnd: {
|
|
349
|
+
alignItems: 'flex-end',
|
|
350
|
+
},
|
|
351
|
+
alignCenter: {
|
|
352
|
+
alignItems: 'center',
|
|
353
|
+
},
|
|
354
|
+
textLeft: {
|
|
355
|
+
textAlign: 'left',
|
|
356
|
+
},
|
|
357
|
+
textRight: {
|
|
358
|
+
textAlign: 'right',
|
|
359
|
+
},
|
|
360
|
+
textCenter: {
|
|
361
|
+
textAlign: 'center',
|
|
362
|
+
},
|
|
363
|
+
});
|