I'm trying to create binary trees using the Graphviz tool but not as I would like.
For example: I would like to draw this tree:
With Graphviz I managed to do this:
In principle is fine but I would like that the nodes were arranged as the sample image. There is more space between nodes brothers.. I wish every time a parent node generates a son (though only child), the latter is or left or right of the father, and not in the middle.
Then I would like that the arrows are more subtle.
Searching the internet I could not find how to change the layout of the nodes nor how to make thinner arrows. I only found how to change the shape of the arrow but it is not what interests me.
Thanks to anyone who can help me!
Related
I can't figure out how to control edge placement with dot. I have created a small example to show my question. This may or may not be a MCVE; in the process of making it Minimal and Verifiable, I may have dropped the Complete. Anyway:
digraph stuff {
rankdir=LR;
a->b->c->b->a
}
$ dot -V
dot - graphviz version 2.38.0 (20140413.2041)
dot barfu.dot -Tpng > barfu.png
gives me this:
But I'd like to have the left-to-right arrows consistently on top, to reflect the normal state transitions. (Actually, it would be preferable to have them be straight lines in the middle, and have the right-to-left ones always curve below.)
I tried changing the line weight, the length, adding groups, setting connector directions, etc. Nothing seems to help, at least in the bigger graph this comes from.
This doesn't work in my larger diagram, so other answers are still most welcome, but it appears that, since graphviz starts with a default top-down graph, with the most important (downward pointing edges) on the left, they do a simple rotation when you make the graph go left to right, which rotates the top of the graph to the left, and thus the most important edges from the left to the bottom. So, of course, this really simple test case can be fixed by making the graph go right-to-left instead of left-to-right.
digraph stuff {
rankdir=RL;
c->b->a->b->c;
}
I'm building a a collapsible tree in d3 based on the tried and true Reingold-Tilford algorithm tree with the flare.json data.
you can see it here on one of my otherwise unused domain names: http://www.irreduciblecomplexity.co/
As you can see, it's getting awfully tall, and I'd like to move some of the branches to go outward from the left side instead of all from the right.
I'm not clear on how to do this, though.
http://bl.ocks.org/mbostock/3184089
This seems to be most on point, but I don't know how to replicate stemming from a single root. Any help is most appreciated.
(Also, this: Collapsible tree with combined horizontal and vertical layouts)
Thanks!
I used word to make this graph, how to make it in dot language? The line style is perpendicular. Thanks very much!
You can use the 'pos' attribute to place your nodes on an imaginary grid:
graph X
{
a [pos="1,1"]
b [pos="2,2"]
c [pos="2,3"]
d [pos="2,4"]
}
and then use the appropriate flag to the layout program to override neato's desire to place your nodes (you may also need to fiddle with the size of your nodes). You probably end up with edges which are not straight. In that case, define invisible nodes for the junction points on your imaginary grid and draw edges from your top node to the invisible ones and from the invisible ones to RIL_Init and so on. If your graphs are big, this will get pretty tedious..still straightforward...and you still get all the output options of graphviz. The need for pos="1,1!" usually comes up too, the bang meaning 'put it exactly there'.
In d3.js, i find that the tree layout cannot calculate the previous nodes by a certain node, it only can draw the successor nodes. is that some layout like DAG can be draw in d3.js?
Couple of ideas you might find useful:
You can use the tree layout to place the nodes in the canvas, create link objects pointing back and forth, then bind the link objects to a diagonal.
http://www.durablejs.org/examples/flowchart/1/admin.html
You can also use place the nodes using a pack layout, create the link objects pointing back and forth, and bind the links to a Bezier curve.
http://www.durablejs.org/examples/statechart/1/admin.html
You can find the code for the graphs above:
https://github.com/jruizgit/durable/tree/master/lib/durabjevisual.js
I have some data in a tree structure, and I want to represent them in a graphical way, with the root node in the middle of the stage, his children displaced in a circle around him, and so on for every children, around their parent.
I don't want overlapping nodes, so the question is how to arrange space in an optimal way.
Something less or more like (found via google)
What algorhythms I have to search to realize something like this?
If you don't care about how it's done, but just that you are visualizing the data, then take a look at graphviz's radial layout. Although the example doesn't look exactly what you want, it is the layout you'd need. It'll also give you some ideas on how it's done too with the loads of research papers in there. Good luck!
You could also see how easy it is to extend this paper into a circular structure.
You can do it in an emergent way by setting up a system in which each tree node tries to keep as much distance from all other nodes (except parent) as possible, but as short a distance as possible from the parent (down to some minimum distance which it must maintain). If you run that algorithm for each node repeatedly until it stabilizes, you'll have an arrangement like the one you describe. I'm sure there are a lot of optimizations you can do to it, but I'm pretty sure this is going to be the simplest approach. Trying to calculate all the layout up front would be very complex...
You are trying to draw a planar representation of a graph.
Find some buzzwords and perhaps a resource here
And in wikipedia
Ah and I forgot: You can do this the newtonian way with forces.
Simply give all nodes a repelling potential, like make them all Protons which push each other away. Give the edges the properties of newtonian springs, exerting forces that pull them together and you are all set.
Could even create nice animations that way.
This is also an official way of graph drawing, but I don't know the name.
If you want to draw the tree with a minimum of wasted space and short connections, then you're in for a computationally expensive solution. It will be hard to get this to be realtime on a tree of decent size, not to mention that making small changes to the tree might result in a radically different equilibrium.
Another approach would be to abandon the physical simulation and just build it iteratively. I've done something similar last week, but my trees are probably a lot less involved than yours.
For this tree-layout, each node object has to store an angle and an offset. These two numbers control where on the graphics surface they end up.
Here is my basic algorithm:
1) recurse over your entire tree-data and find all the Leaf nodes.
2) while you're doing this, be sure to measure the length of each branching structure, so you know which is the longest.
3) once you have all your leaf nodes, distribute them equally over a concentric circle. You can either use the entire circle, or only some part of the angle domain.
4) once all Leaf nodes have been solved, you recurse again over the tree, going from the outside in. Each node you encounter that is not a leaf node is in need of layout. Essentially, every node from here on has an angle which is the average of all it's child nodes, and the offset is the graph_radius * (depth_of_node / maximum_depth)
I found this gives me a very decent and humanly readable distribution, albeit not a very efficient one in terms of screen usage. I uploaded an animation of my tree-display here: GIF anim