From e7ec9a669a5989405c439cce64532c5e7fe25adc Mon Sep 17 00:00:00 2001 From: jos Date: Mon, 25 Aug 2014 14:53:41 +0200 Subject: [PATCH] A fix in applying fit on initialization of the Timeline --- lib/timeline/Range.js | 6 +++--- lib/timeline/Timeline.js | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/timeline/Range.js b/lib/timeline/Range.js index a658aec6..a9924b7e 100644 --- a/lib/timeline/Range.js +++ b/lib/timeline/Range.js @@ -128,13 +128,13 @@ Range.prototype.setRange = function(start, end, animate) { var now = new Date().valueOf(); var time = now - initTime; var done = time > duration; - var s = done ? start : util.easeInOutQuad(time, initStart, _start, duration); - var e = done ? end : util.easeInOutQuad(time, initEnd, _end, duration); + var s = (done || _start === null) ? _start : util.easeInOutQuad(time, initStart, _start, duration); + var e = (done || _end === null) ? _end : util.easeInOutQuad(time, initEnd, _end, duration); changed = me._applyRange(s, e); anyChanged = anyChanged || changed; if (changed) { - me.body.emitter.emit('rangechange', {start: new Date(s), end: new Date(e)}); + me.body.emitter.emit('rangechange', {start: new Date(me.start), end: new Date(me.end)}); } if (done) { diff --git a/lib/timeline/Timeline.js b/lib/timeline/Timeline.js index c688bfaf..cd6f1fd5 100644 --- a/lib/timeline/Timeline.js +++ b/lib/timeline/Timeline.js @@ -132,14 +132,16 @@ Timeline.prototype.setItems = function(items) { // set items this.itemsData = newDataSet; this.itemSet && this.itemSet.setItems(newDataSet); + if (initialLoad) { + if (this.options.start != undefined || this.options.end != undefined) { + var start = this.options.start != undefined ? this.options.start : null; + var end = this.options.end != undefined ? this.options.end : null; - if (initialLoad && ('start' in this.options || 'end' in this.options)) { - this.fit(); - - var start = ('start' in this.options) ? util.convert(this.options.start, 'Date') : null; - var end = ('end' in this.options) ? util.convert(this.options.end, 'Date') : null; - - this.setWindow(start, end, false); + this.setWindow(start, end, {animate: false}); + } + else { + this.fit({animate: false}); + } } };