react-native-wagmi-charts 1.0.4 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/.DS_Store +0 -0
  2. package/.prettierrc.js +5 -0
  3. package/README.md +171 -121
  4. package/example/.DS_Store +0 -0
  5. package/example/README.md +32 -0
  6. package/example/package.json +1 -1
  7. package/example/src/App.tsx +32 -7
  8. package/example/src/CandlestickChart.tsx +23 -11
  9. package/example/src/LineChart.tsx +51 -20
  10. package/example/src/{candlestick-data.json → data/candlestick-data.json} +0 -0
  11. package/example/src/{candlestick-data2.json → data/candlestick-data2.json} +0 -0
  12. package/example/src/{line-data.json → data/line-data.json} +0 -0
  13. package/example/src/{line-data2.json → data/line-data2.json} +0 -0
  14. package/example/yarn.lock +5 -5
  15. package/lib/commonjs/charts/candle/Crosshair.js +6 -17
  16. package/lib/commonjs/charts/candle/Crosshair.js.map +1 -1
  17. package/lib/commonjs/charts/candle/CrosshairTooltip.js +12 -8
  18. package/lib/commonjs/charts/candle/CrosshairTooltip.js.map +1 -1
  19. package/lib/commonjs/charts/candle/DatetimeText.js +7 -8
  20. package/lib/commonjs/charts/candle/DatetimeText.js.map +1 -1
  21. package/lib/commonjs/charts/candle/Line.js.map +1 -1
  22. package/lib/commonjs/charts/candle/PriceText.js +7 -8
  23. package/lib/commonjs/charts/candle/PriceText.js.map +1 -1
  24. package/lib/commonjs/charts/candle/useCandleData.js.map +1 -1
  25. package/lib/commonjs/charts/candle/useCandlestickChart.js.map +1 -1
  26. package/lib/commonjs/charts/candle/useDatetime.js.map +1 -1
  27. package/lib/commonjs/charts/candle/usePrice.js.map +1 -1
  28. package/lib/commonjs/charts/candle/utils.js.map +1 -1
  29. package/lib/commonjs/charts/line/Chart.js.map +1 -1
  30. package/lib/commonjs/charts/line/Cursor.js.map +1 -1
  31. package/lib/commonjs/charts/line/CursorCrosshair.js +4 -3
  32. package/lib/commonjs/charts/line/CursorCrosshair.js.map +1 -1
  33. package/lib/commonjs/charts/line/CursorLine.js +8 -1
  34. package/lib/commonjs/charts/line/CursorLine.js.map +1 -1
  35. package/lib/commonjs/charts/line/DatetimeText.js +7 -8
  36. package/lib/commonjs/charts/line/DatetimeText.js.map +1 -1
  37. package/lib/commonjs/charts/line/Path.js +13 -16
  38. package/lib/commonjs/charts/line/Path.js.map +1 -1
  39. package/lib/commonjs/charts/line/PriceText.js +7 -8
  40. package/lib/commonjs/charts/line/PriceText.js.map +1 -1
  41. package/lib/commonjs/charts/line/interpolatePath.js +600 -0
  42. package/lib/commonjs/charts/line/interpolatePath.js.map +1 -0
  43. package/lib/commonjs/charts/line/useDatetime.js.map +1 -1
  44. package/lib/commonjs/charts/line/usePrice.js.map +1 -1
  45. package/lib/commonjs/charts/line/utils.js +1 -70
  46. package/lib/commonjs/charts/line/utils.js.map +1 -1
  47. package/lib/commonjs/components/AnimatedText.js +63 -0
  48. package/lib/commonjs/components/AnimatedText.js.map +1 -0
  49. package/lib/commonjs/utils.js.map +1 -1
  50. package/lib/module/charts/candle/Crosshair.js +7 -16
  51. package/lib/module/charts/candle/Crosshair.js.map +1 -1
  52. package/lib/module/charts/candle/CrosshairTooltip.js +10 -8
  53. package/lib/module/charts/candle/CrosshairTooltip.js.map +1 -1
  54. package/lib/module/charts/candle/DatetimeText.js +6 -7
  55. package/lib/module/charts/candle/DatetimeText.js.map +1 -1
  56. package/lib/module/charts/candle/Line.js.map +1 -1
  57. package/lib/module/charts/candle/PriceText.js +6 -7
  58. package/lib/module/charts/candle/PriceText.js.map +1 -1
  59. package/lib/module/charts/candle/useCandleData.js.map +1 -1
  60. package/lib/module/charts/candle/useCandlestickChart.js.map +1 -1
  61. package/lib/module/charts/candle/useDatetime.js.map +1 -1
  62. package/lib/module/charts/candle/usePrice.js.map +1 -1
  63. package/lib/module/charts/candle/utils.js.map +1 -1
  64. package/lib/module/charts/line/Chart.js.map +1 -1
  65. package/lib/module/charts/line/Cursor.js.map +1 -1
  66. package/lib/module/charts/line/CursorCrosshair.js +4 -3
  67. package/lib/module/charts/line/CursorCrosshair.js.map +1 -1
  68. package/lib/module/charts/line/CursorLine.js +7 -1
  69. package/lib/module/charts/line/CursorLine.js.map +1 -1
  70. package/lib/module/charts/line/DatetimeText.js +6 -7
  71. package/lib/module/charts/line/DatetimeText.js.map +1 -1
  72. package/lib/module/charts/line/Path.js +11 -15
  73. package/lib/module/charts/line/Path.js.map +1 -1
  74. package/lib/module/charts/line/PriceText.js +6 -7
  75. package/lib/module/charts/line/PriceText.js.map +1 -1
  76. package/lib/module/charts/line/interpolatePath.js +587 -0
  77. package/lib/module/charts/line/interpolatePath.js.map +1 -0
  78. package/lib/module/charts/line/useDatetime.js.map +1 -1
  79. package/lib/module/charts/line/usePrice.js.map +1 -1
  80. package/lib/module/charts/line/utils.js +1 -66
  81. package/lib/module/charts/line/utils.js.map +1 -1
  82. package/lib/module/components/AnimatedText.js +43 -0
  83. package/lib/module/components/AnimatedText.js.map +1 -0
  84. package/lib/module/utils.js.map +1 -1
  85. package/lib/typescript/src/charts/candle/Crosshair.d.ts +4 -4
  86. package/lib/typescript/src/charts/candle/DatetimeText.d.ts +3 -2
  87. package/lib/typescript/src/charts/candle/Line.d.ts +1 -1
  88. package/lib/typescript/src/charts/candle/PriceText.d.ts +3 -3
  89. package/lib/typescript/src/charts/candle/types.d.ts +8 -3
  90. package/lib/typescript/src/charts/candle/useCandleData.d.ts +3 -3
  91. package/lib/typescript/src/charts/candle/useCandlestickChart.d.ts +2 -1
  92. package/lib/typescript/src/charts/candle/useDatetime.d.ts +5 -7
  93. package/lib/typescript/src/charts/candle/usePrice.d.ts +5 -8
  94. package/lib/typescript/src/charts/candle/utils.d.ts +1 -1
  95. package/lib/typescript/src/charts/line/Chart.d.ts +1 -1
  96. package/lib/typescript/src/charts/line/Cursor.d.ts +1 -2
  97. package/lib/typescript/src/charts/line/CursorCrosshair.d.ts +3 -2
  98. package/lib/typescript/src/charts/line/DatetimeText.d.ts +5 -6
  99. package/lib/typescript/src/charts/line/Path.d.ts +17 -1
  100. package/lib/typescript/src/charts/line/PriceText.d.ts +3 -2
  101. package/lib/typescript/src/charts/line/interpolatePath.d.ts +50 -0
  102. package/lib/typescript/src/charts/line/useDatetime.d.ts +4 -5
  103. package/lib/typescript/src/charts/line/usePrice.d.ts +3 -2
  104. package/lib/typescript/src/charts/line/utils.d.ts +0 -13
  105. package/lib/typescript/src/components/AnimatedText.d.ts +9 -0
  106. package/lib/typescript/src/utils.d.ts +2 -4
  107. package/package.json +4 -4
  108. package/src/charts/candle/Crosshair.tsx +20 -20
  109. package/src/charts/candle/CrosshairTooltip.tsx +11 -4
  110. package/src/charts/candle/DatetimeText.tsx +5 -4
  111. package/src/charts/candle/Line.tsx +1 -1
  112. package/src/charts/candle/PriceText.tsx +5 -5
  113. package/src/charts/candle/types.ts +11 -3
  114. package/src/charts/candle/useCandleData.ts +3 -2
  115. package/src/charts/candle/useCandlestickChart.ts +2 -1
  116. package/src/charts/candle/useDatetime.ts +7 -3
  117. package/src/charts/candle/usePrice.ts +10 -3
  118. package/src/charts/candle/utils.ts +1 -1
  119. package/src/charts/line/Chart.tsx +1 -1
  120. package/src/charts/line/Cursor.tsx +7 -3
  121. package/src/charts/line/CursorCrosshair.tsx +4 -3
  122. package/src/charts/line/CursorLine.tsx +9 -1
  123. package/src/charts/line/DatetimeText.tsx +8 -7
  124. package/src/charts/line/Path.tsx +25 -21
  125. package/src/charts/line/PriceText.tsx +5 -4
  126. package/src/charts/line/interpolatePath.ts +650 -0
  127. package/src/charts/line/useDatetime.ts +3 -2
  128. package/src/charts/line/usePrice.ts +2 -1
  129. package/src/charts/line/utils.ts +2 -79
  130. package/src/components/AnimatedText.tsx +53 -0
  131. package/src/utils.ts +3 -3
  132. package/yarn.lock +5 -5
