1+ import {
2+ LineChart ,
3+ PieChart
4+ } from "react-native-chart-kit" ;
5+ import { StyleSheet , TouchableOpacity , Text } from 'react-native' ;
6+
7+ // Dummy pie chart data
8+ const data = [
9+ {
10+ name : "Bus" ,
11+ emissions : 20 ,
12+ color : "#e0ac2b" ,
13+ legendFontColor : "#7F7F7F" ,
14+ legendFontSize : 15
15+ } ,
16+ {
17+ name : "Luas" ,
18+ emissions : 34 ,
19+ color : "#e85252" ,
20+ legendFontColor : "#7F7F7F" ,
21+ legendFontSize : 15
22+ } ,
23+ {
24+ name : "Train" ,
25+ emissions : 28 ,
26+ color : "#6689c6" ,
27+ legendFontColor : "#7F7F7F" ,
28+ legendFontSize : 15
29+ } ,
30+ {
31+ name : "Walk" ,
32+ emissions : 45 ,
33+ color : "#9a6fb0" ,
34+ legendFontColor : "#7F7F7F" ,
35+ legendFontSize : 15
36+ } ,
37+ {
38+ name : "Cycle" ,
39+ emissions : 75 ,
40+ color : "#a53253" ,
41+ legendFontColor : "#7F7F7F" ,
42+ legendFontSize : 15
43+ }
44+ ] ;
45+
46+ // Dummy line chart data - year
47+ const yearData_lineGraph = {
48+ labels : [ "January" , "February" , "March" , "April" , "May" , "June" ] ,
49+ datasets : [
50+ {
51+ data : [ 455 , 896 , 231 , 473 , 147 , 369 ] ,
52+ color : ( opacity = 1 ) => `rgba(7, 32, 114, ${ opacity } )` ,
53+ strokeWidth : 2
54+ }
55+ ] ,
56+ legend : [ "Rainy Days" ] ,
57+ } ;
58+
59+ // Dummy line chart data - month
60+ const monthData_lineGraph = {
61+ labels : [ "Week 1" , "Week 2" , "Week 3" , "Week 4" ] ,
62+ datasets : [
63+ {
64+ data : [ 20 , 45 , 28 , 80 ] ,
65+ color : ( opacity = 1 ) => `rgba(7, 32, 114, ${ opacity } )` ,
66+ strokeWidth : 2
67+ }
68+ ] ,
69+ legend : [ "Rainy Days" ] ,
70+ } ;
71+
72+ // chart configuration (for chart kit)
73+ const chartConfig = {
74+ backgroundGradientFrom : "#1E2923" ,
75+ backgroundGradientFromOpacity : 0 ,
76+ backgroundGradientTo : "#08130D" ,
77+ backgroundGradientToOpacity : 0 ,
78+ color : ( opacity = 1 ) => `rgba(91, 87, 89, ${ opacity } )` ,
79+ strokeWidth : 2 ,
80+ useShadowColorFromDataset : false
81+ } ;
82+
83+ export default function Dashboard ( { navigation } ) {
84+ // this needs to be updated reactively, perhaps using usestate
85+ let lineGraphData = yearData_lineGraph ;
86+
87+ const switchTimeframe = ( time_frame ) => {
88+
89+ if ( time_frame == 'm' ) {
90+ lineGraphData = monthData_lineGraph ;
91+ }
92+ else if ( time_frame == 'y' ) {
93+ lineGraphData = yearData_lineGraph ;
94+ }
95+ } ;
96+
97+ return (
98+ < >
99+ < PieChart
100+ data = { data }
101+ width = { 370 }
102+ height = { 240 }
103+ chartConfig = { chartConfig }
104+ accessor = { "emissions" }
105+ backgroundColor = { "transparent" }
106+ paddingLeft = { "15" }
107+ center = { [ 10 , 0 ] }
108+ absolute
109+ />
110+ < LineChart
111+ style = { styles . lineChart }
112+ data = { lineGraphData }
113+ width = { 370 }
114+ height = { 220 }
115+ chartConfig = { chartConfig }
116+ />
117+ < TouchableOpacity style = { styles . monthButton } onPress = { switchTimeframe ( 'm' ) } >
118+ < Text style = { styles . buttonText } > Month</ Text >
119+ </ TouchableOpacity >
120+ < TouchableOpacity style = { styles . yearButton } onPress = { switchTimeframe ( 'y' ) } >
121+ < Text style = { styles . buttonText } > Year</ Text >
122+ </ TouchableOpacity >
123+ </ >
124+ )
125+ }
126+
127+ const styles = StyleSheet . create ( {
128+ lineChart : {
129+ position : 'absolute' ,
130+ bottom : 40 ,
131+ right : '0%' ,
132+ paddingVertical : 10 ,
133+ paddingHorizontal : 20 ,
134+ borderRadius : 10 ,
135+ } ,
136+ monthButton : {
137+ position : 'absolute' ,
138+ bottom : 15 ,
139+ left : '80%' ,
140+ transform : [ { translateX : - 50 } ] ,
141+ backgroundColor : '#007bff' ,
142+ paddingVertical : 10 ,
143+ paddingHorizontal : 20 ,
144+ borderRadius : 10 ,
145+ } ,
146+ yearButton : {
147+ position : 'absolute' ,
148+ bottom : 15 ,
149+ left : '20%' ,
150+ transform : [ { translateX : - 50 } ] ,
151+ backgroundColor : '#007bff' ,
152+ paddingVertical : 10 ,
153+ paddingHorizontal : 20 ,
154+ borderRadius : 10 ,
155+ }
156+ } )
0 commit comments