Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Commit

Permalink
Week scale - enhance and add to auto-scaling (almende#3549)
Browse files Browse the repository at this point in the history
* Move majorLables to 1st week in the month, for 'week' scale

* next() always adds 1 week to current date
* show 1st week in the month as majorLabel

* Add 'week' to auto-scale

* Update week scale example

* Revert "Move majorLables to 1st week in the month, for 'week' scale"

This reverts commit 52df3c3.

* Correct value of week's minimumStep
  • Loading branch information
knokit authored and mojoaxel committed Jun 9, 2019
1 parent 6f5168a commit 22441cb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
29 changes: 26 additions & 3 deletions examples/timeline/styling/weekStyling.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@
of moment.js including locales.</p>
<p>To set a locale for the timeline, specify the option
<code>{locale: STRING}</code>.</p>
<p>To set the scale to use week numbers, use for example <code>{scale: 'week', step: 1}</code>.</p>
<p>
To set the scale to use week numbers, use the following options:
<code>
{
timeAxis: {
scale: 'week',
step: 1
},
format: {
minorLabels: {week: 'w'}
}
}
</code>
</p>

<p>The following timeline is initialized with the 'de' locale and items are added with locally localized moment.js
objects. The timeline locale can be switched to another locale at runtime. If you choose the 'en' locale, the week
numbers will be calculated according to the US week calendar numbering scheme.</p>
Expand Down Expand Up @@ -93,7 +107,16 @@
}

// Configuration for the Timeline
var options = {timeAxis: {scale: 'week', step: 1}, locale: 'de'};
var options = {
locale: 'de',
timeAxis: {
scale: 'week',
step: 1
},
format: {
minorLabels: {week: 'w'}
}
};

// Create a Timeline
var timeline = new vis.Timeline(container, items, groups, options);
Expand All @@ -108,4 +131,4 @@
select.onchange();
</script>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions lib/timeline/TimeStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TimeStep.FORMAT = {
hour: 'HH:mm',
weekday: 'ddd D',
day: 'D',
week: 'w',
week: 'D',
month: 'MMM',
year: 'YYYY'
},
Expand Down Expand Up @@ -340,7 +340,7 @@ TimeStep.prototype.setMinimumStep = function(minimumStep) {
if (stepYear > minimumStep) {this.scale = 'year'; this.step = 1;}
if (stepMonth*3 > minimumStep) {this.scale = 'month'; this.step = 3;}
if (stepMonth > minimumStep) {this.scale = 'month'; this.step = 1;}
if (stepDay*5 > minimumStep) {this.scale = 'day'; this.step = 5;}
if (stepDay*7 > minimumStep) {this.scale = 'week'; this.step = 1;}
if (stepDay*2 > minimumStep) {this.scale = 'day'; this.step = 2;}
if (stepDay > minimumStep) {this.scale = 'day'; this.step = 1;}
if (stepDay/2 > minimumStep) {this.scale = 'weekday'; this.step = 1;}
Expand Down

0 comments on commit 22441cb

Please sign in to comment.