rubyplb 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/bin/rubyplb +6 -2
  3. data/lib/rubyplb.rb +42 -30
  4. data/rubyplb.gemspec +1 -1
  5. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
data/bin/rubyplb CHANGED
@@ -28,10 +28,14 @@ EOS
28
28
  opt :simple, "Use simple labels for pattern nodes", :default=> false
29
29
  opt :full, "Generate a full pattern lattice without contracting nodes", :default=> false
30
30
  opt :vertical, "Draw the graph from top to bottom instead of left to right)", :default => false
31
- opt :coloring, "Color pattern nodes", :default => false
31
+ opt :coloring, "Color pattern nodes [0 = none (default), 1 = cool/warm, 2 = monochrome]", :default => 0
32
32
  opt :straight, "Straighten edges (available when output format is either png, jpg, or eps)", :default => false
33
+ opt :nodesep, "Size of separation between sister nodes (from 0.1 to 5.0)", :default => 0.8
34
+ opt :ranksep, "Size of separation between ranks (from 0.1 to 5.0)", :default => 0.8
33
35
  end
34
-
36
+ Trollop::die :coloring, "must be 0, 1, or 2" if (opts[:coloring] > 2 || opts[:coloring] < 0)
37
+ Trollop::die :ranksep, "must be within 0.1 - 5.0" if (opts[:ranksep] < 0.1 || opts[:ranksep] > 5.0)
38
+ Trollop::die :nodesep, "must be within 0.1 - 5.0" if (opts[:nodesep] < 0.1 || opts[:nodesep] > 5.0)
35
39
  ############### main program ###############
36
40
 
37
41
  if ARGV.size != 2
data/lib/rubyplb.rb CHANGED
@@ -223,7 +223,7 @@ class PatLattice
223
223
  end
224
224
 
225
225
  def create_nodelabel(node)
226
- if (@opts[:coloring] || !@opts[:simple])
226
+ if (@opts[:coloring] != 0 || !@opts[:simple])
227
227
  if node.level != 0 and node.children_instances > 0
228
228
  ldata = @level_data[node.level]
229
229
  dev = node.children_instances - ldata[:avg_num_children]
@@ -234,30 +234,31 @@ class PatLattice
234
234
  end
235
235
  end
236
236
 
237
- color = "#ffffff"
238
- if @opts[:coloring]
239
- if !zscore.nan? and zscore != 0.0
240
- if zscore >= 3.0
241
- color = "2"
242
- elsif zscore >= 2.0
243
- color = "3"
244
- elsif zscore >= 1.5
245
- color = "4"
246
- elsif zscore >= 1.0
247
- color = "5"
248
- elsif zscore > 0.5
249
- color = "6"
250
- elsif zscore >= 0.0
251
- color = "7"
252
- elsif zscore >= -0.5
253
- color = "8"
254
- elsif zscore >= -1.0
255
- color = "9"
256
- elsif zscore >= -1.5
257
- color = "10"
258
- else
259
- color = "11"
260
- end
237
+ if @opts[:coloring] == 0
238
+ color = "#ffffff"
239
+ else
240
+ if zscore.nan? or zscore == 0.0
241
+ color = "#ffffff"
242
+ elsif zscore >= 3.0
243
+ color = @opts[:coloring] == 1 ? "2" : "6"
244
+ elsif zscore >= 1.5
245
+ color = @opts[:coloring] == 1 ? "3" : "5"
246
+ elsif zscore >= 1.0
247
+ color = @opts[:coloring] == 1 ? "4" : "4"
248
+ elsif zscore >= 0.5
249
+ color = @opts[:coloring] == 1 ? "5" : "3"
250
+ elsif zscore > 0.0
251
+ color = @opts[:coloring] == 1 ? "6" : "2"
252
+ elsif zscore >= -0.5
253
+ color = @opts[:coloring] == 1 ? "7" : "1"
254
+ elsif zscore >= -1.0
255
+ color = @opts[:coloring] == 1 ? "8" : "1"
256
+ elsif zscore >= -1.5
257
+ color = @opts[:coloring] == 1 ? "9" : "1"
258
+ elsif zscore >= -3.5
259
+ color = @opts[:coloring] == 1 ? "10" : "1"
260
+ else
261
+ color = @opts[:coloring] == 1 ? "11" : "1"
261
262
  end
262
263
  end
263
264
  border = "0"
@@ -278,16 +279,27 @@ class PatLattice
278
279
  end
279
280
 
280
281
  def create_node(graph, node_id, node_label)
282
+ case @opts[:coloring]
283
+ when 1
284
+ colorscheme = "rdylbu11"
285
+ when 2
286
+ colorscheme = "greys9"
287
+ else
288
+ colorscheme = ""
289
+ end
290
+
281
291
  graph.node(node_id, :label => node_label, :shape => "plaintext",
282
292
  :height => "0.0", :width => "0.0",
283
- :margin => "0.0", :colorscheme => "rdylbu11", :URL => node_id)
293
+ :margin => "0.0", :colorscheme => colorscheme, :URL => node_id)
284
294
  end
285
295
 
286
296
  def generate_dot
287
- setup_data if (@opts[:coloring] || !@opts[:simple])
297
+ setup_data if (@opts[:coloring] != 0 || !@opts[:simple])
288
298
  nodes_drawn = []
289
299
  rankdir = @opts[:vertical] ? "" : "LR"
290
- plb = RubyGraphviz.new("plb", :rankdir => rankdir, :nodesep => "0.8", :ranksep => "0.8")
300
+ nodesep = @opts[:nodesep] ? @opts[:nodesep].to_s : "0.8"
301
+ ranksep = @opts[:ranksep] ? @opts[:ranksep].to_s : "0.8"
302
+ plb = RubyGraphviz.new("plb", :rankdir => rankdir, :nodesep => nodesep, :ranksep => ranksep)
291
303
  levels.each do |level|
292
304
  level.each do |node|
293
305
  node_id = node.object_id
@@ -303,7 +315,7 @@ class PatLattice
303
315
  create_node(plb, cnode_id, cnode_label)
304
316
  nodes_drawn << node_id
305
317
  end
306
- if @opts[:coloring]
318
+ if @opts[:coloring] != 0
307
319
  colors = []
308
320
  @coloring.each do |color, val|
309
321
  if val.index(node.data) and val.index(cnode.data)
@@ -311,7 +323,7 @@ class PatLattice
311
323
  end
312
324
  end
313
325
  else
314
- colors = ["black"]
326
+ colors = ["gray60"]
315
327
  end
316
328
  plb.edge(node_id, cnode_id, :color => colors.join(":"))
317
329
  end
data/rubyplb.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rubyplb}
8
- s.version = "0.2.6"
8
+ s.version = "0.2.7"
9
9
  s.required_ruby_version = ">=1.8.6"
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kow Kuroda", "Yoichiro Hasebe"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyplb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kow Kuroda