Browse Source

Implemented a method `clear([what])`, to clear items, groups, and configuration of a Timeline instance.

css_transitions
jos 10 years ago
parent
commit
94741fbd51
4 changed files with 128 additions and 31 deletions
  1. +37
    -26
      HISTORY.md
  2. +13
    -0
      docs/timeline.html
  3. +44
    -5
      src/timeline/Timeline.js
  4. +34
    -0
      src/util.js

+ 37
- 26
HISTORY.md View File

@ -7,6 +7,8 @@ http://visjs.org
### Timeline
- Implemented option `minHeight`, similar to option `maxHeight`.
- Implemented a method `clear([what])`, to clear items, groups, and configuration
of a Timeline instance.
- Added function `repaint()` to force a repaint of the Timeline.
- Some tweaks in snapping dragged items to nice dates.
- Made the instance of moment.js packaged with vis.js accessibly via `vis.moment`.
@ -14,6 +16,7 @@ http://visjs.org
is `"range"` or `"rangeoverflow"`.
- Fixed a bug in replacing the DataSet of groups via `Timeline.setGroups(groups)`.
- Fixed a bug when rendering the Timeline inside a hidden container.
- Fixed axis scale being determined wrongly for a second Timeline in a single page.
### Graph
@ -32,9 +35,9 @@ http://visjs.org
### Graph
- Added coordinate conversion from DOM to Canvas.
- fixed bug where the graph stopped animation after settling in playing with physics.
- fixed bug where hierarchical physics properties were not handled.
- added events for change of view and zooming.
- Fixed bug where the graph stopped animation after settling in playing with physics.
- Fixed bug where hierarchical physics properties were not handled.
- Added events for change of view and zooming.
## 2014-05-02, version 1.0.0
@ -64,8 +67,8 @@ http://visjs.org
### Graph
- added recalculate hierarchical layout to update node event.
- added arrowScaleFactor to scale the arrows on the edges.
- Added recalculate hierarchical layout to update node event.
- Added arrowScaleFactor to scale the arrows on the edges.
### DataSet
@ -77,48 +80,53 @@ http://visjs.org
### Graph
- fixed IE9 bug.
- style fixes.
- minor bug fixes.
- Fixed IE9 bug.
- Style fixes.
- Minor bug fixes.
## 2014-04-16, version 0.7.3
### Graph
- fixed color bug.
- added pull requests from kannonboy and vierja: tooltip styling, label fill color
- Fixed color bug.
- Added pull requests from kannonboy and vierja: tooltip styling, label fill
color.
## 2014-04-09, version 0.7.2
### Graph
- fixed edge select bug.
- fixed zoom bug on empty initialization.
- Fixed edge select bug.
- Fixed zoom bug on empty initialization.
## 2014-03-27, version 0.7.1
### Graph
- fixed edge color bug.
- fixed select event bug.
- clarified docs, stressing importance of css inclusion for correct display of navigation an manipulation icons.
- improved and expanded playing with physics (configurePhysics option).
- added highlights to navigation icons if the corresponding key is pressed.
- added freezeForStabilization option to improve stabilization with cached positions.
- Fixed edge color bug.
- Fixed select event bug.
- Clarified docs, stressing importance of css inclusion for correct display of
navigation an manipulation icons.
- Improved and expanded playing with physics (configurePhysics option).
- Added highlights to navigation icons if the corresponding key is pressed.
- Added freezeForStabilization option to improve stabilization with cached
positions.
## 2014-03-07, version 0.7.0
### Graph
- changed navigation CSS. Icons are now always correctly positioned.
- added stabilizationIterations option to graph.
- added storePosition() method to save the XY positions of nodes in the DataSet.
- separated allowedToMove into allowedToMoveX and allowedToMoveY. This is required for initializing nodes from hierarchical layouts after storePosition().
- added color options for the edges.
- Changed navigation CSS. Icons are now always correctly positioned.
- Added stabilizationIterations option to graph.
- Added storePosition() method to save the XY positions of nodes in the DataSet.
- Separated allowedToMove into allowedToMoveX and allowedToMoveY. This is
required for initializing nodes from hierarchical layouts after
storePosition().
- Added color options for the edges.
## 2014-03-06, version 0.6.1
@ -132,7 +140,8 @@ http://visjs.org
### Timeline
- Fixed a bug with options `margin.axis` and `margin.item` being ignored when setting them to zero.
- Fixed a bug with options `margin.axis` and `margin.item` being ignored when
setting them to zero.
- Some clarifications in the documentation.
@ -140,7 +149,8 @@ http://visjs.org
### Graph
- Added Physics Configuration option. This makes tweaking the physics system to suit your needs easier.
- Added Physics Configuration option. This makes tweaking the physics system to
suit your needs easier.
- Click and doubleClick events.
- Initial zoom bugfix.
- Directions for Hierarchical layout.
@ -170,7 +180,8 @@ http://visjs.org
- Performance improvements.
- Fixed scroll to zoom not working on IE in standards mode.
- Added hierarchical layout option.
- Overhauled physics system, now using Barnes-Hut simulation by default. Great performance gains.
- Overhauled physics system, now using Barnes-Hut simulation by default. Great
performance gains.
- Modified clustering system to give better results.
- Adaptive performance system to increase visual performance (60fps target).

