|
@ -218,8 +218,6 @@ Timeline.prototype.setItems = function(items) { |
|
|
this.setWindow(start, end, {animation: false}); |
|
|
this.setWindow(start, end, {animation: false}); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
// call fit twice as
|
|
|
|
|
|
this.fit({animation: false}); |
|
|
|
|
|
this.fit({animation: false}); |
|
|
this.fit({animation: false}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -345,12 +343,71 @@ Timeline.prototype.focus = function(id, options) { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Set Timeline window such that it fits all items |
|
|
|
|
|
* @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'. |
|
|
|
|
|
*/ |
|
|
|
|
|
Timeline.prototype.fit = function (options) { |
|
|
|
|
|
// then, make sure all items are drawn and have a width, and fit the timeline window exactly.
|
|
|
|
|
|
var min = null; |
|
|
|
|
|
var max = null; |
|
|
|
|
|
var minItem = null; |
|
|
|
|
|
var maxItem = null; |
|
|
|
|
|
|
|
|
|
|
|
util.forEach(this.itemSet.items, function (item) { |
|
|
|
|
|
item.show(); |
|
|
|
|
|
item.repositionX(); |
|
|
|
|
|
|
|
|
|
|
|
if (item.left < min) { |
|
|
|
|
|
min = item.left; |
|
|
|
|
|
minItem = item; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var right = item.left + item.width; |
|
|
|
|
|
if (right > max) { |
|
|
|
|
|
max = right; |
|
|
|
|
|
maxItem = item; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (minItem && maxItem) { |
|
|
|
|
|
var start = util.convert(minItem.data.start, 'Date').valueOf(); |
|
|
|
|
|
var end = maxItem.data.end != undefined |
|
|
|
|
|
? util.convert(maxItem.data.end, 'Date').valueOf() |
|
|
|
|
|
: util.convert(maxItem.data.start, 'Date').valueOf(); |
|
|
|
|
|
|
|
|
|
|
|
var lhs = this._toScreen(start) - minItem.left - 10; |
|
|
|
|
|
var rhs = maxItem.left + maxItem.width - this._toScreen(end) + 10; |
|
|
|
|
|
|
|
|
|
|
|
var interval = end - start; // ms
|
|
|
|
|
|
if (interval <= 0) {interval = 10;} |
|
|
|
|
|
var delta = this.props.center.width - lhs - rhs; // px
|
|
|
|
|
|
|
|
|
|
|
|
//console.log(start, end, lhs, rhs, delta)
|
|
|
|
|
|
|
|
|
|
|
|
if (delta > 0) { |
|
|
|
|
|
start -= lhs * interval / delta; // ms
|
|
|
|
|
|
end += rhs * interval / delta; // ms
|
|
|
|
|
|
|
|
|
|
|
|
var animation = (options && options.animation !== undefined) ? options.animation : true; |
|
|
|
|
|
this.range.setRange(start, end, animation); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Get the data range of the item set. |
|
|
* Get the data range of the item set. |
|
|
* @returns {{min: Date, max: Date}} range A range with a start and end Date. |
|
|
* @returns {{min: Date, max: Date}} range A range with a start and end Date. |
|
|
* When no minimum is found, min==null |
|
|
* When no minimum is found, min==null |
|
|
* When no maximum is found, max==null |
|
|
* When no maximum is found, max==null |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
// TODO: remove this function
|
|
|
Timeline.prototype.getItemRange = function() { |
|
|
Timeline.prototype.getItemRange = function() { |
|
|
var min = null; |
|
|
var min = null; |
|
|
var max = null; |
|
|
var max = null; |
|
@ -378,11 +435,26 @@ Timeline.prototype.getItemRange = function() { |
|
|
var minItem = this.itemSet.items[minId]; |
|
|
var minItem = this.itemSet.items[minId]; |
|
|
var maxItem = this.itemSet.items[maxId]; |
|
|
var maxItem = this.itemSet.items[maxId]; |
|
|
if (minItem && minItem.width && maxItem && maxItem.width) { |
|
|
if (minItem && minItem.width && maxItem && maxItem.width) { |
|
|
var left = minItem.left; |
|
|
|
|
|
var right = maxItem.left + maxItem.width; |
|
|
|
|
|
|
|
|
//var left = minItem.left;
|
|
|
|
|
|
//var right = maxItem.left + maxItem.width;
|
|
|
|
|
|
//
|
|
|
|
|
|
//min = this._toTime(left - 10);
|
|
|
|
|
|
//max = this._toTime(right + 10);
|
|
|
|
|
|
|
|
|
|
|
|
var lhs = minItem.widthLhs(); // px
|
|
|
|
|
|
var rhs = maxItem.widthRhs(); // px
|
|
|
|
|
|
|
|
|
min = this._toTime(left - 10); |
|
|
|
|
|
max = this._toTime(right + 10); |
|
|
|
|
|
|
|
|
var interval = max - min; // ms
|
|
|
|
|
|
if (interval <= 0) {interval = 10;} |
|
|
|
|
|
var delta = this.props.center.width - lhs - rhs; // px
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(minId, maxId, minItem.left, this._toScreen(min), this._toScreen(minItem.data.start), lhs, rhs, interval, delta) |
|
|
|
|
|
|
|
|
|
|
|
if (delta > 0) { |
|
|
|
|
|
min -= lhs * interval / delta; // ms
|
|
|
|
|
|
max += rhs * interval / delta; // ms
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
@ -391,6 +463,35 @@ Timeline.prototype.getItemRange = function() { |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Calculate the data range of the items start and end dates |
|
|
|
|
|
* @returns {{min: Date | null, max: Date | null}} |
|
|
|
|
|
* @protected |
|
|
|
|
|
*/ |
|
|
|
|
|
Timeline.prototype.getDataRange = function() { |
|
|
|
|
|
var min = null; |
|
|
|
|
|
var max = null; |
|
|
|
|
|
|
|
|
|
|
|
var dataset = this.itemsData && this.itemsData.getDataSet(); |
|
|
|
|
|
if (dataset) { |
|
|
|
|
|
dataset.forEach(function (item) { |
|
|
|
|
|
var start = util.convert(item.start, 'Date').valueOf(); |
|
|
|
|
|
var end = util.convert(item.end != undefined ? item.end : item.start, 'Date').valueOf(); |
|
|
|
|
|
if (min === null || start < min) { |
|
|
|
|
|
min = start; |
|
|
|
|
|
} |
|
|
|
|
|
if (max === null || end > max) { |
|
|
|
|
|
max = start; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
min: min, |
|
|
|
|
|
max: max |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Generate Timeline related information from an event |
|
|
* Generate Timeline related information from an event |
|
|
* @param {Event} event |
|
|
* @param {Event} event |
|
|