From 36ff1f5b6435c6d1285983053efc8b633ff39638 Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 21 May 2014 11:03:13 +0200 Subject: [PATCH] Some tweaks in snapping dragged items to nice dates. --- HISTORY.md | 9 +++++++-- src/timeline/TimeStep.js | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index c427513b..e2e28c90 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,11 +2,16 @@ http://visjs.org -## 2014-05-09, version 1.0.2 +## not yet released, version 1.0.2 + +### Timeline + +- Some tweaks in snapping dragged items to nice dates. + ### Graph -- changes setOptions to avoid resetting view. +- Changes setOptions to avoid resetting view. ## 2014-05-09, version 1.0.1 diff --git a/src/timeline/TimeStep.js b/src/timeline/TimeStep.js index 958a3a5f..febe04fc 100644 --- a/src/timeline/TimeStep.js +++ b/src/timeline/TimeStep.js @@ -314,8 +314,7 @@ TimeStep.prototype.snap = function(date) { clone.setSeconds(0); clone.setMilliseconds(0); } - else if (this.scale == TimeStep.SCALE.DAY || - this.scale == TimeStep.SCALE.WEEKDAY) { + else if (this.scale == TimeStep.SCALE.DAY) { //noinspection FallthroughInSwitchStatementJS switch (this.step) { case 5: @@ -328,6 +327,19 @@ TimeStep.prototype.snap = function(date) { clone.setSeconds(0); clone.setMilliseconds(0); } + else if (this.scale == TimeStep.SCALE.WEEKDAY) { + //noinspection FallthroughInSwitchStatementJS + switch (this.step) { + case 5: + case 2: + clone.setHours(Math.round(clone.getHours() / 12) * 12); break; + default: + clone.setHours(Math.round(clone.getHours() / 6) * 6); break; + } + clone.setMinutes(0); + clone.setSeconds(0); + clone.setMilliseconds(0); + } else if (this.scale == TimeStep.SCALE.HOUR) { switch (this.step) { case 4: