From b04325eb87177ed61e21597f1d6ddb01140bcb2e Mon Sep 17 00:00:00 2001 From: Yaroslav Nechaev Date: Tue, 22 Apr 2014 18:52:48 +0400 Subject: [PATCH] Fixed setRange bug in Timeline --- src/timeline/Timeline.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/timeline/Timeline.js b/src/timeline/Timeline.js index 497bd54e..6209fcad 100644 --- a/src/timeline/Timeline.js +++ b/src/timeline/Timeline.js @@ -290,10 +290,23 @@ Timeline.prototype.setItems = function(items) { end = util.convert(this.options.end, 'Date'); } - // apply range if there is a min or max available - if (start != null || end != null) { - this.range.setRange(start, end); + // skip range set if there is no start and end date + if (start === null && end === null) { + return; } + + // if start and end dates are set but cannot be satisfyed due to zoom restrictions — correct end date + if (start != null && end != null) { + var diff = end.valueOf() - start.valueOf(); + if (this.options.zoomMax != undefined && this.options.zoomMax < diff) { + end = new Date(start.valueOf() + this.options.zoomMax); + } + if (this.options.zoomMin != undefined && this.options.zoomMin > diff) { + end = new Date(start.valueOf() + this.options.zoomMin); + } + } + + this.range.setRange(start, end); } };