import React, { Component } from 'react'; import PropTypes from 'prop-types'; import ms from 'ms'; import { ResponsiveContainer, AreaChart, XAxis, YAxis, CartesianGrid, Tooltip, Area, ReferenceLine, } from 'recharts'; import './Graph.css'; export default class Graph extends Component { static propTypes = { data: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)).isRequired, } state = { screenWidth: window.innerWidth, } componentDidMount() { window.addEventListener('resize', this.handleScreenChange); } componentWillUnmount() { window.removeEventListener('resize', this.handleScreenChange); } handleScreenChange = () => { this.setState({ screenWidth: window.innerWidth, }); } processData() { const { data } = this.props; return data.map(([timestamp, latency]) => ({ timestamp, latency, })).sort(({ timestamp: a }, { timestamp: b }) => a - b); } isSmallScreen() { return this.state.screenWidth < 500; } render() { return (
ms(Date.now() - tick)} tickLine={false} /> {this.isSmallScreen() ? null : `${tick}ms`} /> } `${value}ms`} label="DAB" separator=": " labelFormatter={() => null} />
); } }