@@ -85,54 +85,60 @@ async function resetDatabaseLayout() {
8585 }
8686}
8787
88- function initAutoResizeForCard ( cardId ) {
88+ function initAutoHeightGrid ( ) {
8989
90- const gridItem = document . getElementById ( cardId ) ;
91- const content = gridItem . querySelector ( ".card" ) ;
90+ const items = document . querySelectorAll ( ".grid-stack-item.auto-height" ) ;
9291
93- if ( ! gridItem || ! content ) return ;
92+ items . forEach ( item => {
9493
95- let resizeTimeout ;
94+ const content = item . querySelector ( ".grid-stack-item-content" ) ;
95+ const card = content ?. querySelector ( ".card" ) ;
9696
97- const observer = new ResizeObserver ( ( ) => {
97+ if ( ! content || ! card ) return ;
9898
99- // kleines Debounce (wichtig wegen Chart.js Render-Zyklen)
100- clearTimeout ( resizeTimeout ) ;
99+ let resizeTimeout ;
101100
102- resizeTimeout = setTimeout ( ( ) => {
101+ const resize = ( ) => {
103102
104- const newHeightPx = content . scrollHeight ;
103+ const rect = card . getBoundingClientRect ( ) ;
104+ const heightPx = rect . height ;
105105
106106 const cellHeight = dashboardGrid . getCellHeight ( ) ;
107- const newGridHeight = Math . ceil ( newHeightPx / cellHeight ) ;
107+ const newH = Math . ceil ( heightPx / cellHeight ) ;
108108
109- dashboardGrid . update ( gridItem , { h : newGridHeight } ) ;
109+ // 🔥 Nur updaten wenn nötig (sehr wichtig!)
110+ if ( item . gridstackNode . h !== newH ) {
111+ dashboardGrid . update ( item , { h : newH } ) ;
112+ }
113+ } ;
110114
111- } , 80 ) ; // Sweet Spot
115+ const observer = new ResizeObserver ( ( ) => {
112116
113- } ) ;
117+ clearTimeout ( resizeTimeout ) ;
114118
115- observer . observe ( content ) ;
116- }
119+ resizeTimeout = setTimeout ( ( ) => {
120+ resize ( ) ;
121+ } , 60 ) ; // debounce für Chart.js
117122
118- function forceGridResize ( cardId ) {
119- const gridItem = document . getElementById ( cardId ) ;
120- const content = gridItem . querySelector ( ".card" ) ;
123+ } ) ;
121124
122- if ( ! gridItem || ! content ) return ;
125+ observer . observe ( card ) ;
123126
124- const newHeightPx = content . scrollHeight ;
125- const cellHeight = dashboardGrid . getCellHeight ( ) ;
126- const newGridHeight = Math . ceil ( newHeightPx / cellHeight ) ;
127+ // 👉 initial nach Render
128+ setTimeout ( resize , 300 ) ;
127129
128- dashboardGrid . update ( gridItem , { h : newGridHeight } ) ;
130+ // 👉 fallback (Fonts / async Layout)
131+ requestAnimationFrame ( ( ) => {
132+ requestAnimationFrame ( resize ) ;
133+ } ) ;
134+ } ) ;
129135}
130136
131137document . addEventListener ( "DOMContentLoaded" , async ( ) => {
132138 // --- PHASE 1: Das Gerüst aufbauen ---
133139 initGridstack ( ) ;
134140 await loadLayout ( ) ; // Wartet, bis Boxen aus DB oder LocalStorage da sind
135- initAutoResizeForCard ( "card-forecast" ) ;
141+ initAutoHeightGrid ( ) ;
136142
137143 // --- PHASE 2: Startwerte für Datumsfelder setzen ---
138144 const t = new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
0 commit comments