Class | RDoc::Diagram |
In: |
rdoc/diagram.rb
|
Parent: | Object |
Draw a set of diagrams representing the modules and classes in the system. We draw one diagram for each file, and one for each toplevel class or module. This means there will be overlap. However, it also means that you’ll get better context for objects.
To use, simply
d = Diagram.new(info) # pass in collection of top level infos d.draw
The results will be written to the dot subdirectory. The process also sets the diagram attribute in each object it graphs to the name of the file containing the image. This can be used by output generators to insert images.
FONT | = | "Arial" |
DOT_PATH | = | "dot" |
Pass in the set of top level objects. The method also creates the subdirectory to hold the images
# File rdoc/diagram.rb, line 36 def initialize(info, options) @info = info @options = options @counter = 0 File.makedirs(DOT_PATH) end
Draw the diagrams. We traverse the files, drawing a diagram for each. We also traverse each top-level class and module in that file drawing a diagram for these too.
# File rdoc/diagram.rb, line 47 def draw unless @options.quiet $stderr.print "Diagrams: " $stderr.flush end @info.each_with_index do |i, file_count| @done_modules = {} @local_names = find_names(i) @global_names = [] @global_graph = graph = DOT::DOTDigraph.new('name' => 'TopLevel', 'label' => i.file_absolute_name, 'fontname' => FONT, 'fontsize' => '8', 'bgcolor' => 'lightcyan1', 'compound' => 'true') # it's a little hack %) i'm too lazy to create a separate class # for default node graph << DOT::DOTNode.new('name' => 'node', 'fontname' => FONT, 'color' => 'black', 'fontsize' => 8) i.modules.each do |mod| draw_module(mod, graph, true, i.file_relative_name) end add_classes(i, graph, i.file_relative_name) i.diagram = convert_to_png("f_#{file_count}", graph, i.name) # now go through and document each top level class and # module independently i.modules.each_with_index do |mod, count| @done_modules = {} @local_names = find_names(mod) @global_names = [] @global_graph = graph = DOT::DOTDigraph.new('name' => 'TopLevel', 'label' => i.full_name, 'fontname' => FONT, 'fontsize' => '8', 'bgcolor' => 'lightcyan1', 'compound' => 'true') graph << DOT::DOTNode.new('name' => 'node', 'fontname' => FONT, 'color' => 'black', 'fontsize' => 8) draw_module(mod, graph, true) mod.diagram = convert_to_png("m_#{file_count}_#{count}", graph, "Module: #{mod.name}") end end $stderr.puts unless @options.quiet end