Browse Source

Fixed non working `start` and `end` options.

css_transitions
josdejong 11 years ago
parent
commit
43414f85ba
4 changed files with 24 additions and 24 deletions
  1. +1
    -0
      HISTORY.md
  2. +8
    -8
      examples/timeline/02_dataset.html
  3. +2
    -2
      src/timeline/Range.js
  4. +13
    -14
      src/timeline/Timeline.js

+ 1
- 0
HISTORY.md View File

@ -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

+ 8
- 8
examples/timeline/02_dataset.html View File

@ -39,18 +39,18 @@
}
});
items.add([
{id: 1, content: 'item 1<br>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<br>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

+ 2
- 2
src/timeline/Range.js View File

@ -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;

+ 13
- 14
src/timeline/Timeline.js View File

@ -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);
}
}
};

Loading…
Cancel
Save