From 6f1dc4200d31cb57722b1fa38680352a05f57863 Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 5 Apr 2016 09:42:24 +0200 Subject: [PATCH] Fixed #1774: Wrong initial scale when Timeline contains a single item --- HISTORY.md | 1 + lib/timeline/Timeline.js | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 0af9696f..a3ef2044 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,7 @@ http://visjs.org ### Timeline - Fixed #1697: Timeline not drawn when used within the Angular.js directive. +- Fixed #1774: Wrong initial scale when Timeline contains a single item. ## 2016-03-08, version 4.15.1 diff --git a/lib/timeline/Timeline.js b/lib/timeline/Timeline.js index a69f58dd..ada7b422 100644 --- a/lib/timeline/Timeline.js +++ b/lib/timeline/Timeline.js @@ -135,7 +135,7 @@ function Timeline (container, items, groups, options) { } var start = me.options.start != undefined ? me.options.start : range.min; - var end = me.options.end != undefined ? me.options.end : range.max; + var end = me.options.end != undefined ? me.options.end : range.max; me.setWindow(start, end, {animation: false}); } @@ -373,8 +373,19 @@ Timeline.prototype.focus = function(id, options) { */ Timeline.prototype.fit = function (options) { var animation = (options && options.animation !== undefined) ? options.animation : true; - var range = this.getItemRange(); - this.range.setRange(range.min, range.max, animation); + var range; + + var dataset = this.itemsData && this.itemsData.getDataSet(); + if (dataset.length === 1 && dataset.get()[0].end === undefined) { + // a single item -> don't fit, just show a range around the item from -4 to +3 days + range = this.getDataRange(); + this.moveTo(range.min.valueOf(), {animation}); + } + else { + // exactly fit the items (plus a small margin) + range = this.getItemRange(); + this.range.setRange(range.min, range.max, animation); + } }; /**