@@ -4,7 +4,6 @@ import * as shape from 'd3-shape';
4
4
  import { scaleLinear } from 'd3-scale';
5
5
 
6
6
  import type { TLineChartData, TLineChartPoint } from './types';
7
- import type { Path } from 'react-native-redash';
8
7
 
9
8
  export function getDomain(rows: TLineChartPoint[]): [number, number] {
10
9
  'worklet';
@@ -35,84 +34,8 @@ export function getPath({
35
34
  .range([height - gutter, gutter]);
36
35
  const path = shape
37
36
  .line()
38
- .x((_: any, i: number) => scaleX(i))
39
- .y((data: any) => scaleY(data.value))
37
+ .x((_: unknown, i: number) => scaleX(i))
38
+ .y((d: { value: unknown }) => scaleY(d.value))
40
39
  .curve(_shape)(data);
41
40
  return path;
42
41
  }
43
-
44
- export function syncChangingPaths({
45
- pointsToAdd,
46
- parsedPath,
47
- curves,
48
- }: {
49
- pointsToAdd: number;
50
- parsedPath: Path;
51
- curves: Path['curves'];
52
- }) {
53
- 'worklet';
54
- const firstPoint = curves?.[0];
55
-
56
- let newParsedPath = parsedPath;
57
- for (let i = 0; i < Math.abs(pointsToAdd); i++) {
58
- newParsedPath = {
59
- ...newParsedPath,
60
- curves: [
61
- {
62
- c1: {
63
- x: firstPoint.c1.x,
64
- y: firstPoint.c1.y,
65
- },
66
- c2: {
67
- x: firstPoint.c2.x,
68
- y: firstPoint.c2.y,
69
- },
70
- to: {
71
- x: firstPoint.to.x,
72
- y: firstPoint.to.y,
73
- },
74
- },
75
- ...newParsedPath.curves,
76
- ],
77
- };
78
- }
79
- return newParsedPath;
80
- }
81
-
82
- export function syncPaths({
83
- parsedPath,
84
- previousParsedPath,
85
- }: {
86
- parsedPath: Path;
87
- previousParsedPath: Path | undefined;
88
- }) {
89
- 'worklet';
90
- const previousCurves = (previousParsedPath as any)?.curves;
91
- const nextCurves = parsedPath?.curves;
92
-
93
- let newPreviousParsedPath = previousParsedPath || parsedPath;
94
- let newParsedPath = parsedPath;
95
-
96
- if (previousCurves?.length !== nextCurves?.length) {
97
- const pointsToAdd = nextCurves?.length - previousCurves?.length || 0;
98
-
99
- if (pointsToAdd > 0) {
100
- newPreviousParsedPath = syncChangingPaths({
101
- pointsToAdd,
102
- parsedPath: newPreviousParsedPath,
103
- curves: previousCurves,
104
- });
105
- } else if (pointsToAdd < 0) {
106
- newParsedPath = syncChangingPaths({
107
- pointsToAdd,
108
- parsedPath: newParsedPath,
109
- curves: nextCurves,
110
- });
111
- }
112
- }
113
-
114
- return {
115
- previousParsedPath: newPreviousParsedPath,
116
- parsedPath: newParsedPath,
117
- };
118
- }
@@ -0,0 +1,53 @@
1
+ // forked from https://github.com/wcandillon/react-native-redash/blob/master/src/ReText.tsx
2
+
3
+ import React from 'react';
4
+ import { Platform, TextProps as RNTextProps } from 'react-native';
5
+ import { TextInput } from 'react-native';
6
+ import Animated, {
7
+ useAnimatedProps,
8
+ useAnimatedReaction,
9
+ } from 'react-native-reanimated';
10
+
11
+ Animated.addWhitelistedNativeProps({ text: true });
12
+
13
+ interface AnimatedTextProps {
14
+ text: Animated.SharedValue<string>;
15
+ style?: Animated.AnimateProps<RNTextProps>['style'];
16
+ }
17
+
18
+ const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);
19
+
20
+ export const AnimatedText = ({ text, style }: AnimatedTextProps) => {
21
+ const inputRef = React.useRef<TextInput>(null);
22
+
23
+ useAnimatedReaction(
24
+ () => {
25
+ // always return false unless web to prevent unnecessary reactions
26
+ return Platform.OS === 'web' && text.value;
27
+ },
28
+ (data, prevData) => {
29
+ if (Platform.OS === 'web' && data !== prevData && inputRef.current) {
30
+ inputRef.current.setNativeProps({
31
+ value: data,
32
+ });
33
+ }
34
+ }
35
+ );
36
+ const animatedProps = useAnimatedProps(() => {
37
+ return {
38
+ text: text.value,
39
+ // Here we use any because the text prop is not available in the type
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ } as any;
42
+ });
43
+ return (
44
+ <AnimatedTextInput
45
+ underlineColorAndroid="transparent"
46
+ editable={false}
47
+ ref={Platform.select({ web: inputRef })}
48
+ value={text.value}
49
+ style={style}
50
+ animatedProps={animatedProps}
51
+ />
52
+ );
53
+ };
package/src/utils.ts CHANGED
@@ -45,17 +45,17 @@ export function formatDatetime({
45
45
  }: {
46
46
  value: number;
47
47
  locale?: string;
48
- options?: { [key: string]: string };
48
+ options?: Intl.DateTimeFormatOptions;
49
49
  }) {
50
50
  'worklet';
51
51
  const d = new Date(value);
52
52
  return d.toLocaleString(locale, options);
53
53
  }
54
54
 
55
- export function usePrevious(value: any) {
55
+ export function usePrevious<T>(value: T) {
56
56
  // The ref object is a generic container whose current property is mutable ...
57
57
  // ... and can hold any value, similar to an instance property on a class
58
- const ref = React.useRef();
58
+ const ref = React.useRef<T>();
59
59
  // Store current value in ref
60
60
  React.useEffect(() => {
61
61
  ref.current = value;
package/yarn.lock CHANGED
@@ -2752,6 +2752,11 @@ d3-format@1:
2752
2752
  resolved "https://registry.yarnpkg.com/d3-format/-/d3-format-1.4.5.tgz#374f2ba1320e3717eb74a9356c67daee17a7edb4"
2753
2753
  integrity sha512-J0piedu6Z8iB6TbIGfZgDzfXxUFN3qQRMofy2oPdXzQibYGqPB/9iMcxr/TGalU+2RsyDO+U4f33id8tbnSRMQ==
2754
2754
 
2755
+ d3-interpolate-path@^2.2.3:
2756
+ version "2.2.3"
2757
+ resolved "https://registry.yarnpkg.com/d3-interpolate-path/-/d3-interpolate-path-2.2.3.tgz#7a2a906231c316c5166872c13400aae918e604fa"
2758
+ integrity sha512-1i1WUmOzSHI7nYqhjnL9v/gA5VQNgMMfX4u1Emv2vKmUUQsRPx/Ghl/AvcyOq3GRINW8iSz5elCdoHX0imyWCg==
2759
+
2755
2760
  d3-interpolate@1:
2756
2761
  version "1.4.0"
2757
2762
  resolved "https://registry.yarnpkg.com/d3-interpolate/-/d3-interpolate-1.4.0.tgz#526e79e2d80daa383f9e0c1c1c7dcc0f0583e987"
@@ -6210,11 +6215,6 @@ react-native-gesture-handler@^1.10.3:
6210
6215
  invariant "^2.2.4"
6211
6216
  prop-types "^15.7.2"
6212
6217
 
6213
- react-native-haptic-feedback@^1.11.0:
6214
- version "1.11.0"
6215
- resolved "https://registry.yarnpkg.com/react-native-haptic-feedback/-/react-native-haptic-feedback-1.11.0.tgz#adfd841f3b67046532f912c6ec827aea0037d8ad"
6216
- integrity sha512-KTIy7lExwMtB6pOpCARyUzFj5EzYTh+A1GN/FB5Eb0LrW5C6hbb1kdj9K2/RHyZC+wyAJD1M823ZaDCU6n6cLA==
6217
-
6218
6218
  react-native-reanimated@^2.2.0:
6219
6219
  version "2.2.0"
6220
6220
  resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-2.2.0.tgz#a6412c56b4e591d1f00fac949f62d0c72c357c78"