From 56083ec6f3f1e13fd729c94318d540c7b741a0c4 Mon Sep 17 00:00:00 2001 From: Rafael G Goes Date: Tue, 13 Jun 2017 15:07:17 -0400 Subject: [PATCH] Adding caching to Range getMillisecondsPerPixel function (#3154) --- lib/timeline/Range.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/timeline/Range.js b/lib/timeline/Range.js index 0ae6dec0..38ddd317 100644 --- a/lib/timeline/Range.js +++ b/lib/timeline/Range.js @@ -16,7 +16,8 @@ function Range(body, options) { var now = moment().hours(0).minutes(0).seconds(0).milliseconds(0); var start = now.clone().add(-3, 'days').valueOf(); var end = now.clone().add(3, 'days').valueOf(); - + this.millisecondsPerPixelCache = undefined; + if(options === undefined) { this.start = start; this.end = end; @@ -200,6 +201,7 @@ Range.prototype.setRange = function(start, end, options, callback) { var finalStart = start != undefined ? util.convert(start, 'Date').valueOf() : null; var finalEnd = end != undefined ? util.convert(end, 'Date').valueOf() : null; this._cancelAnimation(); + this.millisecondsPerPixelCache = undefined; if (options.animation) { // true or an Object var initStart = this.start; @@ -280,7 +282,10 @@ Range.prototype.setRange = function(start, end, options, callback) { * Get the number of milliseconds per pixel. */ Range.prototype.getMillisecondsPerPixel = function() { - return (this.end - this.start) / this.body.dom.center.clientWidth; + if (this.millisecondsPerPixelCache === undefined) { + this.millisecondsPerPixelCache = (this.end - this.start) / this.body.dom.center.clientWidth; + } + return this.millisecondsPerPixelCache; } /**