Browse Source

Adding caching to Range getMillisecondsPerPixel function (#3154)

gemini
Rafael G Goes 7 years ago
committed by yotamberk
parent
commit
56083ec6f3
1 changed files with 7 additions and 2 deletions
  1. +7
    -2
      lib/timeline/Range.js

+ 7
- 2
lib/timeline/Range.js View File

@ -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;
}
/**

Loading…
Cancel
Save