如何优化 GraphViz 输出宽度?
我制作的图表具有巨大的宽度比:它们的大小为 51706 x 503 像素。 我如何告诉 GraphViz 优化宽度?
注1:该图实际上是一棵树,每个节点都有很多子节点。 这是一个示例。
注 2:我想我使用点:)
注 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
I make graphs that have huge width ratio: they are 51706 x 503 pixels in size.
How can I tell GraphViz to optimize width ?
Note 1: the graph is in fact a tree with each node having a lot of children.
Here is a sample.
Note 2: I think I use dot :)
Note 3: Here is the Ruby code
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果图表由几棵未连接的树组成,您可以将它们分开(如 Graphviz:将平坦但稀疏连接的图形分解为多行?)
根据您的特定图形,您在使用时可能会获得较小的图形
(您必须指定
size
)对于特定图表的详细优化,您可以添加
rank
属性并手动将节点分布在不同的等级上。编辑:
有一个名为 unflatten 的 graphviz 工具似乎正是为了这个目的而存在:
从来没有需要使用它,但我认为值得一试。
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
(You'll have to specify
size
though)For detailed optimizations on a specific graph, you may add
rank
attributes and distribute the nodes manually on different ranks.Edit:
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.
我还遇到了一个问题,neato 在盒子之间保留了很大的空间。最后,我还使用以下图形设置获得了合理的结果:
测试重叠缩放和比率的不同值特别有用。使用较小的示例(<50 个节点)并使用 gvedit.exe 查看效果是最快的。
我花了很长时间才确定这些设置,这些设置记录在 http://www. graphviz.org/doc/info/attrs.html
I also had the problem that neato kept lots of space between the boxes. Finally I achieved a reasonable result using following graph settings in addition:
It's especially useful testing different values for overlap_scaling and ratio. It's the quickest to use smaller examples (<50 nodes) and use gvedit.exe to see the effects.
It took me quite a while to identify these settings, which are documented at http://www.graphviz.org/doc/info/attrs.html
您可以尝试使用 ratio 参数。
You can try to play with the ratio parameter.