MCPcopy Create free account
hub / github.com/chartbrew/chartbrew / stretchTrailingGaps

Function stretchTrailingGaps

client/src/modules/autoLayout.js:89–113  ·  view source on GitHub ↗
(items, bpCols)

Source from the content-addressed store, hash-verified

87}
88
89function stretchTrailingGaps(items, bpCols) {
90 const cloned = cloneItems(items);
91 // Group by exact y (rows)
92 const rowsMap = {};
93 cloned.forEach((it) => {
94 const key = `${it.y}`;
95 if (!rowsMap[key]) rowsMap[key] = [];
96 rowsMap[key].push(it);
97 });
98
99 Object.keys(rowsMap).forEach((key) => {
100 const row = rowsMap[key].sort((a, b) => a.x - b.x);
101 const last = row[row.length - 1];
102 const rightEdge = last.x + last.w;
103 const gap = bpCols - rightEdge;
104 if (gap > 0) {
105 const originalW = Math.max(1, last.w);
106 const maxExtension = Math.max(1, Math.floor(originalW / 2));
107 const apply = Math.min(gap, maxExtension);
108 last.w = originalW + apply;
109 }
110 });
111
112 return cloned;
113}
114
115export function tidyLayout(layout, widgets, bp) {
116 const bpCols = cols[bp] || 12;

Callers 1

normalizeAndCompactFunction · 0.85

Calls 1

cloneItemsFunction · 0.85

Tested by

no test coverage detected