Skip to content

EAGLE-1688: Minor fixes and optimisations to GraphRenderer - #1069

Open
james-strauss-uwa wants to merge 8 commits into
masterfrom
eagle-1688
Open

EAGLE-1688: Minor fixes and optimisations to GraphRenderer#1069
james-strauss-uwa wants to merge 8 commits into
masterfrom
eagle-1688

Conversation

@james-strauss-uwa

@james-strauss-uwa james-strauss-uwa commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Fixed bug where selecting a node would become a drag, even if the node didn't move or hardly moved.
Prevent possible divide-by-zero when scaling graph.
Use squared distance when finding nearby matching ports.
Better way to detect cycles in graphs (no arbitrary 32 edge or 10 edge limits)
Optimised method for depth first traversal of nodes when determining draw order.
Optimised method for determining which edges are contained within a selection area.

Summary by Sourcery

Improve GraphRenderer interaction reliability and graph traversal performance while adding safeguards for scaling and cyclic hierarchies.

Bug Fixes:

  • Prevent small or stationary node clicks from being treated as drags.
  • Prevent graph scaling from reaching zero and improve drag-direction threshold handling.
  • Replace arbitrary traversal limits with cycle detection when walking node ancestry.

Enhancements:

  • Optimise edge containment checks and accept graph iterables directly.
  • Reduce repeated graph-node collection during depth-first draw-order traversal.
  • Optimise nearest-port matching by comparing squared distances.

Tests:

  • Add end-to-end coverage for edge containment with graph iterators and nested-parent depth traversal.

@james-strauss-uwa james-strauss-uwa self-assigned this Sep 2, 2026
@sourcery-ai

sourcery-ai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

GraphRenderer receives interaction and zoom robustness fixes, iterable- and set-based edge selection optimization with E2E coverage, cycle-safe ancestry/depth traversal, and squared-distance port matching.

Sequence diagram for optimized edge selection

sequenceDiagram
    participant GraphRenderer
    participant NodeCollection
    participant EdgeCollection
    participant Edge

    GraphRenderer->>NodeCollection: iterate selected nodes
    NodeCollection-->>GraphRenderer: Node iterable
    GraphRenderer->>GraphRenderer: node.getId()
    GraphRenderer->>GraphRenderer: node.getInputApplication()
    GraphRenderer->>GraphRenderer: node.getOutputApplication()
    GraphRenderer->>EdgeCollection: iterate edges
    EdgeCollection-->>GraphRenderer: Edge iterable
    GraphRenderer->>Edge: getSrcNode() and getDestNode()
    GraphRenderer->>GraphRenderer: findEdgesContainedByNodes()
    GraphRenderer-->>GraphRenderer: edges with both endpoints in nodeIds
Loading

Sequence diagram for cycle-safe ancestry traversal

sequenceDiagram
    participant GraphRenderer
    participant Node

    GraphRenderer->>Node: getId()
    GraphRenderer->>GraphRenderer: visitedIds.has(nodeId)
    alt ancestor found
        GraphRenderer-->>GraphRenderer: return true
    else unvisited parent
        GraphRenderer->>GraphRenderer: visitedIds.add(nodeId)
        GraphRenderer->>Node: getParent()
        Node-->>GraphRenderer: parent or null
    else cycle detected
        GraphRenderer-->>GraphRenderer: return false
    end
Loading

Flow diagram for robust graph zoom scaling

flowchart TD
    A[Wheel zoom input] --> B[Read current global scale]
    B --> C[Compute newScale]
    C --> D[Take absolute value]
    D --> E[Clamp to MIN_GRAPH_SCALE]
    E --> F[Update eagle.globalScale]
Loading

File-Level Changes

Change Details Files
Improve pointer interaction and graph scaling robustness.
  • Clamp zoom scale to a positive minimum to avoid degenerate or inverted scaling.
  • Track drag origin consistently and use absolute pointer deltas to distinguish clicks from meaningful movement.
  • Handle missing selection-region coordinates without continuing selection processing.
src/GraphRenderer.ts
Optimize edge containment checks for selected nodes.
  • Accept iterable graph collections directly.
  • Build a node/application ID set once, then test edge endpoints against it in linear passes.
  • Add end-to-end coverage for graph iterators and partial selections.
src/GraphRenderer.ts
e2e/findEdgesContainedByNodes.spec.ts
Replace traversal iteration caps with cycle detection and reduce repeated graph materialization.
  • Track visited node IDs while walking ancestor chains.
  • Materialize graph nodes once during depth-first ordering instead of repeatedly converting the node collection.
src/GraphRenderer.ts
Optimize nearby-port matching without changing distance semantics.
  • Compare squared distances to avoid square-root calculations.
  • Use squared suggestion and snap radii for threshold checks.
src/GraphRenderer.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/GraphRenderer.ts" line_range="2286-2288" />
<code_context>
         while (nodeParent != null){
-            if (iterations > MAX_ITERATIONS){
-                console.error("too many iterations in findDepthOfNode()");
+            nodeId = node.getId();
+            if (visitedIds.has(nodeId)){
+                console.error("cycle detected in findDepthOfNode()");
                 break;
             }
</code_context>
<issue_to_address>
**issue (bug_risk):** `nodeId` is assigned from the original `node` on every parent-traversal iteration, so the second iteration always sees the original node ID in `visitedIds` and breaks. Nodes nested more than one parent deep therefore receive an incomplete depth, producing incorrect draw order and selection ordering.

**Triggers:** When a node has a parent that itself has a parent.

**Suggested fix:** Track the node currently being traversed, such as using `nodeParent.getId()` for cycle detection and advancing the traversal node after each parent lookup.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/GraphRenderer.ts:2288


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/GraphRenderer.ts

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

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.

1 participant