问题描述
我制作的图形具有很大的宽度比:它们的尺寸为51706 x 503像素.如何告诉GraphViz优化宽度?
I make graphs that have huge width ratio: they are 51706 x 503 pixels in size.How can I tell GraphViz to optimize width ?
注1:图实际上是一棵树,每个节点都有很多子代.这里是一个.
Note 1: the graph is in fact a tree with each node having a lot of children.Here is a sample.
注2:我认为我使用点:)
Note 2: I think I use dot :)
注意3:这是 Ruby代码
def graph_node(n, parent=nil, depth=0)
#print n, " "
gn = @g.add_node(n.object_id.to_s, :label=>n.to_graphviz, :shape=>"Mrecord")
if parent
e = @g.add_edge(parent, gn)
end
if n == @current_pos_node
gn[:color] = "brown3"
gn[:style] = "filled"
elsif @s.tree.pv(@current_pos_node).include?(n)
gn[:color] = "cadetblue"
gn[:style] = "filled"
elsif @s.tree.pv(@root).include?(n)
gn[:color] = "yellow"
gn[:style] = "filled"
end
return if !n.children # or depth == 2
i = 0
for c in n.children
graph_node(c, gn, depth+1)
i += 1
#break if i > 2
end
end
def graph(name="tree", root_node=@current_pos_node)
@g = GraphViz::new("G")
#@g['sep'] = "10,100"
#@g["overlap"] = "compress"
#@g["rankdir"] = "BT"
#@g["ratio"] = "0.9"
@g["size"] = "350,500"
graph_node(root_node)
@g.output(:svg => "#{name}.svg")
end
推荐答案
如果图形由未连接的几棵树组成,则可以将它们拆分(如)
In case the graph consists of several trees which are not connected, you could split them up (as mentioned in Graphviz: break flat but sparsely connected graph into multiple rows?)
根据您的特定图形,使用时可能会获得较小的图形
Depending on your particular graph, you may obtain a smaller graph when using
ratio="compress"
(不过,您必须指定size
)
要对特定图形进行详细的优化,可以添加rank
属性,并手动将节点分布在不同的等级上.
For detailed optimizations on a specific graph, you may add rank
attributes and distribute the nodes manually on different ranks.
有一个称为 取消展开 的graphviz工具.似乎正是为此目的而存在的:
There is a graphviz tool called unflatten which seems to exist exactly for this purpose :
不需要使用它,但我认为值得尝试.
Never had the need to use it, but I think it's worth a try.
这篇关于如何优化GraphViz输出宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!