Class: SchemaRenderer

Inherits:
Object
  • Object
show all
Defined in:
src/ruby/render-schema.rb,
src/ruby/schema_renderer.rb

Direct Known Subclasses

DashboardSchema

Instance Method Summary collapse

Constructor Details

#initializeSchemaRenderer

Returns a new instance of SchemaRenderer.



2
3
# File 'src/ruby/render-schema.rb', line 2

def initialize()
end

Instance Method Details

#node(label, &block) ⇒ Object



5
6
# File 'src/ruby/render-schema.rb', line 5

def node(&block)
end

#to_dotObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'src/ruby/schema_renderer.rb', line 44

def to_dot()
    StringIO.open do |io|
        io.puts "digraph {"
        io.puts "graph [fontname = Arial, fontsize = 10, nodesep = 0.2, ranksep = 0.3];"
        io.puts "node [fontname = Arial, fontsize = 10, shape = rect, margin = 0];"
        io.puts "edge [fontname = Arial, fontsize = 10, arrowsize = 0.6, color = \"#000000\"];"
        io.puts "splines=true;"
        
        @nodes.each do |node|
            io.puts "n_#{node.label} [label=\"  #{node.label}  \", style=\"filled\", fillcolor=\"#fce94f\"];"
        end
        @nodes.each do |node|
            node.rels.each do |rel|
                l = "r_#{node.label}_#{rel[:type]}_#{rel[:target]}"
                io.puts "#{l} [label=\"  #{rel[:type]}  \"];"
                if rel[:dir] == :out
                    io.puts "n_#{node.label} -> #{l};"
                    io.puts "#{l} -> n_#{rel[:target]};"
                else
                    io.puts "n_#{rel[:target]} -> #{l};"
                    io.puts "#{l} -> n_#{node.label};"
#                         io.puts "n_#{rel[:target]} -> n_#{node.label} [label=\"#{rel[:type]}\"];"
                end
            end
        end
        io.puts "}"
        io.string
    end
end