Skip to content

Commit cae987c

Browse files
show less ticks in chart x-axes when viewing 15-31 data points
1 parent f5cd87f commit cae987c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

assets/src/js/components/Chart.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ const
1717

1818
const t = d3.transition().duration(600).ease(d3.easeQuadOut);
1919

20-
function padZero(s) {
21-
return s < 10 ? "0" + s : s;
22-
}
23-
2420
function timeFormatPicker(n, days) {
2521
return function(d, i) {
2622
if( days <= 1 ) {
@@ -58,7 +54,7 @@ class Chart extends Component {
5854
return;
5955
}
6056

61-
let daysDiff = Math.round((newProps.dateRange[1]-newProps.dateRange[0])/24/60/60);
57+
let daysDiff = Math.round((newProps.dateRange[1]-newProps.dateRange[0])/1000/24/60/60);
6258
let stepHours = daysDiff > 1 ? 24 : 1;
6359
this.setState({
6460
diffInDays: daysDiff,
@@ -187,6 +183,8 @@ class Chart extends Component {
187183
// hide all "day" ticks if we're watching more than 31 items of data
188184
if(data.length > 31) {
189185
xAxis.tickValues(data.filter(d => d.Date.getDate() === 1).map(d => d.Date))
186+
} else if(data.length > 15) {
187+
xAxis.tickValues(data.filter((d, i) => d.Date.getDate() === 1 || i === 0 || i == Math.floor((data.length-1)/2)|| i === data.length-1).map(d => d.Date))
190188
}
191189

192190
// empty previous graph

0 commit comments

Comments
 (0)