dogviz 0.0.16 → 0.0.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c139e3de9b60c343ea816c730a3e88667a3e79d2
4
- data.tar.gz: 0329e13153d5fa3079f2783a3c32370209e99d5d
3
+ metadata.gz: b2f28cea79616735c3ff115295186438f33407ff
4
+ data.tar.gz: afbe975455318158f50c85cf236f8308e385ed21
5
5
  SHA512:
6
- metadata.gz: cfc8beaad531936c0f9b9cb7ded8d0ae84999c4ef027ded83276adb1a91ebf8e994f60c12e90774f6722c3b55fb5ecaddf070bceabb49e74f91215da75b7f48f
7
- data.tar.gz: aee0a0735f84f82c45d54a1da12e53b69d8bb4480920f9b2b7722e04eda67c07ee04e8c18e14dddc261c77586c0282b89ca16ef41b08d7918b0eb1d08c5ce648
6
+ metadata.gz: 5facef62f26a853f1569cafe84b9c66724830d461816f1ed264c66d9d379da95670e959a89512bf74baa35bd5bd08d8e6bf8e3a571c16799ad006c2a12c61b84
7
+ data.tar.gz: c1eac0792f9a326575726b4d321c615c331526c30081bb1fe04d3b4afac463c8851d8bf4409fdeed04be5eb952bc0e6bec0f995b5269f29dcc0b8e3c18067ef3
@@ -1,3 +1,3 @@
1
1
  module Dogviz
2
- VERSION = '0.0.16'
2
+ VERSION = '0.0.17'
3
3
  end
data/lib/dogviz.rb CHANGED
@@ -103,6 +103,11 @@ module Dogviz
103
103
  def on_top_rollup?
104
104
  rollup? && !under_rollup?
105
105
  end
106
+ def inherited_render_options
107
+ inherited = {}
108
+ inherited[:fontname] = parent.render_options[:fontname] if parent.render_options.include?(:fontname)
109
+ inherited
110
+ end
106
111
  end
107
112
  module Parent
108
113
  def find_all(&matcher)
@@ -135,6 +140,30 @@ module Dogviz
135
140
  end
136
141
  end
137
142
 
