remove graph y axis on small devices
This commit is contained in:
parent
3bddbaa15d
commit
a3eeef15eb
1 changed files with 30 additions and 10 deletions
|
@ -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) => {
|
||||
|
|
Loading…
Reference in a new issue