Class | RDoc::Diagram |
In: |
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 diagram.rb, line 36 36: def initialize(info, options) 37: @info = info 38: @options = options 39: @counter = 0 40: File.makedirs(DOT_PATH) 41: 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 diagram.rb, line 47 47: def draw 48: unless @options.quiet 49: $stderr.print "Diagrams: " 50: $stderr.flush 51: end 52: 53: @info.each_with_index do |i, file_count| 54: @done_modules = {} 55: @local_names = find_names(i) 56: @global_names = [] 57: @global_graph = graph = DOT::DOTDigraph.new('name' => 'TopLevel', 58: 'label' => i.file_absolute_name, 59: 'fontname' => FONT, 60: 'fontsize' => '8', 61: 'bgcolor' => 'lightcyan1', 62: 'compound' => 'true') 63: 64: # it's a little hack %) i'm too lazy to create a separate class 65: # for default node 66: graph << DOT::DOTNode.new('name' => 'node', 67: 'fontname' => FONT, 68: 'color' => 'black', 69: 'fontsize' => 8) 70: 71: i.modules.each do |mod| 72: draw_module(mod, graph, true, i.file_relative_name) 73: end 74: add_classes(i, graph, i.file_relative_name) 75: 76: i.diagram = convert_to_png("f_#{file_count}", graph, i.name) 77: 78: # now go through and document each top level class and 79: # module independently 80: i.modules.each_with_index do |mod, count| 81: @done_modules = {} 82: @local_names = find_names(mod) 83: @global_names = [] 84: 85: @global_graph = graph = DOT::DOTDigraph.new('name' => 'TopLevel', 86: 'label' => i.full_name, 87: 'fontname' => FONT, 88: 'fontsize' => '8', 89: 'bgcolor' => 'lightcyan1', 90: 'compound' => 'true') 91: 92: graph << DOT::DOTNode.new('name' => 'node', 93: 'fontname' => FONT, 94: 'color' => 'black', 95: 'fontsize' => 8) 96: draw_module(mod, graph, true) 97: mod.diagram = convert_to_png("m_#{file_count}_#{count}", 98: graph, 99: "Module: #{mod.name}") 100: end 101: end 102: $stderr.puts unless @options.quiet 103: end