Doxygen:是否可以控制依赖图的方向?
Doxygen: Is it possible to control the orientation of dependency graphs?
直到今天,我一直在使用 doxygen (+dot) 的 "ancient" 版本 (1.4.7),它通常会绘制垂直方向的图形,例如
..但是最近的一个(通过 Ubuntu 分发的 1.8.6),图表似乎是水平的,即
水平方向的问题在于许多图表都很好地偏离了 window 的右边缘,因此您必须进行“2D”滚动才能查看数据。
我查看了 doxygen 网页,但看不到是否有一个选项可以让 dot 以垂直方向绘制它们。有谁知道这样的选项是否存在?
2014 年有人问过类似的问题,我重复回答了这个问题:
Flip doxygen's graphs from top-to-bottom orientation to left-to-right
在我自己寻找同样的东西但一无所获之后,我能提供的最好的是使用图形属性 rankdir 的 hack。
步骤 1) 确保 Doxygen 保留点文件。将 DOT_CLEANUP=NO 放入您的配置文件中。
步骤 2) 找到 Doxygen 生成的点文件。应采用 *__incl.dot 形式。对于下面的步骤,我将此文件称为 <source>.dot
步骤 3a) 假设 dot 文件没有明确指定 rankdir(通常默认为 TB"),使用此命令重新生成输出。
dot -Grankdir="LR" -Tpng -o<source>.png -Tcmapx -o<source>.map <source>.dot
步骤 3b) 如果出于某种原因在点文件中指定了 rankdir,请进入文件并添加 rankdir="LR"
(默认情况下它们是 rankdir
设置为 "TB"
).
digraph "AppMain"
{
rankdir="LR";
...
然后重新生成输出:
dot -Tpng -o<source>.png -Tcmapx -o<source>.map <source>.dot
您需要在每次 运行 Doxygen 后重做此操作。批处理文件可能很方便,尤其是当您要处理所有文件时。对于步骤 3b,批量替换文本超出了此答案的范围 :)。但这里似乎是一个很好的答案:
How can you find and replace text in a file using the Windows command-line environment?
参考迈克尔的回答,
我写了一个 python3 脚本来 post-process
点图,使它们成为 LR。
这对我来说非常方便,也许对某人有用。
调整输出路径 "../../doxygen_output"
指向你的 doxygen 输出,
然后 运行 当前工作目录的脚本 = 脚本路径。
#!/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)
直到今天,我一直在使用 doxygen (+dot) 的 "ancient" 版本 (1.4.7),它通常会绘制垂直方向的图形,例如
..但是最近的一个(通过 Ubuntu 分发的 1.8.6),图表似乎是水平的,即
水平方向的问题在于许多图表都很好地偏离了 window 的右边缘,因此您必须进行“2D”滚动才能查看数据。
我查看了 doxygen 网页,但看不到是否有一个选项可以让 dot 以垂直方向绘制它们。有谁知道这样的选项是否存在?
2014 年有人问过类似的问题,我重复回答了这个问题: Flip doxygen's graphs from top-to-bottom orientation to left-to-right
在我自己寻找同样的东西但一无所获之后,我能提供的最好的是使用图形属性 rankdir 的 hack。
步骤 1) 确保 Doxygen 保留点文件。将 DOT_CLEANUP=NO 放入您的配置文件中。
步骤 2) 找到 Doxygen 生成的点文件。应采用 *__incl.dot 形式。对于下面的步骤,我将此文件称为 <source>.dot
步骤 3a) 假设 dot 文件没有明确指定 rankdir(通常默认为 TB"),使用此命令重新生成输出。
dot -Grankdir="LR" -Tpng -o<source>.png -Tcmapx -o<source>.map <source>.dot
步骤 3b) 如果出于某种原因在点文件中指定了 rankdir,请进入文件并添加 rankdir="LR"
(默认情况下它们是 rankdir
设置为 "TB"
).
digraph "AppMain"
{
rankdir="LR";
...
然后重新生成输出:
dot -Tpng -o<source>.png -Tcmapx -o<source>.map <source>.dot
您需要在每次 运行 Doxygen 后重做此操作。批处理文件可能很方便,尤其是当您要处理所有文件时。对于步骤 3b,批量替换文本超出了此答案的范围 :)。但这里似乎是一个很好的答案:
How can you find and replace text in a file using the Windows command-line environment?
参考迈克尔的回答,
我写了一个 python3 脚本来 post-process
点图,使它们成为 LR。
这对我来说非常方便,也许对某人有用。
调整输出路径 "../../doxygen_output"
指向你的 doxygen 输出,
然后 运行 当前工作目录的脚本 = 脚本路径。
#!/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)