Browse Source

Fixed #1774: Wrong initial scale when Timeline contains a single item

codeClimate
jos 8 years ago
parent
commit
6f1dc4200d
2 changed files with 15 additions and 3 deletions
  1. +1
    -0
      HISTORY.md
  2. +14
    -3
      lib/timeline/Timeline.js

+ 1
- 0
HISTORY.md View File

@ -7,6 +7,7 @@ http://visjs.org
### Timeline ### Timeline
- Fixed #1697: Timeline not drawn when used within the Angular.js directive. - Fixed #1697: Timeline not drawn when used within the Angular.js directive.
- Fixed #1774: Wrong initial scale when Timeline contains a single item.
## 2016-03-08, version 4.15.1 ## 2016-03-08, version 4.15.1

+ 14
- 3
lib/timeline/Timeline.js View File

@ -135,7 +135,7 @@ function Timeline (container, items, groups, options) {
} }
var start = me.options.start != undefined ? me.options.start : range.min; var start = me.options.start != undefined ? me.options.start : range.min;
var end = me.options.end != undefined ? me.options.end : range.max;
var end = me.options.end != undefined ? me.options.end : range.max;
me.setWindow(start, end, {animation: false}); me.setWindow(start, end, {animation: false});
} }
@ -373,8 +373,19 @@ Timeline.prototype.focus = function(id, options) {
*/ */
Timeline.prototype.fit = function (options) { Timeline.prototype.fit = function (options) {
var animation = (options && options.animation !== undefined) ? options.animation : true; var animation = (options && options.animation !== undefined) ? options.animation : true;
var range = this.getItemRange();
this.range.setRange(range.min, range.max, animation);
var range;
var dataset = this.itemsData && this.itemsData.getDataSet();
if (dataset.length === 1 && dataset.get()[0].end === undefined) {
// a single item -> don't fit, just show a range around the item from -4 to +3 days
range = this.getDataRange();
this.moveTo(range.min.valueOf(), {animation});
}
else {
// exactly fit the items (plus a small margin)
range = this.getItemRange();
this.range.setRange(range.min, range.max, animation);
}
}; };
/** /**

Loading…
Cancel
Save