@ -14,6 +14,7 @@ function Group (groupId, data, itemSet) {
this . subgroupIndex = 0 ;
this . subgroupIndex = 0 ;
this . subgroupOrderer = data && data . subgroupOrder ;
this . subgroupOrderer = data && data . subgroupOrder ;
this . itemSet = itemSet ;
this . itemSet = itemSet ;
this . isVisible = null ;
this . dom = { } ;
this . dom = { } ;
this . props = {
this . props = {
@ -180,6 +181,8 @@ Group.prototype.redraw = function(range, margin, restack) {
// recalculate the height of the subgroups
// recalculate the height of the subgroups
this . _calculateSubGroupHeights ( ) ;
this . _calculateSubGroupHeights ( ) ;
this . isVisible = this . _isGroupVisible ( range , margin ) ;
// reposition visible items vertically
// reposition visible items vertically
if ( typeof this . itemSet . options . order === 'function' ) {
if ( typeof this . itemSet . options . order === 'function' ) {
// a custom order function
// a custom order function
@ -219,6 +222,10 @@ Group.prototype.redraw = function(range, margin, restack) {
}
}
}
}
if ( ! this . isVisible && this . height ) {
return resized = false ;
}
// recalculate the height of the group
// recalculate the height of the group
var height = this . _calculateHeight ( margin ) ;
var height = this . _calculateHeight ( margin ) ;
@ -265,6 +272,17 @@ Group.prototype._calculateSubGroupHeights = function () {
}
}
} ;
} ;
/ * *
* check if group is visible
* @ private
* /
Group . prototype . _isGroupVisible = function ( range , margin ) {
var isVisible =
( this . top <= range . body . domProps . centerContainer . height - range . body . domProps . scrollTop + margin . axis )
&& ( this . top + this . height + margin . axis >= - range . body . domProps . scrollTop ) ;
return isVisible ;
}
/ * *
/ * *
* recalculate the height of the group
* recalculate the height of the group
* @ param { { item : { horizontal : number , vertical : number } , axis : number } } margin
* @ param { { item : { horizontal : number , vertical : number } , axis : number } } margin
@ -475,10 +493,18 @@ Group.prototype.order = function() {
Group . prototype . _updateVisibleItems = function ( orderedItems , oldVisibleItems , range ) {
Group . prototype . _updateVisibleItems = function ( orderedItems , oldVisibleItems , range ) {
var visibleItems = [ ] ;
var visibleItems = [ ] ;
var visibleItemsLookup = { } ; // we keep this to quickly look up if an item already exists in the list without using indexOf on visibleItems
var visibleItemsLookup = { } ; // we keep this to quickly look up if an item already exists in the list without using indexOf on visibleItems
if ( ! this . isVisible ) {
for ( var i = 0 ; i < oldVisibleItems . length ; i ++ ) {
var item = oldVisibleItems [ i ] ;
if ( item . displayed ) item . hide ( ) ;
}
return visibleItems ;
}
var interval = ( range . end - range . start ) / 4 ;
var interval = ( range . end - range . start ) / 4 ;
var lowerBound = range . start - interval ;
var lowerBound = range . start - interval ;
var upperBound = range . end + interval ;
var upperBound = range . end + interval ;
var item , i ;
// this function is used to do the binary search.
// this function is used to do the binary search.
var searchFunction = function ( value ) {
var searchFunction = function ( value ) {
@ -491,7 +517,7 @@ Group.prototype._updateVisibleItems = function(orderedItems, oldVisibleItems, ra
// IMPORTANT: this handles the case for the items with startdate before the window and enddate after the window!
// IMPORTANT: this handles the case for the items with startdate before the window and enddate after the window!
// also cleans up invisible items.
// also cleans up invisible items.
if ( oldVisibleItems . length > 0 ) {
if ( oldVisibleItems . length > 0 ) {
for ( i = 0 ; i < oldVisibleItems . length ; i ++ ) {
for ( var i = 0 ; i < oldVisibleItems . length ; i ++ ) {
this . _checkIfVisibleWithReference ( oldVisibleItems [ i ] , visibleItems , visibleItemsLookup , range ) ;
this . _checkIfVisibleWithReference ( oldVisibleItems [ i ] , visibleItems , visibleItemsLookup , range ) ;
}
}
}
}
@ -524,8 +550,8 @@ Group.prototype._updateVisibleItems = function(orderedItems, oldVisibleItems, ra
// finally, we reposition all the visible items.
// finally, we reposition all the visible items.
for ( i = 0 ; i < visibleItems . length ; i ++ ) {
item = visibleItems [ i ] ;
for ( var i = 0 ; i < visibleItems . length ; i ++ ) {
var item = visibleItems [ i ] ;
if ( ! item . displayed ) item . show ( ) ;
if ( ! item . displayed ) item . show ( ) ;
// reposition item horizontally
// reposition item horizontally
item . repositionX ( ) ;
item . repositionX ( ) ;
@ -548,12 +574,9 @@ Group.prototype._updateVisibleItems = function(orderedItems, oldVisibleItems, ra
} ;
} ;
Group . prototype . _traceVisible = function ( initialPos , items , visibleItems , visibleItemsLookup , breakCondition ) {
Group . prototype . _traceVisible = function ( initialPos , items , visibleItems , visibleItemsLookup , breakCondition ) {
var item ;
var i ;
if ( initialPos != - 1 ) {
if ( initialPos != - 1 ) {
for ( i = initialPos ; i >= 0 ; i -- ) {
item = items [ i ] ;
for ( var i = initialPos ; i >= 0 ; i -- ) {
var item = items [ i ] ;
if ( breakCondition ( item ) ) {
if ( breakCondition ( item ) ) {
break ;
break ;
}
}
@ -565,8 +588,8 @@ Group.prototype._traceVisible = function (initialPos, items, visibleItems, visib
}
}
}
}
for ( i = initialPos + 1 ; i < items . length ; i ++ ) {
item = items [ i ] ;
for ( var i = initialPos + 1 ; i < items . length ; i ++ ) {
var item = items [ i ] ;
if ( breakCondition ( item ) ) {
if ( breakCondition ( item ) ) {
break ;
break ;
}
}