prevent duplicate ticks on x axis

This commit is contained in:
Skip R. 2018-07-13 19:54:05 -07:00
parent b525404d9b
commit 8f744326b2
No known key found for this signature in database
GPG key ID: 1508C19D7436A26D

View file

@ -60,6 +60,8 @@ export default class Graph extends Component {
tickSize: 0, tickSize: 0,
}; };
const minutesAllocated = [];
return ( return (
<div className="graph-container"> <div className="graph-container">
<ResponsiveLine <ResponsiveLine
@ -76,10 +78,13 @@ export default class Graph extends Component {
format: (epoch) => { format: (epoch) => {
const interval = this.isSmallScreen() ? 7 : 5; const interval = this.isSmallScreen() ? 7 : 5;
const minutesAgo = Math.floor((Date.now() - epoch) / (1000 * 60)); const minutesAgo = Math.floor((Date.now() - epoch) / (1000 * 60));
if (minutesAgo % interval !== 0 || minutesAgo === 0) {
return undefined; if (minutesAgo % interval !== 0 || minutesAgo === 0
|| minutesAllocated.includes(minutesAgo)) {
return '';
} }
minutesAllocated.push(minutesAgo);
return ms(Date.now() - epoch); return ms(Date.now() - epoch);
}, },
tickSize: 0, tickSize: 0,