import React from 'react'; import Loading from '../utils/Loading'; import _chartjs from 'chart.js'; import Chart from 'react-chartjs'; import { ChartOptions, DataTemplate } from './chartOptions'; import './SensorInfo.scss'; const LineChart = Chart.Line; export default class SensorInfo extends React.Component { componentWillMount() { let location = this.props.params.location; this.props.sensorActions.fetchUniqueDates(location); } componentWillUpdate(nextProps) { let currentLocation = this.props.params.location, nextLocation = nextProps.params.location; if (currentLocation !== nextLocation){ this.props.sensorActions.fetchUniqueDates(nextLocation); } } loadYearOptions = (date, index) => { return ( ); } loadMonthOptions = (date, index) => { return ( ); } 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 temp = JSON.parse(JSON.stringify(DataTemplate)); for (let d of data) { let label = `${d.month}/${d.day}`; temp.labels.push(label); temp.datasets[0].data.push(d.maxtemp); temp.datasets[1].data.push(d.mintemp); } return temp; } render() { let sensor = this.props.sensor; let data = this.filterData(sensor.info); return (
{sensor.fetchedUniqueDates ?

{this.props.params.location}

: } {sensor.fetchedUniqueDates && sensor.fetchedInfo ? : null}
); } }