Dot2tex v. 2.5.0 released

  • Published 2007-06-28 (10 months, 2 weeks ago)

I'm pleased to announce a new release of dot2tex. Highlights of the new release are:

  • The new tikz output format for tighter integration with PGF and TikZ
  • Alternative edge label placement
  • Custom edges using to paths.

For a full list of changes see the changelog.

The tikz output format

The tikz output format, like the default pgf format, uses PGF and TikZ for drawing. The main difference is that the tikz format does not rely on Graphviz' drawing information. Instead TikZ' node and edge constructs are used. The advantages of using the new format are:

  • The generated code is very compact and clean.
  • It is easy to modify the output.
  • Labels will fit inside nodes without preprocessing.
  • Full access to the power of PGF and TikZ.

The difference between the tikz and pgf formats are best explained using an example:

graph G {
    mindist = 0.5;
    node [shape=circle];
    a -- b -- c -- a;
} 

Rendering the graph with both the pgf and tikz formats,

$ circo -Txdot simple.dot | dot2tex -tmath -fpgf -s
$ circo -Txdot simple.dot | dot2tex -tmath -ftikz -s

gives visually different results:

""

However, the main difference is in the generated code. Here is the pgf code:

% Edge: a -- b
\draw [] (19bp,38bp) -- (19bp,60bp);
% Edge: b -- c
\draw [] (35bp,70bp) -- (55bp,58bp);
% Edge: c -- a
\draw [] (55bp,40bp) -- (35bp,28bp);
% Node: a
\begin{scope}
\pgfsetstrokecolor{black}
\draw (19bp,19bp) ellipse (18bp and 19bp);
\draw (19bp,19bp) node {$a$};
\end{scope}
% Node: b
\begin{scope}
\pgfsetstrokecolor{black}
\draw (19bp,79bp) ellipse (18bp and 19bp);
\draw (19bp,79bp) node {$b$};
\end{scope}
% Node: c
\begin{scope}
\pgfsetstrokecolor{black}
\draw (71bp,49bp) ellipse (18bp and 19bp);
\draw (71bp,49bp) node {$c$};
\end{scope} 

Compare it with the tikz output:

\node (a) at (19bp,19bp) [draw,circle] {$a$};
\node (b) at (19bp,79bp) [draw,circle] {$b$};
\node (c) at (71bp,49bp) [draw,circle] {$c$};
\draw [] (a) -- (b);
\draw [] (b) -- (c);
\draw [] (c) -- (a); 

Alternative edge label placement

The pgf and tikz output formats now supports the --tikzedgelabels option. Dot2tex will then bypass Graphviz' edge label placement and let TikZ do the job instead.

Example:

graph G {
    mindist = 0.5;
    node [shape="circle"];
    edge [lblstyle="mystyle"];
    a -- b [label="ab"];
    b -- c [label="bc"];
    c -- a [label="ca"];
}

Without the tikzedgelabels option, the code for placing labels will look something like this:

% Edge: a -- b
\draw [] (28bp,55bp) -- (28bp,75bp);
\draw (40bp,65bp) node[mystyle] {ab};
% Edge: b -- c
\draw [] (51bp,88bp) -- (68bp,78bp);
\draw (66bp,96bp) node[mystyle] {bc};
% Edge: c -- a
\draw [] (69bp,51bp) -- (52bp,41bp);
\draw (53bp,57bp) node[mystyle] {ca};

With the option, the code will look like this:

\draw [] (a) -- node[mystyle] {ab} (b);
\draw [] (b) -- node[mystyle] {bc} (c);
\draw [] (c) -- node[mystyle] {ca} (a);

The placement of the edge labels depends on the options passed to the edge label node (in this case mystyle), and the curve used to connect the nodes. Some examples of mystyle values are shown in the figure below.

""

Custom edges

The pgf and tikz output formats now supports the special topath edge attribute, which offers a way to override the edges drawn by Graphviz. When a topath attribute is encountered, dot2tex inserts a so called to path operation to connect the nodes. A number of predefined to paths are defined by TikZ, and you can create your own. Example:

digraph G {
    mindist = 0.5;
    node [shape="circle"];
    a -> b [topath="bend right"];
    c -> b [topath="bend left"];
    c -> a [topath="out=10,in=-90"];
    b -> b [topath="loop above"];
}

Rendering the graph with

$ circo -Txdot topaths1.dot | dot2tex -ftikz > topaths1.tex

yields:

""

The generated edge drawing code is:

\draw [->] (a) to[bend right] (b);
\draw [->] (c) to[bend left] (b);
\draw [->] (c) to[out=10,in=-90] (a);
\draw [->] (b) to[loop above] (b);

Future plans

Dot2tex has now become a useful and flexible tool . However, there are still a few things that could be improved and streamlined. I appreciate all feedback on how to improve dot2tex!

Comments

  • #1 Jan, July 1, 2007 at 8:44 p.m.

    Well, congrats. (I just came across your site again three days ago to review how I can get from dvi to png, and saw this announcement.)

  • #2 Kjell Magne Fauske, July 4, 2007 at 8:30 p.m.

    @Jan Thanks! I really like your Pasi diagram editor. The interface is very nice. Saving diagrams in PGF/TikZ format would be a nice feature.

  • #3 Jan, August 18, 2007 at 9:58 p.m.

    Thanks, Kjell. (I just found your reply via Google, lol. Must have overlooked the notification email, if there was one.)

    Different output formats would be cool, obviously. But as it stands, I just don't have very much time for programming. Summer's going to be over soon, and grad work needs to be done.

  • #4 sara ajay, August 21, 2007 at 7:05 a.m.

    how to draw curve based on random number generates(10000) EX:ATGC WHERE angle AG& AA-180 degrees, AT-35 degrees, AC-90 degrees.And A-RED,T-BULE,C-VIOLET,G-GREEN

  • #5 Kjell Magne Fauske, August 21, 2007 at 8:41 a.m.

    @sara ajay

    I am not sure if I fully understand your question. You could experiment with a graph like this:

    graph G {
        node [shape="circle"];
        A -- G [topath="out=180"];
        A -- A [topath="loop above"];
        A -- T [topath="out=35"];
        A -- C [topath="out=90"];
        A [style="fill=red"];
        T [style="fill=blue"];
        C [style="fill=violet"];
        G [style="fill=green"];
    }
    

    However, modifying the edges usually requires some manual adjustments to make it look good. If you plan to generate graphs with 10000 nodes this may be difficult unless the nodes are arranged in a nice pattern.

  • #6 Crocodilesky, October 15, 2007 at 10:56 a.m.

    I want to try it,don't I?

  • #7 HixLiepebex, November 2, 2007 at 9:24 p.m.

    ONLINE - DRUGSTORE! PRICES of ALL MEDICINES!

    FIND THAT NECESSARY... VIAGRA, CIALIS, PHENTERMINE, SOMA... and other pills!

    Welcome please: pills-prices.blogspot.com

    NEW INFORMATION ABOUT PAYDAY LOANS!

    Welcome please: payday-d-loans.blogspot.com

    GOOD LUCK!

Comments are disabled for this entry