Skip to content

[BUG] cellsAdded ignores constrain and extend parameters #1045

@Dario638

Description

@Dario638

Describe the bug

cellsAdded in CellsMixin.ts has two conditions that always evaluate to true, introduced in commit bc400a3:

// Line 673
if ((!extend || extend) && this.isExtendParentsOnAdd(cell) && this.isExtendParent(cell)) {
// Line 681
if (!constrain || constrain) {

The original code used extend == null || extend and constrain == null || constrain, which correctly defaulted to true when the parameter was omitted but honored an explicit false. The rewrite to !x || x is always true for any boolean value, making both parameters dead code.

This breaks groupCells, which passes constrain=false, extend=false at lines 96 and 100 of GroupingMixin.ts. For cells at negative coordinates, extendParent does not trigger, so constrainChild clamps children into the group's initial 0x0 area, destroying their width and position.

To Reproduce

Steps to reproduce the behavior:

const v1 = graph.insertVertex(parent, null, 'A', -200, -200, 80, 40);
const v2 = graph.insertVertex(parent, null, 'B', -100, -100, 80, 40);
graph.groupCells(null, 0, [v1, v2]);
// v1 and v2 now have width=0 and height=0

Expected behavior

groupCells should preserve child cell geometries. This likely worked correctly in mxGraph.

Screenshots

N/A

Environment

  • maxGraph version or commit: present on current main
  • Desktop or mobile: Desktop
  • OS and version: Linux
  • Browser and version: Latest Chromium

Additional context

The fix is to replace the always-true conditions with simple boolean checks, matching how cellsMoved (line 1359 in the same file) already handles the same parameters correctly:

if (extend && this.isExtendParentsOnAdd(cell) && this.isExtendParent(cell)) {
  this.extendParent(cell);
}
if (constrain) {
  this.constrainChild(cell);
}
Pinned by tbouffard

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions