Class: RDocF95::Diagram

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc-f95/diagram.rb

Overview

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.

Constant Summary collapse

FONT =
"Arial"
DOT_PATH =
"dot"

Instance Method Summary collapse

Constructor Details

#initialize(info, options) ⇒ Diagram

Pass in the set of top level objects. The method also creates the subdirectory to hold the images



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rdoc-f95/diagram.rb', line 37

def initialize(info, options)
  @info = info
  @options = options
  @counter = 0
  FileUtils.mkdir_p(DOT_PATH)
  @diagram_cache = {}
  @html_suffix = ".html"
  if @options.mathml
    @html_suffix = ".xhtml"
  end
end

Instance Method Details

#drawObject

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.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rdoc-f95/diagram.rb', line 54

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::Digraph.new('name' => 'TopLevel',
                                             '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::Node.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)

    # 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::Digraph.new('name' => 'TopLevel',
                                               'fontname' => FONT,
                                               'fontsize' => '8',
                                               'bgcolor'  => 'lightcyan1',
                                               'compound' => 'true')

      graph << DOT::Node.new('name' => 'node',
                             'fontname' => FONT,
                             'color' => 'black',
                             'fontsize' => 8)
      draw_module(mod, graph, true)
      mod.diagram = convert_to_png("m_#{file_count}_#{count}",
                                   graph)
    end
  end
  $stderr.puts unless @options.quiet
end