import React from 'react'; import Loading from '../utils/Loading'; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts'; import './SensorInfo.scss'; 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 ( ); } 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; } render() { let sensor = this.props.sensor; let data = this.filterData(sensor.info); return (
{sensor.fetchedInfo ? : }
); } }