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

Nathanbennett improve timeline stack performance #3078

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
dcb2d58
Fix redraw order
yotamberk Dec 2, 2016
582fc64
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Dec 6, 2016
f96e6bf
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Dec 8, 2016
ffa8e0e
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Dec 17, 2016
2f04345
Fix error when option is not defined
yotamberk Dec 20, 2016
3cfa8d0
Allow template labels
yotamberk Dec 22, 2016
aee0fb3
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Dec 22, 2016
4681ace
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Dec 23, 2016
e9d1ebf
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Dec 31, 2016
cd37b2d
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Dec 31, 2016
9a27aa7
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Jan 5, 2017
4982679
Add .travis.yml file
yotamberk Jan 5, 2017
b9144d3
Add experiment travis code
yotamberk Jan 5, 2017
001fd9f
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Jan 15, 2017
e504dc7
Merge branch 'develop' of https://github.com/yotamberk/vis into develop
yotamberk Jan 15, 2017
ada1c90
Fix react example
yotamberk Jan 15, 2017
3124d8e
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Jan 27, 2017
4870ad2
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Feb 11, 2017
fae21a0
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Feb 15, 2017
91c2c31
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Mar 4, 2017
40bac1b
Improve redraw performance by not restacking non-visible groups (rela…
nathanbennett Mar 9, 2017
286fa0f
only restack necessary groups on redraw (related to #2835)
nathanbennett Mar 17, 2017
ea1d8c1
Merge branch 'develop' of https://github.com/almende/vis into develop
yotamberk Mar 18, 2017
457fa3e
Merge branch 'improve-timeline-stack-performance' of https://github.c…
yotamberk Mar 18, 2017
a345c70
Merge branch 'develop' into improve-timeline-stack-performance
mojoaxel Mar 18, 2017
eb8d979
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Mar 18, 2017
adabd7d
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Mar 20, 2017
1f7159d
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Mar 21, 2017
a76fc34
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Apr 11, 2017
51c6f3e
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Apr 20, 2017
90c4b83
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Apr 22, 2017
aac0790
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Apr 26, 2017
6922be5
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Apr 28, 2017
fcad011
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Apr 28, 2017
34d7505
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Apr 30, 2017
fcdc523
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk Apr 30, 2017
32c73fb
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk May 3, 2017
626d224
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk May 13, 2017
39168e8
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk May 15, 2017
24e648d
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk May 19, 2017
3a81085
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk May 19, 2017
8415b5b
Merge branch 'develop' into improve-timeline-stack-performance
yotamberk May 20, 2017
abaecdd
Merge branch 'develop' into improve-timeline-stack-performance
wimrijnders May 20, 2017
84424df
Merge branch 'improve-timeline-stack-performance' of https://github.c…
yotamberk May 20, 2017
a3bdf63
Merge branch 'develop' into nathanbennett-improve-timeline-stack-perf…
yotamberk May 20, 2017
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
4 changes: 2 additions & 2 deletions lib/timeline/component/BackgroundGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ BackgroundGroup.prototype = Object.create(Group.prototype);
* Repaint this group
* @param {{start: number, end: number}} range
* @param {{item: {horizontal: number, vertical: number}, axis: number}} margin
* @param {boolean} [restack=false] Force restacking of all items
* @param {boolean} [forceRestack=false] Force restacking of all items
* @return {boolean} Returns true if the group is resized
*/
BackgroundGroup.prototype.redraw = function(range, margin, restack) {
BackgroundGroup.prototype.redraw = function(range, margin, forceRestack) {
var resized = false;

this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);
Expand Down
54 changes: 30 additions & 24 deletions lib/timeline/component/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function Group (groupId, data, itemSet) {
this.subgroupOrderer = data && data.subgroupOrder;
this.itemSet = itemSet;
this.isVisible = null;
this.stackDirty = true; // if true, items will be restacked on next redraw

if (data && data.nestedGroups) {
this.nestedGroups = data.nestedGroups;
Expand Down Expand Up @@ -212,12 +213,12 @@ Group.prototype.getLabelWidth = function() {
* Repaint this group
* @param {{start: number, end: number}} range
* @param {{item: {horizontal: number, vertical: number}, axis: number}} margin
* @param {boolean} [restack=false] Force restacking of all items
* @param {boolean} [forceRestack=false] Force restacking of all items
* @return {boolean} Returns true if the group is resized
*/
Group.prototype.redraw = function(range, margin, restack) {
Group.prototype.redraw = function(range, margin, forceRestack) {
var resized = false;

// 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;
Expand All @@ -228,9 +229,9 @@ Group.prototype.redraw = function(range, margin, restack) {
if (item.displayed) item.redraw();
});

restack = true;
}

forceRestack = true;
}
// recalculate the height of the subgroups
this._calculateSubGroupHeights(margin);

Expand All @@ -240,12 +241,15 @@ Group.prototype.redraw = function(range, margin, restack) {
this.right = foreground.offsetLeft;
this.width = foreground.offsetWidth;

var lastIsVisible = this.isVisible;
this.isVisible = this._isGroupVisible(range, margin);
// reposition visible items vertically
if (typeof this.itemSet.options.order === 'function') {
// a custom order function

var restack = forceRestack || this.stackDirty || (this.isVisible && !lastIsVisible);

if (restack) {
// if restacking, reposition visible items vertically
if(restack) {
if (typeof this.itemSet.options.order === 'function') {
// a custom order function
// brute force restack of all items

// show all items
Expand All @@ -264,23 +268,24 @@ Group.prototype.redraw = function(range, margin, restack) {
return me.itemSet.options.order(a.data, b.data);
});
stack.stack(customOrderedItems, margin, true /* restack=true */);
}

this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);
}
else {
// no custom order function, lazy stacking
this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);

this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);

if (this.itemSet.options.stack) { // TODO: ugly way to access options...
stack.stack(this.visibleItems, margin, restack);
}
else { // no stacking
stack.nostack(this.visibleItems, margin, this.subgroups, this.itemSet.options.stackSubgroups);
else {
// no custom order function, lazy stacking
this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);

if (this.itemSet.options.stack) { // TODO: ugly way to access options...
stack.stack(this.visibleItems, margin, true /* restack=true */);
}
else { // no stacking
stack.nostack(this.visibleItems, margin, this.subgroups, this.itemSet.options.stackSubgroups);
}
}

this.stackDirty = false;
}

this._updateSubgroupsSizes();

// recalculate the height of the group
Expand Down Expand Up @@ -435,7 +440,7 @@ Group.prototype.hide = function() {
Group.prototype.add = function(item) {
this.items[item.id] = item;
item.setParent(this);

this.stackDirty = true;
// add to
if (item.data.subgroup !== undefined) {
this._addToSubgroup(item);
Expand Down Expand Up @@ -540,6 +545,7 @@ Group.prototype.resetSubgroups = function() {
Group.prototype.remove = function(item) {
delete this.items[item.id];
item.setParent(null);
this.stackDirty = true;

// remove from visible items
var index = this.visibleItems.indexOf(item);
Expand Down
18 changes: 4 additions & 14 deletions lib/timeline/component/ItemSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ function ItemSet(body, options) {
this.groupIds = [];

this.selection = []; // list with the ids of all selected nodes
this.stackDirty = true; // if true, all items will be restacked on next redraw

this.popup = null;

Expand Down Expand Up @@ -418,7 +417,6 @@ ItemSet.prototype.setOptions = function(options) {
*/
ItemSet.prototype.markDirty = function(options) {
this.groupIds = [];
this.stackDirty = true;

if (options && options.refreshItems) {
util.forEach(this.items, function (item) {
Expand Down Expand Up @@ -617,12 +615,11 @@ ItemSet.prototype.redraw = function() {
var visibleInterval = range.end - range.start;
var zoomed = (visibleInterval != this.lastVisibleInterval) || (this.props.width != this.props.lastWidth);
var scrolled = range.start != this.lastRangeStart;
if (zoomed || scrolled) this.stackDirty = true;
var forceRestack = (zoomed || scrolled);
this.lastVisibleInterval = visibleInterval;
this.lastRangeStart = range.start;
this.props.lastWidth = this.props.width;

var restack = this.stackDirty;
var firstGroup = this._firstGroup();
var firstMargin = {
item: margin.item,
Expand All @@ -636,17 +633,16 @@ ItemSet.prototype.redraw = function() {
var minHeight = margin.axis + margin.item.vertical;

// redraw the background group
this.groups[BACKGROUND].redraw(range, nonFirstMargin, restack);
this.groups[BACKGROUND].redraw(range, nonFirstMargin, forceRestack);

// redraw all regular groups
util.forEach(this.groups, function (group) {
var groupMargin = (group == firstGroup) ? firstMargin : nonFirstMargin;
var groupResized = group.redraw(range, groupMargin, restack);
var groupResized = group.redraw(range, groupMargin, forceRestack);
resized = groupResized || resized;
height += group.height;
});
height = Math.max(height, minHeight);
this.stackDirty = false;

// update frame height
frame.style.height = asSize(height);
Expand Down Expand Up @@ -978,7 +974,6 @@ ItemSet.prototype._onUpdate = function(ids) {
}.bind(this));

this._order();
this.stackDirty = true; // force re-stacking of all items next redraw
this.body.emitter.emit('_change', {queue: true});
};

Expand Down Expand Up @@ -1008,7 +1003,6 @@ ItemSet.prototype._onRemove = function(ids) {
if (count) {
// update order
this._order();
this.stackDirty = true; // force re-stacking of all items next redraw
this.body.emitter.emit('_change', {queue: true});
}
};
Expand Down Expand Up @@ -1540,7 +1534,6 @@ ItemSet.prototype._onDrag = function (event) {
//make sure we stay in bounds
newOffset = Math.max(0, newOffset);
newOffset = Math.min(me.groupIds.length-1, newOffset);

itemData.group = me.groupIds[newOffset];
}
}
Expand All @@ -1553,8 +1546,7 @@ ItemSet.prototype._onDrag = function (event) {
}
}.bind(this));
}.bind(this));

this.stackDirty = true; // force re-stacking of all items next redraw

this.body.emitter.emit('_change');
}
};
Expand Down Expand Up @@ -1607,7 +1599,6 @@ ItemSet.prototype._onDragEnd = function (event) {
}

// force re-stacking of all items next redraw
me.stackDirty = true;
me.body.emitter.emit('_change');
});
}
Expand All @@ -1624,7 +1615,6 @@ ItemSet.prototype._onDragEnd = function (event) {
// restore original values
props.item.setData(props.data);

me.stackDirty = true; // force re-stacking of all items next redraw
me.body.emitter.emit('_change');
}
});
Expand Down
3 changes: 2 additions & 1 deletion lib/timeline/component/item/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Item.prototype.setData = function(data) {
if (groupChanged && this.parent != null) {
this.parent.itemSet._moveToGroup(this, data.group);
}
this.parent.stackDirty = true;

var subGroupChanged = data.subgroup != undefined && this.data.subgroup != data.subgroup;
if (subGroupChanged && this.parent != null) {
Expand All @@ -78,7 +79,7 @@ Item.prototype.setData = function(data) {

/**
* Set a parent for the item
* @param {ItemSet | Group} parent
* @param {Group} parent
*/
Item.prototype.setParent = function(parent) {
if (this.displayed) {
Expand Down