dogviz 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dogviz/colorizer.rb +25 -0
- data/lib/dogviz/common.rb +89 -0
- data/lib/dogviz/container.rb +88 -0
- data/lib/dogviz/duplicate_lookup_error.rb +7 -0
- data/lib/dogviz/flow.rb +67 -0
- data/lib/dogviz/flowable.rb +9 -0
- data/lib/dogviz/graphviz_renderer.rb +60 -0
- data/lib/dogviz/logical_container.rb +8 -0
- data/lib/dogviz/lookup_error.rb +7 -0
- data/lib/dogviz/missing_match_block_error.rb +7 -0
- data/lib/dogviz/nominator.rb +18 -0
- data/lib/dogviz/parent.rb +38 -0
- data/lib/dogviz/process.rb +18 -0
- data/lib/dogviz/registry.rb +39 -0
- data/lib/dogviz/rendered_sequence.rb +13 -0
- data/lib/dogviz/sequence_renderer.rb +47 -0
- data/lib/dogviz/sigma_graph_hash.rb +25 -0
- data/lib/dogviz/sigma_renderer.rb +32 -0
- data/lib/dogviz/system.rb +95 -0
- data/lib/dogviz/thing.rb +135 -0
- data/lib/dogviz/version.rb +1 -1
- data/lib/dogviz.rb +7 -687
- data/tests/test_dogviz_sigma_rendering.rb +68 -0
- data/todo.txt +7 -0
- metadata +24 -2
@@ -0,0 +1,95 @@
|
|
1
|
+
require_relative 'parent'
|
2
|
+
require_relative 'nominator'
|
3
|
+
require_relative 'registry'
|
4
|
+
|
5
|
+
module Dogviz
|
6
|
+
class System
|
7
|
+
include Parent
|
8
|
+
include Nominator
|
9
|
+
|
10
|
+
attr_reader :render_hints, :title, :children, :graph
|
11
|
+
|
12
|
+
alias :name :title
|
13
|
+
alias :render_options :render_hints
|
14
|
+
|
15
|
+
def initialize(name, hints = {splines: 'line'})
|
16
|
+
@children = []
|
17
|
+
@by_name = Registry.new name
|
18
|
+
@non_render_hints = remove_dogviz_hints!(hints)
|
19
|
+
@render_hints = hints
|
20
|
+
@title = create_title(name)
|
21
|
+
@rendered = false
|
22
|
+
end
|
23
|
+
|
24
|
+
def output(*args)
|
25
|
+
render
|
26
|
+
out = graph.output *args
|
27
|
+
puts "Created output: #{args.join ' '}" if run_from_command_line?
|
28
|
+
out
|
29
|
+
end
|
30
|
+
|
31
|
+
def flow(name)
|
32
|
+
Flow.new self, name
|
33
|
+
end
|
34
|
+
|
35
|
+
def render(type=:graphviz)
|
36
|
+
return @graph if @rendered
|
37
|
+
renderer = create_renderer(type)
|
38
|
+
|
39
|
+
children.each { |c|
|
40
|
+
c.render renderer
|
41
|
+
}
|
42
|
+
children.each { |c|
|
43
|
+
c.render_edges renderer
|
44
|
+
}
|
45
|
+
@rendered = true
|
46
|
+
@graph = renderer.graph
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_renderer(type)
|
50
|
+
if type == :graphviz
|
51
|
+
GraphvizRenderer.new @title, render_hints
|
52
|
+
elsif type == :sigma
|
53
|
+
SigmaRenderer.new @title
|
54
|
+
else
|
55
|
+
raise "dunno bout that '#{type}', only know :graphviz or :sigma"
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def rollup?
|
61
|
+
false
|
62
|
+
end
|
63
|
+
|
64
|
+
def skip?
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
68
|
+
def register(name, thing)
|
69
|
+
@by_name.register name, thing
|
70
|
+
end
|
71
|
+
|
72
|
+
def colorize_edges?
|
73
|
+
@non_render_hints[:colorize_edges]
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def remove_dogviz_hints!(hints)
|
79
|
+
dogviz_only_hints = {}
|
80
|
+
%i(colorize_edges).each { |k|
|
81
|
+
dogviz_only_hints[k] = hints.delete k
|
82
|
+
}
|
83
|
+
dogviz_only_hints
|
84
|
+
end
|
85
|
+
|
86
|
+
def create_title(name)
|
87
|
+
now = DateTime.now
|
88
|
+
"#{now.strftime '%H:%M'} #{name} #{now.strftime '%F'}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def run_from_command_line?
|
92
|
+
$stdout.isatty
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/dogviz/thing.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require_relative 'common'
|
2
|
+
require_relative 'nominator'
|
3
|
+
require_relative 'flowable'
|
4
|
+
require_relative 'colorizer'
|
5
|
+
|
6
|
+
module Dogviz
|
7
|
+
class Thing
|
8
|
+
include Common
|
9
|
+
include Nominator
|
10
|
+
include Flowable
|
11
|
+
attr_reader :parent
|
12
|
+
attr_reader :name, :id, :pointers, :edge_heads
|
13
|
+
|
14
|
+
@@colorizer = Colorizer.new
|
15
|
+
|
16
|
+
def initialize(parent, name, options = {})
|
17
|
+
@parent = parent
|
18
|
+
@name = name
|
19
|
+
@id = create_id(name, parent)
|
20
|
+
@pointers = []
|
21
|
+
@rollup = false
|
22
|
+
@skip = false
|
23
|
+
@info = {}
|
24
|
+
@edge_heads = []
|
25
|
+
|
26
|
+
rollup! if options[:rollup]
|
27
|
+
options.delete(:rollup)
|
28
|
+
|
29
|
+
@render_options = options
|
30
|
+
setup_render_attributes({label: name}.merge inherited_render_options)
|
31
|
+
|
32
|
+
parent.register name, self
|
33
|
+
end
|
34
|
+
|
35
|
+
def points_to_all(*others)
|
36
|
+
others.each { |other|
|
37
|
+
points_to other
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def points_to(other, options = {})
|
42
|
+
setup_render_edge(other, options)
|
43
|
+
other
|
44
|
+
end
|
45
|
+
|
46
|
+
def render(renderer)
|
47
|
+
do_render_node(renderer) unless in_rollup? || in_skip?
|
48
|
+
end
|
49
|
+
|
50
|
+
def render_edges(renderer)
|
51
|
+
pointers.each { |p|
|
52
|
+
render_pointer p, renderer
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def do_render_node(renderer)
|
59
|
+
render_options = @render_options
|
60
|
+
attributes = @attributes
|
61
|
+
renderer.render_node(parent, id, render_options, attributes)
|
62
|
+
end
|
63
|
+
|
64
|
+
def setup_render_edge(other, options)
|
65
|
+
pointers << {
|
66
|
+
other: other,
|
67
|
+
options: {
|
68
|
+
xlabel: options[:name],
|
69
|
+
style: options[:style]
|
70
|
+
}.merge(inherited_render_options)
|
71
|
+
}
|
72
|
+
|
73
|
+
if options[:colorize] || root.colorize_edges?
|
74
|
+
edge_color = next_colorizer_color
|
75
|
+
pointers.last[:options].merge!({
|
76
|
+
color: edge_color,
|
77
|
+
fontcolor: edge_color
|
78
|
+
})
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def render_pointer(pointer, renderer)
|
84
|
+
other = pointer[:other]
|
85
|
+
while (other.in_rollup? && !other.on_top_rollup?) do
|
86
|
+
other = other.parent
|
87
|
+
end
|
88
|
+
return if other.under_rollup?
|
89
|
+
|
90
|
+
from = self
|
91
|
+
while (from.in_rollup? && !from.on_top_rollup?) do
|
92
|
+
from = from.parent
|
93
|
+
end
|
94
|
+
|
95
|
+
return if from.in_skip?
|
96
|
+
|
97
|
+
return if from == self && from.in_rollup?
|
98
|
+
return if from == other
|
99
|
+
return if already_added_connection?(other)
|
100
|
+
|
101
|
+
if other.in_skip?
|
102
|
+
others = resolve_skipped_others other
|
103
|
+
else
|
104
|
+
others = [other]
|
105
|
+
end
|
106
|
+
|
107
|
+
others.each do |other|
|
108
|
+
edge_heads << other
|
109
|
+
render_options = pointer[:options]
|
110
|
+
renderer.render_edge(from, other, render_options)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def already_added_connection?(other)
|
115
|
+
edge_heads.include? other
|
116
|
+
end
|
117
|
+
|
118
|
+
def resolve_skipped_others(skipped)
|
119
|
+
resolved = []
|
120
|
+
skipped.pointers.each { |pointer|
|
121
|
+
next_in_line = pointer[:other]
|
122
|
+
if next_in_line.in_skip?
|
123
|
+
resolved += resolve_skipped_others next_in_line
|
124
|
+
else
|
125
|
+
resolved << next_in_line
|
126
|
+
end
|
127
|
+
}
|
128
|
+
resolved
|
129
|
+
end
|
130
|
+
|
131
|
+
def next_colorizer_color
|
132
|
+
@@colorizer.next
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/lib/dogviz/version.rb
CHANGED