From f8be0a5a21d7ae93e768520909b8ce072407e956 Mon Sep 17 00:00:00 2001 From: yotamberk Date: Sun, 5 Mar 2017 23:55:22 +0200 Subject: [PATCH] Add animation options for zoomIn/zoomOut funtions (#2830) * Fix redraw order * Fix error when option is not defined * Allow template labels * Add .travis.yml file * Add experiment travis code * Fix react example * Add animation options for zoomIn and zoomOut --- docs/timeline/index.html | 14 ++++++++++---- lib/timeline/Core.js | 28 ++++++++++++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/docs/timeline/index.html b/docs/timeline/index.html index cfaee114..b69d05bd 100644 --- a/docs/timeline/index.html +++ b/docs/timeline/index.html @@ -1439,15 +1439,21 @@ document.getElementById('myTimeline').onclick = function (event) { - zoomIn(percentage) + zoomIn(percentage [, options]) none - Zoom in the current visible window. The parameter percentage can be a Number and must be between 0 and 1. If the parameter value of percentage is null, the window will be left unchanged. + Zoom in the current visible window. The parameter percentage can be a Number and must be between 0 and 1. If the parameter value of percentage is null, the window will be left unchanged. Available options: + - zoomOut(percentage) + zoomOut(percentage [, options]) none - Zoom out the current visible window. The parameter percentage can be a Number and must be between 0 and 1. If the parameter value of percentage is null, the window will be left unchanged. + Zoom out the current visible window. The parameter percentage can be a Number and must be between 0 and 1. If the parameter value of percentage is null, the window will be left unchanged. Available options: + diff --git a/lib/timeline/Core.js b/lib/timeline/Core.js index 0d42edf5..01bf3993 100644 --- a/lib/timeline/Core.js +++ b/lib/timeline/Core.js @@ -708,8 +708,15 @@ Core.prototype.getWindow = function() { /** * Zoom in the window such that given time is centered on screen. * @param {Number} percentage - must be between [0..1] + * @param {Object} [options] Available options: + * `animation: boolean | {duration: number, easingFunction: string}` + * If true (default), the range is animated + * smoothly to the new window. An object can be + * provided to specify duration and easing function. + * Default duration is 500 ms, and default easing + * function is 'easeInOutQuad'. */ -Core.prototype.zoomIn = function(percentage) { +Core.prototype.zoomIn = function(percentage, options) { if (!percentage || percentage < 0 || percentage > 1) return var range = this.getWindow(); var start = range.start.valueOf(); @@ -720,17 +727,21 @@ Core.prototype.zoomIn = function(percentage) { var newStart = start + distance; var newEnd = end - distance; - this.setWindow({ - start : newStart, - end : newEnd - }); + this.setWindow(newStart, newEnd, options); }; /** * Zoom out the window such that given time is centered on screen. * @param {Number} percentage - must be between [0..1] + * @param {Object} [options] Available options: + * `animation: boolean | {duration: number, easingFunction: string}` + * If true (default), the range is animated + * smoothly to the new window. An object can be + * provided to specify duration and easing function. + * Default duration is 500 ms, and default easing + * function is 'easeInOutQuad'. */ -Core.prototype.zoomOut = function(percentage) { +Core.prototype.zoomOut = function(percentage, options) { if (!percentage || percentage < 0 || percentage > 1) return var range = this.getWindow(); var start = range.start.valueOf(); @@ -739,10 +750,7 @@ Core.prototype.zoomOut = function(percentage) { var newStart = start - interval * percentage / 2; var newEnd = end + interval * percentage / 2; - this.setWindow({ - start : newStart, - end : newEnd - }); + this.setWindow(newStart, newEnd, options); }; /**