manual layout of graphs described in graphviz (DOT) format - graphviz

I have a graph that I've written down as a DOT file. I picked this because it's pretty easy to read and write programmatically, and I have a fair amount of tooling that uses the DOT file as input.
Graphviz does a decent job drawing it, but not a great job. (And that's all it's really meant to do, as far as I know.)
I am looking for, and cannot find, a tool that will read in the DOT file and let me manually drag around the vertices and edges I've already described in the DOT file similar to https://www.draw.io.
The thing that I really do not want to do is manually re-enter the graph I've already written down (or computed as output from a program or whatever) into draw.io and then have two different files that may or may not have the same set of edges and vertices because of transcription errors.
Ideally, I want something that will write its own file of only the metadata about where things are drawn, without adding a bunch of cruft to the DOT file, so that the tooling I have there still works and I can still use it as the unified representation of the graph between a bunch of different tasks.

You can run dot requesting output as another dot file with the command dot -Tdot. dot will then calculate the layout but instead of outputting a pictorial representation, it will output another dot file with exactly the same information as the input, with the addition of layout information as additional attributes. You can then edit the layout information by hand and run it through dot a second time to obtain the pictorial representation.
If your tools process a dot file properly, they should be able to process a dot file with layout attributes.
If you want a WYSIWYG tool to aid in the hand-layout process, take a look at dotty.

Here is what I have done when I want to manually adjust the node positioning and edges that are drawn by dot:
tell dot to generate an SVG image:
dot -Tsvg < graph_text.dot > output_image.svg
use an SVG editor such as Inkscape or Sketch (two that I have used) to open the SVG
When you open the SVG in an image editor that can handle the SVG format, each node and edge in the graph will be an independent draggable component.

Related

GraphViz Dot. How to distribute elements around a boxed size?

I have a dot graphviz file that geneates the following output:
http://www.qlands.com/other_files/test.png
However the output is organized vertically. If I setup the size to be for example 8.27 inches; How can I distribute the elements around a box of 8.27 x 8.27 inches?
Your graph is a directed graph layed out with dot from left to right, and the first rank contains many nodes which results in a very high image.
The main tool to break up graphs with this problem is unflatten:
unflatten is a preprocessor to dot that is used to improve the aspect
ratio of graphs having many leaves or disconnected nodes. The usual
layout for such a graph is generally very wide or tall. unflatten
inserts invisible edges or adjusts the minlen on edges to improve
layout compaction.
You may combine this with other tools and techniques to get the result you want:
Use the unflatten utility - please see this answer for a detailed example using unflatten.
Use invisible edges to introduce new ranks (basically what unflatten does automatically, but with human inspiration... example also here)
If you need the output to be of this exact size, be sure to understand graphviz's various attributes which have an impact on it, such as size, margin, ratio... (see also this and yet another answer providing details)
Finally, you could simply use a different layout (neato for example)

Camera calibration patterns

I would like to know if there is a process to generate camera calibration patterns.
We can use paint or any other graphic tool and set the precise measurements but then we need to hard-code the point positions or create a txt/xml file.
Is there a software that exports the data to a file that we can upload in our software.
What about 3D targets like boxes and/or cubes. Is there a method to generate the correct data points?
Cheers.
For 2D targets such as checkerboards, I used to do it like user469049 describes. Which was quite time consuming. In the end I gave up and created a web tool that does all of the leg work:
https://calib.io/pages/camera-calibration-pattern-generator
I'm using inkscape:
http://dominoc925.blogspot.co.uk/2012/06/create-camera-calibration-chess-board.html
I usually create a pdf file used to print and save files as LaTeX with PSTricks extensions.
The tex file has paths, so for a square it has a \moveto command to set the starting point and it has \line to command to set the next points.
In the dominoc925 example they define black and white squares but I just define the black squares to avoid repeated points.
I have a simple file loader in my code to get the points, just search for the \moveto and \line commands and workout the points from there.
For the 3D targets I treat each patter as one view because I don't have the tools to build a precise 3D target.
So instead of having different views of one patter like in the Matlab toolbox, I treat each detected pattern as a view.
In other words, if you have a 3D object then the target on each face is treated as a independent view.
There is probably a more professional way to do the job but this is my process :)
I hope this helps.

