dagrejs / dagre

Directed graph layout for JavaScript
MIT License
4.72k stars 606 forks source link

Controling the order of outgoing edges #112

Open cpettitt opened 10 years ago

cpettitt commented 10 years ago

From @bzaborow:

Hi,

I started to use the dagre-d3 for visualisation of data similar to one of examples (the Sentence Tokenization). Extending this example to display a DAG instead of a tree was super easy, but I've lost control of an order in which edges leave a particular node. Is it possible to restrict it somehow? If not, could you point me where to start looking into your code? For my data the order of edges is quite important.

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 (issue cpettitt/dagre-d3#25 ?).

Thanks

bzaborow commented 10 years ago

It should be possible to add an order attribute to nodes and edges in the input graph to indicate to dagre what the ordering for edges and nodes should be. This information could be used in the order phase instead of the barycenter heuristic. The implementation should be much simpler than that required for #25.

I'd be interested in what drives the requirement for edge ordering if you're at liberty to describe it. I can already imagine several reasons for wanting to explicitly order the nodes, though.

Sorry for messing the dagre-d3 tracker. I'll try to look into the dagree code and hack something next week. And motivation for edge ordering: I'm working with linguistic data, syntactic structures in particular ("sentence diagram" and similar things). In languages where the word order is flexible, it's useful to mark a cannonical order of substructures. Example: words within a noun phrase - in English this will be determiner, then a number of adjectives and then a number of nouns, but e.g. in Polish you can put some of the adjectives after the nouns.

cpettitt commented 10 years ago

I added Forster's constrained ordering algorithm which should give us the ability to constrain edge order while still being able to optimize ordering for edges that don't have constraints. While we could explicitly define ordering for each edge / node, it looks like the approach use by graphviz is more convenient. To enable this, we need to keep track of the order in which edges are added to the graph. This requires some change to graphlib.

brianchin commented 10 years ago

I'm going to need this feature for an application of mine in the near future. What's the current status of this bug? Is there anything a third-party can do to help get this running?

tzookb commented 6 years ago

@cpettitt

went through the above link by Graphviz

and it just says to add : {ordering: "out" OR "in"}

so I did something like this:

var graph = new dagreD3.graphlib.Graph({ordering: "in").setGraph({});

and tried out as well, but still got the elements to jump sides

any idea what Im doing wrong?

cpettitt commented 6 years ago

The graphviz feature is not currently supported in dagre.

tzookb commented 6 years ago

Thanks @cpettitt

so currently no option to set the order and not make the leafs swap?

cpettitt commented 6 years ago

Not without a contribution. If someone were willing to work on it the pieces are already there with the constraint graph in the order phase, but they need to be exposed in an intuitive way through the public API.

tzookb commented 6 years ago

great, can u please elaborate more so I could dig into that?

cpettitt commented 6 years ago

See https://github.com/dagrejs/dagre-d3/issues/64#issuecomment-52138308

tzookb commented 6 years ago

already been there but the links there to sweepUp sweepDown are not relevant anymore...

and I cant find them in the code as well

cpettitt commented 6 years ago

https://github.com/dagrejs/dagre/blob/a299bf8a83ed4c973d6f8bccf6a57e0cd5e2e44c/lib/order/index.js#L61