Skip to content

Commit 78399b3

Browse files
author
jacquesbach
committed
Introduce Auto Card Resize
1 parent d2274d1 commit 78399b3

3 files changed

Lines changed: 67 additions & 24 deletions

File tree

static/css/style.css

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,12 @@
164164
}
165165

166166
.grid-stack-item-content {
167-
overflow-x: hidden;
168-
overflow-y: auto;
169-
overflow: visible !important;
167+
height: 100%;
168+
overflow: hidden;
170169
background: transparent !important;
171170
box-shadow: none !important;
172171
}
173-
172+
174173
.edit-mode .grid-stack-item-content {
175174
cursor: grab;
176175
border: 1px dashed var(--accent);
@@ -196,19 +195,19 @@
196195
display: flex;
197196
flex-direction: column;
198197
justify-content: center;
198+
height: 100%;
199+
}
200+
201+
.card canvas {
202+
width: 100% !important;
199203
}
200-
201-
background: var(--card-bg);
202-
203-
/* WICHTIG: Ändere 'center' auf 'flex-start' */
204-
205204

206205
.card-gradient {
207206
background: var(--gradient);
208207
color: white;
209208
box-shadow: 0 15px 35px rgba(255, 75, 114, 0.25);
210209
}
211-
210+
212211
.card-gradient .label {
213212
color: rgba(255, 255, 255, 0.85);
214213
font-size: 0.9em;

static/js/layout.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ function initGridstack() {
1515
dashboardGrid.on('change', function(event, items) {
1616
saveLayout();
1717
});
18+
19+
dashboardGrid.on('resizestop', function(event, el) {
20+
const charts = el.querySelectorAll("canvas");
21+
charts.forEach(canvas => {
22+
const chart = Chart.getChart(canvas);
23+
if (chart) {
24+
chart.resize();
25+
}
26+
});
27+
});
1828
}
1929

2030
// 2. Layout speichern (Nur in DB und nur wenn PW da ist)
@@ -85,10 +95,58 @@ async function resetDatabaseLayout() {
8595
}
8696
}
8797

98+
function resizeGridItemToContent(gridItemId) {
99+
100+
const el = document.getElementById(gridItemId);
101+
if (!el || !dashboardGrid) return;
102+
103+
const content = el.querySelector(".card");
104+
105+
const contentHeight = content.scrollHeight;
106+
107+
const cellHeight = dashboardGrid.getCellHeight();
108+
const margin = dashboardGrid.opts.margin;
109+
110+
const newHeight = Math.ceil((contentHeight + margin) / cellHeight);
111+
112+
dashboardGrid.update(el, { h: newHeight });
113+
}
114+
115+
function initAutoCardResize() {
116+
117+
const cards = document.querySelectorAll(".grid-stack-item");
118+
119+
const observer = new ResizeObserver(entries => {
120+
121+
entries.forEach(entry => {
122+
123+
const gridItem = entry.target.closest(".grid-stack-item");
124+
125+
if (!gridItem) return;
126+
127+
const id = gridItem.id;
128+
129+
resizeGridItemToContent(id);
130+
131+
});
132+
133+
});
134+
135+
cards.forEach(card => {
136+
137+
const content = card.querySelector(".card");
138+
139+
if (content) observer.observe(content);
140+
141+
});
142+
143+
}
144+
88145
document.addEventListener("DOMContentLoaded", async () => {
89146
// --- PHASE 1: Das Gerüst aufbauen ---
90147
initGridstack();
91148
await loadLayout(); // Wartet, bis Boxen aus DB oder LocalStorage da sind
149+
initAutoCardResize();
92150

93151
// --- PHASE 2: Startwerte für Datumsfelder setzen ---
94152
const t = new Date().toISOString().split('T')[0];

static/js/script.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,20 +1151,6 @@ function showShapDetails(point) {
11511151
};
11521152

11531153
const container = document.getElementById("shapForcePlot");
1154-
1155-
// ===== ResizeObserver nur einmal registrieren =====
1156-
if (!container._resizeObserverAttached) {
1157-
1158-
const observer = new ResizeObserver(() => {
1159-
if (window._lastShapPoint) {
1160-
showShapDetails(window._lastShapPoint);
1161-
}
1162-
});
1163-
1164-
observer.observe(container);
1165-
container._resizeObserverAttached = true;
1166-
}
1167-
11681154
container.innerHTML = "";
11691155
container.style.position = "relative";
11701156
container.style.display = "flex";

0 commit comments

Comments
 (0)