Browse Source

Oops. Move the shared function `fit` back to Core

v3_develop
jos 10 years ago
parent
commit
12f11ed8d5
2 changed files with 35 additions and 35 deletions
  1. +35
    -0
      lib/timeline/Core.js
  2. +0
    -35
      lib/timeline/Timeline.js

+ 35
- 0
lib/timeline/Core.js View File

@ -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 * Set the visible window. Both parameters are optional, you can change only
* start or only end. Syntax: * start or only end. Syntax:

+ 0
- 35
lib/timeline/Timeline.js View File

@ -197,41 +197,6 @@ Timeline.prototype.getSelection = function() {
return this.itemSet && this.itemSet.getSelection() || []; 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) * Adjust the visible window such that the selected item (or multiple items)
* are centered on screen. * are centered on screen.

Loading…
Cancel
Save