-
Notifications
You must be signed in to change notification settings - Fork 6
/
makesvg.rb
34 lines (29 loc) · 1.14 KB
/
makesvg.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Convert graph.jsonl to dot and svg files
# Usage: mkdir graphs; cat README.graph.jsonl | ruby makesvg.rb
require 'json'
puts "-- drawings --"
scripts = ["Ruby","Shell","Perl"]
inputs = ["read", "get"]
while line = gets
obj = JSON.parse(line)
sys = obj['name']
graph = obj['graph']
puts "#{sys} has #{graph['nodes'].size} nodes, #{graph['rels'].size} relations"
File.open("graphs/#{sys}.dot", 'w') { |file|
file.puts "digraph { node [shape=box style=filled fillcolor=palegreen]"
graph['nodes'].each_with_index {|n,i|
color = if scripts.include?n['type'] then 'fillcolor=lightblue' else '' end
file.puts "#{i} [label=\"#{n['type']}\\n#{n['props']['name']}\" #{color}]"}
graph['rels'].each {|r|
src = "https://github.com/WardCunningham/search/blob/master/#{r['props']['file']}"
props = "label=\"#{r['type']}\" URL=\"#{src}#L#{r['props']['line']}\""
if inputs.include?r['type']
file.puts "#{r['to']} -> #{r['from']} [#{props} dir=back]"
else
file.puts "#{r['from']} -> #{r['to']} [#{props}]"
end
}
file.puts "}"
}
`dot -Tsvg graphs/#{sys}.dot > graphs/#{sys}.svg`
end