From 3c5983c78cd7d6851cbcba54a97c91bbfb4742f3 Mon Sep 17 00:00:00 2001 From: Eric Gillingham Date: Wed, 10 Jul 2013 18:02:15 -0700 Subject: [PATCH] Add a new moveTo function to range to allow a program to recenter the timeline on any given date. --- src/timeline/Range.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/timeline/Range.js b/src/timeline/Range.js index 9f02fe69..ae9b43af 100644 --- a/src/timeline/Range.js +++ b/src/timeline/Range.js @@ -522,3 +522,19 @@ Range.prototype.move = function(moveFactor) { this.start = newStart; this.end = newEnd; }; + +/** + * Move the range to a new center point + * @param {Number} moveTo New center point of the range + */ +Range.prototype.moveTo = function(moveTo) { + var center = (this.start + this.end) / 2; + + var diff = center - moveTo; + + // calculate new start and end + var newStart = this.start - diff; + var newEnd = this.end - diff; + + this.setRange(newStart, newEnd); +}