+ 13
- 0
docs/timeline.html View File

@ -633,6 +633,19 @@ var options = {
<th>Description</th>
</tr>
<tr>
<td>clear([what])</td>
<td>none</td>
<td>
Clear the Timeline. An object can be passed specifying which sections to clear: items, groups,
and/or options. By Default, items, groups and options are cleared, i.e. <code>what = {items: true, groups: true, options: true}</code>. Example usage:
<pre class="prettyprint lang-js">timeline.clear(); // clear items, groups, and options
timeline.clear({options: true}); // clear options only
</pre>
</td>
</tr>
<tr>
<td>fit()</td>
<td>none</td>

+ 44
- 5
src/timeline/Timeline.js View File

@ -11,7 +11,7 @@ function Timeline (container, items, options) {
var me = this;
var now = moment().hours(0).minutes(0).seconds(0).milliseconds(0);
this.options = {
this.defaultOptions = {
orientation: 'bottom',
direction: 'horizontal', // 'horizontal' or 'vertical'
autoResize: true,
@ -25,7 +25,6 @@ function Timeline (container, items, options) {
},
selectable: true,
snap: null, // will be specified after timeaxis is created
min: null,
max: null,
@ -39,6 +38,13 @@ function Timeline (container, items, options) {
showCurrentTime: false,
showCustomTime: false,
groupOrder: null,
width: null,
height: null,
maxHeight: null,
minHeight: null,
type: 'box',
align: 'center',
margin: {
@ -58,11 +64,17 @@ function Timeline (container, items, options) {
},
onRemove: function (item, callback) {
callback(item);
},
}
};
this.options = {};
util.deepExtend(this.options, this.defaultOptions);
util.deepExtend(this.options, {
snap: null, // will be specified after timeaxis is created
toScreen: me._toScreen.bind(me),
toTime: me._toTime.bind(me)
};
});
// root panel
var rootOptions = util.extend(Object.create(this.options), {
@ -280,7 +292,7 @@ Emitter(Timeline.prototype);
* @param {Object} options TODO: describe the available options
*/
Timeline.prototype.setOptions = function (options) {
util.extend(this.options, options);
util.deepExtend(this.options, options);
if ('editable' in options) {
var isBoolean = typeof options.editable === 'boolean';
@ -439,6 +451,33 @@ Timeline.prototype.setGroups = function setGroups(groups) {
this.itemSet.setGroups(newDataSet);
};
/**
* Clear the Timeline. By Default, items, groups and options are cleared.
* Example usage:
*
* timeline.clear(); // clear items, groups, and options
* timeline.clear({options: true}); // clear options only
*
* @param {Object} [what] Optionally specify what to clear. By default:
* {items: true, groups: true, options: true}
*/
Timeline.prototype.clear = function clear(what) {
// clear items
if (!what || what.items) {
this.setItems(null);
}
// clear groups
if (!what || what.groups) {
this.setGroups(null);
}
// clear options
if (!what || what.options) {
this.setOptions(this.defaultOptions);
}
};
/**
* Set Timeline window such that it fits all items
*/

+ 34
- 0
src/util.js View File

@ -97,6 +97,40 @@ util.extend = function (a, b) {
return a;
};
/**
* Deep extend an object a with the properties of object b
* @param {Object} a
* @param {Object} b
* @returns {Object}
*/
util.deepExtend = function deepExtend (a, b) {
// TODO: add support for Arrays to deepExtend
if (Array.isArray(b)) {
throw new TypeError('Arrays are not supported by deepExtend');
}
for (var prop in b) {
if (b.hasOwnProperty(prop)) {
if (b[prop] && b[prop].constructor === Object) {
if (a[prop] === undefined) {
a[prop] = {};
}
if (a[prop].constructor === Object) {
deepExtend(a[prop], b[prop]);
}
else {
a[prop] = b[prop];
}
} else if (Array.isArray(b[prop])) {
throw new TypeError('Arrays are not supported by deepExtend');
} else {
a[prop] = b[prop];
}
}
}
return a;
};
/**
* Test whether all elements in two arrays are equal.
* @param {Array} a

Loading…
Cancel
Save