@@ -12,17 +12,62 @@ const chartColors: ChartProps['colors'] = {
1212 border : '#555' ,
1313 cursorStroke : '#0ff' ,
1414 highlightLabel : '#000' ,
15- highlightTime : '#ff0' ,
15+ highlightTime : '#444' ,
16+ } ;
17+
18+ // Generate data points every minute from a month ago to now
19+ const generateDataPoints = ( {
20+ startingValue = 400 ,
21+ minimum = 0 ,
22+ radomFactor = 20 ,
23+ } = { } ) => {
24+ const points = [ ] ;
25+ const now = Date . now ( ) ;
26+ const monthAgo = now - 30 * 24 * 60 * 60 * 1000 ; // 30 days ago
27+ let value = startingValue ;
28+
29+ for ( let timestamp = monthAgo ; timestamp <= now ; timestamp += 60 * 1000 ) {
30+ const randomVariation = ( Math . random ( ) - 0.5 ) * radomFactor ;
31+ value += randomVariation ;
32+
33+ // randomVariation was negative and value went below minimum
34+ if ( value < minimum ) {
35+ // invert direction to keep above minimum
36+ value -= 2 * randomVariation ;
37+ }
38+
39+ points . push ( { timestamp, value } ) ;
40+ }
41+
42+ return points ;
1643} ;
1744
1845const datasets : Dataset [ ] = [
1946 {
20- unit : 'units ' ,
21- points : [ ] ,
47+ unit : 'kg ' ,
48+ points : generateDataPoints ( ) ,
2249 decimals : 0 ,
2350 color : '#e66' ,
2451 measurementName : 'Red' ,
2552 } ,
53+ {
54+ unit : 'cm' ,
55+ points : generateDataPoints ( {
56+ startingValue : 160 ,
57+ minimum : 50 ,
58+ radomFactor : 6 ,
59+ } ) ,
60+ decimals : 0 ,
61+ color : '#66e' ,
62+ measurementName : 'Blue' ,
63+ } ,
64+ {
65+ unit : 'kg' ,
66+ points : generateDataPoints ( ) ,
67+ decimals : 0 ,
68+ color : '#6e6' ,
69+ measurementName : 'Green' ,
70+ } ,
2671] ;
2772
2873export default function App ( ) {
@@ -56,23 +101,23 @@ export default function App() {
56101 onLayout = { ( e ) => setWidth ( e . nativeEvent . layout . width ) }
57102 >
58103 < Chart
104+ zoomEnabled
59105 width = { width }
60106 height = { height }
61107 datasets = { datasets }
62108 colors = { chartColors }
63109 timeDomain = { timeDomain }
64110 marginHorizontal = { PADDING }
111+ noDataString = "No data available"
65112 />
66- < View style = { { height : 10 } } />
113+ < View style = { styles . spacer } />
67114 < View style = { styles . timeDomainRow } >
68115 { TIME_DOMAIN_TYPES . map ( ( type ) => (
69116 < TouchableOpacity
70117 key = { type }
71118 style = { [
72119 styles . timeDomainItem ,
73- type === timeDomainType && {
74- backgroundColor : '#f0f' ,
75- } ,
120+ type === timeDomainType && styles . timeDomainItemActive ,
76121 ] }
77122 onPress = { ( ) => setTimeDomainType ( type ) }
78123 >
@@ -98,6 +143,9 @@ const styles = StyleSheet.create({
98143 paddingVertical : PADDING ,
99144 backgroundColor : '#fff' ,
100145 } ,
146+ spacer : {
147+ height : 10 ,
148+ } ,
101149 timeDomainRow : {
102150 flexDirection : 'row' ,
103151 paddingHorizontal : PADDING ,
@@ -109,6 +157,9 @@ const styles = StyleSheet.create({
109157 justifyContent : 'center' ,
110158 alignItems : 'center' ,
111159 } ,
160+ timeDomainItemActive : {
161+ backgroundColor : '#b22' ,
162+ } ,
112163 timeDomainItemText : {
113164 fontSize : 13 ,
114165 } ,
0 commit comments