diff --git a/client/assets/scss/Content.scss b/client/assets/scss/Content.scss
index 9c41fdf..fa8132f 100644
--- a/client/assets/scss/Content.scss
+++ b/client/assets/scss/Content.scss
@@ -2,6 +2,7 @@
flex: 1;
flex-wrap: wrap;
min-width: 0;
+ min-height: 500px;
.post+ .post {
margin-top: 2em;
}
diff --git a/client/js/components/sensors/SensorInfo.js b/client/js/components/sensors/SensorInfo.js
index 84b46e3..2f8663e 100644
--- a/client/js/components/sensors/SensorInfo.js
+++ b/client/js/components/sensors/SensorInfo.js
@@ -1,52 +1,110 @@
import React from 'react';
+import Loading from '../utils/Loading';
+import {
+ LineChart,
+ Line,
+ XAxis,
+ YAxis,
+ CartesianGrid,
+ Tooltip,
+ Legend
+}
+from 'recharts';
-let location, sensor, actions, uniqueDates, fetchedAll;
+import './SensorInfo.scss';
-export default class SensorInfo extends React.Component{
-
- componentDidMount(){
- location = this.props.params.location;
+export default class SensorInfo extends React.Component {
+
+ componentDidMount() {
+ let location = this.props.params.location;
this.props.sensorActions.fetchUniqueDates(location);
}
-
+
loadYearOptions = (date, index) => {
return (
);
}
-
+
loadMonthOptions = (date, index) => {
return (
);
}
-
- onYearChange(event){
- this.props.sensorActions.setSelectedYearIndex(parseInt(event.target.value));
+
+ onChange(event, type) {
+ let location = this.props.params.location,
+ sensor = this.props.sensor,
+ actions = this.props.sensorActions,
+ yearIndex = sensor.selectedYearIndex,
+ monthIndex = sensor.selectedMonthIndex;
+
+ if (type === 'year') {
+ yearIndex = parseInt(event.target.value);
+ monthIndex = 0;
+ }
+ else if (type === 'month') {
+ monthIndex = parseInt(event.target.value);
+ }
+
+ let year = sensor.uniqueDates[yearIndex].year;
+ let monthname = sensor.uniqueDates[yearIndex].months[monthIndex].monthname;
+
+ actions.setSelectedMonthIndex(monthIndex);
+ actions.setSelectedYearIndex(yearIndex);
+ this.props.sensorActions.fetchSensorInfoMonth(location, year, monthname);
+ }
+
+ filterData(data) {
+ let filteredData = [];
+
+ for (let d of data) {
+ filteredData.push({
+ name: d.day,
+ max: d.maxtemp,
+ min: d.mintemp
+ });
+ }
+
+ return filteredData;
}
- onMonthChange(event){
- this.props.sensorActions.setSelectedMonthIndex(parseInt(event.target.value));
- }
-
- render(){
- sensor = this.props.sensor;
- return(
-
-
-
-
+ render() {
+ let sensor = this.props.sensor;
+ let data = this.filterData(sensor.info);
+
+ return (
+
+
+
+
+
+
+
+ {sensor.fetchedInfo ?
+
+
+
+
+
+
+
+
+
+ : }
+
- );
+ );
}
}
\ No newline at end of file
diff --git a/client/js/components/sensors/SensorInfo.scss b/client/js/components/sensors/SensorInfo.scss
new file mode 100644
index 0000000..6b3016c
--- /dev/null
+++ b/client/js/components/sensors/SensorInfo.scss
@@ -0,0 +1,15 @@
+.SensorInfo{
+ flex: 1;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+
+ .selector-row{
+ display: flex;
+ justify-content: center;
+ }
+
+ .recharts-wrapper{
+ flex: 1;
+ }
+}
\ No newline at end of file
diff --git a/client/js/redux/actions/sensor.js b/client/js/redux/actions/sensor.js
index 3394c55..cd2f74d 100644
--- a/client/js/redux/actions/sensor.js
+++ b/client/js/redux/actions/sensor.js
@@ -8,16 +8,9 @@ function loadSensorList(sensor_list){
}
}
-function loadSensorInfoYear(sensor_info){
+function loadSensorInfo(sensor_info){
return{
- type: types.LOAD_SENSOR_INFO_YEAR,
- sensor_info
- }
-}
-
-function loadSensorInfoMonth(sensor_info){
- return{
- type: types.LOAD_SENSOR_INFO_MONTH,
+ type: types.LOAD_SENSOR_INFO,
sensor_info
}
}
@@ -49,15 +42,9 @@ function fetchingList(){
}
}
-function fetchingInfoYear(){
+function fetchingInfo(){
return {
- type: types.FETCHING_INFO_YEAR
- }
-}
-
-function fetchingInfoMonth(){
- return {
- type: types.FETCHING_INFO_MONTH
+ type: types.FETCHING_INFO
}
}
@@ -83,11 +70,11 @@ export function fetchSensorList(){
export function fetchSensorInfoYear(location, year){
return (dispatch) => {
- dispatch(fetchingInfoYear());
+ dispatch(fetchingInfo());
return fetch(`/api/sensor/${location}/${year}`)
.then(response => response.json())
.then(json => {
- dispatch(loadSensorInfoYear(json));
+ dispatch(loadSensorInfo(json));
})
.catch(error => {
console.log(error);
@@ -97,11 +84,11 @@ export function fetchSensorInfoYear(location, year){
export function fetchSensorInfoMonth(location, year, month){
return (dispatch) => {
- dispatch(fetchingInfoMonth());
+ dispatch(fetchingInfo());
return fetch(`/api/sensor/${location}/${year}/${month}`)
.then(response => response.json())
.then(json => {
- dispatch(loadSensorInfoMonth(json));
+ dispatch(loadSensorInfo(json));
})
.catch(error => {
console.log(error);
@@ -119,7 +106,6 @@ export function fetchUniqueDates(location){
if(json.length > 0){
let year = json[0].year;
let month = json[0].months[0].monthname;
- dispatch(fetchSensorInfoYear(location, year));
dispatch(fetchSensorInfoMonth(location, year, month));
}
})
diff --git a/client/js/redux/constants/sensor.js b/client/js/redux/constants/sensor.js
index a277743..a23112b 100644
--- a/client/js/redux/constants/sensor.js
+++ b/client/js/redux/constants/sensor.js
@@ -1,13 +1,11 @@
//constants
export const LOAD_SENSOR_LIST = 'LOAD_SENSOR_LIST';
-export const LOAD_SENSOR_INFO_YEAR = 'LOAD_SENSOR_INFO_YEAR';
-export const LOAD_SENSOR_INFO_MONTH = 'LOAD_SENSOR_INFO_MONTH';
+export const LOAD_SENSOR_INFO = 'LOAD_SENSOR_INFO';
export const LOAD_UNIQUE_DATES = 'LOAD_UNIQUE_DATES';
//fetching
export const FETCHING_LIST = 'FETCHING_LIST';
-export const FETCHING_INFO_YEAR = 'FETCHING_INFO_YEAR';
-export const FETCHING_INFO_MONTH = 'FETCHING_INFO_MONTH';
+export const FETCHING_INFO = 'FETCHING_INFO_YEAR';
export const FETCHING_UNIQUE_DATES = 'FETCHING_UNIQUE_DATES';
//indexes
diff --git a/client/js/redux/reducers/sensor.js b/client/js/redux/reducers/sensor.js
index 5d74606..7fbfaa2 100644
--- a/client/js/redux/reducers/sensor.js
+++ b/client/js/redux/reducers/sensor.js
@@ -4,21 +4,18 @@ import * as types from '../constants/sensor';
//defaults -
const defaultState = {
list : [],
- infoMonth: [],
- infoYear: [],
+ info: [],
uniqueDates: {},
selectedYearIndex: 0,
selectedMonthIndex: 0,
fetchingList: false,
- fetchingInfoMonth: false,
- fetchingInfoYear: false,
+ fetchingInfo: false,
fetchingUniqueDates: false,
fetchedList: false,
- fetchedInfoMonth: false,
- fetchedInfoYear: false,
+ fetchedInfo: false,
fetchedUniqueDates: false
};
@@ -31,15 +28,10 @@ export default function app(state = defaultState, action) {
fetchingList: true,
fetchedList: false
});
- case types.FETCHING_INFO_MONTH:
+ case types.FETCHING_INFO:
return Object.assign({}, state, {
- fetchingInfoMonth: true,
- fetchedInfoMonth: false
- });
- case types.FETCHING_INFO_YEAR:
- return Object.assign({}, state, {
- fetchingInfoYear: true,
- fetchedInfoYear: false
+ fetchingInfo: true,
+ fetchedInfo: false
});
case types:FETCHING_UNIQUE_DATES:
return Object.assign({}, state, {
@@ -54,17 +46,11 @@ export default function app(state = defaultState, action) {
fetchingList: false,
fetchedList: true
});
- case types.LOAD_SENSOR_INFO_MONTH:
+ case types.LOAD_SENSOR_INFO:
return Object.assign({}, state, {
- infoMonth: action.sensor_info,
- fetchingInfoMonth: false,
- fetchedInfoMonth: true
- });
- case types.LOAD_SENSOR_INFO_YEAR:
- return Object.assign({}, state, {
- infoYear: action.sensor_info,
- fetchingInfoYear: false,
- fetchedInfoYear: true
+ info: action.sensor_info,
+ fetchingInfo: false,
+ fetchedInfo: true
});
case types.LOAD_UNIQUE_DATES:
return Object.assign({}, state, {
diff --git a/package.json b/package.json
index 96412e7..ef7fd3b 100644
--- a/package.json
+++ b/package.json
@@ -48,10 +48,12 @@
"node-sass": "^3.8.0",
"postcss-loader": "^0.13.0",
"react": "^15.3.0",
+ "react-addons-transition-group": "^15.3.1",
"react-dom": "^15.3.0",
"react-redux": "^4.4.5",
"react-router": "^2.6.1",
"react-router-redux": "^4.0.5",
+ "recharts": "^0.14.1",
"redux": "^3.5.2",
"redux-logger": "^2.6.1",
"redux-thunk": "^2.1.0",