143
+ class Colorizer
144
+ def initialize
145
+ @i = 0
146
+ @colors = %w(#9e0142
147
+ #d53e4f
148
+ #e45d33
149
+ #ed9e61
150
+ #762a83
151
+ #9970ab
152
+ #c6f578
153
+ #abdda4
154
+ #66c2a5
155
+ #3288bd
156
+ #5e4fa2)
157
+ end
158
+
159
+ def next
160
+ color = @colors[@i]
161
+ @i += 1
162
+ @i = 0 unless @i < @colors.length
163
+ color
164
+ end
165
+ end
166
+
138
167
  class Thing
139
168
  include Common
140
169
  include Nominator
@@ -142,6 +171,8 @@ module Dogviz
142
171
  attr_reader :parent
143
172
  attr_reader :name, :id, :pointers, :edge_heads
144
173
 
174
+ @@colorizer = Colorizer.new
175
+
145
176
  def initialize(parent, name, options = {})
146
177
  @parent = parent
147
178
  @name = name
@@ -156,17 +187,11 @@ module Dogviz
156
187
  options.delete(:rollup)
157
188
 
158
189
  @render_options = options
159
- setup_render_attributes label: name
190
+ setup_render_attributes({label: name}.merge inherited_render_options)
160
191
 
161
192
  parent.register name, self
162
193
  end
163
194
 
164
- def do_render_node(renderer)
165
- render_options = @render_options
166
- attributes = @attributes
167
- renderer.render_node(parent, id, render_options, attributes)
168
- end
169
-
170
195
  def points_to_all(*others)
171
196
  others.each {|other|
172
197
  points_to other
@@ -180,7 +205,7 @@ module Dogviz
180
205
 
181
206
  def render(renderer)
182
207
  do_render_node(renderer) unless in_rollup? || in_skip?
183
- end
208
+ end
184
209
 
185
210
  def render_edges(renderer)
186
211
  pointers.each {|p|
@@ -190,14 +215,29 @@ module Dogviz
190
215
 
191
216
  private
192
217
 
218
+ def do_render_node(renderer)
219
+ render_options = @render_options
220
+ attributes = @attributes
221
+ renderer.render_node(parent, id, render_options, attributes)
222
+ end
223
+
193
224
  def setup_render_edge(other, options)
194
225
  pointers << {
195
226
  other: other,
196
227
  options: {
197
- label: options[:name],
228
+ xlabel: options[:name],
198
229
  style: options[:style]
199
- }
230
+ }.merge(inherited_render_options)
200
231
  }
232
+
233
+ if options[:colorize] || root.colorize_edges?
234
+ edge_color = next_colorizer_color
235
+ pointers.last[:options].merge!({
236
+ color: edge_color,
237
+ fontcolor: edge_color
238
+ })
239
+ end
240
+
201
241
  end
202
242
 
203
243
  def render_pointer(pointer, renderer)
@@ -247,6 +287,10 @@ module Dogviz
247
287
  }
248
288
  resolved
249
289
  end
290
+
291
+ def next_colorizer_color
292
+ @@colorizer.next
293
+ end
250
294
  end
251
295
 
252
296
  class Container
@@ -269,7 +313,7 @@ module Dogviz
269
313
 
270
314
  setup_render_attributes label: name
271
315
 
272
- @render_options = options
316
+ @render_options = options.merge inherited_render_options
273
317
 
274
318
  parent.register name, self
275
319
  end
@@ -519,10 +563,12 @@ module Dogviz
519
563
  attr_reader :render_hints, :title, :children, :graph
520
564
 
521
565
  alias :name :title
566
+ alias :render_options :render_hints
522
567
 
523
568
  def initialize(name, hints = {splines: 'line'})
524
569
  @children = []
525
570
  @by_name = Registry.new name
571
+ @non_render_hints = remove_dogviz_hints!(hints)
526
572
  @render_hints = hints
527
573
  @title = create_title(name)
528
574
  @rendered = false
@@ -567,8 +613,20 @@ module Dogviz
567
613
  @by_name.register name, thing
568
614
  end
569
615
 
616
+ def colorize_edges?
617
+ @non_render_hints[:colorize_edges]
618
+ end
619
+
570
620
  private
571
621
 
622
+ def remove_dogviz_hints!(hints)
623
+ dogviz_only_hints = {}
624
+ %i(colorize_edges).each {|k|
625
+ dogviz_only_hints[k] = hints.delete k
626
+ }
627
+ dogviz_only_hints
628
+ end
629
+
572
630
  def create_title(name)
573
631
  now = DateTime.now
574
632
  "#{now.strftime '%H:%M'} #{name} #{now.strftime '%F'}"
@@ -0,0 +1,36 @@
1
+ require_relative 'setup_tests'
2
+ require_relative 'svg_graph'
3
+
4
+ module Tests
5
+ class TestContainer < Test::Unit::TestCase
6
+ include Dogviz
7
+
8
+ class StubParent
9
+ attr_accessor :render_options
10
+ def register(name, thing)
11
+
12
+ end
13
+ def colorize_edges?
14
+ false
15
+ end
16
+ def rollup?
17
+ false
18
+ end
19
+ def skip?
20
+ false
21
+ end
22
+ end
23
+
24
+ def setup
25
+ @parent = StubParent.new
26
+ end
27
+
28
+ attr_reader :parent
29
+
30
+ def test_container_exposes_inherited_render_options_from_parent
31
+ inheritable_options = {fontname: 'glyphoz'}
32
+ parent.render_options = inheritable_options
33
+ assert_equal inheritable_options, Container.new(parent, 'container').render_options
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,63 @@
1
+ require_relative 'setup_tests'
2
+ require_relative 'svg_graph'
3
+
4
+ module Tests
5
+ class TestThing < Test::Unit::TestCase
6
+ include Dogviz
7
+
8
+ class StubRenderer
9
+ attr_reader :last_node_options, :last_edge_options
10
+ def render_node(parent, id, render_options, attributes)
11
+ @last_node_options = render_options.merge attributes
12
+ end
13
+ def render_edge(from, other, options)
14
+ @last_edge_options = options
15
+ end
16
+ end
17
+
18
+ class StubParent
19
+ attr_accessor :render_options
20
+ def register(name, thing)
21
+
22
+ end
23
+ def colorize_edges?
24
+ false
25
+ end
26
+ def rollup?
27
+ false
28
+ end
29
+ def skip?
30
+ false
31
+ end
32
+ end
33
+
34
+ def setup
35
+ @parent = StubParent.new
36
+ @renderer = StubRenderer.new
37
+ end
38
+
39
+ attr_reader :parent, :renderer
40
+
41
+ def test_thing_name_rendered_with_inherited_fontname
42
+ parent.render_options = {fontname: 'funky-font'}
43
+
44
+ thing = Thing.new parent, 'thing'
45
+
46
+ thing.render renderer
47
+
48
+ assert_equal 'funky-font', renderer.last_node_options[:fontname]
49
+ end
50
+
51
+ def test_thing_edges_rendered_with_inherited_fontname
52
+ parent.render_options = {fontname: 'crazy-font'}
53
+
54
+ thing = Thing.new parent, 'thing'
55
+ thing.points_to Thing.new parent, 'other thing'
56
+
57
+ thing.render_edges renderer
58
+
59
+ assert_equal 'crazy-font', renderer.last_edge_options[:fontname]
60
+ end
61
+
62
+ end
63
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - damned
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-07 00:00:00.000000000 Z
11
+ date: 2016-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,10 +119,12 @@ files:
119
119
  - tests/graph_checking.rb
120
120
  - tests/setup_tests.rb
121
121
  - tests/svg_graph.rb
122
+ - tests/test_container.rb
122
123
  - tests/test_dogviz_flows.rb
123
124
  - tests/test_dogviz_functionally.rb
124
125
  - tests/test_dogviz_graph.rb
125
126
  - tests/test_dogviz_graphviz_rendering.rb
127
+ - tests/test_thing.rb
126
128
  homepage: https://github.com/damned/dogviz
127
129
  licenses:
128
130
  - MIT