in scripts/dashboard-importer/src/dashboards/converter/layout/layout_utils.ts [28:55]
export function getYOffsetToFit(
gridPos: GridPos, // Grid Position of panel that is we're trying to add
grid: Set<string>, // Grid of occupied string coordinates
yOffSet: number, // Existing yOffset
): number {
const {x: xPos, y: yPos, h: height, w: width} = gridPos;
let newYOffSet = yOffSet;
let overlapping = true;
while (overlapping) {
let succeeded = true;
outer: for (let y = yPos; y < yPos + height; y++) {
for (let x = xPos; x < xPos + width; x++) {
// Check for overlap
if (grid.has(x + ',' + (y + newYOffSet))) {
// If tiles overlap vertically offset all subsequent tiles by 1
newYOffSet++;
succeeded = false;
break outer;
}
}
}
if (succeeded) {
overlapping = false;
}
}
return newYOffSet;
}