|
|
@ -197,41 +197,6 @@ Timeline.prototype.getSelection = function() { |
|
|
|
return this.itemSet && this.itemSet.getSelection() || []; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Set Timeline window such that it fits all items |
|
|
|
* @param {Object} [options] Available options: |
|
|
|
* `animate: boolean | number` |
|
|
|
* If true (default), the range is animated |
|
|
|
* smoothly to the new window. |
|
|
|
* If a number, the number is taken as duration |
|
|
|
* for the animation. Default duration is 500 ms. |
|
|
|
*/ |
|
|
|
Timeline.prototype.fit = function(options) { |
|
|
|
// apply the data range as range
|
|
|
|
var dataRange = this.getItemRange(); |
|
|
|
|
|
|
|
// add 5% space on both sides
|
|
|
|
var start = dataRange.min; |
|
|
|
var end = dataRange.max; |
|
|
|
if (start != null && end != null) { |
|
|
|
var interval = (end.valueOf() - start.valueOf()); |
|
|
|
if (interval <= 0) { |
|
|
|
// prevent an empty interval
|
|
|
|
interval = 24 * 60 * 60 * 1000; // 1 day
|
|
|
|
} |
|
|
|
start = new Date(start.valueOf() - interval * 0.05); |
|
|
|
end = new Date(end.valueOf() + interval * 0.05); |
|
|
|
} |
|
|
|
|
|
|
|
// skip range set if there is no start and end date
|
|
|
|
if (start === null && end === null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var animate = (options && options.animate !== undefined) ? options.animate : true; |
|
|
|
this.range.setRange(start, end, animate); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Adjust the visible window such that the selected item (or multiple items) |
|
|
|
* are centered on screen. |
|
|
|