Fix overlapping widgets when changing layout columns count
This commit is contained in:
parent
c6636ff6b8
commit
075b33f0fa
@ -753,8 +753,46 @@ export class DashboardUtilsService {
|
|||||||
const widget = layout.widgets[w];
|
const widget = layout.widgets[w];
|
||||||
widget.row = Math.round(widget.row * ratio);
|
widget.row = Math.round(widget.row * ratio);
|
||||||
widget.col = Math.round(widget.col * ratio);
|
widget.col = Math.round(widget.col * ratio);
|
||||||
widget.sizeX = Math.round(widget.sizeX * ratio);
|
widget.sizeX = Math.max(1, Math.round(widget.sizeX * ratio));
|
||||||
widget.sizeY = Math.round(widget.sizeY * 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--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user