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