-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathApp.js
92 lines (81 loc) · 2.11 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// @flow
'use strict';
import React, { Component } from 'react';
import {
StyleSheet,
Text,
ScrollView,
TouchableWithoutFeedback,
View,
} from 'react-native';
import AreaSpline from './js/charts/AreaSpline';
import Pie from './js/charts/Pie';
import Theme from './js/theme';
import data from './resources/data';
type State = {
activeIndex: number,
spendingsPerYear: any
}
export default class App extends Component {
state: State;
constructor(props) {
super(props);
this.state = {
activeIndex: 0,
spendingsPerYear: data.spendingsPerYear,
};
this._onPieItemSelected = this._onPieItemSelected.bind(this);
this._shuffle = this._shuffle.bind(this);
}
_onPieItemSelected(newIndex){
this.setState({...this.state, activeIndex: newIndex, spendingsPerYear: this._shuffle(data.spendingsPerYear)});
}
_shuffle(a) {
for (let i = a.length; i; i--) {
let j = Math.floor(Math.random() * i);
[a[i - 1], a[j]] = [a[j], a[i - 1]];
}
return a;
}
render() {
const height = 200;
const width = 500;
return (
<ScrollView>
<View style={styles.container} >
<Text style={styles.chart_title}>Distribution of spending this month</Text>
<Pie
pieWidth={150}
pieHeight={150}
onItemSelected={this._onPieItemSelected}
colors={Theme.colors}
width={width}
height={height}
data={data.spendingsLastMonth} />
<Text style={styles.chart_title}>Spending per year in {data.spendingsLastMonth[this.state.activeIndex].name}</Text>
<AreaSpline
width={width}
height={height}
data={this.state.spendingsPerYear}
color={Theme.colors[this.state.activeIndex]} />
</View>
</ScrollView>
);
}
}
const styles = {
container: {
backgroundColor:'whitesmoke',
marginTop: 21,
},
chart_title : {
paddingTop: 15,
textAlign: 'center',
paddingBottom: 5,
paddingLeft: 5,
fontSize: 18,
backgroundColor:'white',
color: 'grey',
fontWeight:'bold',
}
}