@@ -897,7 +897,40 @@ function FreeboardModel(datasourcePlugins, widgetPlugins, freeboardUI)
897897
898898 this . addPane = function ( pane )
899899 {
900- self . panes . push ( pane ) ;
900+ var newPaneHeight = pane . getCalculatedHeight ( ) ;
901+
902+ _ . each ( self . panes ( ) , function ( existingPane )
903+ {
904+ if ( _ . isNumber ( existingPane . row ) && _ . isNumber ( existingPane . col ) )
905+ {
906+ existingPane . row += newPaneHeight ;
907+ return ;
908+ }
909+
910+ if ( ! _ . isObject ( existingPane . row ) )
911+ {
912+ existingPane . row = { } ;
913+ }
914+
915+ _ . each ( existingPane . row , function ( rowValue , columnKey )
916+ {
917+ var currentRow = Number ( rowValue ) || 1 ;
918+ existingPane . row [ columnKey ] = currentRow + newPaneHeight ;
919+ } ) ;
920+ } ) ;
921+
922+ if ( ! _ . isObject ( pane . row ) )
923+ {
924+ pane . row = { } ;
925+ }
926+ if ( ! _ . isObject ( pane . col ) )
927+ {
928+ pane . col = { } ;
929+ }
930+
931+ pane . row [ 1 ] = 1 ;
932+ pane . col [ 1 ] = 1 ;
933+ self . panes . unshift ( pane ) ;
901934 freeboard . emit ( "config_updated" , self . getCurrentConfig ( ) ) ;
902935 }
903936
@@ -1243,18 +1276,25 @@ function FreeboardUI()
12431276
12441277 var elementHeight = Number ( $element . attr ( "data-sizey" ) ) ;
12451278 var elementWidth = Number ( $element . attr ( "data-sizex" ) ) ;
1279+ var heightChanged = calculatedHeight != elementHeight ;
1280+ var widthChanged = viewModel . col_width ( ) != elementWidth ;
12461281
1247- if ( calculatedHeight != elementHeight || viewModel . col_width ( ) != elementWidth )
1282+ if ( heightChanged || widthChanged )
12481283 {
12491284 grid . resize_widget ( $element , viewModel . col_width ( ) , calculatedHeight , function ( ) {
12501285 grid . set_dom_grid_height ( ) ;
12511286 } ) ;
1252- // If a resize introduces overlap (gridster doesn't resolve horizontal collisions on resize), rebuild layout.
1253- var currentCol = Number ( $element . attr ( "data-col" ) ) ;
1254- var currentRow = Number ( $element . attr ( "data-row" ) ) ;
1255- if ( ! grid . can_move_to ( { size_x : viewModel . col_width ( ) , size_y : calculatedHeight } , currentCol , currentRow ) )
1287+
1288+ // Let Gridster keep vertical growth stable when widgets are added to a pane.
1289+ // Only fall back to a full relayout when the pane width changes.
1290+ if ( widthChanged )
12561291 {
1257- processResize ( true ) ;
1292+ var currentCol = Number ( $element . attr ( "data-col" ) ) ;
1293+ var currentRow = Number ( $element . attr ( "data-row" ) ) ;
1294+ if ( ! grid . can_move_to ( { size_x : viewModel . col_width ( ) , size_y : calculatedHeight } , currentCol , currentRow ) )
1295+ {
1296+ processResize ( true ) ;
1297+ }
12581298 }
12591299 }
12601300 }
0 commit comments