MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / findEmptyPosition

Method findEmptyPosition

src/gridstack-engine.ts:722–741  ·  view source on GitHub ↗

* Find the first available empty spot for the given node dimensions. * Updates the node's x,y attributes with the found position. * * @param node the node to find a position for (w,h must be set) * @param nodeList optional list of nodes to check against (defaults to engine nodes) * @p

(node: GridStackNode, nodeList = this.nodes, column = this.column, after?: GridStackNode)

Source from the content-addressed store, hash-verified

720 * }
721 */
722 public findEmptyPosition(node: GridStackNode, nodeList = this.nodes, column = this.column, after?: GridStackNode): boolean {
723 const start = after ? after.y * column + (after.x + after.w) : 0;
724 let found = false;
725 for (let i = start; !found; ++i) {
726 const x = i % column;
727 const y = Math.floor(i / column);
728 if (x + node.w > column) {
729 continue;
730 }
731 const box = {x, y, w: node.w, h: node.h};
732 if (!nodeList.find(n => Utils.isIntercepted(box, n))) {
733 if (node.x !== x || node.y !== y) node._dirty = true;
734 node.x = x;
735 node.y = y;
736 delete node.autoPosition;
737 found = true;
738 }
739 }
740 return found;
741 }
742
743 /**
744 * Add the given node to the grid, handling collision detection and re-packing.

Callers 3

addNodeMethod · 0.95
columnChangedMethod · 0.95
loadMethod · 0.80

Calls 2

findMethod · 0.80
isInterceptedMethod · 0.80

Tested by

no test coverage detected