@@ -3,10 +3,12 @@ import { ScrollView, StyleSheet, View, Text } from "react-native";
3
3
4
4
import { ThemedText } from "@/components/ThemedText" ;
5
5
import { ThemedView } from "@/components/ThemedView" ;
6
- import { useFont } from "@shopify/react-native-skia" ;
7
- import { CartesianChart , Line } from "victory-native" ;
8
6
9
- import spacemono from '../assets/fonts/SpaceMono-Regular.ttf' ;
7
+ import { LineGraph } from "react-native-graph" ;
8
+ import { GestureHandlerRootView } from "react-native-gesture-handler" ;
9
+
10
+ import * as Haptics from 'expo-haptics' ;
11
+ import { useState } from "react" ;
10
12
11
13
// orm = "one rep max"
12
14
type ormChartData = {
@@ -17,8 +19,8 @@ type ormChartData = {
17
19
}
18
20
19
21
type DataPoint = {
20
- timestamp : number ;
21
- orm : number ;
22
+ date : Date ;
23
+ value : number ;
22
24
}
23
25
24
26
const dataFromApi : ormChartData = {
@@ -29,10 +31,10 @@ const dataFromApi: ormChartData = {
29
31
"orm"
30
32
] ,
31
33
values : [
32
- [ 1634044477 , 70 ] ,
33
- [ 1635293049 , 72.33 ] ,
34
- [ 1700000000 , 71.94 ] ,
35
- [ 1734044477 , 80 ]
34
+ [ 1726191377 , 70 ] ,
35
+ [ 1728783377 , 72.33 ] ,
36
+ [ 1731461777 , 71.94 ] ,
37
+ [ 1734053777 , 73 ]
36
38
]
37
39
}
38
40
@@ -42,8 +44,8 @@ function reformatChartData(dataFromApi: ormChartData): DataPoint[] {
42
44
const reformattedData = [ ] ;
43
45
for ( const dataPoint of dataFromApi . values ) {
44
46
reformattedData . push ( {
45
- timestamp : dataPoint [ 0 ] ,
46
- orm : dataPoint [ 1 ]
47
+ date : new Date ( dataPoint [ 0 ] ) ,
48
+ value : dataPoint [ 1 ]
47
49
} ) ;
48
50
}
49
51
@@ -52,48 +54,53 @@ function reformatChartData(dataFromApi: ormChartData): DataPoint[] {
52
54
53
55
export default function WorkoutView ( ) {
54
56
const DATA = reformatChartData ( dataFromApi ) ;
57
+ const graphColor = "#4484B2" ;
58
+
59
+ const [ currOrm , setCurrOrm ] = useState ( DATA [ DATA . length - 1 ] [ "value" ] ) ;
60
+
61
+ function updateCurrOrm ( newOrm : DataPoint ) : void {
62
+ setCurrOrm ( newOrm . value ) ;
63
+ }
64
+
65
+ function resetCurrOrm ( ) : void {
66
+ setCurrOrm ( DATA [ DATA . length - 1 ] [ "value" ] ) ;
67
+ }
55
68
56
69
return (
57
70
< >
58
- < Stack . Screen options = { { title : "Oops!" , headerShown : false } } />
59
- { /* <ThemedView style={styles.container}> */ }
60
- < ScrollView contentContainerStyle = { styles . scrollViewContent } >
61
- < Text style = { styles . title } > { dataFromApi . exercise_name } </ Text >
62
- < View style = { styles . chartContainer } >
63
- < CartesianChart data = { DATA } xKey = "timestamp" yKeys = { [ "orm" ] } axisOptions = { { font : useFont ( spacemono , 12 ) } } >
64
- { ( { points } ) => (
65
- < Line
66
- points = { points . orm }
67
- color = "red"
68
- strokeWidth = { 3 }
69
- animate = { { type : "timing" , duration : 300 } }
70
- />
71
- ) }
72
- </ CartesianChart >
73
- </ View >
74
- </ ScrollView >
75
- { /* </ThemedView> */ }
71
+ < GestureHandlerRootView >
72
+ < Stack . Screen options = { { title : "Oops!" , headerShown : false } } />
73
+ < ThemedView style = { styles . container } >
74
+ < ThemedText type = "title" style = { styles . title } > { dataFromApi . exercise_name } </ ThemedText >
75
+ < ThemedText type = "subtitle" style = { styles . title } > { currOrm } </ ThemedText >
76
+ < LineGraph
77
+ style = { styles . graph }
78
+ animated = { true }
79
+ enablePanGesture = { true }
80
+ color = { graphColor }
81
+ points = { DATA }
82
+ onGestureStart = { ( ) => Haptics . impactAsync ( Haptics . ImpactFeedbackStyle . Light ) }
83
+ onPointSelected = { ( o ) => updateCurrOrm ( o ) }
84
+ onGestureEnd = { ( ) => resetCurrOrm ( ) }
85
+ />
86
+ </ ThemedView >
87
+ </ GestureHandlerRootView >
76
88
</ >
77
89
) ;
78
90
}
79
91
80
92
const styles = StyleSheet . create ( {
93
+ graph : {
94
+ width : 300 ,
95
+ height : 500 ,
96
+ } ,
81
97
container : {
82
98
flex : 1 ,
83
99
padding : 20 ,
84
- } ,
85
- scrollViewContent : {
86
- flexGrow : 1 ,
87
- alignItems : "center" ,
88
- justifyContent : "center" ,
100
+ alignItems : "center"
89
101
} ,
90
102
title : {
91
103
marginTop : 100 ,
92
104
fontSize : 30
93
105
} ,
94
- chartContainer : {
95
- height : 600 , // Ensure the chart has a defined height
96
- width : '80%' ,
97
- padding : 10
98
- } ,
99
106
} ) ;
0 commit comments