Browse Source

Merge branch 'develop' of https://github.com/almende/vis into develop

Conflicts:
	dist/vis.js
css_transitions
Alex de Mulder 10 years ago
parent
commit
d5cc56a167
12 changed files with 224 additions and 31 deletions
  1. +10
    -2
      HISTORY.md
  2. +47
    -6
      dist/vis.js
  3. +10
    -10
      dist/vis.min.js
  4. +19
    -7
      docs/timeline.html
  5. +88
    -0
      examples/timeline/16_navigation_menu.html
  6. +1
    -0
      examples/timeline/index.html
  7. +1
    -0
      src/module/exports.js
  8. +14
    -1
      src/timeline/Timeline.js
  9. +22
    -1
      src/timeline/component/Group.js
  10. +1
    -0
      src/timeline/component/RootPanel.js
  11. +7
    -2
      src/timeline/component/TimeAxis.js
  12. +4
    -2
      test/timeline.html

+ 10
- 2
HISTORY.md View File

@ -1,17 +1,25 @@
# vis.js history # vis.js history
http://visjs.org http://visjs.org
## not yet released, version 1.0.2 ## not yet released, version 1.0.2
### Timeline ### Timeline
- Implemented option `minHeight`, similar to option `maxHeight`.
- Added function `repaint()` to force a repaint of the Timeline.
- Some tweaks in snapping dragged items to nice dates. - Some tweaks in snapping dragged items to nice dates.
- Made the instance of moment.js packaged with vis.js accessibly via `vis.moment`.
- A newly created item is initialized with `end` property when option `type`
is `"range"` or `"rangeoverflow"`.
- Fixed a bug in replacing the DataSet of groups via `Timeline.setGroups(groups)`. - Fixed a bug in replacing the DataSet of groups via `Timeline.setGroups(groups)`.
- Fixed a bug when rendering the Timeline inside a hidden container.
### Graph ### Graph
- added zoomable and moveable options.
- changes setOptions to avoid resetting view.
- Added zoomable and moveable options.
- Changes setOptions to avoid resetting view.
## 2014-05-09, version 1.0.1 ## 2014-05-09, version 1.0.1

+ 47
- 6
dist/vis.js View File

