Skip to content

Graph node placement algorithms#1

Merged
Kadajett merged 1 commit intomainfrom
cursor/graph-node-placement-algorithms-7abf
Dec 20, 2025
Merged

Graph node placement algorithms#1
Kadajett merged 1 commit intomainfrom
cursor/graph-node-placement-algorithms-7abf

Conversation

@danroblewis
Copy link
Contributor

Add several popular and more sophisticated network graph layout algorithms to the UI to improve visualization options.

The previous layouts were basic; these new options (Breadth-first, COSE, fCOSE, CoSE-Bilkent) provide better representations for various graph structures, especially directed ones. The implementation also ensures smooth transitions between layouts by stopping any active layout before starting a new one.


Open in Cursor Open in Web

Co-authored-by: daniel.robert.lewis <daniel.robert.lewis@gmail.com>
@cursor
Copy link

cursor bot commented Dec 16, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@danroblewis danroblewis marked this pull request as ready for review December 16, 2025 04:37
@Kadajett Kadajett requested a review from Copilot December 20, 2025 14:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances graph visualization capabilities by adding four sophisticated network graph layout algorithms to provide better representations for various graph structures, particularly directed call graphs. The implementation includes proper lifecycle management to ensure smooth transitions between layouts.

Key Changes:

  • Added four new layout algorithms: Breadth-first, COSE, fCOSE, and CoSE-Bilkent with optimized configurations for call graph visualization
  • Implemented layout instance tracking and proper cleanup to prevent overlapping layout animations
  • Updated UI with new toolbar buttons for each layout algorithm with descriptive icons

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/graph.js Added imports and registration for fcose and cose-bilkent extensions; configured four new layout algorithms with tuned parameters; added layout instance management with stop() calls before transitions; added special handling for breadthfirst to auto-detect root nodes
package.json Added dependencies for cytoscape-fcose (^2.2.0) and cytoscape-cose-bilkent (^4.1.0)
package-lock.json Updated lock file with new dependencies including cose-base and layout-base transitive dependencies
index.html Added four new toolbar buttons with SVG icons and descriptive titles for the new layout algorithms

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
const layout = LAYOUTS[layoutName] || LAYOUTS.dagre;

const layout = { ...(LAYOUTS[layoutName] || LAYOUTS.dagre) };
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

Creating a shallow copy of the layout configuration object is good practice, but the copy doesn't handle nested objects deeply. While this works for the current implementation since most properties are primitives, if future layouts include nested configuration objects (like the concentric function which is a reference type), this could lead to unintended mutations of the original LAYOUTS object. Consider documenting this limitation or using a deep clone if nested objects become common.

Copilot uses AI. Check for mistakes.
import fcose from 'cytoscape-fcose';
import coseBilkent from 'cytoscape-cose-bilkent';

// Register dagre layout
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

The comment on line 10 says "Register dagre layout" but the following lines also register fcose and coseBilkent layouts. The comment should be updated to reflect that multiple layout extensions are being registered, for example: "Register layout extensions" or list all of them.

Suggested change
// Register dagre layout
// Register layout extensions (dagre, fcose, coseBilkent)

Copilot uses AI. Check for mistakes.
@@ -440,14 +498,35 @@ export class GraphManager {
* @param {string} layoutName - Layout name (dagre, circle, grid, concentric, clustered)
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

The JSDoc comment for runLayout is outdated. It lists the old layout options (dagre, circle, grid, concentric, clustered) but doesn't include the newly added layouts (breadthfirst, cose, fcose, cose-bilkent). The documentation should be updated to reflect all available layout options.

Suggested change
* @param {string} layoutName - Layout name (dagre, circle, grid, concentric, clustered)
* @param {string} layoutName - Layout name (dagre, circle, grid, concentric, clustered, breadthfirst, cose, fcose, cose-bilkent)

Copilot uses AI. Check for mistakes.
Comment on lines +505 to +506
} catch {
// ignore
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

The empty catch block silently ignores all errors when stopping the layout. While this might be intentional to prevent errors from blocking layout transitions, consider logging the error to the console for debugging purposes. This would help identify if there are issues with the layout stop operation without breaking the user experience.

Suggested change
} catch {
// ignore
} catch (error) {
// Log the error for debugging but do not block layout transitions
console.error('Failed to stop current layout:', error);

Copilot uses AI. Check for mistakes.
@Kadajett
Copy link
Contributor

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link

Copilot AI commented Dec 20, 2025

@Kadajett I've opened a new pull request, #2, to work on those changes. Once the pull request is ready, I'll request review from you.

@Kadajett Kadajett merged commit eccc472 into main Dec 20, 2025
6 checks passed
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.

5 participants