@ -15,6 +15,7 @@ function Group (groupId, data, itemSet) {
this . subgroupOrderer = data && data . subgroupOrder ;
this . subgroupOrderer = data && data . subgroupOrder ;
this . itemSet = itemSet ;
this . itemSet = itemSet ;
this . isVisible = null ;
this . isVisible = null ;
this . stackDirty = true ; // if true, items will be restacked on next redraw
if ( data && data . nestedGroups ) {
if ( data && data . nestedGroups ) {
this . nestedGroups = data . nestedGroups ;
this . nestedGroups = data . nestedGroups ;
@ -212,12 +213,12 @@ Group.prototype.getLabelWidth = function() {
* Repaint this group
* Repaint this group
* @ param { { start : number , end : number } } range
* @ param { { start : number , end : number } } range
* @ param { { item : { horizontal : number , vertical : number } , axis : number } } margin
* @ param { { item : { horizontal : number , vertical : number } , axis : number } } margin
* @ param { boolean } [ restack = false ] Force restacking of all items
* @ param { boolean } [ fo rceR estack= false ] Force restacking of all items
* @ return { boolean } Returns true if the group is resized
* @ return { boolean } Returns true if the group is resized
* /
* /
Group . prototype . redraw = function ( range , margin , restack ) {
Group . prototype . redraw = function ( range , margin , fo rceR estack) {
var resized = false ;
var resized = false ;
// force recalculation of the height of the items when the marker height changed
// 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)
// (due to the Timeline being attached to the DOM or changed from display:none to visible)
var markerHeight = this . dom . marker . clientHeight ;
var markerHeight = this . dom . marker . clientHeight ;
@ -228,9 +229,9 @@ Group.prototype.redraw = function(range, margin, restack) {
if ( item . displayed ) item . redraw ( ) ;
if ( item . displayed ) item . redraw ( ) ;
} ) ;
} ) ;
restack = true ;
}
fo rceR estack = true ;
}
// recalculate the height of the subgroups
// recalculate the height of the subgroups
this . _calculateSubGroupHeights ( margin ) ;
this . _calculateSubGroupHeights ( margin ) ;
@ -240,12 +241,15 @@ Group.prototype.redraw = function(range, margin, restack) {
this . right = foreground . offsetLeft ;
this . right = foreground . offsetLeft ;
this . width = foreground . offsetWidth ;
this . width = foreground . offsetWidth ;
var lastIsVisible = this . isVisible ;
this . isVisible = this . _isGroupVisible ( range , margin ) ;
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
// brute force restack of all items
// show all items
// show all items
@ -264,23 +268,24 @@ Group.prototype.redraw = function(range, margin, restack) {
return me . itemSet . options . order ( a . data , b . data ) ;
return me . itemSet . options . order ( a . data , b . data ) ;
} ) ;
} ) ;
stack . stack ( customOrderedItems , margin , true /* restack=true */ ) ;
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 ( ) ;
this . _updateSubgroupsSizes ( ) ;
// recalculate the height of the group
// recalculate the height of the group
@ -435,7 +440,7 @@ Group.prototype.hide = function() {
Group . prototype . add = function ( item ) {
Group . prototype . add = function ( item ) {
this . items [ item . id ] = item ;
this . items [ item . id ] = item ;
item . setParent ( this ) ;
item . setParent ( this ) ;
this . stackDirty = true ;
// add to
// add to
if ( item . data . subgroup !== undefined ) {
if ( item . data . subgroup !== undefined ) {
this . _addToSubgroup ( item ) ;
this . _addToSubgroup ( item ) ;
@ -540,6 +545,7 @@ Group.prototype.resetSubgroups = function() {
Group . prototype . remove = function ( item ) {
Group . prototype . remove = function ( item ) {
delete this . items [ item . id ] ;
delete this . items [ item . id ] ;
item . setParent ( null ) ;
item . setParent ( null ) ;
this . stackDirty = true ;
// remove from visible items
// remove from visible items
var index = this . visibleItems . indexOf ( item ) ;
var index = this . visibleItems . indexOf ( item ) ;