Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to sort nodes and edges #100

Merged
merged 3 commits into from
Oct 31, 2022
Merged

Conversation

treardon17
Copy link
Contributor

Some of the default layouts in cytoscape have a sort option (or some variation of it) that lets you sort the nodes/edges so the resulting graph is predictable if you're adding/removing nodes.

examples layouts with sort:
https://js.cytoscape.org/#layouts/grid
https://js.cytoscape.org/#layouts/circle
https://js.cytoscape.org/#layouts/breadthfirst

Without this, the graph will have a different outcome if several nodes/edges are added, then some middle nodes/edges are removed, and then those same removed nodes/edges are added back.

@treardon17 treardon17 changed the title chore: add ability to sort nodes and edges Add ability to sort nodes and edges Sep 2, 2022
@stale
Copy link

stale bot commented Sep 16, 2022

This issue has been automatically marked as stale, because it has not had activity within the past 30 days. It will be closed if no further activity occurs within the next 30 days. If a feature request is important to you, please consider making a pull request. Thank you for your contributions.

@stale stale bot added the stale label Sep 16, 2022
@maxkfranz
Copy link
Member

maxkfranz commented Sep 21, 2022

Does Dagre have guarantees, i.e. explicit API documentation, that the ordering of the elements affects the end result?

@treardon17
Copy link
Contributor Author

@maxkfranz dagre itself doesn't have explicit documentation, but dagre uses graphlib, and graphlib has documentation for the order of nodes: https://github.com/dagrejs/graphlib/wiki/API-Reference#graph-concepts.

From the graphlib docs:

directed: set to true to get a directed graph and false to get an undirected graph. An undirected graph does not treat the order of nodes in an edge as significant. In other words, g.edge("a", "b") === g.edge("b", "a") for an undirected graph. Default: true.

cytoscape dagre uses the default value for directed here, so the order of the nodes are significant.

@stale stale bot removed the stale label Sep 21, 2022
@maxkfranz
Copy link
Member

Great.

What could we do to clarify how this proposed sorting feature would affect the resultant layout, especially for people who are reading the documentation for the first time? The circle layout and grid layout have conventional orderings, clockwise and the Western reading direction respectively (also the typical x/y graphics axes in CS). The natural ordering of a tree is the topology, so the reader can't necessarily make a connection for what sorting would do.

@treardon17
Copy link
Contributor Author

We could clarify in the docs that by default cycoscape dagre creates a directed graph, and directed graphs use the node order as a tie breaker when defining the topology of a graph. This feature is most useful when adding and removing the same nodes and edges multiple times in a graph.

Would that make sense?

@maxkfranz
Copy link
Member

maxkfranz commented Sep 26, 2022 via email

@treardon17
Copy link
Contributor Author

@maxkfranz I updated the readme based on what we talked about 👍

@maxkfranz maxkfranz self-assigned this Oct 18, 2022
@maxkfranz
Copy link
Member

Great, @treardon17. I'll set aside some time tomorrow for a merge & release

@maxkfranz maxkfranz merged commit f6da1f9 into cytoscape:master Oct 31, 2022
@maxkfranz
Copy link
Member

Sorry, this slipped past me somehow.

Released to npm with your updates for 2.5.0

@treardon17
Copy link
Contributor Author

Thanks @maxkfranz!

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.

2 participants