react-native-wagmi-charts 2.3.0 → 2.4.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/.DS_Store +0 -0
- package/.editorconfig +15 -0
- package/.gitattributes +3 -0
- package/.gitignore +60 -0
- package/.husky/pre-commit +4 -0
- package/.prettierrc.js +5 -0
- package/.yarnrc +3 -0
- package/README.md +25 -24
- package/babel.config.js +3 -0
- package/example/.expo/README.md +8 -0
- package/example/.expo/devices.json +3 -0
- package/example/README.md +32 -0
- package/example/app.json +22 -0
- package/example/babel.config.js +23 -0
- package/example/index.js +8 -0
- package/example/metro.config.js +40 -0
- package/example/package.json +42 -0
- package/example/src/App.tsx +64 -0
- package/example/src/CandlestickChart.tsx +155 -0
- package/example/src/LineChart.tsx +267 -0
- package/example/src/data/candlestick-data.json +142 -0
- package/example/src/data/candlestick-data2.json +142 -0
- package/example/src/data/line-data-non-linear-domain.json +34 -0
- package/example/src/data/line-data.json +82 -0
- package/example/src/data/line-data2.json +82 -0
- package/example/src/line-data-gh.json +18 -0
- package/example/tsconfig.json +6 -0
- package/example/webpack.config.js +25 -0
- package/example/yarn.lock +9306 -0
- package/lib/commonjs/charts/candle/Candle.js +6 -19
- package/lib/commonjs/charts/candle/Candle.js.map +1 -1
- package/lib/commonjs/charts/candle/Candles.js +6 -13
- package/lib/commonjs/charts/candle/Candles.js.map +1 -1
- package/lib/commonjs/charts/candle/Chart.js +3 -12
- package/lib/commonjs/charts/candle/Chart.js.map +1 -1
- package/lib/commonjs/charts/candle/Context.js +4 -12
- package/lib/commonjs/charts/candle/Context.js.map +1 -1
- package/lib/commonjs/charts/candle/Crosshair.js +3 -18
- package/lib/commonjs/charts/candle/Crosshair.js.map +1 -1
- package/lib/commonjs/charts/candle/CrosshairTooltip.js +6 -21
- package/lib/commonjs/charts/candle/CrosshairTooltip.js.map +1 -1
- package/lib/commonjs/charts/candle/DatetimeText.js +2 -8
- package/lib/commonjs/charts/candle/DatetimeText.js.map +1 -1
- package/lib/commonjs/charts/candle/HoverTrap/index.web.js +11 -25
- package/lib/commonjs/charts/candle/HoverTrap/index.web.js.map +1 -1
- package/lib/commonjs/charts/candle/Line.js +3 -12
- package/lib/commonjs/charts/candle/Line.js.map +1 -1
- package/lib/commonjs/charts/candle/PriceText.js +2 -8
- package/lib/commonjs/charts/candle/PriceText.js.map +1 -1
- package/lib/commonjs/charts/candle/index.js +1 -32
- package/lib/commonjs/charts/candle/index.js.map +1 -1
- package/lib/commonjs/charts/candle/types.js.map +1 -1
- package/lib/commonjs/charts/candle/useCandleData.js +0 -4
- package/lib/commonjs/charts/candle/useCandleData.js.map +1 -1
- package/lib/commonjs/charts/candle/useCandlestickChart.js +2 -7
- package/lib/commonjs/charts/candle/useCandlestickChart.js.map +1 -1
- package/lib/commonjs/charts/candle/useDatetime.js +0 -4
- package/lib/commonjs/charts/candle/useDatetime.js.map +1 -1
- package/lib/commonjs/charts/candle/usePrice.js +0 -8
- package/lib/commonjs/charts/candle/usePrice.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/getDomain.js +0 -1
- package/lib/commonjs/charts/candle/utils/getDomain.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/getHeight.js +0 -2
- package/lib/commonjs/charts/candle/utils/getHeight.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/getPrice.js +0 -2
- package/lib/commonjs/charts/candle/utils/getPrice.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/getY.js +0 -2
- package/lib/commonjs/charts/candle/utils/getY.js.map +1 -1
- package/lib/commonjs/charts/candle/utils/index.js +0 -8
- package/lib/commonjs/charts/candle/utils/index.js.map +1 -1
- package/lib/commonjs/charts/candle/utils.js +1 -6
- package/lib/commonjs/charts/candle/utils.js.map +1 -1
- package/lib/commonjs/charts/line/Chart.js +9 -28
- package/lib/commonjs/charts/line/Chart.js.map +1 -1
- package/lib/commonjs/charts/line/ChartPath.js +23 -46
- package/lib/commonjs/charts/line/ChartPath.js.map +1 -1
- package/lib/commonjs/charts/line/Context.js +8 -19
- package/lib/commonjs/charts/line/Context.js.map +1 -1
- package/lib/commonjs/charts/line/Cursor.js +41 -66
- package/lib/commonjs/charts/line/Cursor.js.map +1 -1
- package/lib/commonjs/charts/line/CursorCrosshair.js +5 -14
- package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
- package/lib/commonjs/charts/line/CursorLine.js +5 -19
- package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
- package/lib/commonjs/charts/line/Data.js +5 -17
- package/lib/commonjs/charts/line/Data.js.map +1 -1
- package/lib/commonjs/charts/line/DatetimeText.js +2 -9
- package/lib/commonjs/charts/line/DatetimeText.js.map +1 -1
- package/lib/commonjs/charts/line/Dot.js +27 -33
- package/lib/commonjs/charts/line/Dot.js.map +1 -1
- package/lib/commonjs/charts/line/Gradient.js +12 -19
- package/lib/commonjs/charts/line/Gradient.js.map +1 -1
- package/lib/commonjs/charts/line/Group.js +2 -14
- package/lib/commonjs/charts/line/Group.js.map +1 -1
- package/lib/commonjs/charts/line/Highlight.js +9 -21
- package/lib/commonjs/charts/line/Highlight.js.map +1 -1
- package/lib/commonjs/charts/line/HorizontalLine.js +8 -23
- package/lib/commonjs/charts/line/HorizontalLine.js.map +1 -1
- package/lib/commonjs/charts/line/HoverTrap/index.js +0 -4
- package/lib/commonjs/charts/line/HoverTrap/index.js.map +1 -1
- package/lib/commonjs/charts/line/HoverTrap/index.web.js +11 -24
- package/lib/commonjs/charts/line/HoverTrap/index.web.js.map +1 -1
- package/lib/commonjs/charts/line/LineChartPathContext.js +1 -6
- package/lib/commonjs/charts/line/LineChartPathContext.js.map +1 -1
- package/lib/commonjs/charts/line/Path.js +9 -18
- package/lib/commonjs/charts/line/Path.js.map +1 -1
- package/lib/commonjs/charts/line/PriceText.js +2 -9
- package/lib/commonjs/charts/line/PriceText.js.map +1 -1
- package/lib/commonjs/charts/line/Tooltip.js +25 -47
- package/lib/commonjs/charts/line/Tooltip.js.map +1 -1
- package/lib/commonjs/charts/line/index.js +1 -39
- package/lib/commonjs/charts/line/index.js.map +1 -1
- package/lib/commonjs/charts/line/types.js.map +1 -1
- package/lib/commonjs/charts/line/useAnimatedPath.js +6 -12
- package/lib/commonjs/charts/line/useAnimatedPath.js.map +1 -1
- package/lib/commonjs/charts/line/useCurrentY.js +0 -7
- package/lib/commonjs/charts/line/useCurrentY.js.map +1 -1
- package/lib/commonjs/charts/line/useDatetime.js +0 -4
- package/lib/commonjs/charts/line/useDatetime.js.map +1 -1
- package/lib/commonjs/charts/line/useLineChart.js +4 -10
- package/lib/commonjs/charts/line/useLineChart.js.map +1 -1
- package/lib/commonjs/charts/line/usePrice.js +1 -5
- package/lib/commonjs/charts/line/usePrice.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getArea.js +11 -11
- package/lib/commonjs/charts/line/utils/getArea.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getDomain.js +0 -1
- package/lib/commonjs/charts/line/utils/getDomain.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getPath.js +5 -8
- package/lib/commonjs/charts/line/utils/getPath.js.map +1 -1
- package/lib/commonjs/charts/line/utils/getXPositionForCurve.js +15 -0
- package/lib/commonjs/charts/line/utils/getXPositionForCurve.js.map +1 -0
- package/lib/commonjs/charts/line/utils/index.js +0 -10
- package/lib/commonjs/charts/line/utils/index.js.map +1 -1
- package/lib/commonjs/charts/line/utils/interpolatePath.js +119 -124
- package/lib/commonjs/charts/line/utils/interpolatePath.js.map +1 -1
- package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js +0 -3
- package/lib/commonjs/charts/line/utils/lineChartDataPropToArray.js.map +1 -1
- package/lib/commonjs/components/AnimatedText.js +6 -17
- package/lib/commonjs/components/AnimatedText.js.map +1 -1
- package/lib/commonjs/index.js +0 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/formatDatetime.js +0 -1
- package/lib/commonjs/utils/formatDatetime.js.map +1 -1
- package/lib/commonjs/utils/formatPrice.js +2 -12
- package/lib/commonjs/utils/formatPrice.js.map +1 -1
- package/lib/commonjs/utils/index.js +0 -6
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/usePrevious.js +4 -9
- package/lib/commonjs/utils/usePrevious.js.map +1 -1
- package/lib/module/charts/candle/Candle.js +4 -2
- package/lib/module/charts/candle/Candle.js.map +1 -1
- package/lib/module/charts/candle/Candles.js +4 -3
- package/lib/module/charts/candle/Candles.js.map +1 -1
- package/lib/module/charts/candle/Chart.js.map +1 -1
- package/lib/module/charts/candle/Context.js.map +1 -1
- package/lib/module/charts/candle/Crosshair.js +1 -4
- package/lib/module/charts/candle/Crosshair.js.map +1 -1
- package/lib/module/charts/candle/CrosshairTooltip.js +3 -6
- package/lib/module/charts/candle/CrosshairTooltip.js.map +1 -1
- package/lib/module/charts/candle/DatetimeText.js.map +1 -1
- package/lib/module/charts/candle/HoverTrap/index.web.js +11 -15
- package/lib/module/charts/candle/HoverTrap/index.web.js.map +1 -1
- package/lib/module/charts/candle/Line.js +1 -2
- package/lib/module/charts/candle/Line.js.map +1 -1
- package/lib/module/charts/candle/PriceText.js.map +1 -1
- package/lib/module/charts/candle/index.js.map +1 -1
- package/lib/module/charts/candle/types.js.map +1 -1
- package/lib/module/charts/candle/useCandleData.js +0 -1
- package/lib/module/charts/candle/useCandleData.js.map +1 -1
- package/lib/module/charts/candle/useCandlestickChart.js.map +1 -1
- package/lib/module/charts/candle/useDatetime.js.map +1 -1
- package/lib/module/charts/candle/usePrice.js +0 -2
- package/lib/module/charts/candle/usePrice.js.map +1 -1
- package/lib/module/charts/candle/utils/getDomain.js.map +1 -1
- package/lib/module/charts/candle/utils/getHeight.js.map +1 -1
- package/lib/module/charts/candle/utils/getPrice.js.map +1 -1
- package/lib/module/charts/candle/utils/getY.js.map +1 -1
- package/lib/module/charts/candle/utils/index.js.map +1 -1
- package/lib/module/charts/candle/utils.js.map +1 -1
- package/lib/module/charts/line/Chart.js +8 -12
- package/lib/module/charts/line/Chart.js.map +1 -1
- package/lib/module/charts/line/ChartPath.js +21 -28
- package/lib/module/charts/line/ChartPath.js.map +1 -1
- package/lib/module/charts/line/Context.js +4 -6
- package/lib/module/charts/line/Context.js.map +1 -1
- package/lib/module/charts/line/Cursor.js +37 -50
- package/lib/module/charts/line/Cursor.js.map +1 -1
- package/lib/module/charts/line/CursorCrosshair.js +3 -3
- package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
- package/lib/module/charts/line/CursorLine.js +3 -3
- package/lib/module/charts/line/CursorLine.js.map +1 -1
- package/lib/module/charts/line/Data.js +0 -2
- package/lib/module/charts/line/Data.js.map +1 -1
- package/lib/module/charts/line/DatetimeText.js.map +1 -1
- package/lib/module/charts/line/Dot.js +25 -18
- package/lib/module/charts/line/Dot.js.map +1 -1
- package/lib/module/charts/line/Gradient.js +10 -5
- package/lib/module/charts/line/Gradient.js.map +1 -1
- package/lib/module/charts/line/Group.js +0 -2
- package/lib/module/charts/line/Group.js.map +1 -1
- package/lib/module/charts/line/Highlight.js +7 -5
- package/lib/module/charts/line/Highlight.js.map +1 -1
- package/lib/module/charts/line/HorizontalLine.js +6 -8
- package/lib/module/charts/line/HorizontalLine.js.map +1 -1
- package/lib/module/charts/line/HoverTrap/index.js.map +1 -1
- package/lib/module/charts/line/HoverTrap/index.web.js +11 -15
- package/lib/module/charts/line/HoverTrap/index.web.js.map +1 -1
- package/lib/module/charts/line/LineChartPathContext.js.map +1 -1
- package/lib/module/charts/line/Path.js +7 -4
- package/lib/module/charts/line/Path.js.map +1 -1
- package/lib/module/charts/line/PriceText.js.map +1 -1
- package/lib/module/charts/line/Tooltip.js +21 -33
- package/lib/module/charts/line/Tooltip.js.map +1 -1
- package/lib/module/charts/line/index.js.map +1 -1
- package/lib/module/charts/line/types.js.map +1 -1
- package/lib/module/charts/line/useAnimatedPath.js +3 -5
- package/lib/module/charts/line/useAnimatedPath.js.map +1 -1
- package/lib/module/charts/line/useCurrentY.js +0 -1
- package/lib/module/charts/line/useCurrentY.js.map +1 -1
- package/lib/module/charts/line/useDatetime.js.map +1 -1
- package/lib/module/charts/line/useLineChart.js +2 -1
- package/lib/module/charts/line/useLineChart.js.map +1 -1
- package/lib/module/charts/line/usePrice.js +1 -1
- package/lib/module/charts/line/usePrice.js.map +1 -1
- package/lib/module/charts/line/utils/getArea.js +9 -6
- package/lib/module/charts/line/utils/getArea.js.map +1 -1
- package/lib/module/charts/line/utils/getDomain.js.map +1 -1
- package/lib/module/charts/line/utils/getPath.js +3 -3
- package/lib/module/charts/line/utils/getPath.js.map +1 -1
- package/lib/module/charts/line/utils/getXPositionForCurve.js +9 -0
- package/lib/module/charts/line/utils/getXPositionForCurve.js.map +1 -0
- package/lib/module/charts/line/utils/index.js.map +1 -1
- package/lib/module/charts/line/utils/interpolatePath.js +116 -117
- package/lib/module/charts/line/utils/interpolatePath.js.map +1 -1
- package/lib/module/charts/line/utils/lineChartDataPropToArray.js +0 -2
- package/lib/module/charts/line/utils/lineChartDataPropToArray.js.map +1 -1
- package/lib/module/components/AnimatedText.js +4 -3
- package/lib/module/components/AnimatedText.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/formatDatetime.js.map +1 -1
- package/lib/module/utils/formatPrice.js +2 -11
- package/lib/module/utils/formatPrice.js.map +1 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/usePrevious.js +2 -3
- package/lib/module/utils/usePrevious.js.map +1 -1
- package/lib/typescript/example/src/App.d.ts +4 -0
- package/lib/typescript/example/src/App.d.ts.map +1 -0
- package/lib/typescript/example/src/CandlestickChart.d.ts +3 -0
- package/lib/typescript/example/src/CandlestickChart.d.ts.map +1 -0
- package/lib/typescript/example/src/LineChart.d.ts +3 -0
- package/lib/typescript/example/src/LineChart.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/Candle.d.ts +7 -5
- package/lib/typescript/src/charts/candle/Candle.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/Candles.d.ts +4 -3
- package/lib/typescript/src/charts/candle/Candles.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/Chart.d.ts +3 -2
- package/lib/typescript/src/charts/candle/Chart.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/Context.d.ts +3 -2
- package/lib/typescript/src/charts/candle/Context.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/Crosshair.d.ts +3 -2
- package/lib/typescript/src/charts/candle/Crosshair.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/CrosshairTooltip.d.ts +4 -3
- package/lib/typescript/src/charts/candle/CrosshairTooltip.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/DatetimeText.d.ts +4 -3
- package/lib/typescript/src/charts/candle/DatetimeText.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/HoverTrap/index.web.d.ts +3 -2
- package/lib/typescript/src/charts/candle/HoverTrap/index.web.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/Line.d.ts +4 -3
- package/lib/typescript/src/charts/candle/Line.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/PriceText.d.ts +4 -3
- package/lib/typescript/src/charts/candle/PriceText.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/index.d.ts +3 -2
- package/lib/typescript/src/charts/candle/index.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/types.d.ts +7 -6
- package/lib/typescript/src/charts/candle/types.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/useCandleData.d.ts +1 -0
- package/lib/typescript/src/charts/candle/useCandleData.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/useCandlestickChart.d.ts +1 -0
- package/lib/typescript/src/charts/candle/useCandlestickChart.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/useDatetime.d.ts +1 -0
- package/lib/typescript/src/charts/candle/useDatetime.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/usePrice.d.ts +1 -0
- package/lib/typescript/src/charts/candle/usePrice.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/utils/getDomain.d.ts +1 -0
- package/lib/typescript/src/charts/candle/utils/getDomain.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/utils/getHeight.d.ts +1 -0
- package/lib/typescript/src/charts/candle/utils/getHeight.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/utils/getPrice.d.ts +1 -0
- package/lib/typescript/src/charts/candle/utils/getPrice.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/utils/getY.d.ts +1 -0
- package/lib/typescript/src/charts/candle/utils/getY.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/utils/index.d.ts +1 -0
- package/lib/typescript/src/charts/candle/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/charts/candle/utils.d.ts +1 -0
- package/lib/typescript/src/charts/candle/utils.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Chart.d.ts +3 -2
- package/lib/typescript/src/charts/line/Chart.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/ChartPath.d.ts +3 -2
- package/lib/typescript/src/charts/line/ChartPath.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Context.d.ts +3 -2
- package/lib/typescript/src/charts/line/Context.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Cursor.d.ts +3 -2
- package/lib/typescript/src/charts/line/Cursor.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +3 -2
- package/lib/typescript/src/charts/line/CursorCrosshair.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/CursorLine.d.ts +3 -2
- package/lib/typescript/src/charts/line/CursorLine.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Data.d.ts +6 -4
- package/lib/typescript/src/charts/line/Data.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/DatetimeText.d.ts +4 -3
- package/lib/typescript/src/charts/line/DatetimeText.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Dot.d.ts +4 -3
- package/lib/typescript/src/charts/line/Dot.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Gradient.d.ts +3 -2
- package/lib/typescript/src/charts/line/Gradient.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Group.d.ts +4 -2
- package/lib/typescript/src/charts/line/Group.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Highlight.d.ts +4 -3
- package/lib/typescript/src/charts/line/Highlight.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/HorizontalLine.d.ts +4 -3
- package/lib/typescript/src/charts/line/HorizontalLine.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/HoverTrap/index.d.ts +3 -2
- package/lib/typescript/src/charts/line/HoverTrap/index.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts +3 -2
- package/lib/typescript/src/charts/line/HoverTrap/index.web.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/LineChartPathContext.d.ts +1 -0
- package/lib/typescript/src/charts/line/LineChartPathContext.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Path.d.ts +4 -3
- package/lib/typescript/src/charts/line/Path.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/PriceText.d.ts +4 -3
- package/lib/typescript/src/charts/line/PriceText.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/Tooltip.d.ts +4 -3
- package/lib/typescript/src/charts/line/Tooltip.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/index.d.ts +2 -1
- package/lib/typescript/src/charts/line/index.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/types.d.ts +8 -7
- package/lib/typescript/src/charts/line/types.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/useAnimatedPath.d.ts +1 -0
- package/lib/typescript/src/charts/line/useAnimatedPath.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/useCurrentY.d.ts +1 -0
- package/lib/typescript/src/charts/line/useCurrentY.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/useDatetime.d.ts +1 -0
- package/lib/typescript/src/charts/line/useDatetime.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/useLineChart.d.ts +1 -0
- package/lib/typescript/src/charts/line/useLineChart.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/usePrice.d.ts +1 -0
- package/lib/typescript/src/charts/line/usePrice.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/utils/getArea.d.ts +3 -1
- package/lib/typescript/src/charts/line/utils/getArea.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/utils/getDomain.d.ts +1 -0
- package/lib/typescript/src/charts/line/utils/getDomain.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/utils/getPath.d.ts +1 -0
- package/lib/typescript/src/charts/line/utils/getPath.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/utils/getXPositionForCurve.d.ts +3 -0
- package/lib/typescript/src/charts/line/utils/getXPositionForCurve.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/utils/index.d.ts +1 -0
- package/lib/typescript/src/charts/line/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/utils/interpolatePath.d.ts +1 -0
- package/lib/typescript/src/charts/line/utils/interpolatePath.d.ts.map +1 -0
- package/lib/typescript/src/charts/line/utils/lineChartDataPropToArray.d.ts +1 -0
- package/lib/typescript/src/charts/line/utils/lineChartDataPropToArray.d.ts.map +1 -0
- package/lib/typescript/src/components/AnimatedText.d.ts +3 -2
- package/lib/typescript/src/components/AnimatedText.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/formatDatetime.d.ts +1 -0
- package/lib/typescript/src/utils/formatDatetime.d.ts.map +1 -0
- package/lib/typescript/src/utils/formatPrice.d.ts +1 -0
- package/lib/typescript/src/utils/formatPrice.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +1 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/usePrevious.d.ts +1 -0
- package/lib/typescript/src/utils/usePrevious.d.ts.map +1 -0
- package/package.json +12 -9
- package/scripts/bootstrap.js +24 -0
- package/src/charts/candle/Candle.tsx +3 -3
- package/src/charts/candle/CrosshairTooltip.tsx +2 -2
- package/src/charts/candle/HoverTrap/index.web.tsx +0 -1
- package/src/charts/line/Chart.tsx +6 -4
- package/src/charts/line/Cursor.tsx +52 -67
- package/src/charts/line/Dot.tsx +8 -8
- package/src/charts/line/Gradient.tsx +1 -0
- package/src/charts/line/HorizontalLine.tsx +8 -15
- package/src/charts/line/HoverTrap/index.web.tsx +0 -1
- package/src/charts/line/Tooltip.tsx +21 -13
- package/src/charts/line/useAnimatedPath.ts +3 -3
- package/src/charts/line/utils/getArea.ts +8 -5
- package/src/charts/line/utils/getXPositionForCurve.ts +9 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +28 -0
- package/yarn.lock +8529 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Reanimated compatible fork of https://github.com/pbeshai/d3-interpolate-path
|
|
5
5
|
*/
|
|
6
|
+
|
|
6
7
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -20,7 +21,6 @@ function decasteljau(points, t) {
|
|
|
20
21
|
|
|
21
22
|
const left = [];
|
|
22
23
|
const right = [];
|
|
23
|
-
|
|
24
24
|
function decasteljauRecurse(points, t) {
|
|
25
25
|
'worklet';
|
|
26
26
|
|
|
@@ -29,32 +29,27 @@ function decasteljau(points, t) {
|
|
|
29
29
|
right.push(points[0]);
|
|
30
30
|
} else {
|
|
31
31
|
const newPoints = Array(points.length - 1);
|
|
32
|
-
|
|
33
32
|
for (let i = 0; i < newPoints.length; i++) {
|
|
34
33
|
if (i === 0) {
|
|
35
34
|
left.push(points[0]);
|
|
36
35
|
}
|
|
37
|
-
|
|
38
36
|
if (i === newPoints.length - 1) {
|
|
39
37
|
right.push(points[i + 1]);
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
newPoints[i] = [(1 - t) * points[i][0] + t * points[i + 1][0], (1 - t) * points[i][1] + t * points[i + 1][1]];
|
|
43
40
|
}
|
|
44
|
-
|
|
45
41
|
decasteljauRecurse(newPoints, t);
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
|
-
|
|
49
44
|
if (points.length) {
|
|
50
45
|
decasteljauRecurse(points, t);
|
|
51
46
|
}
|
|
52
|
-
|
|
53
47
|
return {
|
|
54
48
|
left,
|
|
55
49
|
right: right.reverse()
|
|
56
50
|
};
|
|
57
51
|
}
|
|
52
|
+
|
|
58
53
|
/**
|
|
59
54
|
* Convert segments represented as points back into a command object
|
|
60
55
|
*
|
|
@@ -62,26 +57,20 @@ function decasteljau(points, t) {
|
|
|
62
57
|
* Represents a segment
|
|
63
58
|
* @return {Object} A command object representing the segment.
|
|
64
59
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
60
|
function pointsToCommand(points) {
|
|
68
61
|
'worklet';
|
|
69
62
|
|
|
70
63
|
const command = {};
|
|
71
|
-
|
|
72
64
|
if (points.length === 4) {
|
|
73
65
|
command.x2 = points[2][0];
|
|
74
66
|
command.y2 = points[2][1];
|
|
75
67
|
}
|
|
76
|
-
|
|
77
68
|
if (points.length >= 3) {
|
|
78
69
|
command.x1 = points[1][0];
|
|
79
70
|
command.y1 = points[1][1];
|
|
80
71
|
}
|
|
81
|
-
|
|
82
72
|
command.x = points[points.length - 1][0];
|
|
83
73
|
command.y = points[points.length - 1][1];
|
|
84
|
-
|
|
85
74
|
if (points.length === 4) {
|
|
86
75
|
// start, control1, control2, end
|
|
87
76
|
command.type = 'C';
|
|
@@ -92,9 +81,9 @@ function pointsToCommand(points) {
|
|
|
92
81
|
// start, end
|
|
93
82
|
command.type = 'L';
|
|
94
83
|
}
|
|
95
|
-
|
|
96
84
|
return command;
|
|
97
85
|
}
|
|
86
|
+
|
|
98
87
|
/**
|
|
99
88
|
* Runs de Casteljau's algorithm enough times to produce the desired number of segments.
|
|
100
89
|
*
|
|
@@ -102,20 +91,21 @@ function pointsToCommand(points) {
|
|
|
102
91
|
* @param {Number} segmentCount Number of segments to split the original into
|
|
103
92
|
* @return {Number[][][]} Array of segments
|
|
104
93
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
94
|
function splitCurveAsPoints(points, segmentCount) {
|
|
108
95
|
'worklet';
|
|
109
96
|
|
|
110
97
|
segmentCount = segmentCount || 2;
|
|
111
98
|
const segments = [];
|
|
112
99
|
let remainingCurve = points;
|
|
113
|
-
const tIncrement = 1 / segmentCount;
|
|
100
|
+
const tIncrement = 1 / segmentCount;
|
|
101
|
+
|
|
102
|
+
// x-----x-----x-----x
|
|
114
103
|
// t= 0.33 0.66 1
|
|
115
104
|
// x-----o-----------x
|
|
116
105
|
// r= 0.33
|
|
117
106
|
// x-----o-----x
|
|
118
107
|
// r= 0.5 (0.33 / (1 - 0.33)) === tIncrement / (1 - (tIncrement * (i - 1))
|
|
108
|
+
|
|
119
109
|
// x-----x-----x-----x----x
|
|
120
110
|
// t= 0.25 0.5 0.75 1
|
|
121
111
|
// x-----o----------------x
|
|
@@ -130,12 +120,13 @@ function splitCurveAsPoints(points, segmentCount) {
|
|
|
130
120
|
const split = decasteljau(remainingCurve, tRelative);
|
|
131
121
|
segments.push(split.left);
|
|
132
122
|
remainingCurve = split.right;
|
|
133
|
-
}
|
|
134
|
-
|
|
123
|
+
}
|
|
135
124
|
|
|
125
|
+
// last segment is just to the end from the last point
|
|
136
126
|
segments.push(remainingCurve);
|
|
137
127
|
return segments;
|
|
138
128
|
}
|
|
129
|
+
|
|
139
130
|
/**
|
|
140
131
|
* Convert command objects to arrays of points, run de Casteljau's algorithm on it
|
|
141
132
|
* to split into to the desired number of segments.
|
|
@@ -145,28 +136,23 @@ function splitCurveAsPoints(points, segmentCount) {
|
|
|
145
136
|
* @param {Number} segmentCount The number of segments to create
|
|
146
137
|
* @return {Object[]} An array of commands representing the segments in sequence
|
|
147
138
|
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
139
|
export function splitCurve(commandStart, commandEnd, segmentCount) {
|
|
151
140
|
'worklet';
|
|
152
141
|
|
|
153
142
|
const points = [[commandStart.x, commandStart.y]];
|
|
154
|
-
|
|
155
143
|
if (commandEnd.x1 != null) {
|
|
156
144
|
points.push([commandEnd.x1, commandEnd.y1]);
|
|
157
145
|
}
|
|
158
|
-
|
|
159
146
|
if (commandEnd.x2 != null) {
|
|
160
147
|
points.push([commandEnd.x2, commandEnd.y2]);
|
|
161
148
|
}
|
|
162
|
-
|
|
163
149
|
points.push([commandEnd.x, commandEnd.y]);
|
|
164
150
|
return splitCurveAsPoints(points, segmentCount).map(pointsToCommand);
|
|
165
151
|
}
|
|
152
|
+
|
|
166
153
|
/**
|
|
167
154
|
* List of params for each command type in a path `d` attribute
|
|
168
155
|
*/
|
|
169
|
-
|
|
170
156
|
const typeMap = {
|
|
171
157
|
M: ['x', 'y'],
|
|
172
158
|
L: ['x', 'y'],
|
|
@@ -178,35 +164,33 @@ const typeMap = {
|
|
|
178
164
|
T: ['x', 'y'],
|
|
179
165
|
A: ['rx', 'ry', 'xAxisRotation', 'largeArcFlag', 'sweepFlag', 'x', 'y'],
|
|
180
166
|
Z: []
|
|
181
|
-
};
|
|
167
|
+
};
|
|
182
168
|
|
|
169
|
+
// Add lower case entries too matching uppercase (e.g. 'm' == 'M')
|
|
183
170
|
Object.keys(typeMap).forEach(key => {
|
|
184
171
|
typeMap[key.toLowerCase()] = typeMap[key];
|
|
185
172
|
});
|
|
186
|
-
|
|
187
173
|
function arrayOfLength(length, value) {
|
|
188
174
|
'worklet';
|
|
189
175
|
|
|
190
176
|
const array = Array(length);
|
|
191
|
-
|
|
192
177
|
for (let i = 0; i < length; i++) {
|
|
193
178
|
array[i] = value;
|
|
194
179
|
}
|
|
195
|
-
|
|
196
180
|
return array;
|
|
197
181
|
}
|
|
182
|
+
|
|
198
183
|
/**
|
|
199
184
|
* Converts a command object to a string to be used in a `d` attribute
|
|
200
185
|
* @param {Object} command A command object
|
|
201
186
|
* @return {String} The string for the `d` attribute
|
|
202
187
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
188
|
function commandToString(command) {
|
|
206
189
|
'worklet';
|
|
207
190
|
|
|
208
191
|
return `${command.type}${typeMap[command.type].map(p => command[p]).join(',')}`;
|
|
209
192
|
}
|
|
193
|
+
|
|
210
194
|
/**
|
|
211
195
|
* Converts command A to have the same type as command B.
|
|
212
196
|
*
|
|
@@ -227,8 +211,6 @@ function commandToString(command) {
|
|
|
227
211
|
* @param {Object} bCommand Command object from path `d` attribute to match against
|
|
228
212
|
* @return {Object} aCommand converted to type of bCommand
|
|
229
213
|
*/
|
|
230
|
-
|
|
231
|
-
|
|
232
214
|
function convertToSameType(aCommand, bCommand) {
|
|
233
215
|
'worklet';
|
|
234
216
|
|
|
@@ -238,15 +220,17 @@ function convertToSameType(aCommand, bCommand) {
|
|
|
238
220
|
x2: 'x',
|
|
239
221
|
y2: 'y'
|
|
240
222
|
};
|
|
241
|
-
const readFromBKeys = ['xAxisRotation', 'largeArcFlag', 'sweepFlag'];
|
|
223
|
+
const readFromBKeys = ['xAxisRotation', 'largeArcFlag', 'sweepFlag'];
|
|
242
224
|
|
|
225
|
+
// convert (but ignore M types)
|
|
243
226
|
if (aCommand.type !== bCommand.type && bCommand.type.toUpperCase() !== 'M') {
|
|
244
227
|
const aConverted = {};
|
|
245
228
|
Object.keys(bCommand).forEach(bKey => {
|
|
246
|
-
const bValue = bCommand[bKey];
|
|
247
|
-
|
|
248
|
-
let aValue = aCommand[bKey];
|
|
229
|
+
const bValue = bCommand[bKey];
|
|
230
|
+
// first read from the A command
|
|
231
|
+
let aValue = aCommand[bKey];
|
|
249
232
|
|
|
233
|
+
// if it is one of these values, read from B no matter what
|
|
250
234
|
if (aValue === undefined) {
|
|
251
235
|
if (readFromBKeys.includes(bKey)) {
|
|
252
236
|
aValue = bValue;
|
|
@@ -254,24 +238,24 @@ function convertToSameType(aCommand, bCommand) {
|
|
|
254
238
|
// if it wasn't in the A command, see if an equivalent was
|
|
255
239
|
if (aValue === undefined && conversionMap[bKey]) {
|
|
256
240
|
aValue = aCommand[conversionMap[bKey]];
|
|
257
|
-
}
|
|
258
|
-
|
|
241
|
+
}
|
|
259
242
|
|
|
243
|
+
// if it doesn't have a converted value, use 0
|
|
260
244
|
if (aValue === undefined) {
|
|
261
245
|
aValue = 0;
|
|
262
246
|
}
|
|
263
247
|
}
|
|
264
248
|
}
|
|
265
|
-
|
|
266
249
|
aConverted[bKey] = aValue;
|
|
267
|
-
});
|
|
250
|
+
});
|
|
268
251
|
|
|
252
|
+
// update the type to match B
|
|
269
253
|
aConverted.type = bCommand.type;
|
|
270
254
|
aCommand = aConverted;
|
|
271
255
|
}
|
|
272
|
-
|
|
273
256
|
return aCommand;
|
|
274
257
|
}
|
|
258
|
+
|
|
275
259
|
/**
|
|
276
260
|
* Interpolate between command objects commandStart and commandEnd segmentCount times.
|
|
277
261
|
* If the types are L, Q, or C then the curves are split as per de Casteljau's algorithm.
|
|
@@ -284,26 +268,26 @@ function convertToSameType(aCommand, bCommand) {
|
|
|
284
268
|
* @return {Object[]} Array of ~segmentCount command objects between commandStart and
|
|
285
269
|
* commandEnd. (Can be segmentCount+1 objects if commandStart is type M).
|
|
286
270
|
*/
|
|
287
|
-
|
|
288
|
-
|
|
289
271
|
function splitSegment(commandStart, commandEnd, segmentCount) {
|
|
290
272
|
'worklet';
|
|
291
273
|
|
|
292
|
-
let segments = [];
|
|
274
|
+
let segments = [];
|
|
293
275
|
|
|
276
|
+
// line, quadratic bezier, or cubic bezier
|
|
294
277
|
if (commandEnd.type === 'L' || commandEnd.type === 'Q' || commandEnd.type === 'C') {
|
|
295
|
-
segments = segments.concat(splitCurve(commandStart, commandEnd, segmentCount));
|
|
278
|
+
segments = segments.concat(splitCurve(commandStart, commandEnd, segmentCount));
|
|
279
|
+
|
|
280
|
+
// general case - just copy the same point
|
|
296
281
|
} else {
|
|
297
|
-
const copyCommand = Object.assign({}, commandStart);
|
|
282
|
+
const copyCommand = Object.assign({}, commandStart);
|
|
298
283
|
|
|
284
|
+
// convert M to L
|
|
299
285
|
if (copyCommand.type === 'M') {
|
|
300
286
|
copyCommand.type = 'L';
|
|
301
287
|
}
|
|
302
|
-
|
|
303
288
|
segments = segments.concat(arrayOfLength(segmentCount - 1).map(() => copyCommand));
|
|
304
289
|
segments.push(commandEnd);
|
|
305
290
|
}
|
|
306
|
-
|
|
307
291
|
return segments;
|
|
308
292
|
}
|
|
309
293
|
/**
|
|
@@ -317,114 +301,128 @@ function splitSegment(commandStart, commandEnd, segmentCount) {
|
|
|
317
301
|
* end command object and returns true if the segment should be excluded from splitting.
|
|
318
302
|
* @return {Object[]} The extended commandsToExtend array
|
|
319
303
|
*/
|
|
320
|
-
|
|
321
|
-
|
|
322
304
|
function extend(commandsToExtend, referenceCommands, excludeSegment) {
|
|
323
|
-
'worklet';
|
|
305
|
+
'worklet';
|
|
306
|
+
|
|
307
|
+
// compute insertion points:
|
|
324
308
|
// number of segments in the path to extend
|
|
309
|
+
const numSegmentsToExtend = commandsToExtend.length - 1;
|
|
325
310
|
|
|
326
|
-
|
|
311
|
+
// number of segments in the reference path.
|
|
312
|
+
const numReferenceSegments = referenceCommands.length - 1;
|
|
327
313
|
|
|
328
|
-
|
|
314
|
+
// this value is always between [0, 1].
|
|
315
|
+
const segmentRatio = numSegmentsToExtend / numReferenceSegments;
|
|
329
316
|
|
|
330
|
-
|
|
317
|
+
// create a map, mapping segments in referenceCommands to how many points
|
|
331
318
|
// should be added in that segment (should always be >= 1 since we need each
|
|
332
319
|
// point itself).
|
|
333
320
|
// 0 = segment 0-1, 1 = segment 1-2, n-1 = last vertex
|
|
334
|
-
|
|
335
321
|
const countPointsPerSegment = arrayOfLength(numReferenceSegments).reduce((accum, d, i) => {
|
|
336
|
-
let insertIndex = Math.floor(segmentRatio * i);
|
|
322
|
+
let insertIndex = Math.floor(segmentRatio * i);
|
|
337
323
|
|
|
324
|
+
// handle excluding segments
|
|
338
325
|
if (excludeSegment && insertIndex < commandsToExtend.length - 1 && excludeSegment(commandsToExtend[insertIndex], commandsToExtend[insertIndex + 1])) {
|
|
339
326
|
// set the insertIndex to the segment that this point should be added to:
|
|
327
|
+
|
|
340
328
|
// round the insertIndex essentially so we split half and half on
|
|
341
329
|
// neighbouring segments. hence the segmentRatio * i < 0.5
|
|
342
|
-
const addToPriorSegment = segmentRatio * i % 1 < 0.5;
|
|
330
|
+
const addToPriorSegment = segmentRatio * i % 1 < 0.5;
|
|
343
331
|
|
|
332
|
+
// only skip segment if we already have 1 point in it (can't entirely remove a segment)
|
|
344
333
|
if (accum[insertIndex]) {
|
|
345
334
|
// TODO - Note this is a naive algorithm that should work for most d3-area use cases
|
|
346
335
|
// but if two adjacent segments are supposed to be skipped, this will not perform as
|
|
347
336
|
// expected. Could be updated to search for nearest segment to place the point in, but
|
|
348
337
|
// will only do that if necessary.
|
|
338
|
+
|
|
349
339
|
// add to the prior segment
|
|
350
340
|
if (addToPriorSegment) {
|
|
351
341
|
if (insertIndex > 0) {
|
|
352
|
-
insertIndex -= 1;
|
|
342
|
+
insertIndex -= 1;
|
|
343
|
+
|
|
344
|
+
// not possible to add to previous so adding to next
|
|
353
345
|
} else if (insertIndex < commandsToExtend.length - 1) {
|
|
354
346
|
insertIndex += 1;
|
|
355
|
-
}
|
|
356
|
-
|
|
347
|
+
}
|
|
348
|
+
// add to next segment
|
|
357
349
|
} else if (insertIndex < commandsToExtend.length - 1) {
|
|
358
|
-
insertIndex += 1;
|
|
350
|
+
insertIndex += 1;
|
|
351
|
+
|
|
352
|
+
// not possible to add to next so adding to previous
|
|
359
353
|
} else if (insertIndex > 0) {
|
|
360
354
|
insertIndex -= 1;
|
|
361
355
|
}
|
|
362
356
|
}
|
|
363
357
|
}
|
|
364
|
-
|
|
365
358
|
accum[insertIndex] = (accum[insertIndex] || 0) + 1;
|
|
366
359
|
return accum;
|
|
367
|
-
}, []);
|
|
360
|
+
}, []);
|
|
368
361
|
|
|
362
|
+
// extend each segment to have the correct number of points for a smooth interpolation
|
|
369
363
|
const extended = countPointsPerSegment.reduce((extended, segmentCount, i) => {
|
|
370
364
|
// if last command, just add `segmentCount` number of times
|
|
371
365
|
if (i === commandsToExtend.length - 1) {
|
|
372
|
-
const lastCommandCopies = arrayOfLength(segmentCount, Object.assign({}, commandsToExtend[commandsToExtend.length - 1]));
|
|
366
|
+
const lastCommandCopies = arrayOfLength(segmentCount, Object.assign({}, commandsToExtend[commandsToExtend.length - 1]));
|
|
373
367
|
|
|
368
|
+
// convert M to L
|
|
374
369
|
if (lastCommandCopies[0].type === 'M') {
|
|
375
370
|
lastCommandCopies.forEach(d => {
|
|
376
371
|
d.type = 'L';
|
|
377
372
|
});
|
|
378
373
|
}
|
|
379
|
-
|
|
380
374
|
return extended.concat(lastCommandCopies);
|
|
381
|
-
}
|
|
382
|
-
|
|
375
|
+
}
|
|
383
376
|
|
|
377
|
+
// otherwise, split the segment segmentCount times.
|
|
384
378
|
return extended.concat(splitSegment(commandsToExtend[i], commandsToExtend[i + 1], segmentCount));
|
|
385
|
-
}, []);
|
|
379
|
+
}, []);
|
|
386
380
|
|
|
381
|
+
// add in the very first point since splitSegment only adds in the ones after it
|
|
387
382
|
extended.unshift(commandsToExtend[0]);
|
|
388
383
|
return extended;
|
|
389
384
|
}
|
|
385
|
+
|
|
390
386
|
/**
|
|
391
387
|
* Takes a path `d` string and converts it into an array of command
|
|
392
388
|
* objects. Drops the `Z` character.
|
|
393
389
|
*
|
|
394
390
|
* @param {String|null} d A path `d` string
|
|
395
391
|
*/
|
|
396
|
-
|
|
397
|
-
|
|
398
392
|
export function pathCommandsFromString(d) {
|
|
399
|
-
'worklet';
|
|
393
|
+
'worklet';
|
|
400
394
|
|
|
395
|
+
// split into valid tokens
|
|
401
396
|
const tokens = (d || '').match(/[MLCSTQAHVZmlcstqahv]|-?[\d.e+-]+/g) || [];
|
|
402
397
|
const commands = [];
|
|
403
398
|
let commandArgs;
|
|
404
|
-
let command;
|
|
405
|
-
// by presence in the typeMap
|
|
399
|
+
let command;
|
|
406
400
|
|
|
401
|
+
// iterate over each token, checking if we are at a new command
|
|
402
|
+
// by presence in the typeMap
|
|
407
403
|
for (let i = 0; i < tokens.length; ++i) {
|
|
408
|
-
commandArgs = typeMap[tokens[i]];
|
|
404
|
+
commandArgs = typeMap[tokens[i]];
|
|
409
405
|
|
|
406
|
+
// new command found:
|
|
410
407
|
if (commandArgs) {
|
|
411
408
|
command = {
|
|
412
409
|
type: tokens[i]
|
|
413
|
-
};
|
|
410
|
+
};
|
|
414
411
|
|
|
412
|
+
// add each of the expected args for this command:
|
|
415
413
|
for (let a = 0; a < commandArgs.length; ++a) {
|
|
416
414
|
command[commandArgs[a]] = +tokens[i + a + 1];
|
|
417
|
-
}
|
|
418
|
-
// we consumed token args
|
|
419
|
-
|
|
415
|
+
}
|
|
420
416
|
|
|
417
|
+
// need to increment our token index appropriately since
|
|
418
|
+
// we consumed token args
|
|
421
419
|
i += commandArgs.length;
|
|
422
420
|
commands.push(command);
|
|
423
421
|
}
|
|
424
422
|
}
|
|
425
|
-
|
|
426
423
|
return commands;
|
|
427
424
|
}
|
|
425
|
+
|
|
428
426
|
/**
|
|
429
427
|
* Interpolate from A to B by extending A and B during interpolation to have
|
|
430
428
|
* the same number of points. This allows for a smooth transition when they
|
|
@@ -441,59 +439,63 @@ export function pathCommandsFromString(d) {
|
|
|
441
439
|
* end command object and returns true if the segment should be excluded from splitting.
|
|
442
440
|
* @returns {Function} Interpolation function that maps t ([0, 1]) to an array of path commands.
|
|
443
441
|
*/
|
|
444
|
-
|
|
445
442
|
export function interpolatePathCommands(aCommandsInput, bCommandsInput, excludeSegment) {
|
|
446
|
-
'worklet';
|
|
443
|
+
'worklet';
|
|
447
444
|
|
|
445
|
+
// make a copy so we don't mess with the input arrays
|
|
448
446
|
let aCommands = aCommandsInput == null ? [] : aCommandsInput.slice();
|
|
449
|
-
let bCommands = bCommandsInput == null ? [] : bCommandsInput.slice();
|
|
447
|
+
let bCommands = bCommandsInput == null ? [] : bCommandsInput.slice();
|
|
450
448
|
|
|
449
|
+
// both input sets are empty, so we don't interpolate
|
|
451
450
|
if (!aCommands.length && !bCommands.length) {
|
|
452
451
|
return function nullInterpolator() {
|
|
453
452
|
'worklet';
|
|
454
453
|
|
|
455
454
|
return [];
|
|
456
455
|
};
|
|
457
|
-
}
|
|
458
|
-
|
|
456
|
+
}
|
|
459
457
|
|
|
460
|
-
|
|
458
|
+
// do we add Z during interpolation? yes if both have it. (we'd expect both to have it or not)
|
|
459
|
+
const addZ = (aCommands.length === 0 || aCommands[aCommands.length - 1].type === 'Z') && (bCommands.length === 0 || bCommands[bCommands.length - 1].type === 'Z');
|
|
461
460
|
|
|
461
|
+
// we temporarily remove Z
|
|
462
462
|
if (aCommands.length > 0 && aCommands[aCommands.length - 1].type === 'Z') {
|
|
463
463
|
aCommands.pop();
|
|
464
464
|
}
|
|
465
|
-
|
|
466
465
|
if (bCommands.length > 0 && bCommands[bCommands.length - 1].type === 'Z') {
|
|
467
466
|
bCommands.pop();
|
|
468
|
-
}
|
|
469
|
-
// of B. This makes it so the line extends out of from that first point.
|
|
470
|
-
|
|
467
|
+
}
|
|
471
468
|
|
|
469
|
+
// if A is empty, treat it as if it used to contain just the first point
|
|
470
|
+
// of B. This makes it so the line extends out of from that first point.
|
|
472
471
|
if (!aCommands.length) {
|
|
473
|
-
aCommands.push(bCommands[0]);
|
|
472
|
+
aCommands.push(bCommands[0]);
|
|
473
|
+
|
|
474
|
+
// otherwise if B is empty, treat it as if it contains the first point
|
|
474
475
|
// of A. This makes it so the line retracts into the first point.
|
|
475
476
|
} else if (!bCommands.length) {
|
|
476
477
|
bCommands.push(aCommands[0]);
|
|
477
|
-
}
|
|
478
|
-
|
|
478
|
+
}
|
|
479
479
|
|
|
480
|
+
// extend to match equal size
|
|
480
481
|
const numPointsToExtend = Math.abs(bCommands.length - aCommands.length);
|
|
481
|
-
|
|
482
482
|
if (numPointsToExtend !== 0) {
|
|
483
483
|
// B has more points than A, so add points to A before interpolating
|
|
484
484
|
if (bCommands.length > aCommands.length) {
|
|
485
|
-
aCommands = extend(aCommands, bCommands, excludeSegment);
|
|
485
|
+
aCommands = extend(aCommands, bCommands, excludeSegment);
|
|
486
|
+
|
|
487
|
+
// else if A has more points than B, add more points to B
|
|
486
488
|
} else if (bCommands.length < aCommands.length) {
|
|
487
489
|
bCommands = extend(bCommands, aCommands, excludeSegment);
|
|
488
490
|
}
|
|
489
|
-
}
|
|
490
|
-
// convert commands in A to the same type as those in B
|
|
491
|
-
|
|
491
|
+
}
|
|
492
492
|
|
|
493
|
-
|
|
493
|
+
// commands have same length now.
|
|
494
|
+
// convert commands in A to the same type as those in B
|
|
495
|
+
aCommands = aCommands.map((aCommand, i) => convertToSameType(aCommand, bCommands[i]));
|
|
494
496
|
|
|
497
|
+
// create mutable interpolated command objects
|
|
495
498
|
const interpolatedCommands = aCommands.map(aCommand => aCommand);
|
|
496
|
-
|
|
497
499
|
if (addZ) {
|
|
498
500
|
interpolatedCommands.push({
|
|
499
501
|
type: 'Z'
|
|
@@ -502,39 +504,40 @@ export function interpolatePathCommands(aCommandsInput, bCommandsInput, excludeS
|
|
|
502
504
|
type: 'Z'
|
|
503
505
|
}); // required for when returning at t == 0
|
|
504
506
|
}
|
|
505
|
-
|
|
506
507
|
return function pathCommandInterpolator(t) {
|
|
507
|
-
'worklet';
|
|
508
|
+
'worklet';
|
|
508
509
|
|
|
510
|
+
// at 1 return the final value without the extensions used during interpolation
|
|
509
511
|
if (t === 1) {
|
|
510
512
|
return bCommandsInput == null ? [] : bCommandsInput;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
+
}
|
|
513
514
|
|
|
515
|
+
// work with aCommands directly since interpolatedCommands are mutated
|
|
514
516
|
if (t === 0) {
|
|
515
517
|
return aCommands;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
+
}
|
|
518
519
|
|
|
520
|
+
// interpolate the commands using the mutable interpolated command objs
|
|
519
521
|
for (let i = 0; i < interpolatedCommands.length; ++i) {
|
|
520
522
|
// if (interpolatedCommands[i].type === 'Z') continue;
|
|
523
|
+
|
|
521
524
|
const aCommand = aCommands[i];
|
|
522
525
|
const bCommand = bCommands[i];
|
|
523
526
|
const interpolatedCommand = interpolatedCommands[i];
|
|
524
|
-
|
|
525
527
|
for (let j = 0; j < typeMap[interpolatedCommand.type].length; j++) {
|
|
526
528
|
const arg = typeMap[interpolatedCommand.type][j];
|
|
527
|
-
interpolatedCommand[arg] = (1 - t) * aCommand[arg] + t * bCommand[arg];
|
|
529
|
+
interpolatedCommand[arg] = (1 - t) * aCommand[arg] + t * bCommand[arg];
|
|
528
530
|
|
|
531
|
+
// do not use floats for flags (#27), round to integer
|
|
529
532
|
if (arg === 'largeArcFlag' || arg === 'sweepFlag') {
|
|
530
533
|
interpolatedCommand[arg] = Math.round(interpolatedCommand[arg]);
|
|
531
534
|
}
|
|
532
535
|
}
|
|
533
536
|
}
|
|
534
|
-
|
|
535
537
|
return interpolatedCommands;
|
|
536
538
|
};
|
|
537
539
|
}
|
|
540
|
+
|
|
538
541
|
/**
|
|
539
542
|
* Interpolate from A to B by extending A and B during interpolation to have
|
|
540
543
|
* the same number of points. This allows for a smooth transition when they
|
|
@@ -548,13 +551,11 @@ export function interpolatePathCommands(aCommandsInput, bCommandsInput, excludeS
|
|
|
548
551
|
* end command object and returns true if the segment should be excluded from splitting.
|
|
549
552
|
* @returns {Function} Interpolation function that maps t ([0, 1]) to a path `d` string.
|
|
550
553
|
*/
|
|
551
|
-
|
|
552
554
|
export function interpolatePath(a, b, excludeSegment) {
|
|
553
555
|
'worklet';
|
|
554
556
|
|
|
555
557
|
let aCommands = pathCommandsFromString(a);
|
|
556
558
|
let bCommands = pathCommandsFromString(b);
|
|
557
|
-
|
|
558
559
|
if (!aCommands.length && !bCommands.length) {
|
|
559
560
|
return function nullInterpolator() {
|
|
560
561
|
'worklet';
|
|
@@ -562,24 +563,22 @@ export function interpolatePath(a, b, excludeSegment) {
|
|
|
562
563
|
return '';
|
|
563
564
|
};
|
|
564
565
|
}
|
|
565
|
-
|
|
566
566
|
const commandInterpolator = interpolatePathCommands(aCommands, bCommands, excludeSegment);
|
|
567
567
|
return function pathStringInterpolator(t) {
|
|
568
|
-
'worklet';
|
|
568
|
+
'worklet';
|
|
569
569
|
|
|
570
|
+
// at 1 return the final value without the extensions used during interpolation
|
|
570
571
|
if (t === 1) {
|
|
571
572
|
return b == null ? '' : b;
|
|
572
573
|
}
|
|
574
|
+
const interpolatedCommands = commandInterpolator(t);
|
|
573
575
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
+
// convert to a string (fastest concat: https://jsperf.com/join-concat/150)
|
|
576
577
|
let interpolatedString = '';
|
|
577
|
-
|
|
578
578
|
for (let i = 0; i < interpolatedCommands.length; i++) {
|
|
579
579
|
const interpolatedCommand = interpolatedCommands[i];
|
|
580
580
|
interpolatedString += commandToString(interpolatedCommand);
|
|
581
581
|
}
|
|
582
|
-
|
|
583
582
|
return interpolatedString;
|
|
584
583
|
};
|
|
585
584
|
}
|