Skip to content

Commit

Permalink
show less ticks in chart x-axes when viewing 15-31 data points
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Nov 23, 2018
1 parent f5cd87f commit cae987c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions assets/src/js/components/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ const

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

function padZero(s) {
return s < 10 ? "0" + s : s;
}

function timeFormatPicker(n, days) {
return function(d, i) {
if( days <= 1 ) {
Expand Down Expand Up @@ -58,7 +54,7 @@ class Chart extends Component {
return;
}

let daysDiff = Math.round((newProps.dateRange[1]-newProps.dateRange[0])/24/60/60);
let daysDiff = Math.round((newProps.dateRange[1]-newProps.dateRange[0])/1000/24/60/60);
let stepHours = daysDiff > 1 ? 24 : 1;
this.setState({
diffInDays: daysDiff,
Expand Down Expand Up @@ -187,6 +183,8 @@ class Chart extends Component {
// hide all "day" ticks if we're watching more than 31 items of data
if(data.length > 31) {
xAxis.tickValues(data.filter(d => d.Date.getDate() === 1).map(d => d.Date))
} else if(data.length > 15) {
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))
}

// empty previous graph
Expand Down

0 comments on commit cae987c

Please sign in to comment.