From 5bfd3e404552cdecbb385db90e7e6409ad7399e6 Mon Sep 17 00:00:00 2001 From: furest Date: Thu, 23 Oct 2025 22:30:20 +0200 Subject: [PATCH 1/4] calculate grid dimensions --- src/dhmap.js | 69 ++++++++++++++++++++++----------------------- src/ipplan2dhmap.py | 5 +++- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/dhmap.js b/src/dhmap.js index 989e83e..99df3a8 100644 --- a/src/dhmap.js +++ b/src/dhmap.js @@ -249,7 +249,7 @@ var dhmap = {}; var hallsizelist = []; for ( var hall in objects ) { - if (hall.toLowerCase() == "dist" || hall.toLowerCase() == "prod") + if (hall.toLowerCase() == "dist" || hall.toLowerCase() == "prod" || hall.toLowerCase() == "grid") continue; // Calculate new bounding box for this hall @@ -272,52 +272,49 @@ var dhmap = {}; } // Second phase: Figure out hall order. - hallsizelist.sort(function(a, b) { return a[0] - b[0]; }); - hallsizelist.reverse(); + // Generate 2D array from the halls position objects + // Find grid size + const maxrows = Math.max(...positions.map(p => p.x1)); + const maxcols = Math.max(...positions.map(p => p.y1)); + var hallgrid = Array.from({ length: maxcols + 1 }, () => + Array.from({ length: maxrows + 1 }, () => null) + ); + + objects["Grid"].forEach(h => { + hallgrid[h.y1][h.x1] = h.name + }); - var hallorder = []; - for ( var i in hallsizelist ) { - hallorder.push(hallsizelist[i][1]); - } - - // Third pass: Order halls in size order. - // Try to compact halls if possible. - var maxHallHeight = hallsizes[hallorder[0]].h; - var maxX = 0; var padY = 100; var padX = 100; - for ( var j in hallorder ) { - var hall = hallorder[j]; + const colswidths = Array.from({length: maxcols + 1}, () => padX) + const rowsheights = Array.from({length: maxcols + 1}, () => padY) - boundingX = 0; - boundingY = 0; + for (let y = 0; y < maxrows+1; y++) { + var maxHeight = 0; + for (let x = 0; x < maxcols+1; x++) { + const hallName = hallgrid[y][x]; + const hall = hallsizes[hallName]; - for ( var i in objects[hall] ) { - renders[objects[hall][i]['class']](objects[hall][i], true); + if (hall && hall.h > maxHeight) { + maxHeight = hall.h; + } } - hallsizes[hall] = { - 'x': offsetX, - 'y': offsetY, - 'w': boundingX, - 'h': boundingY, - }; + rowsheights[y] = maxHeight; + } - if (maxX < offsetX + boundingX + padX) { - maxX = offsetX + boundingX + padX; - } + for (let x = 0; x < maxcols+1; x++) { + var maxWidth = 0; + for (let y = 0; y < maxrows+1; y++) { + const hallName = grid[y][x]; + const hall = hallsizes[hallName]; - // Look ahead and see where if we can squeeze the hall in below this one. - var nj = parseInt(j) + 1; - if (nj < hallorder.length) { - var nextHall = hallorder[nj]; - if ((hallsizes[hall].y + hallsizes[hall].h + padY + hallsizes[nextHall].h) < maxHallHeight) { - offsetY += boundingY + padY; - } else { - offsetY = 0; - offsetX = maxX; + if (hall && hall.w > maxWidth) { + maxWidth = hall.w; } } + + colswidths[x] = maxWidth; } // Fourth phase: draw bounding boxes of halls. diff --git a/src/ipplan2dhmap.py b/src/ipplan2dhmap.py index c966391..0d85ace 100755 --- a/src/ipplan2dhmap.py +++ b/src/ipplan2dhmap.py @@ -27,7 +27,10 @@ ' FROM host h INNER JOIN option o ON o.node_id = h.node_id' ' LEFT JOIN switch_coordinates sc ON sc.name = h.name' ' WHERE sc.name IS NULL AND o.name = "layer" AND o.value = "access" AND h.name LIKE "%prod%"' - + + ' UNION SELECT hp.name name, 0 horizontal, "hall" class, "Grid" hall, hp.x x1, hp.y y1, 0 x2, 0 y2, 0 height, 0 width' + ' FROM hall_positions hp' + ' ORDER BY hall' ) results = c.fetchall() From 70923e5bd8e9932772916e26e93038c93f51c75b Mon Sep 17 00:00:00 2001 From: Yannick Diepart Date: Sat, 25 Oct 2025 15:45:32 +0200 Subject: [PATCH 2/4] Draw halls according to the grid pattern from seatmap --- src/dhmap.js | 127 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 84 insertions(+), 43 deletions(-) diff --git a/src/dhmap.js b/src/dhmap.js index 99df3a8..bb5aa14 100644 --- a/src/dhmap.js +++ b/src/dhmap.js @@ -274,25 +274,36 @@ var dhmap = {}; // Second phase: Figure out hall order. // Generate 2D array from the halls position objects // Find grid size - const maxrows = Math.max(...positions.map(p => p.x1)); - const maxcols = Math.max(...positions.map(p => p.y1)); - var hallgrid = Array.from({ length: maxcols + 1 }, () => - Array.from({ length: maxrows + 1 }, () => null) + const maxrows = Math.max(...objects['Grid'].map(p => p.y1)); + const maxcols = Math.max(...objects['Grid'].map(p => p.x1)); + const nbrows = maxrows+1; + const nbcols = maxcols+1; + + var hallgrid = Array.from({ length: nbcols }, () => + Array.from({ length: nbrows }, () => ({'x': null, 'y': null, 'hall':null})) ); objects["Grid"].forEach(h => { - hallgrid[h.y1][h.x1] = h.name + hallgrid[h.x1][h.y1]['hall'] = h.name }); var padY = 100; var padX = 100; - const colswidths = Array.from({length: maxcols + 1}, () => padX) - const rowsheights = Array.from({length: maxcols + 1}, () => padY) - - for (let y = 0; y < maxrows+1; y++) { + const colswidths = Array.from({length: nbcols}, () => padX) + const rowsheights = Array.from({length: nbrows}, () => padY) + + /* [ + ["normal", "20plus"] + ] + x=0: x=1: + y=0: [normal][20plus] + */ + for (let y = 0; y < nbrows; y++) { var maxHeight = 0; - for (let x = 0; x < maxcols+1; x++) { - const hallName = hallgrid[y][x]; + for (let x = 0; x < nbcols; x++) { + const hallName = hallgrid[x][y].hall; + if(hallName===null) + continue const hall = hallsizes[hallName]; if (hall && hall.h > maxHeight) { @@ -303,10 +314,12 @@ var dhmap = {}; rowsheights[y] = maxHeight; } - for (let x = 0; x < maxcols+1; x++) { + for (let x = 0; x < nbcols; x++) { var maxWidth = 0; - for (let y = 0; y < maxrows+1; y++) { - const hallName = grid[y][x]; + for (let y = 0; y < nbrows; y++) { + const hallName = hallgrid[x][y].hall; + if(hallName===null) + continue const hall = hallsizes[hallName]; if (hall && hall.w > maxWidth) { @@ -317,42 +330,70 @@ var dhmap = {}; colswidths[x] = maxWidth; } + // Calculate top left corner of each grid cell + var curcol_offset = 0 + for (let x = 0; x < nbcols; x++) { + var currow_offset = 0 + for (let y = 0 ; y < nbrows; y++) { + hallgrid[x][y].x = curcol_offset; + hallgrid[x][y].y = currow_offset; + currow_offset += rowsheights[y] + 45 + 45; // Account for hall box padding + label + } + curcol_offset += colswidths[x] + 45; // Account for hall box padding + } + // Fourth phase: draw bounding boxes of halls. var halls = Object.keys(objects).length; var hallidx = 0; - for ( var i in hallorder ) { - var hall = hallorder[i]; - var hue = (hallidx/halls) * 360; - - var size = hallsizes[hall]; - - var hallRect = paper.rect( - (size.x - 15) * scaling, - (size.y - 15) * scaling, - (size.w + 30) * scaling, - (size.h + 30) * scaling); - var labelOffsetX = (size.w + 30) * scaling / 2; - var labelOffsetY = -100; - hallRect.attr({fill: 'hsla(' + hue + ',100%,50%,0.3)'}); - hallRect.label = paper.text(hallRect.attr('x') + labelOffsetX, hallRect.attr('y') + labelOffsetY, hall); - hallRect.label.attr({'font-size': 144}); - hallRect.label.attr({'border': '1px solid red'}); - hallRect.label.attr({'fill': 'rgba(200, 200, 200, 0.7)'}); - - hallidx++; + for (let x = 0; x < nbcols; x++) { + for (let y = 0 ; y < nbrows; y++) { + var hall = hallgrid[x][y].hall; + if(hall===null){ + continue + } + var hue = (hallidx/halls) * 360; + var size = hallsizes[hall]; + + var gridOffsetX = hallgrid[x][y].x; + var gridOffsetY = hallgrid[x][y].y; + + var hallRect = paper.rect( + (gridOffsetX + size.x - 15) * scaling, + (gridOffsetY + size.y - 15) * scaling, + (size.w + 30) * scaling, + (size.h + 30) * scaling); + var labelOffsetX = (size.w + 30) * scaling / 2; + var labelOffsetY = -100; + hallRect.attr({fill: 'hsla(' + hue + ',100%,50%,0.3)'}); + hallRect.label = paper.text(hallRect.attr('x') + labelOffsetX, hallRect.attr('y') + labelOffsetY, hall); + hallRect.label.attr({'font-size': 144}); + hallRect.label.attr({'border': '1px solid red'}); + hallRect.label.attr({'fill': 'rgba(200, 200, 200, 0.7)'}); + + hallidx++; + } } // Fifth phase: draw objects. - for ( var i in hallorder ) { - var hall = hallorder[i]; - offsetX = hallsizes[hall].x; - offsetY = hallsizes[hall].y; + for (let x = 0; x < nbcols; x++) { + for (let y = 0 ; y < nbrows; y++) { + var hall = hallgrid[x][y].hall; + if(hall===null){ + continue + } - // Re-do with real paint this time - boundingX = 0; - boundingY = 0; - for ( var i in objects[hall] ) { - renders[objects[hall][i]['class']](objects[hall][i], false); + var gridOffsetX = hallgrid[x][y].x; + var gridOffsetY = hallgrid[x][y].y; + + offsetX = hallsizes[hall].x + gridOffsetX ; + offsetY = hallsizes[hall].y + gridOffsetY; + + // Re-do with real paint this time + boundingX = 0; + boundingY = 0; + for ( var i in objects[hall] ) { + renders[objects[hall][i]['class']](objects[hall][i], false); + } } } } From ef48abd3cf4048bb47dbbd39a22ac64b0cf8538b Mon Sep 17 00:00:00 2001 From: furest Date: Sun, 26 Oct 2025 13:39:47 +0100 Subject: [PATCH 3/4] refactor --- src/dhmap.js | 59 ++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/src/dhmap.js b/src/dhmap.js index bb5aa14..81c757c 100644 --- a/src/dhmap.js +++ b/src/dhmap.js @@ -271,62 +271,57 @@ var dhmap = {}; hallsizelist.push([boundingY * boundingX, hall]); } - // Second phase: Figure out hall order. - // Generate 2D array from the halls position objects - // Find grid size - const maxrows = Math.max(...objects['Grid'].map(p => p.y1)); - const maxcols = Math.max(...objects['Grid'].map(p => p.x1)); - const nbrows = maxrows+1; - const nbcols = maxcols+1; - + // Second phase: Generate 2D array from the halls position objects + // Figure out grid size + var maxrows = Math.max(...objects['Grid'].map(p => p.y1)); + var maxcols = Math.max(...objects['Grid'].map(p => p.x1)); + var nbrows = maxrows+1; + var nbcols = maxcols+1; + + // Create grid var hallgrid = Array.from({ length: nbcols }, () => Array.from({ length: nbrows }, () => ({'x': null, 'y': null, 'hall':null})) ); - + + // Populate grid objects["Grid"].forEach(h => { hallgrid[h.x1][h.y1]['hall'] = h.name }); var padY = 100; var padX = 100; - const colswidths = Array.from({length: nbcols}, () => padX) - const rowsheights = Array.from({length: nbrows}, () => padY) - - /* [ - ["normal", "20plus"] - ] - x=0: x=1: - y=0: [normal][20plus] - */ + var colswidths = Array.from({length: nbcols}, () => padX) + var rowsheights = Array.from({length: nbrows}, () => padY) + + // Calulate the max height in each row for (let y = 0; y < nbrows; y++) { var maxHeight = 0; for (let x = 0; x < nbcols; x++) { - const hallName = hallgrid[x][y].hall; - if(hallName===null) + var hallName = hallgrid[x][y].hall; + if (hallName === null ) { continue - const hall = hallsizes[hallName]; - + } + var hall = hallsizes[hallName]; if (hall && hall.h > maxHeight) { maxHeight = hall.h; } } - rowsheights[y] = maxHeight; } + //Calculate the max width of each column for (let x = 0; x < nbcols; x++) { var maxWidth = 0; for (let y = 0; y < nbrows; y++) { - const hallName = hallgrid[x][y].hall; - if(hallName===null) + var hallName = hallgrid[x][y].hall; + if (hallName === null ) { continue - const hall = hallsizes[hallName]; - + } + var hall = hallsizes[hallName]; if (hall && hall.w > maxWidth) { maxWidth = hall.w; } } - colswidths[x] = maxWidth; } @@ -342,13 +337,13 @@ var dhmap = {}; curcol_offset += colswidths[x] + 45; // Account for hall box padding } - // Fourth phase: draw bounding boxes of halls. + // Third phase: draw bounding boxes of halls. var halls = Object.keys(objects).length; var hallidx = 0; for (let x = 0; x < nbcols; x++) { for (let y = 0 ; y < nbrows; y++) { var hall = hallgrid[x][y].hall; - if(hall===null){ + if (hall === null ) { continue } var hue = (hallidx/halls) * 360; @@ -374,11 +369,11 @@ var dhmap = {}; } } - // Fifth phase: draw objects. + // Fourth phase: draw objects. for (let x = 0; x < nbcols; x++) { for (let y = 0 ; y < nbrows; y++) { var hall = hallgrid[x][y].hall; - if(hall===null){ + if (hall === null ) { continue } From 04d3581f5f4cd0cea0f02518ca03f5fdf4f74d6a Mon Sep 17 00:00:00 2001 From: furest Date: Sun, 26 Oct 2025 14:03:25 +0100 Subject: [PATCH 4/4] Do not draw "Grid" in side menu --- src/dhmenu.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dhmenu.js b/src/dhmenu.js index dd2d565..ec6e18b 100644 --- a/src/dhmenu.js +++ b/src/dhmenu.js @@ -30,6 +30,12 @@ dhmenu.write = function(objects){ delete objects["Prod"]; objects["Prod"] = prod; } + + //Skip grid as it will never contain switches. + if(objects["Grid"]){ + var prod = objects["Grid"]; + delete objects["Grid"]; + } if($('#menu')){ var div_menu = $('#menu');