Finding a line in an image file

I am trying to crop out the printer marks that are at the edges of a PDF.
The path i want to take to solve this problem is as follows:
Convert PDF into a bitmap and then traverse the bitmap and try to find the lines, then once the lines are found, find the coordinates of the edges of these lines, set the cropping coordinates to the coordinates just found.
However the problems that pop up in my mind with this approach is how to know when the lines end and the actual page starts. How to differentiate lines from letters.
How do I overcome these hurdles, or is there a better way to crop out the printer marks from a PDF?
There is no general answer that works for ALL PDF files, however there are a few useful strategies that are implemented by existing solutions for graphics arts such as callas pdfToolbox (watch it, I'm associated with this product) or PitStop. The strategies center around a number of facts:
trim and bleed marks are usually simple lines (though thin rectangles are sometimes used as well). They are short and straight (horizontal or vertical).
These marks are usually drawn in specific colours. Either CMYK with the color set to 100%, 100%, 100%, 100% or - more commonly - a special spot color called "All". You're almost guaranteed of this because these marks need to show up on every printed separation (sorry for the technical printing terms if you're not familiar with them).
These marks normally are mirrored symmetrically. You're not looking for a single mark - you're looking for a set of them and this typically helps with recognition a lot. Watch out however that you're not confused by bad applications which don't place marks with absolute accuracy.
Lastly but perhaps not important in your application, different regions can actually work with different types of marks. Japanese trim and bleed marks for example look completely different than European or US marks.

Display labels in line with the edge when using Graphviz

I am using Graphviz 2.30. Horizontal positioning for labels works out, but in a few cases, a modified angle would be desired.
For instance, I tried various values for angle here but without any effect:
ABB -> ABACUS[label="applied", fontname="Arial", fontsize=15, labelangle=110];
How can I display labels in line with (i.e. parallel to) the edge when using a Graphviz digraph.
The entire digraph will not be posted due to an NDA. In addition, the rotation will be applied only to a few labels.
I have read similar threads like this or another (or a thread about alignment for instance) but without any help regarding my issue.
Using dot2latex allows you to specify lblstyle attribute. The value of lblstyle is used by PGF/TikZ in pdf generation.
One can specify parallel labels like this:
digraph G {
edge [lblstyle="above, sloped"];
a -> b [label="ab"];
b -> c [label="bc"];
c -> a [label="ca"];
}
To generate the pdf
$ dot2tex --tikzedgelabel file.dot > file.tex
$ pdflatex file.tex
The result is
Edit: another answer found an option that now exists to align text with edges.
Your best option may be to export the graph as an SVG and use Illustrator or Inkscape to fine-tune it. This is only practical when producing a few graphs.
I frequently have to tweak the output from Graphviz and Gephi; they give me a good starting point though.

Annotate DOT graphs with images

I'm using PyDot to generate Graphviz/dot graphs in python. I would like to annotate my nodes and edges with images read from files, I've found in the documentation how to put an image as a node, but not how to put an image under a node or even less an edge.
http://www.graphviz.org/doc/info/attrs.html
http://www.graphviz.org/doc/info/shapes.html
http://www.graphviz.org/Documentation/html/shapehowto.html
Does anybody know how to do that?
You can use HTML in the labels for nodes and edges. You can find details here: http://www.graphviz.org/doc/info/shapes.html#html
Basically you can say something
"a" -> "b" [label = <<TABLE><TR><TD><IMG SRC="path/to/picture"/></TD></TR></TABLE>>]
You can add as many rows and columns as you want in the html labels. It's a little more verbose than standard text labels, but you can do a bit more with them.
One method which can work in cases where edges will always be drawn in the same position is to create a PNG with a transparent background and position the icon in the same place that your edge will be drawn, or use the labeldistance/labelangle attributes to move. I'm not familiar with PyDot but using SQL I would create a case to determine whether or not the image is displayed on the node..
Problem with this method is that the graphs which I'm working with are always positioned differently and will never be the same, so in an ideal case I'd like to add the image to the edge label, or under/to the right of the edge label etc. Did you ever manage to find a workaround?

Resources