From 6fc2a655d53bb03b17696f27130d793b952a6de4 Mon Sep 17 00:00:00 2001 From: jos Date: Mon, 30 Nov 2015 14:54:45 +0100 Subject: [PATCH] Fixed #1441: Height of subgroups not immediately updated after updating data in a DataSet or DataView --- HISTORY.md | 3 +++ lib/timeline/component/Group.js | 30 ++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 0f2f49fd..12a4ed0a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,7 +4,10 @@ http://visjs.org ## not yet released, version 4.10.1-SNAPSHOT +### Timeline +- Fixed #1441: Height of subgroups not immediately updated after updating + data in a DataSet or DataView. ## 2015-11-27, version 4.10.0 diff --git a/lib/timeline/component/Group.js b/lib/timeline/component/Group.js index 51761959..8a09e4ae 100644 --- a/lib/timeline/component/Group.js +++ b/lib/timeline/component/Group.js @@ -177,6 +177,9 @@ Group.prototype.redraw = function(range, margin, restack) { restack = true; } + // recalculate the height of the subgroups + this._calculateSubGroupHeights(); + // reposition visible items vertically if (typeof this.itemSet.options.order === 'function') { // a custom order function @@ -244,6 +247,25 @@ Group.prototype.redraw = function(range, margin, restack) { return resized; }; +/** + * recalculate the height of the subgroups + * @private + */ +Group.prototype._calculateSubGroupHeights = function () { + if (Object.keys(this.subgroups).length > 0) { + var me = this; + + this.resetSubgroups(); + + util.forEach(this.visibleItems, function (item) { + if (item.data.subgroup !== undefined) { + me.subgroups[item.data.subgroup].height = Math.max(me.subgroups[item.data.subgroup].height, item.height); + me.subgroups[item.data.subgroup].visible = true; + } + }); + } +}; + /** * recalculate the height of the group * @param {{item: {horizontal: number, vertical: number}, axis: number}} margin @@ -254,20 +276,12 @@ Group.prototype._calculateHeight = function (margin) { // recalculate the height of the group var height; var visibleItems = this.visibleItems; - //var visibleSubgroups = []; - //this.visibleSubgroups = 0; - this.resetSubgroups(); - var me = this; if (visibleItems.length > 0) { var min = visibleItems[0].top; var max = visibleItems[0].top + visibleItems[0].height; util.forEach(visibleItems, function (item) { min = Math.min(min, item.top); max = Math.max(max, (item.top + item.height)); - if (item.data.subgroup !== undefined) { - me.subgroups[item.data.subgroup].height = Math.max(me.subgroups[item.data.subgroup].height,item.height); - me.subgroups[item.data.subgroup].visible = true; - } }); if (min > margin.axis) { // there is an empty gap between the lowest item and the axis