Skip to content

fix: support self-loops and preserve node labels in dagre adapter - #219

Closed
EnesKartal wants to merge 1 commit into
erikbrinkman:mainfrom
EnesKartal:fix/dagre-self-loop-and-labels
Closed

EnesKartal wants to merge 1 commit into
erikbrinkman:mainfrom
EnesKartal:fix/dagre-self-loop-and-labels

Conversation

@EnesKartal

Copy link
Copy Markdown

Fixes #218

Root cause

  1. DagreGraph.setEdge(v, v) forwarded self-loop edges directly to MutGraph.link(), which rejects self-loops and threw an error before layout could run.
  2. DagreGraph.setNode() copied width/height into a fresh { id, width, height, x, y } object stored as graphNode.data, losing caller-provided fields and breaking object identity (grf.node(id) === label) as well as in-place x/y updates during dagre.layout(grf).

Fix

  • Track self-loop edges separately in DagreGraph so setEdge(v, v) succeeds and layout ignores self-loops, while graph query/mutation methods (hasEdge, edge, edges, edgeCount,
    emoveEdge,
    emoveNode, predecessors, successors,
    eighbors, inEdges, outEdges,
    odeEdges, sources, sinks, ilterNodes) remain consistent with dagre.
  • Store { id, label } internally on graph nodes so
    ode(id) returns the caller's label object directly, preserving custom fields and writing x/y onto it during layout without adding an id property.

Testing

  • Added unit tests in src/dagre.test.ts covering self-loop layout and graph queries/mutations, node label identity and custom fields, setNode updates, setDefaultNodeLabel, and ilterNodes.
  • Verified with �un test (669/669 passing), sc, �iome check, and ypedoc --emit none.

@erikbrinkman

Copy link
Copy Markdown
Owner

Thanks for submitting this! I went a different direction to support self loops, but I did take some of the tests. lmk if you run into issues or unexpected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dagre adapter: setEdge(v, v) throws, and node labels are copied instead of kept

2 participants