@ -4,8 +4,8 @@
* *
* A dynamic, browser-based visualization library. * A dynamic, browser-based visualization library.
* *
* @version 1.0.2-SNAPSHOT
* @date 2014-05-28
* @version @@version
* @date @@date
* *
* @license * @license
* Copyright (C) 2011-2014 Almende B.V, http://almende.com * Copyright (C) 2011-2014 Almende B.V, http://almende.com
@ -3917,6 +3917,7 @@ RootPanel.prototype.repaint = function repaint() {
// update frame size // update frame size
this.frame.style.maxHeight = util.option.asSize(this.options.maxHeight, ''); this.frame.style.maxHeight = util.option.asSize(this.options.maxHeight, '');
this.frame.style.minHeight = util.option.asSize(this.options.minHeight, '');
this._updateSize(); this._updateSize();
// if the root panel or any of its childs is resized, repaint again, // if the root panel or any of its childs is resized, repaint again,
@ -4399,8 +4400,12 @@ TimeAxis.prototype._repaintLine = function() {
* @private * @private
*/ */
TimeAxis.prototype._calculateCharSize = function () { TimeAxis.prototype._calculateCharSize = function () {
// Note: We only calculate char size once, but in case it is calculated as zero,
// we will recalculate. This is the case if any of the timelines parents
// has display:none for example.
// determine the char width and height on the minor axis // determine the char width and height on the minor axis
if (!('minorCharHeight' in this.props)) {
if (!('minorCharHeight' in this.props) || this.props.minorCharHeight == 0) {
var textMinor = document.createTextNode('0'); var textMinor = document.createTextNode('0');
var measureCharMinor = document.createElement('DIV'); var measureCharMinor = document.createElement('DIV');
measureCharMinor.className = 'text minor measure'; measureCharMinor.className = 'text minor measure';
@ -4413,7 +4418,8 @@ TimeAxis.prototype._calculateCharSize = function () {
this.frame.removeChild(measureCharMinor); this.frame.removeChild(measureCharMinor);
} }
if (!('majorCharHeight' in this.props)) {
// determine the char width and height on the major axis
if (!('majorCharHeight' in this.props) || this.props.majorCharHeight == 0) {
var textMajor = document.createTextNode('0'); var textMajor = document.createTextNode('0');
var measureCharMajor = document.createElement('DIV'); var measureCharMajor = document.createElement('DIV');
measureCharMajor.className = 'text major measure'; measureCharMajor.className = 'text major measure';
@ -6754,6 +6760,14 @@ Group.prototype._create = function() {
this.dom.background = document.createElement('div'); this.dom.background = document.createElement('div');
this.dom.axis = document.createElement('div'); this.dom.axis = document.createElement('div');
// create a hidden marker to detect when the Timelines container is attached
// to the DOM, or the style of a parent of the Timeline is changed from
// display:none is changed to visible.
this.dom.marker = document.createElement('div');
this.dom.marker.style.visibility = 'hidden';
this.dom.marker.innerHTML = '?';
this.dom.background.appendChild(this.dom.marker);
}; };
/** /**
@ -6825,6 +6839,20 @@ Group.prototype.repaint = function repaint(range, margin, restack) {
this.visibleItems = this._updateVisibleItems(this.orderedItems, this.visibleItems, range); this.visibleItems = this._updateVisibleItems(this.orderedItems, this.visibleItems, range);
// force recalculation of the height of the items when the marker height changed
// (due to the Timeline being attached to the DOM or changed from display:none to visible)
var markerHeight = this.dom.marker.clientHeight;
if (markerHeight != this.lastMarkerHeight) {
this.lastMarkerHeight = markerHeight;
util.forEach(this.items, function (item) {
item.dirty = true;
if (item.displayed) item.repaint();
});
restack = true;
}
// reposition visible items vertically // reposition visible items vertically
if (this.itemSet.options.stack) { // TODO: ugly way to access options... if (this.itemSet.options.stack) { // TODO: ugly way to access options...
stack.stack(this.visibleItems, margin, restack); stack.stack(this.visibleItems, margin, restack);
@ -6832,7 +6860,6 @@ Group.prototype.repaint = function repaint(range, margin, restack) {
else { // no stacking else { // no stacking
stack.nostack(this.visibleItems, margin); stack.nostack(this.visibleItems, margin);
} }
this.stackDirty = false;
for (var i = 0, ii = this.visibleItems.length; i < ii; i++) { for (var i = 0, ii = this.visibleItems.length; i < ii; i++) {
var item = this.visibleItems[i]; var item = this.visibleItems[i];
item.repositionY(); item.repositionY();
@ -7691,7 +7718,7 @@ Timeline.prototype.getSelection = function getSelection() {
* Where start and end can be a Date, number, or string, and range is an * Where start and end can be a Date, number, or string, and range is an
* object with properties start and end. * object with properties start and end.
* *
* @param {Date | Number | String} [start] Start date of visible window
* @param {Date | Number | String | Object} [start] Start date of visible window
* @param {Date | Number | String} [end] End date of visible window * @param {Date | Number | String} [end] End date of visible window
*/ */
Timeline.prototype.setWindow = function setWindow(start, end) { Timeline.prototype.setWindow = function setWindow(start, end) {
@ -7716,6 +7743,14 @@ Timeline.prototype.getWindow = function setWindow() {
}; };
}; };
/**
* Force a repaint of the Timeline. Can be useful to manually repaint when
* option autoResize=false
*/
Timeline.prototype.repaint = function repaint() {
this.rootPanel.repaint();
};
/** /**
* Handle selecting/deselecting an item when tapping it * Handle selecting/deselecting an item when tapping it
* @param {Event} event * @param {Event} event
@ -7782,6 +7817,11 @@ Timeline.prototype._onAddItem = function (event) {
content: 'new item' content: 'new item'
}; };
// when default type is a range, add a default end date to the new item
if (this.options.type === 'range' || this.options.type == 'rangeoverflow') {
newItem.end = this.timeAxis.snap(this._toTime(x + this.rootPanel.width / 5));
}
var id = util.randomUUID(); var id = util.randomUUID();
newItem[this.itemsData.fieldId] = id; newItem[this.itemsData.fieldId] = id;
@ -17753,6 +17793,7 @@ Graph.prototype.storePosition = function() {
*/ */
var vis = { var vis = {
util: util, util: util,
moment: moment,
DataSet: DataSet, DataSet: DataSet,
DataView: DataView, DataView: DataView,

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


+ 19
- 7
docs/timeline.html View File

@ -341,8 +341,7 @@ var options = {
<td>autoResize</td> <td>autoResize</td>
<td>boolean</td> <td>boolean</td>
<td>true</td> <td>true</td>
<td>If true, the Timeline will automatically detect when its
container is resized, and redraw itself accordingly.</td>
<td>If true, the Timeline will automatically detect when its container is resized, and redraw itself accordingly. If false, the Timeline can be forced to repaint after its container has been resized using the function <code>repaint()</code>.</td>
</tr> </tr>
<tr> <tr>
@ -402,7 +401,7 @@ var options = {
<tr> <tr>
<td>height</td> <td>height</td>
<td>String</td>
<td>Number | String</td>
<td>none</td> <td>none</td>
<td>The height of the timeline in pixels or as a percentage. <td>The height of the timeline in pixels or as a percentage.
When height is undefined or null, the height of the timeline is automatically When height is undefined or null, the height of the timeline is automatically
@ -438,10 +437,9 @@ var options = {
<tr> <tr>
<td>maxHeight</td> <td>maxHeight</td>
<td>Number</td>
<td>Number | String</td>
<td>none</td> <td>none</td>
<td>Specifies a maximum height for the Timeline in pixels.
</td>
<td>Specifies the maximum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
</tr> </tr>
<tr> <tr>
@ -453,6 +451,13 @@ var options = {
</td> </td>
</tr> </tr>
<tr>
<td>minHeight</td>
<td>Number | String</td>
<td>none</td>
<td>Specifies the minimum height for the Timeline. Can be a number in pixels or a string like "300px".</td>
</tr>
<tr> <tr>
<td>onAdd</td> <td>onAdd</td>
<td>Function</td> <td>Function</td>
@ -583,7 +588,7 @@ var options = {
<td>type</td> <td>type</td>
<td>String</td> <td>String</td>
<td>'box'</td> <td>'box'</td>
<td>Specifies the type for the timeline items. Choose from 'box', 'point', 'range', and 'rangeoverflow'. Note that individual items can override this global type.
<td>Specifies the default type for the timeline items. Choose from 'box', 'point', 'range', and 'rangeoverflow'. Note that individual items can override this default type.
</td> </td>
</tr> </tr>
@ -673,6 +678,13 @@ var options = {
<td>Remove an event listener created before via function <code>on(event, callback)</code>. See section <a href="#Events">Events for more information</a>.</td> <td>Remove an event listener created before via function <code>on(event, callback)</code>. See section <a href="#Events">Events for more information</a>.</td>
</tr> </tr>
<tr>
<td>repaint()</td>
<td>none</td>
<td>Force a repaint of the Timeline. Can be useful to manually repaint when option autoResize=false.
</td>
</tr>
<tr> <tr>
<td>setGroups(groups)</td> <td>setGroups(groups)</td>
<td>none</td> <td>none</td>

+ 88
- 0
examples/timeline/16_navigation_menu.html View File

@ -0,0 +1,88 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Timeline | navigation menu</title>
<style type="text/css">
body, html, input {
font-family: sans-serif;
font-size: 12pt;
}
#visualization {
position: relative;
}
.menu {
position: absolute;
top: 0;
right: 0;
margin: 10px;
z-index: 9999;
}
</style>
<script src="../../dist/vis.js"></script>
<link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="visualization">
<div class="menu">
<input type="button" id="zoomIn" value="Zoom in"/>
<input type="button" id="zoomOut" value="Zoom out"/>
<input type="button" id="moveLeft" value="Move left"/>
<input type="button" id="moveRight" value="Move right"/>
</div>
</div>
<script type="text/javascript">
// create a timeline with some data
var container = document.getElementById('visualization');
var items = [
{id: 1, content: 'item 1', start: '2014-04-20'},
{id: 2, content: 'item 2', start: '2014-04-14'},
{id: 3, content: 'item 3', start: '2014-04-18'},
{id: 4, content: 'item 4', start: '2014-04-16', end: '2014-04-19'},
{id: 5, content: 'item 5', start: '2014-04-25'},
{id: 6, content: 'item 6', start: '2014-04-27', type: 'point'}
];
var options = {};
var timeline = new vis.Timeline(container, items, options);
/**
* Move the timeline a given percentage to left or right
* @param {Number} percentage For example 0.1 (left) or -0.1 (right)
*/
function move (percentage) {
var range = timeline.getWindow();
var interval = range.end - range.start;
timeline.setWindow({
start: range.start.valueOf() - interval * percentage,
end: range.end.valueOf() - interval * percentage
});
}
/**
* Zoom the timeline a given percentage in or out
* @param {Number} percentage For example 0.1 (zoom out) or -0.1 (zoom in)
*/
function zoom (percentage) {
var range = timeline.getWindow();
var interval = range.end - range.start;
timeline.setWindow({
start: range.start.valueOf() - interval * percentage,
end: range.end.valueOf() + interval * percentage
});
}
// attach events to the navigation buttons
document.getElementById('zoomIn').onclick = function () { zoom(-0.2); };
document.getElementById('zoomOut').onclick = function () { zoom( 0.2); };
document.getElementById('moveLeft').onclick = function () { move( 0.2); };
document.getElementById('moveRight').onclick = function () { move(-0.2); };
</script>
</body>
</html>

+ 1
- 0
examples/timeline/index.html View File

@ -27,6 +27,7 @@
<p><a href="13_past_and_future.html">13_past_and_future.html</a></p> <p><a href="13_past_and_future.html">13_past_and_future.html</a></p>
<p><a href="14_a_lot_of_grouped_data.html">14_a_lot_of_grouped_data.html</a></p> <p><a href="14_a_lot_of_grouped_data.html">14_a_lot_of_grouped_data.html</a></p>
<p><a href="15_item_class_names.html">15_item_class_names.html</a></p> <p><a href="15_item_class_names.html">15_item_class_names.html</a></p>
<p><a href="16_navigation_menu.html">16_navigation_menu.html</a></p>
<p><a href="requirejs/requirejs_example.html">requirejs_example.html</a></p> <p><a href="requirejs/requirejs_example.html">requirejs_example.html</a></p>

+ 1
- 0
src/module/exports.js View File

@ -3,6 +3,7 @@
*/ */
var vis = { var vis = {
util: util, util: util,
moment: moment,
DataSet: DataSet, DataSet: DataSet,
DataView: DataView, DataView: DataView,

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

@ -535,7 +535,7 @@ Timeline.prototype.getSelection = function getSelection() {
* Where start and end can be a Date, number, or string, and range is an * Where start and end can be a Date, number, or string, and range is an
* object with properties start and end. * object with properties start and end.
* *
* @param {Date | Number | String} [start] Start date of visible window
* @param {Date | Number | String | Object} [start] Start date of visible window
* @param {Date | Number | String} [end] End date of visible window * @param {Date | Number | String} [end] End date of visible window
*/ */
Timeline.prototype.setWindow = function setWindow(start, end) { Timeline.prototype.setWindow = function setWindow(start, end) {
@ -560,6 +560,14 @@ Timeline.prototype.getWindow = function setWindow() {
}; };
}; };
/**
* Force a repaint of the Timeline. Can be useful to manually repaint when
* option autoResize=false
*/
Timeline.prototype.repaint = function repaint() {
this.rootPanel.repaint();
};
/** /**
* Handle selecting/deselecting an item when tapping it * Handle selecting/deselecting an item when tapping it
* @param {Event} event * @param {Event} event
@ -626,6 +634,11 @@ Timeline.prototype._onAddItem = function (event) {
content: 'new item' content: 'new item'
}; };
// when default type is a range, add a default end date to the new item
if (this.options.type === 'range' || this.options.type == 'rangeoverflow') {
newItem.end = this.timeAxis.snap(this._toTime(x + this.rootPanel.width / 5));
}
var id = util.randomUUID(); var id = util.randomUUID();
newItem[this.itemsData.fieldId] = id; newItem[this.itemsData.fieldId] = id;

+ 22
- 1
src/timeline/component/Group.js View File

@ -51,6 +51,14 @@ Group.prototype._create = function() {
this.dom.background = document.createElement('div'); this.dom.background = document.createElement('div');
this.dom.axis = document.createElement('div'); this.dom.axis = document.createElement('div');
// create a hidden marker to detect when the Timelines container is attached
// to the DOM, or the style of a parent of the Timeline is changed from
// display:none is changed to visible.
this.dom.marker = document.createElement('div');
this.dom.marker.style.visibility = 'hidden';
this.dom.marker.innerHTML = '?';
this.dom.background.appendChild(this.dom.marker);
}; };
/** /**
@ -122,6 +130,20 @@ Group.prototype.repaint = function repaint(range, margin, restack) {
this.visibleItems = this._updateVisibleItems(this.orderedItems, this.visibleItems, range); this.visibleItems = this._updateVisibleItems(this.orderedItems, this.visibleItems, range);
// force recalculation of the height of the items when the marker height changed
// (due to the Timeline being attached to the DOM or changed from display:none to visible)
var markerHeight = this.dom.marker.clientHeight;
if (markerHeight != this.lastMarkerHeight) {
this.lastMarkerHeight = markerHeight;
util.forEach(this.items, function (item) {
item.dirty = true;
if (item.displayed) item.repaint();
});
restack = true;
}
// reposition visible items vertically // reposition visible items vertically
if (this.itemSet.options.stack) { // TODO: ugly way to access options... if (this.itemSet.options.stack) { // TODO: ugly way to access options...
stack.stack(this.visibleItems, margin, restack); stack.stack(this.visibleItems, margin, restack);
@ -129,7 +151,6 @@ Group.prototype.repaint = function repaint(range, margin, restack) {
else { // no stacking else { // no stacking
stack.nostack(this.visibleItems, margin); stack.nostack(this.visibleItems, margin);
} }
this.stackDirty = false;
for (var i = 0, ii = this.visibleItems.length; i < ii; i++) { for (var i = 0, ii = this.visibleItems.length; i < ii; i++) {
var item = this.visibleItems[i]; var item = this.visibleItems[i];
item.repositionY(); item.repositionY();

+ 1
- 0
src/timeline/component/RootPanel.js View File

@ -101,6 +101,7 @@ RootPanel.prototype.repaint = function repaint() {
// update frame size // update frame size
this.frame.style.maxHeight = util.option.asSize(this.options.maxHeight, ''); this.frame.style.maxHeight = util.option.asSize(this.options.maxHeight, '');
this.frame.style.minHeight = util.option.asSize(this.options.minHeight, '');
this._updateSize(); this._updateSize();
// if the root panel or any of its childs is resized, repaint again, // if the root panel or any of its childs is resized, repaint again,

+ 7
- 2
src/timeline/component/TimeAxis.js View File

@ -407,8 +407,12 @@ TimeAxis.prototype._repaintLine = function() {
* @private * @private
*/ */
TimeAxis.prototype._calculateCharSize = function () { TimeAxis.prototype._calculateCharSize = function () {
// Note: We only calculate char size once, but in case it is calculated as zero,
// we will recalculate. This is the case if any of the timelines parents
// has display:none for example.
// determine the char width and height on the minor axis // determine the char width and height on the minor axis
if (!('minorCharHeight' in this.props)) {
if (!('minorCharHeight' in this.props) || this.props.minorCharHeight == 0) {
var textMinor = document.createTextNode('0'); var textMinor = document.createTextNode('0');
var measureCharMinor = document.createElement('DIV'); var measureCharMinor = document.createElement('DIV');
measureCharMinor.className = 'text minor measure'; measureCharMinor.className = 'text minor measure';
@ -421,7 +425,8 @@ TimeAxis.prototype._calculateCharSize = function () {
this.frame.removeChild(measureCharMinor); this.frame.removeChild(measureCharMinor);
} }
if (!('majorCharHeight' in this.props)) {
// determine the char width and height on the major axis
if (!('majorCharHeight' in this.props) || this.props.majorCharHeight == 0) {
var textMajor = document.createTextNode('0'); var textMajor = document.createTextNode('0');
var measureCharMajor = document.createElement('DIV'); var measureCharMajor = document.createElement('DIV');
measureCharMajor.className = 'text major measure'; measureCharMajor.className = 'text major measure';

+ 4
- 2
test/timeline.html View File

@ -69,9 +69,11 @@
{_id: 1, content: 'item 1<br>start', start: now.clone().add('days', 4).toDate()}, {_id: 1, content: 'item 1<br>start', start: now.clone().add('days', 4).toDate()},
{_id: 2, content: 'item 2', start: now.clone().add('days', -2).toDate() }, {_id: 2, content: 'item 2', start: now.clone().add('days', -2).toDate() },
{_id: 3, content: 'item 3', start: now.clone().add('days', 2).toDate()}, {_id: 3, content: 'item 3', start: now.clone().add('days', 2).toDate()},
{_id: 4, content: 'item 4',
{
_id: 4, content: 'item 4',
start: now.clone().add('days', 0).toDate(), start: now.clone().add('days', 0).toDate(),
end: now.clone().add('days', 7).toDate()},
end: now.clone().add('days', 7).toDate()
},
{_id: 5, content: 'item 5', start: now.clone().add('days', 9).toDate(), type:'point'}, {_id: 5, content: 'item 5', start: now.clone().add('days', 9).toDate(), type:'point'},
{_id: 6, content: 'item 6', start: now.clone().add('days', 11).toDate()} {_id: 6, content: 'item 6', start: now.clone().add('days', 11).toDate()}
]); ]);

Loading…
Cancel
Save