Browse Source

added fit() and getItemRange()

v3_develop
Alex de Mulder 10 years ago
parent
commit
b8d5d4629b
8 changed files with 215 additions and 127 deletions
  1. +3
    -0
      HISTORY.md
  2. +114
    -78
      dist/vis.js
  3. +1
    -1
      dist/vis.map
  4. +8
    -8
      dist/vis.min.js
  5. +13
    -0
      docs/graph2d.html
  6. +34
    -0
      lib/timeline/Graph2d.js
  7. +42
    -0
      lib/timeline/Timeline.js
  8. +0
    -40
      lib/timeline/core.js

+ 3
- 0
HISTORY.md View File

@ -12,6 +12,8 @@ http://visjs.org
- Added visible property to the groups.
- Added getLegend() method.
- Added isGroupVisible() method.
- Fixed empty group bug.
- Added fit() and getItemRange() methods.
### Timeline
@ -19,6 +21,7 @@ http://visjs.org
## 2014-07-22, version 3.1.0
### General

+ 114
- 78
dist/vis.js View File

@ -6042,7 +6042,7 @@ return /******/ (function(modules) { // webpackBootstrap
var DataSet = __webpack_require__(3);
var DataView = __webpack_require__(4);
var Range = __webpack_require__(15);
var Core = __webpack_require__(42);
var Core = __webpack_require__(43);
var TimeAxis = __webpack_require__(27);
var CurrentTime = __webpack_require__(19);
var CustomTime = __webpack_require__(20);
@ -6275,6 +6275,48 @@ return /******/ (function(modules) { // webpackBootstrap
};
/**
* Get the data range of the item set.
* @returns {{min: Date, max: Date}} range A range with a start and end Date.
* When no minimum is found, min==null
* When no maximum is found, max==null
*/
Timeline.prototype.getItemRange = function() {
// calculate min from start filed
var dataset = this.itemsData.getDataSet(),
min = null,
max = null;
if (dataset) {
// calculate the minimum value of the field 'start'
var minItem = dataset.min('start');
min = minItem ? util.convert(minItem.start, 'Date').valueOf() : null;
// Note: we convert first to Date and then to number because else
// a conversion from ISODate to Number will fail
// calculate maximum value of fields 'start' and 'end'
var maxStartItem = dataset.max('start');
if (maxStartItem) {
max = util.convert(maxStartItem.start, 'Date').valueOf();
}
var maxEndItem = dataset.max('end');
if (maxEndItem) {
if (max == null) {
max = util.convert(maxEndItem.end, 'Date').valueOf();
}
else {
max = Math.max(max, util.convert(maxEndItem.end, 'Date').valueOf());
}
}
}
return {
min: (min != null) ? new Date(min) : null,
max: (max != null) ? new Date(max) : null
};
};
module.exports = Timeline;
@ -6288,7 +6330,7 @@ return /******/ (function(modules) { // webpackBootstrap
var DataSet = __webpack_require__(3);
var DataView = __webpack_require__(4);
var Range = __webpack_require__(15);
var Core = __webpack_require__(42);
var Core = __webpack_require__(43);
var TimeAxis = __webpack_require__(27);
var CurrentTime = __webpack_require__(19);
var CustomTime = __webpack_require__(20);
@ -6534,6 +6576,40 @@ return /******/ (function(modules) { // webpackBootstrap
}
/**
* Get the data range of the item set.
* @returns {{min: Date, max: Date}} range A range with a start and end Date.
* When no minimum is found, min==null
* When no maximum is found, max==null
*/
Graph2d.prototype.getItemRange = function() {
// calculate min from start filed
var dataset = this.itemsData.getDataSet(),
min = null,
max = null;
if (dataset) {
// calculate the minimum value of the field 'start'
var minItem = dataset.min('x');
min = minItem ? util.convert(minItem.x, 'Date').valueOf() : null;
// Note: we convert first to Date and then to number because else
// a conversion from ISODate to Number will fail
// calculate maximum value of fields 'start' and 'end'
var maxStartItem = dataset.max('x');
if (maxStartItem) {
max = util.convert(maxStartItem.x, 'Date').valueOf();
}
}
return {
min: (min != null) ? new Date(min) : null,
max: (max != null) ? new Date(max) : null
};
};
module.exports = Graph2d;
@ -6769,7 +6845,7 @@ return /******/ (function(modules) { // webpackBootstrap
/***/ function(module, exports, __webpack_require__) {
var util = __webpack_require__(1);
var hammerUtil = __webpack_require__(43);
var hammerUtil = __webpack_require__(42);
var moment = __webpack_require__(40);
var Component = __webpack_require__(18);
@ -13319,7 +13395,7 @@ return /******/ (function(modules) { // webpackBootstrap
var Hammer = __webpack_require__(41);
var mousetrap = __webpack_require__(47);
var util = __webpack_require__(1);
var hammerUtil = __webpack_require__(43);
var hammerUtil = __webpack_require__(42);
var DataSet = __webpack_require__(3);
var DataView = __webpack_require__(4);
var dotparser = __webpack_require__(38);
@ -19100,6 +19176,40 @@ return /******/ (function(modules) { // webpackBootstrap
/***/ },
/* 42 */
/***/ function(module, exports, __webpack_require__) {
var Hammer = __webpack_require__(41);
/**
* Fake a hammer.js gesture. Event can be a ScrollEvent or MouseMoveEvent
* @param {Element} element
* @param {Event} event
*/
exports.fakeGesture = function(element, event) {
var eventType = null;
// for hammer.js 1.0.5
// var gesture = Hammer.event.collectEventData(this, eventType, event);
// for hammer.js 1.0.6+
var touches = Hammer.event.getTouchList(event, eventType);
var gesture = Hammer.event.collectEventData(this, eventType, touches, event);
// on IE in standards mode, no touches are recognized by hammer.js,
// resulting in NaN values for center.pageX and center.pageY
if (isNaN(gesture.center.pageX)) {
gesture.center.pageX = event.pageX;
}
if (isNaN(gesture.center.pageY)) {
gesture.center.pageY = event.pageY;
}
return gesture;
};
/***/ },
/* 43 */
/***/ function(module, exports, __webpack_require__) {
var Emitter = __webpack_require__(46);
@ -19376,46 +19486,6 @@ return /******/ (function(modules) { // webpackBootstrap
this.range.setRange(start, end);
};
/**
* Get the data range of the item set.
* @returns {{min: Date, max: Date}} range A range with a start and end Date.
* When no minimum is found, min==null
* When no maximum is found, max==null
*/
Core.prototype.getItemRange = function() {
// calculate min from start filed
var dataset = this.itemsData.getDataSet(),
min = null,
max = null;
if (dataset) {
// calculate the minimum value of the field 'start'
var minItem = dataset.min('start');
min = minItem ? util.convert(minItem.start, 'Date').valueOf() : null;
// Note: we convert first to Date and then to number because else
// a conversion from ISODate to Number will fail
// calculate maximum value of fields 'start' and 'end'
var maxStartItem = dataset.max('start');
if (maxStartItem) {
max = util.convert(maxStartItem.start, 'Date').valueOf();
}
var maxEndItem = dataset.max('end');
if (maxEndItem) {
if (max == null) {
max = util.convert(maxEndItem.end, 'Date').valueOf();
}
else {
max = Math.max(max, util.convert(maxEndItem.end, 'Date').valueOf());
}
}
}
return {
min: (min != null) ? new Date(min) : null,
max: (max != null) ? new Date(max) : null
};
};
/**
* Set the visible window. Both parameters are optional, you can change only
@ -19806,40 +19876,6 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = Core;
/***/ },
/* 43 */
/***/ function(module, exports, __webpack_require__) {
var Hammer = __webpack_require__(41);
/**
* Fake a hammer.js gesture. Event can be a ScrollEvent or MouseMoveEvent
* @param {Element} element
* @param {Event} event
*/
exports.fakeGesture = function(element, event) {
var eventType = null;
// for hammer.js 1.0.5
// var gesture = Hammer.event.collectEventData(this, eventType, event);
// for hammer.js 1.0.6+
var touches = Hammer.event.getTouchList(event, eventType);
var gesture = Hammer.event.collectEventData(this, eventType, touches, event);
// on IE in standards mode, no touches are recognized by hammer.js,
// resulting in NaN values for center.pageX and center.pageY
if (isNaN(gesture.center.pageX)) {
gesture.center.pageX = event.pageX;
}
if (isNaN(gesture.center.pageY)) {
gesture.center.pageY = event.pageY;
}
return gesture;
};
/***/ },
/* 44 */
/***/ function(module, exports, __webpack_require__) {

+ 1
- 1
dist/vis.map
File diff suppressed because it is too large
View File


+ 8
- 8
dist/vis.min.js
File diff suppressed because it is too large
View File


+ 13
- 0
docs/graph2d.html View File

@ -694,6 +694,19 @@ Graph2d.clear({options: true}); // clear options only
<td>Get the current visible window. Returns an object with properties <code>start: Date</code> and <code>end: Date</code>.</td>
</tr>
<tr>
<td>getItemRange()</td>
<td>Object</td>
<td>Get the range of all the items as an object containing <code>min: Date</code> and <code>max: Date</code>.</td>
</tr>
<tr>
<td>fit()</td>
<td>none</td>
<td>Adjust the visible window such that it fits all items.
</td>
</tr>
<tr>
<td>on(event, callback)</td>
<td>none</td>

+ 34
- 0
lib/timeline/Graph2d.js View File

@ -250,4 +250,38 @@ Graph2d.prototype.isGroupVisible = function(groupId) {
}
/**
* Get the data range of the item set.
* @returns {{min: Date, max: Date}} range A range with a start and end Date.
* When no minimum is found, min==null
* When no maximum is found, max==null
*/
Graph2d.prototype.getItemRange = function() {
// calculate min from start filed
var dataset = this.itemsData.getDataSet(),
min = null,
max = null;
if (dataset) {
// calculate the minimum value of the field 'start'
var minItem = dataset.min('x');
min = minItem ? util.convert(minItem.x, 'Date').valueOf() : null;
// Note: we convert first to Date and then to number because else
// a conversion from ISODate to Number will fail
// calculate maximum value of fields 'start' and 'end'
var maxStartItem = dataset.max('x');
if (maxStartItem) {
max = util.convert(maxStartItem.x, 'Date').valueOf();
}
}
return {
min: (min != null) ? new Date(min) : null,
max: (max != null) ? new Date(max) : null
};
};
module.exports = Graph2d;

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

@ -237,4 +237,46 @@ Timeline.prototype.getSelection = function() {
};
/**
* Get the data range of the item set.
* @returns {{min: Date, max: Date}} range A range with a start and end Date.
* When no minimum is found, min==null
* When no maximum is found, max==null
*/
Timeline.prototype.getItemRange = function() {
// calculate min from start filed
var dataset = this.itemsData.getDataSet(),
min = null,
max = null;
if (dataset) {
// calculate the minimum value of the field 'start'
var minItem = dataset.min('start');
min = minItem ? util.convert(minItem.start, 'Date').valueOf() : null;
// Note: we convert first to Date and then to number because else
// a conversion from ISODate to Number will fail
// calculate maximum value of fields 'start' and 'end'
var maxStartItem = dataset.max('start');
if (maxStartItem) {
max = util.convert(maxStartItem.start, 'Date').valueOf();
}
var maxEndItem = dataset.max('end');
if (maxEndItem) {
if (max == null) {
max = util.convert(maxEndItem.end, 'Date').valueOf();
}
else {
max = Math.max(max, util.convert(maxEndItem.end, 'Date').valueOf());
}
}
}
return {
min: (min != null) ? new Date(min) : null,
max: (max != null) ? new Date(max) : null
};
};
module.exports = Timeline;

+ 0
- 40
lib/timeline/core.js View File

@ -272,46 +272,6 @@ Core.prototype.fit = function() {
this.range.setRange(start, end);
};
/**
* Get the data range of the item set.
* @returns {{min: Date, max: Date}} range A range with a start and end Date.
* When no minimum is found, min==null
* When no maximum is found, max==null
*/
Core.prototype.getItemRange = function() {
// calculate min from start filed
var dataset = this.itemsData.getDataSet(),
min = null,
max = null;
if (dataset) {
// calculate the minimum value of the field 'start'
var minItem = dataset.min('start');
min = minItem ? util.convert(minItem.start, 'Date').valueOf() : null;
// Note: we convert first to Date and then to number because else
// a conversion from ISODate to Number will fail
// calculate maximum value of fields 'start' and 'end'
var maxStartItem = dataset.max('start');
if (maxStartItem) {
max = util.convert(maxStartItem.start, 'Date').valueOf();
}
var maxEndItem = dataset.max('end');
if (maxEndItem) {
if (max == null) {
max = util.convert(maxEndItem.end, 'Date').valueOf();
}
else {
max = Math.max(max, util.convert(maxEndItem.end, 'Date').valueOf());
}
}
}
return {
min: (min != null) ? new Date(min) : null,
max: (max != null) ? new Date(max) : null
};
};
/**
* Set the visible window. Both parameters are optional, you can change only

Loading…
Cancel
Save