Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. 'use strict';
  2.  
  3. import React, { Component } from 'react';
  4. import {
  5. StyleSheet,
  6. Text,
  7. ScrollView,
  8. TouchableWithoutFeedback,
  9. View,
  10. } from 'react-native';
  11. import {Container, Content, Input, List, Footer, FooterTab, Button, Icon} from 'native-base';
  12. import {Actions} from 'react-native-router-flux';
  13. var SearchBar = require('react-native-search-bar');
  14.  
  15.  
  16.  
  17. import AreaSpline from './js/charts/AreaSpline';
  18. import Pie from './js/charts/Pie';
  19. import Theme from './js/theme';
  20. import data from './resources/data';
  21.  
  22. type State = {
  23. activeIndex: number,
  24. wagePerYear: any
  25. }
  26.  
  27. var colors = [
  28. "#1f77b4", "#ff7f0e", "#2ca02c"//, "#d62728", "#9467bd",
  29. // "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"
  30. ]
  31.  
  32. export default class StatsPage extends Component {
  33.  
  34. state: State;
  35.  
  36. constructor(props) {
  37. super(props);
  38. this.state = {
  39. activeIndex: 0,
  40. wagePerYear: data.wagePerYear,
  41. percent: data.certif[0].number,
  42. name: data.certif[0].name,
  43. curColor: colors[0],
  44. initialWage: data.certif[0].initialWage,
  45. currentWage: data.certif[0].currentWage
  46. };
  47. this._onPieItemSelected = this._onPieItemSelected.bind(this);
  48. this._shuffle = this._shuffle.bind(this);
  49.  
  50. }
  51.  
  52. _onPieItemSelected(newIndex){
  53. this.setState({...this.state, activeIndex: newIndex, wagePerYear: this._shuffle(data.wagePerYear), percent: data.certif[newIndex].number, name: data.certif[newIndex].name, curColor: colors[newIndex], initialWage: data.certif[newIndex].initialWage, currentWage: data.certif[newIndex].currentWage});
  54.  
  55. }
  56.  
  57. _shuffle(a) {
  58. for (let i = a.length; i; i--) {
  59. let j = Math.floor(Math.random() * i);
  60. [a[i - 1], a[j]] = [a[j], a[i - 1]];
  61. }
  62. return a;
  63. }
  64.  
  65. renderFooter(){
  66. return (
  67. <Footer style={{backgroundColor:"#09507C"}}>
  68. <FooterTab>
  69. <Button transparent onPress={()=> Actions.FeedPage()} >
  70. <Icon name="ios-home" style={{color:"gray"}} />
  71. </Button>
  72. <Button transparent onPress={() => Actions.StatsPage()}>
  73. <Icon name='ios-stats' style={{color:"gray"}}/>
  74. </Button>
  75. <Button transparent>
  76. <Icon name='ios-chatboxes' style={{color:"gray"}}/>
  77. </Button>
  78. <Button transparent onPress={() => Actions.PeopleList()}>
  79. <Icon name='ios-return-right'/>
  80. </Button>
  81. </FooterTab>
  82. </Footer>
  83. );
  84. }
  85.  
  86. renderPercentage(){
  87. return (
  88. <View style={{marginLeft: 30, marginRight: 20}}>
  89. <Text><Text style={{fontSize: 35, color: this.state.curColor}}>{this.state.percent}%</Text> of all graduates </Text>
  90. <Text style={{marginLeft: 40}}> have a <Text style={{fontSize: 30, color: this.state.curColor}}>{this.state.name}</Text> certificate</Text>
  91. <Text style={{marginLeft: 10}}> Average Starting Wage is <Text style={{fontSize: 30, color: this.state.curColor}}>{this.state.initialWage}</Text> </Text>
  92. <Text style={{marginLeft: 40}}> Average Wage is <Text style={{fontSize: 30, color: this.state.curColor}}>{this.state.currentWage}</Text> </Text>
  93.  
  94. </View>
  95. );
  96.  
  97. }
  98.  
  99. render() {
  100. const height = 200;
  101. const width = 500;
  102.  
  103. return (
  104. <Container style={{backgroundColor:"#DEEDF2"}}>
  105. <Content>
  106. <View style={{height: 70, backgroundColor:"#09507C"}}>
  107. <View style={{marginTop:20, marginLeft:30, marginRight:30}}>
  108. <SearchBar
  109. ref='searchBar'
  110. placeholder='Search'
  111. hideBackground={true}
  112. textFieldBackgroundColor="#DEEDF2"
  113. />
  114. </View>
  115. </View>
  116. <ScrollView>
  117. <View style={{backgroundColor:'#DEEDF2',marginTop: 21}} >
  118. <View style={{ marginLeft: 15, marginRight: 15}}>
  119. <Text style={styles.chart_title}>Distribution of Certificates</Text>
  120. </View>
  121. <Pie
  122. pieWidth={150}
  123. pieHeight={150}
  124. onItemSelected={this._onPieItemSelected}
  125. colors={Theme.colors}
  126. width={width}
  127. height={height}
  128. data={data.certif}
  129. style={{top: 30}}/>
  130. <View style={{borderColor:"white", borderTopWidth: 3, borderBottomWidth: 3, paddingTop: 20, paddingBottom: 20}}>
  131. {this.renderPercentage()}
  132. </View>
  133. <View>
  134. <Text style={{ marginTop: 10, marginLeft: 30, marginRight: 30, paddingTop: 15,textAlign: 'center',paddingBottom: 5,paddingLeft: 5,
  135. fontSize: 15, backgroundColor:'#DEEDF2',color: 'grey', fontWeight:'bold',}}>Percentage of Graduates Graduated With {this.state.name} Over Time</Text>
  136. </View>
  137. <AreaSpline
  138. width={width}
  139. height={height}
  140. data={this.state.wagePerYear}
  141. color={Theme.colors[this.state.activeIndex]} />
  142. </View>
  143. </ScrollView>
  144. </Content>
  145. {this.renderFooter()}
  146. </Container>
  147.  
  148.  
  149. );
  150. }
  151. }
  152.  
  153. const styles = {
  154. chart_title : {
  155. paddingTop: 15,
  156. textAlign: 'center',
  157. paddingBottom: 5,
  158. paddingLeft: 5,
  159. fontSize: 18,
  160. backgroundColor:'#DEEDF2',
  161. color: 'grey',
  162. fontWeight:'bold',
  163. }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement