From 12f11ed8d52457e136736eb863f40f9989b6b121 Mon Sep 17 00:00:00 2001 From: jos Date: Mon, 25 Aug 2014 13:11:54 +0200 Subject: [PATCH] Oops. Move the shared function `fit` back to Core --- lib/timeline/Core.js | 35 +++++++++++++++++++++++++++++++++++ lib/timeline/Timeline.js | 35 ----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/timeline/Core.js b/lib/timeline/Core.js index ca44109b..d816ce38 100644 --- a/lib/timeline/Core.js +++ b/lib/timeline/Core.js @@ -323,6 +323,41 @@ Core.prototype.clear = function(what) { } }; +/** + * Set Core 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. + */ +Core.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); +}; + /** * Set the visible window. Both parameters are optional, you can change only * start or only end. Syntax: diff --git a/lib/timeline/Timeline.js b/lib/timeline/Timeline.js index 3da5da66..c688bfaf 100644 --- a/lib/timeline/Timeline.js +++ b/lib/timeline/Timeline.js @@ -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.