Skip to content

Commit 76af05a

Browse files
committed
makes progress graph better
1 parent 2e6c657 commit 76af05a

File tree

5 files changed

+84
-272
lines changed

5 files changed

+84
-272
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

workout-app/app/ProgressGraph.tsx

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { ScrollView, StyleSheet, View, Text } from "react-native";
33

44
import { ThemedText } from "@/components/ThemedText";
55
import { ThemedView } from "@/components/ThemedView";
6-
import { useFont } from "@shopify/react-native-skia";
7-
import { CartesianChart, Line } from "victory-native";
86

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";
1012

1113
// orm = "one rep max"
1214
type ormChartData = {
@@ -17,8 +19,8 @@ type ormChartData = {
1719
}
1820

1921
type DataPoint = {
20-
timestamp: number;
21-
orm: number;
22+
date: Date;
23+
value: number;
2224
}
2325

2426
const dataFromApi: ormChartData = {
@@ -29,10 +31,10 @@ const dataFromApi: ormChartData = {
2931
"orm"
3032
],
3133
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]
3638
]
3739
}
3840

@@ -42,8 +44,8 @@ function reformatChartData(dataFromApi: ormChartData): DataPoint[] {
4244
const reformattedData = [];
4345
for (const dataPoint of dataFromApi.values){
4446
reformattedData.push({
45-
timestamp: dataPoint[0],
46-
orm: dataPoint[1]
47+
date: new Date(dataPoint[0]),
48+
value: dataPoint[1]
4749
});
4850
}
4951

@@ -52,48 +54,53 @@ function reformatChartData(dataFromApi: ormChartData): DataPoint[] {
5254

5355
export default function WorkoutView() {
5456
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+
}
5568

5669
return (
5770
<>
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>
7688
</>
7789
);
7890
}
7991

8092
const styles = StyleSheet.create({
93+
graph: {
94+
width: 300,
95+
height: 500,
96+
},
8197
container: {
8298
flex: 1,
8399
padding: 20,
84-
},
85-
scrollViewContent: {
86-
flexGrow: 1,
87-
alignItems: "center",
88-
justifyContent: "center",
100+
alignItems: "center"
89101
},
90102
title: {
91103
marginTop: 100,
92104
fontSize: 30
93105
},
94-
chartContainer: {
95-
height: 600, // Ensure the chart has a defined height
96-
width: '80%',
97-
padding: 10
98-
},
99106
});

workout-app/app/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Image, StyleSheet, Platform } from "react-native";
22
import { Link, Stack } from "expo-router";
33

44
import ParallaxScrollView from "@/components/ParallaxScrollView";
5-
import { ThemedText } from "@/components/ThemedText";
65
import Feed from "./Feed";
76

87
const workouts = [

0 commit comments

Comments
 (0)