Doxygen: Is it possible to control the orientation of dependency graphs?
Asked Answered
J

2

6

Up until today, I'd been using an "ancient" version (1.4.7) of doxygen (+dot) and it typically drew graphs with a vertical orientation, e.g.
enter image description here

.. but with a more recent one (1.8.6 as distributed via Ubuntu), the graphs seem to be horizontal, i.e.
enter image description here

The problem with the horizontal orientation is that many of the graphs go well off the right edge of the window and so you have to do "2D" scrolling to see the data.

I've looked in the doxygen web pages but couldn't see if there was an option to tell dot to draw them with the vertical orientation. Does anyone know if such an option exists?

Jaunitajaunt answered 6/10, 2015 at 10:1 Comment(0)
A
5

There is a similar question asked in 2014 which I am duplicate answering: Flip doxygen's graphs from top-to-bottom orientation to left-to-right

After looking for the same myself and finding nothing, the best I can offer is a hack using the graph attribute rankdir.

Step 1) Make sure Doxygen keeps the dot files. Put DOT_CLEANUP=NO in your confige file.

Step 2) find your dot files that Doxygen generated. Should be in the form *__incl.dot. for steps below I will refer to this file as <source>.dot

Step 3a) Assuming the dot file did not explicitly specify rankdir (usually it is TB" by default), regenerate the output with this command.

dot -Grankdir="LR" -Tpng -o<source>.png -Tcmapx -o<source>.map <source>.dot 

Step 3b) If for some reason rankdir is specified in the dot file, go into the file and add the rankdir="LR" (by default they are rankdir is set to "TB").

digraph "AppMain"
{
  rankdir="LR";
...

Then regenerate the output with:

dot -Tpng -o<source>.png -Tcmapx -o<source>.map <source>.dot 

You need to redo this after every run of Doxygen. A batch file might be handy, especially if you want to process all files. For step 3b, batch replacing text is outside of the scope of this answer :). But here seems to be a good answer:

How can you find and replace text in a file using the Windows command-line environment?

Abshire answered 3/11, 2015 at 0:53 Comment(2)
Thanks. As I build everything in Linux with GNU make, running things "batch-like" should be a non-issue.Jaunitajaunt
Thanks. I made a script wrapper for dot itself, which calls the real dot as dot -Grankdir="LR" – and it seems to work as well.Susanasusanetta
F
0

Referring to the answer of Michael, I wrote a little python3 script to post-process the dot graphs, to make them LR. This is very handy to me, maybe it is useful to someone. Adapt the output path "../../doxygen_output" to point to your doxygen output, then just run the script with current work dir = the scripts path.

#!/usr/bin/python3
# -*- coding: utf-8 -*-

""" This script postprocesses a doxygen output to change the dot graphs having rankdir="LR"."""
import os

for path,dirs,files in os.walk("../../doxygen_output"):
    for f in files:
        if len(f) > 5: # prevent index out of range error
            if f[-4:] == ".dot":
                source = os.path.join(path,f.replace(".dot",""))
                cmdTpl = 'dot -Grankdir="LR" -Tpng -o<source>.png -Tcmapx -o<source>.map <source>.dot'
                cmd = cmdTpl.replace("<source>",source)
                os.system(cmd)

Fike answered 11/5, 2020 at 9:40 Comment(3)
Which doxygen version did you use? Note that you didn't take into account the possibility of svg files (will be hard as there is some mapping done as well. Note that for newer doxygen versions there has been a small improvement regarding LR / RL orientation of call / caller graphs.Stolid
I looked in the online documentation and did not find how to "overwrite" the rankdir, or how to control the graphs orientation. I assume that the online documentation reflects the most recent version. Anyway, my script is applicable for older versions, so, at least, it may be useful for someone who does not use the most recent version, for whatever reason. I use it, as an example, to analyze the "architecture" of aged big crufty embedded c projects, for maintenance purposes. For me, things have to be quick because I have, like many other people, a big amount of work to deliver.Fike
From the outside it is not possible to control the orientation of graphs. My remark was geared about the default orientation of arrows as used for call / caller graphs.Stolid

© 2022 - 2024 — McMap. All rights reserved.