Last active
August 29, 2015 14:06
-
-
Save segiddins/a8cf4b99e7feaac384ff to your computer and use it in GitHub Desktop.
PNG of Dependency Graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'ruby-graphviz' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print_graph("#{test_case.name} (expected)", test_case.result) | |
print_graph("#{test_case.name}", result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_graph(name, dependency_graph) | |
require 'graphviz' | |
# Create a new graph | |
g = GraphViz.new(:G, :type => :digraph) | |
add_child = lambda do |graph, parent, child| | |
cn = g.add_node("#{child.name} (#{child.payload.version})") | |
g.add_edges(parent, cn) | |
child.successors.each do |c| | |
add_child.call(graph, cn, c) | |
end | |
end | |
dependency_graph.root_vertices.values.each do |v| | |
node = g.add_node("#{v.name} (#{v.payload.version})") | |
v.successors.each do |s| | |
add_child.call(g, node, s) | |
end | |
end | |
# Generate output image | |
g.output(:png => "#{name}.png") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment