Containers Implementation in Vanilla-Diagram

A container is a node whose symbol has container: true: the basic set's group, or a host's own (the process-flowchart-js sample's lane). Other nodes belong to it through their parent field. Positions stay world px, so the geometry, the routing, the export and the data manager need no conversion. Every change stays a phase 1 command (move, update, remove, batch): undoable, announced by vn-diagram-changed, saved as one change set.

The model

Drawing

Selection

Moving

Joining and leaving

Resizing

A container's resize (the handles, or Ctrl/Cmd + Shift + arrows) moves only its frame: the edges the handle moves can't cross its children's bounding box plus 16 px (_clampContainerBox(); an edge already past it doesn't move further in), as a box can't go below minSize. The children don't move. A child resized past its container's frame stays its child: only a move's release changes membership.

Removing

Removing a container removes every descendant and every connector at them, as one remove: the remove command adds the descendants of the ids it is given, so every path does it. _userRemove() (the Delete key, deleteSelection(), so the toolbar's Delete) and cut() list the descendants in vn-diagram-removing before they remove. Undo restores the tree.

The clipboard and the export

Layout

layout() lays the containers out inside out: each container's children by the connectors among its descendants, then the container takes their box plus 16 px each side, its label band (capped at the text box's maxHeight) kept clear, and is one box at its parent's level (16-auto-layout).

Performance

A container's move of k descendants is O(k + c) per frame, as any move of k nodes; the joining target is looked up per drag frame through the node index (features/groups.feature.js is in DIAGRAM_BUNDLE_FAST_PATH). Parent validation on load is O(n). diagram-performance.spec.js drags a container with 20 children at 1,000 nodes within 16ms (about 2ms in Chromium).