From cf48b7d7ca42855143b8dd11ce63eae277fa6ef8 Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 27 May 2014 16:05:10 +0200 Subject: [PATCH] Fixed #86: A newly created item is now initialized with `end` property when option `type` is `"range"` or `"rangeoverflow"`. --- HISTORY.md | 2 ++ docs/timeline.html | 2 +- src/timeline/Timeline.js | 5 +++++ test/timeline.html | 6 ++++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index d0a740df..27e3b347 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,8 @@ http://visjs.org - Added function `repaint()` to force a repaint of the Timeline. - Some tweaks in snapping dragged items to nice dates. - Made the instance of moment.js packaged with vis.js accessibly via `vis.moment`. +- A newly created item is initialized with `end` property when option `type` + is `"range"` or `"rangeoverflow"`. - Fixed a bug in replacing the DataSet of groups via `Timeline.setGroups(groups)`. - Fixed a bug when rendering the Timeline inside a hidden container. diff --git a/docs/timeline.html b/docs/timeline.html index 6f6f83eb..d10d5d44 100644 --- a/docs/timeline.html +++ b/docs/timeline.html @@ -588,7 +588,7 @@ var options = { type String 'box' - Specifies the type for the timeline items. Choose from 'box', 'point', 'range', and 'rangeoverflow'. Note that individual items can override this global type. + Specifies the default type for the timeline items. Choose from 'box', 'point', 'range', and 'rangeoverflow'. Note that individual items can override this default type. diff --git a/src/timeline/Timeline.js b/src/timeline/Timeline.js index 4d7316c7..51ca57e7 100644 --- a/src/timeline/Timeline.js +++ b/src/timeline/Timeline.js @@ -634,6 +634,11 @@ Timeline.prototype._onAddItem = function (event) { content: 'new item' }; + // when default type is a range, add a default end date to the new item + if (this.options.type === 'range' || this.options.type == 'rangeoverflow') { + newItem.end = this.timeAxis.snap(this._toTime(x + this.rootPanel.width / 5)); + } + var id = util.randomUUID(); newItem[this.itemsData.fieldId] = id; diff --git a/test/timeline.html b/test/timeline.html index a862a6a3..83e49b32 100644 --- a/test/timeline.html +++ b/test/timeline.html @@ -69,9 +69,11 @@ {_id: 1, content: 'item 1
start', start: now.clone().add('days', 4).toDate()}, {_id: 2, content: 'item 2', start: now.clone().add('days', -2).toDate() }, {_id: 3, content: 'item 3', start: now.clone().add('days', 2).toDate()}, - {_id: 4, content: 'item 4', + { + _id: 4, content: 'item 4', start: now.clone().add('days', 0).toDate(), - end: now.clone().add('days', 7).toDate()}, + end: now.clone().add('days', 7).toDate() + }, {_id: 5, content: 'item 5', start: now.clone().add('days', 9).toDate(), type:'point'}, {_id: 6, content: 'item 6', start: now.clone().add('days', 11).toDate()} ]);