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

[Ordering] add ability to define order constraints within rank #302

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

izhan
Copy link

@izhan izhan commented Jun 2, 2020

Allows for node order constraints like:

dagre.layout(g, {constraints: [{left: "node-B", right: "node-A"}]})

Addresses: #112, #201, #251, among others
Related PRs: #263, #252

Usage

interface Constraint {
    left: string;
    right: string;
}

interface Options {
    constraints?: Constraint[];
}

function layout(g: graphlib.Graph, opts: Options) {...}

Example

Without constraints:

With constraints:

const g = new dagre.graphlib.Graph({}).setGraph({}).setDefaultEdgeLabel(function () {
    return {}
})
g.setNode("root")
g.setNode("node-A")
g.setNode("node-B")
g.setEdge("root", "node-A")
g.setEdge("root", "node-B")
dagre.layout(g, {constraints: [{left: "node-B", right: "node-A"}]})

Details

I'm following a suggestion made by @cpettitt in dagrejs/dagre-d3#64 (comment)

To specify the constraints, I'm following the opts approach used in #263, but open to suggestions.

@mx2323
Copy link

mx2323 commented Jun 25, 2020

how does this address #201? im looking for that functionality but dont see how this maps to the ability to incrementally layout a new node to a graph.

@izhan
Copy link
Author

izhan commented Jun 26, 2020

@mx2323 I haven't tested it yet, but after calling layout(), take the output ordering of nodes within the same rank (done by looking at their x + y coordinates) and generate pairwise constraints. further calls to layout() w/ these constraints should not create any shuffling, even after adding a new node

@branpk
Copy link

branpk commented Dec 17, 2020

Are you sure this addresses #112? My understanding is that this adds node order constraints but that doesn't necessary help with outgoing edges. For example:

Capture

Swapping C and D or A and B won't fix the edges by itself. The correct way is to add an extra crossing between either A's outgoing edges or B's outgoing edges.

@izhan
Copy link
Author

izhan commented Dec 17, 2020

@branpk ah good point, this won't necessarily solve outgoing edges. My understanding is that this PR fixes the second ask of #112 (within same rank):

In fact, it would be the best if i could constraint nodes order too (position from left to right in top down graph), but as I understand, it is not possible at the moment

Thanks for the callout, hope that clarifies!

@zygeilit
Copy link

@izhan excellent, solved my question. nice

@danyflorez
Copy link

danyflorez commented Aug 10, 2021

Does anyone knows a hack to accomplish this?

collingreen added a commit to OneSignal/dagre that referenced this pull request Jan 28, 2022
Add ability to pass in a list of graph constraints (list of high node vs
low node relationships) to influence the ordering of the graph. Useful
for picking which way edges go and for making a layout more 'stable'
(the onesignal use case is making all branch edges of the same type go
the same way).

This is essentially this commit by izhan
izhan@4b40097
in this PR dagrejs#302
with a couple changes - high/low over left/right plus some type
overrides (alternatively could fork definitelytyped and put the changes
there)
collingreen added a commit to OneSignal/dagre that referenced this pull request Jan 28, 2022
Add ability to pass in a list of graph constraints (list of high node vs
low node relationships) to influence the ordering of the graph. Useful
for picking which way edges go and for making a layout more 'stable'
(the onesignal use case is making all branch edges of the same type go
the same way).

This is essentially this commit by izhan
izhan@4b40097
in this PR dagrejs#302
with a couple changes - high/low over left/right plus some type
overrides (alternatively could fork definitelytyped and put the changes
there)
collingreen added a commit to OneSignal/dagre that referenced this pull request Jan 28, 2022
Add ability to pass in a list of graph constraints (list of high node vs
low node relationships) to influence the ordering of the graph. Useful
for picking which way edges go and for making a layout more 'stable'
(the onesignal use case is making all branch edges of the same type go
the same way).

This is essentially this commit by izhan
izhan@4b40097
in this PR dagrejs#302
with a couple changes - high/low over left/right plus some type
overrides (alternatively could fork definitelytyped and put the changes
there)
@ZahidChandio
Copy link

Could someone please review and merge the open PRs? It would also be great if we could get responses to the open issues. Thank you!

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.

6 participants