Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

On timeline loaded #3530

Merged
merged 10 commits into from
Oct 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions docs/timeline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -886,71 +886,71 @@ <h2 id="Configuration_Options">Configuration Options</h2>
<td>Callback function triggered when an item is about to be added: when the user double taps an empty space in the Timeline. See section <a href="#Editing_Items">Editing Items</a> for more information. Only applicable when both options <code>selectable</code> and <code>editable.add</code> are set <code><code>true</code></code>.
</td>
</tr>

<tr>
<td>onAddGroup</td>
<td>function</td>
<td>none</td>
<td>Callback function triggered when a group is about to be added. The signature and semantics are the same as for <code>onAdd</code>.
</td>
</tr>

<tr>
<td>onUpdate</td>
<td>onInitialDrawComplete</td>
<td>function</td>
<td>none</td>
<td>Callback function triggered when an item is about to be updated, when the user double taps an item in the Timeline. See section <a href="#Editing_Items">Editing Items</a> for more information. Only applicable when both options <code>selectable</code> and <code>editable.updateTime</code> or <code>editable.updateGroup</code> are set <code><code>true</code></code>.
<td>Callback function triggered when the timeline is initially drawn. This function fires once per timeline creation.
</td>
</tr>

<tr>
<td>onMove</td>
<td>function</td>
<td>none</td>
<td>Callback function triggered when an item has been moved: after the user has dragged the item to an other position. See section <a href="#Editing_Items">Editing Items</a> for more information. Only applicable when both options <code>selectable</code> and <code>editable.updateTime</code> or <code>editable.updateGroup</code> are set <code><code>true</code></code>.
</td>
</tr>

<tr>
<td>onMoveGroup</td>
<td>function</td>
<td>none</td>
<td>Callback function triggered when a group has been moved: after the user has dragged the group to an other position. The signature and semantics are the same as for <code>onMove</code>.
</td>
</tr>

<tr>
<td>onMoving</td>
<td>function</td>
<td>none</td>
<td>Callback function triggered repeatedly when an item is being moved. See section <a href="#Editing_Items">Editing Items</a> for more information. Only applicable when both options <code>selectable</code> and <code>editable.updateTime</code> or <code>editable.updateGroup</code> are set <code><code>true</code></code>.
</td>
</tr>

<tr>
<td>onRemove</td>
<td>function</td>
<td>none</td>
<td>Callback function triggered when an item is about to be removed: when the user tapped the delete button on the top right of a selected item. See section <a href="#Editing_Items">Editing Items</a> for more information. Only applicable when both options <code>selectable</code> and <code>editable.remove</code> are set <code><code>true</code></code>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, why the double <code> tags? It happens more often in the docs.

</td>
</tr>

<tr>
<td>onRemoveGroup</td>
<td>function</td>
<td>none</td>
<td>Callback function triggered when a group is about to be removed. The signature and semantics are the same as for <code>onRemove</code>.
</td>
</tr>

<tr>
<td>onInitialDrawComplete</td>
<td>onUpdate</td>
<td>function</td>
<td>none</td>
<td>Callback function triggered when the timeline is initially drawn. This function fires once per timeline creation.
<td>Callback function triggered when an item is about to be updated, when the user double taps an item in the Timeline. See section <a href="#Editing_Items">Editing Items</a> for more information. Only applicable when both options <code>selectable</code> and <code>editable.updateTime</code> or <code>editable.updateGroup</code> are set <code><code>true</code></code>.
</td>
</tr>

<tr>
<td>order</td>
<td>function</td>
Expand Down
2 changes: 1 addition & 1 deletion examples/timeline/interaction/eventListeners.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
var container = document.getElementById('visualization');
var options = {
editable: true,
onInitialDrawComplete: function() { return logEvent('Timeline initial draw completed', {}) },
onInitialDrawComplete: function() { logEvent('Timeline initial draw completed', {}); },
};
var timeline = new vis.Timeline(container, items, options);

Expand Down
6 changes: 6 additions & 0 deletions lib/timeline/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ Core.prototype._create = function (container) {
this._redraw();
}
}.bind(this));
this.on('rangechanged', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a better place.

if (!this.initialRangeChangeDone) {
this.initialRangeChangeDone = true;
}
}.bind(this));
this.on('touch', this._onTouch.bind(this));
this.on('panmove', this._onDrag.bind(this));

Expand Down Expand Up @@ -319,6 +324,7 @@ Core.prototype._create = function (container) {

this.redrawCount = 0;
this.initialDrawDone = false;
this.initialRangeChangeDone = false;

// attach the root panel to the provided container
if (!container) throw new Error('No container provided');
Expand Down
27 changes: 14 additions & 13 deletions lib/timeline/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function Timeline (container, items, groups, options) {
// Create the DOM, props, and emitter
this._create(container);
if (!options || (options && typeof options.rtl == "undefined")) {
this.dom.root.style.visibility = 'hidden';
var directionFromDom, domNode = this.dom.root;
while (!directionFromDom && domNode) {
directionFromDom = window.getComputedStyle(domNode, null).direction;
Expand Down Expand Up @@ -173,9 +174,19 @@ function Timeline (container, items, groups, options) {

var start = me.options.start != undefined ? me.options.start : range.min;
var end = me.options.end != undefined ? me.options.end : range.max;
me.setWindow(start, end, {animation: false}, this._activateOnInitialDrawDone.bind(this));
me.setWindow(start, end, {animation: false});
} else {
me.fit({animation: false}, this._activateOnInitialDrawDone.bind(this));
me.fit({animation: false});
}
}

if (!me.initialDrawDone && me.initialRangeChangeDone) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes right. If I was just a bit clearer in my head I should have remarked on that. Make sense, not directly connected to the while-loop.

me.initialDrawDone = true;
me.dom.root.style.visibility = 'visible';
if (me.options.onInitialDrawComplete) {
setTimeout(() => {
return me.options.onInitialDrawComplete();
}, 0)
}
}
});
Expand All @@ -202,16 +213,6 @@ function Timeline (container, items, groups, options) {
// Extend the functionality from Core
Timeline.prototype = new Core();

Timeline.prototype._activateOnInitialDrawDone = function() {
if (!this.initialDrawDone) {
this.initialDrawDone = true;
setTimeout(() => {
if (this.options.onInitialDrawComplete) {
return this.options.onInitialDrawComplete();
}
}, 0)
}
}
/**
* Load a configurator
* @return {Object}
Expand Down Expand Up @@ -421,7 +422,7 @@ Timeline.prototype.focus = function(id, options) {
* provided to specify duration and easing function.
* Default duration is 500 ms, and default easing
* function is 'easeInOutQuad'.
* @param {Function} callback
* @param {function} [callback]
*/
Timeline.prototype.fit = function (options, callback) {
var animation = (options && options.animation !== undefined) ? options.animation : true;
Expand Down