Fix overlapping widgets when changing layout columns count

This commit is contained in:
Igor Kulikov 2024-10-14 10:40:43 +03:00
parent c6636ff6b8
commit 075b33f0fa

View File

@ -753,8 +753,46 @@ export class DashboardUtilsService {
const widget = layout.widgets[w];
widget.row = Math.round(widget.row * ratio);
widget.col = Math.round(widget.col * ratio);
widget.sizeX = Math.round(widget.sizeX * ratio);
widget.sizeY = Math.round(widget.sizeY * ratio);
widget.sizeX = Math.max(1, Math.round(widget.sizeX * ratio));
widget.sizeY = Math.max(1, Math.round(widget.sizeY * ratio));
}
for (const w of Object.keys(layout.widgets)) {
const widget = layout.widgets[w];
for (const w2 of Object.keys(layout.widgets)) {
const widget2 = layout.widgets[w2];
if (widget !== widget2) {
const left = widget.col;
const right = widget.col + widget.sizeX;
const top = widget.row;
const bottom = widget.row + widget.sizeY;
const left2 = widget2.col;
const right2 = widget2.col + widget2.sizeX;
const top2 = widget2.row;
const bottom2 = widget2.row + widget2.sizeY;
if (left < right2 && right > left2 &&
top > bottom2 && bottom < top2 ) {
let horizontalOverlapFixed = false;
if (right - left2 === 1) {
if (widget.sizeX > 1) {
widget.sizeX--;
horizontalOverlapFixed = true;
} else if (widget2.sizeX > 1) {
widget2.col++;
widget2.sizeX--;
horizontalOverlapFixed = true;
}
}
if (!horizontalOverlapFixed && (bottom - top2) === 1) {
if (widget.sizeY > 1) {
widget.sizeY--;
} else if (widget2.sizeY > 1) {
widget2.row++;
widget2.sizeY--;
}
}
}
}
}
}
}