Method: Web#create_mind_map

Defined in:
app/models/web.rb

#create_mind_map(prog, missing, show_authors, show_leaves, selected_categories, mm_size) ⇒ Object

create a Mind Map graph and return the PNG and HTML map files generated



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'app/models/web.rb', line 113

def create_mind_map(prog, missing, show_authors, show_leaves, selected_categories, mm_size)
  dotFile = File.expand_path("#{WikiService.storage_path}/graph.dot")
  mapFile = File.expand_path("#{WikiService.storage_path}/graph.map")
  pngFile = File.expand_path("#{WikiService.storage_path}/map.png")
  
  File.open(dotFile, "w") do |file|
  
    # Graph properties:
    output_graph_header_to file, mm_size
  
    # Links and node properties:
    nodes = filter_categories(pages.values, selected_categories)
    auths = authors # avoid repeated selects
    unless show_authors
      nodes.delete_if { |entry|
        auths.include? entry.name
      }
    end
    unless show_leaves
      nodes.delete_if { |page|
        (page.wiki_words - [missing].flatten).size == 0
      }
    end

    # Page Special nodes properties:
    file.puts %{"Home Page" [color=\"##{color}\",style=bold];} if nodes.map{ |p| p.name }.include? "HomePage"

    nodes.each do |page|
      file.puts %{"#{page.plain_name}" [URL=\"../show/#{page.name}\"];}
      page.references.each do |referer|
        unless page.name == referer.name or not nodes.include? referer
          unless !show_authors and auths.include? referer.name
            file.puts %{"#{referer.plain_name}" -> "#{page.plain_name}";}
          end
        end
      end
    end
  
    # find missing pages:
    if missing
      shown_missing = []
      nodes.each do |page|
        missing.each do |wanted|
          if page.content =~ /#{wanted}/
            file.puts %{"#{page.plain_name}" -> "#{WikiWords.separate wanted}";}
            shown_missing << wanted
          end
        end
      end
      shown_missing.each do |wanted|
        file.puts %{"#{WikiWords.separate wanted}" [URL="/#{@address}/show/#{wanted}", fontsize=10,style=filled,color=grey];}
      end
    end

    output_graph_footer_to file
  end

  call_graphviz(prog, dotFile, mapFile, pngFile)
  
  [pngFile, mapFile]
end