@ -88,7 +88,8 @@ Group.prototype._create = function() {
// display:none is changed to visible.
// display:none is changed to visible.
this . dom . marker = document . createElement ( 'div' ) ;
this . dom . marker = document . createElement ( 'div' ) ;
this . dom . marker . style . visibility = 'hidden' ;
this . dom . marker . style . visibility = 'hidden' ;
this . dom . marker . innerHTML = '?' ;
this . dom . marker . style . position = 'absolute' ;
this . dom . marker . innerHTML = '' ;
this . dom . background . appendChild ( this . dom . marker ) ;
this . dom . background . appendChild ( this . dom . marker ) ;
} ;
} ;
@ -218,7 +219,7 @@ Group.prototype.redraw = function(range, margin, restack) {
}
}
// recalculate the height of the subgroups
// recalculate the height of the subgroups
this . _calculateSubGroupHeights ( ) ;
this . _calculateSubGroupHeights ( margin ) ;
// calculate actual size and position
// calculate actual size and position
var foreground = this . dom . foreground ;
var foreground = this . dom . foreground ;
@ -258,14 +259,17 @@ Group.prototype.redraw = function(range, margin, restack) {
// no custom order function, lazy stacking
// 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...
if ( this . itemSet . options . stack ) { // TODO: ugly way to access options...
stack . stack ( this . visibleItems , margin , restack ) ;
stack . stack ( this . visibleItems , margin , restack ) ;
}
}
else { // no stacking
else { // no stacking
stack . nostack ( this . visibleItems , margin , this . subgroups ) ;
stack . nostack ( this . visibleItems , margin , this . subgroups , this . itemSet . options . stackSubgroups ) ;
}
}
}
}
this . _updateSubgroupsSizes ( ) ;
// recalculate the height of the group
// recalculate the height of the group
var height = this . _calculateHeight ( margin ) ;
var height = this . _calculateHeight ( margin ) ;
@ -304,7 +308,7 @@ Group.prototype.redraw = function(range, margin, restack) {
* recalculate the height of the subgroups
* recalculate the height of the subgroups
* @ private
* @ private
* /
* /
Group . prototype . _calculateSubGroupHeights = function ( ) {
Group . prototype . _calculateSubGroupHeights = function ( margin ) {
if ( Object . keys ( this . subgroups ) . length > 0 ) {
if ( Object . keys ( this . subgroups ) . length > 0 ) {
var me = this ;
var me = this ;
@ -312,7 +316,7 @@ Group.prototype._calculateSubGroupHeights = function () {
util . forEach ( this . visibleItems , function ( item ) {
util . forEach ( this . visibleItems , function ( item ) {
if ( item . data . subgroup !== undefined ) {
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 ] . height = Math . max ( me . subgroups [ item . data . subgroup ] . height , item . height + margin . item . vertical ) ;
me . subgroups [ item . data . subgroup ] . visible = true ;
me . subgroups [ item . data . subgroup ] . visible = true ;
}
}
} ) ;
} ) ;
@ -422,9 +426,26 @@ Group.prototype.add = function(item) {
// add to
// add to
if ( item . data . subgroup !== undefined ) {
if ( item . data . subgroup !== undefined ) {
if ( this . subgroups [ item . data . subgroup ] === undefined ) {
if ( this . subgroups [ item . data . subgroup ] === undefined ) {
this . subgroups [ item . data . subgroup ] = { height : 0 , visible : false , index : this . subgroupIndex , items : [ ] } ;
this . subgroups [ item . data . subgroup ] = {
height : 0 ,
top : 0 ,
start : item . data . start ,
end : item . data . end ,
visible : false ,
index : this . subgroupIndex ,
items : [ ]
} ;
this . subgroupIndex ++ ;
this . subgroupIndex ++ ;
}
}
if ( new Date ( item . data . start ) < new Date ( this . subgroups [ item . data . subgroup ] . start ) ) {
this . subgroups [ item . data . subgroup ] . start = item . data . start ;
}
if ( new Date ( item . data . end ) > new Date ( this . subgroups [ item . data . subgroup ] . end ) ) {
this . subgroups [ item . data . subgroup ] . end = item . data . end ;
}
this . subgroups [ item . data . subgroup ] . items . push ( item ) ;
this . subgroups [ item . data . subgroup ] . items . push ( item ) ;
}
}
this . orderSubgroups ( ) ;
this . orderSubgroups ( ) ;
@ -435,6 +456,29 @@ Group.prototype.add = function(item) {
}
}
} ;
} ;
Group . prototype . _updateSubgroupsSizes = function ( ) {
var me = this ;
if ( me . subgroups ) {
for ( var subgroup in me . subgroups ) {
var newStart = me . subgroups [ subgroup ] . items [ 0 ] . data . start ;
var newEnd = me . subgroups [ subgroup ] . items [ 0 ] . data . end ;
me . subgroups [ subgroup ] . items . forEach ( function ( item ) {
if ( new Date ( item . data . start ) < new Date ( newStart ) ) {
newStart = item . data . start ;
}
if ( new Date ( item . data . end ) > new Date ( newEnd ) ) {
newEnd = item . data . end ;
}
} )
me . subgroups [ subgroup ] . start = newStart ;
me . subgroups [ subgroup ] . end = newEnd ;
}
}
}
Group . prototype . orderSubgroups = function ( ) {
Group . prototype . orderSubgroups = function ( ) {
if ( this . subgroupOrderer !== undefined ) {
if ( this . subgroupOrderer !== undefined ) {
var sortArray = [ ] ;
var sortArray = [ ] ;
@ -489,6 +533,8 @@ Group.prototype.remove = function(item) {
if ( ! subgroup . items . length ) {
if ( ! subgroup . items . length ) {
delete this . subgroups [ item . data . subgroup ] ;
delete this . subgroups [ item . data . subgroup ] ;
this . subgroupIndex -- ;
this . subgroupIndex -- ;
} else {
this . _updateSubgroupsSizes ( ) ;
}
}
this . orderSubgroups ( ) ;
this . orderSubgroups ( ) ;
}
}