Skip to content

Commit

Permalink
Move majorLables to 1st week in the month, for 'week' scale
Browse files Browse the repository at this point in the history
* next() always adds 1 week to current date
* show 1st week in the month as majorLabel
  • Loading branch information
knokit committed Oct 13, 2017
1 parent c56fa19 commit 52df3c3
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions lib/timeline/TimeStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,7 @@ TimeStep.prototype.next = function() {
break;
case 'weekday': // intentional fall through
case 'day': this.current.add(this.step, 'day'); break;
case 'week':
if (this.current.weekday() !== 0){ // we had a month break not correlating with a week's start before
this.current.weekday(0); // switch back to week cycles
this.current.add(this.step, 'week');
} else if(this.options.showMajorLabels === false) {
this.current.add(this.step, 'week'); // the default case
} else { // first day of the week
var nextWeek = this.current.clone();
nextWeek.add(1, 'week');
if(nextWeek.isSame(this.current, 'month')){ // is the first day of the next week in the same month?
this.current.add(this.step, 'week'); // the default case
} else { // inject a step at each first day of the month
this.current.add(this.step, 'week');
this.current.date(1);
}
}
break;
case 'week': this.current.add(this.step, 'week'); break;
case 'month': this.current.add(this.step, 'month'); break;
case 'year': this.current.add(this.step, 'year'); break;
default: break;
Expand Down Expand Up @@ -548,7 +532,7 @@ TimeStep.prototype.isMajor = function() {
case 'day':
return (date.date() == 1);
case 'week':
return (date.date() == 1);
return (Math.ceil(date.date() / 7) == 1); // is 1st week in the month?
case 'month':
return (date.month() == 0);
case 'year':
Expand Down

0 comments on commit 52df3c3

Please sign in to comment.