From 1d7982f5916d08f6756092bc44cc54c54b2c2969 Mon Sep 17 00:00:00 2001 From: jos Date: Mon, 9 Feb 2015 16:32:58 +0100 Subject: [PATCH] Fixed #401: width of range items not always being maintained when moving due to snapping to nice dates --- HISTORY.md | 2 ++ lib/timeline/component/ItemSet.js | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 2bee89bc..d9db9de3 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -21,6 +21,8 @@ http://visjs.org - Implemented option `timeAxis: {scale: string, step: number}` to set a fixed scale. +- Fixed width of range items not always being maintained when moving due to + snapping to nice dates. ## 2015-01-16, version 3.9.1 diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index 801f38a2..a5ed4408 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -1130,8 +1130,15 @@ ItemSet.prototype._onDragStart = function (event) { }; if (me.options.editable.updateTime) { - if ('start' in item.data) props.start = item.data.start.valueOf(); - if ('end' in item.data) props.end = item.data.end.valueOf(); + if ('start' in item.data) { + props.start = item.data.start.valueOf(); + + if ('end' in item.data) { + // we store a duration here in order not to change the width + // of the item when moving it. + props.duration = item.data.end.valueOf() - props.start; + } + } } if (me.options.editable.updateGroup) { if ('group' in item.data) props.group = item.data.group; @@ -1151,7 +1158,7 @@ ItemSet.prototype._onDragStart = function (event) { * @private */ ItemSet.prototype._onDrag = function (event) { - event.preventDefault() + event.preventDefault(); if (this.touchParams.itemProps) { var me = this; @@ -1174,6 +1181,9 @@ ItemSet.prototype._onDrag = function (event) { var end = new Date(props.end + offset); newProps.end = snap ? snap(end) : end; } + else if ('duration' in props) { + newProps.end = new Date(newProps.start.valueOf() + props.duration); + } if ('group' in props) { // drag from one group to another