diff --git a/HISTORY.md b/HISTORY.md
index d26ffd66..6afe2f65 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -10,6 +10,7 @@ http://visjs.org
`rangechange`, `rangechanged`, and `select`.
- Impelmented function `select` to get and set the selected items.
- Items can be selected by clicking them, muti-select by holding them.
+- Fixed non working `start` and `end` options.
### Graph
diff --git a/examples/timeline/02_dataset.html b/examples/timeline/02_dataset.html
index e493663d..c15e9c7b 100644
--- a/examples/timeline/02_dataset.html
+++ b/examples/timeline/02_dataset.html
@@ -39,18 +39,18 @@
}
});
items.add([
- {id: 1, content: 'item 1
start', start: now.clone().add('days', 4)},
- {id: 2, content: 'item 2', start: now.clone().add('days', -2)},
- {id: 3, content: 'item 3', start: now.clone().add('days', 2)},
- {id: 4, content: 'item 4', start: now.clone().add('days', 0), end: now.clone().add('days', 3).toDate()},
- {id: 5, content: 'item 5', start: now.clone().add('days', 9), type:'point'},
- {id: 6, content: 'item 6', start: now.clone().add('days', 11)}
+ {id: 1, content: 'item 1
start', start: '2014-01-23'},
+ {id: 2, content: 'item 2', start: '2014-01-18'},
+ {id: 3, content: 'item 3', start: '2014-01-21'},
+ {id: 4, content: 'item 4', start: '2014-01-19', end: '2014-01-24'},
+ {id: 5, content: 'item 5', start: '2014-01-28', type:'point'},
+ {id: 6, content: 'item 6', start: '2014-01-26'}
]);
var container = document.getElementById('visualization');
var options = {
- start: now.clone().add('days', -3),
- end: now.clone().add('days', 7),
+ start: '2014-01-10',
+ end: '2014-02-10',
orientation: 'top',
height: '100%',
showCurrentTime: true
diff --git a/src/timeline/Range.js b/src/timeline/Range.js
index f6d72299..70c9083d 100644
--- a/src/timeline/Range.js
+++ b/src/timeline/Range.js
@@ -154,8 +154,8 @@ Range.prototype.setRange = function(start, end) {
* @private
*/
Range.prototype._applyRange = function(start, end) {
- var newStart = (start != null) ? util.convert(start, 'Number') : this.start,
- newEnd = (end != null) ? util.convert(end, 'Number') : this.end,
+ var newStart = (start != null) ? util.convert(start, 'Date').valueOf() : this.start,
+ newEnd = (end != null) ? util.convert(end, 'Date').valueOf() : this.end,
max = (this.options.max != null) ? util.convert(this.options.max, 'Date').valueOf() : null,
min = (this.options.min != null) ? util.convert(this.options.min, 'Date').valueOf() : null,
diff;
diff --git a/src/timeline/Timeline.js b/src/timeline/Timeline.js
index 8d88e68a..38c19fae 100644
--- a/src/timeline/Timeline.js
+++ b/src/timeline/Timeline.js
@@ -147,10 +147,9 @@ function Timeline (container, items, options) {
Timeline.prototype.setOptions = function (options) {
util.extend(this.options, options);
- // force update of range
- // options.start and options.end can be undefined
- //this.range.setRange(options.start, options.end);
- this.range.setRange();
+ // force update of range (apply new min/max etc.)
+ // both start and end are optional
+ this.range.setRange(options.start, options.end);
this.controller.reflow();
this.controller.repaint();
@@ -206,29 +205,29 @@ Timeline.prototype.setItems = function(items) {
var dataRange = this.getItemRange();
// add 5% space on both sides
- var min = dataRange.min;
- var max = dataRange.max;
- if (min != null && max != null) {
- var interval = (max.valueOf() - min.valueOf());
+ 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
}
- min = new Date(min.valueOf() - interval * 0.05);
- max = new Date(max.valueOf() + interval * 0.05);
+ start = new Date(start.valueOf() - interval * 0.05);
+ end = new Date(end.valueOf() + interval * 0.05);
}
// override specified start and/or end date
if (this.options.start != undefined) {
- min = util.convert(this.options.start, 'Date');
+ start = util.convert(this.options.start, 'Date');
}
if (this.options.end != undefined) {
- max = util.convert(this.options.end, 'Date');
+ end = util.convert(this.options.end, 'Date');
}
// apply range if there is a min or max available
- if (min != null || max != null) {
- this.range.setRange(min, max);
+ if (start != null || end != null) {
+ this.range.setRange(start, end);
}
}
};