remove graph y axis on small devices

This commit is contained in:
slice 2018-07-13 19:36:42 -07:00
parent 3bddbaa15d
commit a3eeef15eb
No known key found for this signature in database
GPG Key ID: 1508C19D7436A26D
1 changed files with 30 additions and 10 deletions

View File

@ -6,6 +6,24 @@ import { ResponsiveLine } from '@nivo/line';
import './Graph.css';
export default class Graph extends Component {
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: unprocessedData } = this.props;
@ -24,28 +42,30 @@ export default class Graph extends Component {
}
isSmallScreen() {
return window.innerWidth < 500;
return this.state.screenWidth < 500;
}
render() {
const leftAxis = {
format: (d) => `${d}ms`,
tickCount: 3,
legend: 'latency',
legendPosition: 'center',
legendOffset: -55,
tickSize: 0,
};
return (
<div className="graph-container">
<ResponsiveLine
data={this.processData()}
margin={{ top: 30, left: 70, bottom: 50 }}
margin={{ top: 30, left: this.isSmallScreen() ? 0 : 70, bottom: 50 }}
maxY="auto"
curve="monotoneX"
tooltipFormat={(d) => `${d}ms`}
axisLeft={{
format: (d) => `${d}ms`,
tickCount: 3,
legend: 'latency',
legendPosition: 'center',
legendOffset: -55,
tickSize: 0,
}}
axisLeft={this.isSmallScreen() ? null : leftAxis}
axisBottom={{
format: (epoch) => {