|
|
@ -841,10 +841,14 @@ export class DashboardUtilsService { |
|
|
const widgets: WidgetLayout[] = []; |
|
|
const widgets: WidgetLayout[] = []; |
|
|
for (const w of Object.keys(layout.widgets)) { |
|
|
for (const w of Object.keys(layout.widgets)) { |
|
|
const widget = layout.widgets[w]; |
|
|
const widget = layout.widgets[w]; |
|
|
widget.row = Math.round(widget.row * ratio); |
|
|
const col = widget.col || 0; |
|
|
widget.col = Math.round(widget.col * ratio); |
|
|
const row = widget.row || 0; |
|
|
widget.sizeX = Math.max(1, Math.round(widget.sizeX * ratio)); |
|
|
const right = Math.round((col + widget.sizeX) * ratio); |
|
|
widget.sizeY = Math.max(1, Math.round(widget.sizeY * ratio)); |
|
|
const bottom = Math.round((row + widget.sizeY) * ratio); |
|
|
|
|
|
widget.col = Math.round(col * ratio); |
|
|
|
|
|
widget.row = Math.round(row * ratio); |
|
|
|
|
|
widget.sizeX = Math.max(1, right - widget.col); |
|
|
|
|
|
widget.sizeY = Math.max(1, bottom - widget.row); |
|
|
widgets.push(widget); |
|
|
widgets.push(widget); |
|
|
} |
|
|
} |
|
|
widgets.sort((w1, w2) => { |
|
|
widgets.sort((w1, w2) => { |
|
|
@ -890,6 +894,40 @@ export class DashboardUtilsService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
// The loop above only repairs a one unit overlap and mutates widgets it has already
|
|
|
|
|
|
// visited, so it may leave - or introduce - conflicts. Re-place whatever is still colliding.
|
|
|
|
|
|
this.resolveWidgetCollisions(widgets, gridSettings.minColumns || columns); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private resolveWidgetCollisions(widgets: WidgetLayout[], columns: number) { |
|
|
|
|
|
const placed: WidgetLayout[] = []; |
|
|
|
|
|
for (const widget of widgets) { |
|
|
|
|
|
if (this.hasWidgetCollision(widget.row, widget.col, widget.sizeX, widget.sizeY, placed)) { |
|
|
|
|
|
this.findFreeWidgetPosition(widget, placed, columns); |
|
|
|
|
|
} |
|
|
|
|
|
placed.push(widget); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private findFreeWidgetPosition(widgetLayout: WidgetLayout, widgetLayouts: WidgetLayout[], columns: number) { |
|
|
|
|
|
let maxCol = columns; |
|
|
|
|
|
let maxRow = 0; |
|
|
|
|
|
widgetLayouts.forEach(widget => { |
|
|
|
|
|
maxCol = Math.max(maxCol, widget.col + widget.sizeX); |
|
|
|
|
|
maxRow = Math.max(maxRow, widget.row + widget.sizeY); |
|
|
|
|
|
}); |
|
|
|
|
|
for (let row = 0; row <= maxRow; row++) { |
|
|
|
|
|
for (let col = 0; col + widgetLayout.sizeX <= maxCol; col++) { |
|
|
|
|
|
if (!this.hasWidgetCollision(row, col, widgetLayout.sizeX, widgetLayout.sizeY, widgetLayouts)) { |
|
|
|
|
|
widgetLayout.row = row; |
|
|
|
|
|
widgetLayout.col = col; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
// Wider than the grid: park it on a fresh row.
|
|
|
|
|
|
widgetLayout.row = maxRow; |
|
|
|
|
|
widgetLayout.col = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public moveWidgets(layout: DashboardLayout, cols: number, rows: number) { |
|
|
public moveWidgets(layout: DashboardLayout, cols: number, rows: number) { |
|
|
|