skieffer / hola

Human-like Orthogonal Layout Algorithm
46 stars 10 forks source link

How to include layer constraints? #9

Closed dominicfollett closed 5 years ago

dominicfollett commented 5 years ago

@skieffer Thanks for this very useful library.

I am aware the library doesn't currently support this, but ... I'm curious to know if you have any recommendations on how one could constrain the layout by layer?

For example, if the nodes belonged to either one of say: layers = [layer1, layer2, layer3, layer4], then how might hola produce a layout where each node is positioned only within its given layer?

skieffer commented 5 years ago

Thanks for your interest.

In theory it could produce good results, but it would depend on the structure of the network.

HOLA mostly tries to respect pre-existing constraints. The exception is that it pays no heed on the network's exterior subtrees. However, it would be easy enough to make an option that says e.g. all trees must grow SOUTH, say.

Somehow I did not make an easy way to set initial constraints on the Graph in this project; however, there is a very easy way in the new C++ version of HOLA!

The new version will soon be a part of the official Adaptagrams. In fact there's an open pull request for it right now, which is currently being reviewed. If you don't want to wait, you can check out the HOLA branch of my fork of Adaptagrams.

In that version you can build a graph from a file format I call TGLF = Trivial Graph Layout Format (based on Trivial Graph Format). For example,

0 0 0 30 30
1 100 0 30 30
2 200 0 30 30
#
0 1
0 2
1 2
#
0 1 B E >= 30
0 2 B S >= 30

makes a graph of three nodes (defined before the first #, in format id x y w h), connected to form a triangle (edges defined before the next #), and with two constraints (defined after the last #).

These are "boundary constraints", hence the B. This means they specify a minimal gap between the boundaries (not the centers) of the nodes. (Use C for centers.)

Here, node 1 must lie to the East of node 0, while node 2 must lie South of node 0. Both have a minimal gap of 30.

So my recommendation is: get the new C++ version, write your network with layering constraints in TGLF, and see what happens! You can build a test case by following this example. Or if you want to stick with Python, you can use the new version through SWIG, as in this example.

dominicfollett commented 5 years ago

@skieffer

thank you for your help, this is a good avenue for me to pursue. The graphing problem I'm facing is, I think, a unique constrained orthogonal layout problem with varying constraints that need to be balanced against each other. Additionally, some of the graphs are disjoint but need to be laid other together.

If you're interested I'd like to show you what we're building, and what some of our problems are in the constrained orthogonal layout space.

skieffer commented 5 years ago

Sure, always interested to see new applications. : )