rsyntaxtree 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46e87b5eb3718ca486b7db30381bf64d2c276f6e60173bbf686c150c3a40a54e
4
- data.tar.gz: 24c796def12932596bd4a4df5b29a758e4a8f633b986cae1d33663bf19e2836c
3
+ metadata.gz: 9fb3b6ae45edfeea2b1b280bfc432d7f3c669b235139638fba59c633b8326e70
4
+ data.tar.gz: 7c7d7e76f03a70eea5514c6d8d9bae87a4d05f78ee4ff9c63785da0058a38b9f
5
5
  SHA512:
6
- metadata.gz: cf98fca2b5ce268499bfdea7a6d745de7f5bf6c0b26bacff1bea79d42df360dad1ec013d9f96b54f9111c951839d74c84a9725d12a81c364d504d39cec2432c2
7
- data.tar.gz: 8efcf521ecb186456be69b8060c9a3b6c7724805897fb2aef6716aa5420f0da38fa4639c9798528d32b845498c2484cff56b95bb4e4a1df401972131910a315e
6
+ metadata.gz: 8f4754c519c2687b25df411c9a5025cd93363dc9bcb20cf3c7ef3281ac01fe05cf7414d35b0eb565ea00c7b3aac8d83fb4a1bb016428f1ddcb13cde08e197de3
7
+ data.tar.gz: 9d3c8fa5126ca404f4d32ebc6b8af4d3feac4252d729acca6048501dea39e377ea597c8a7d406f98e46d8bb3fa22b43d3b5243678c8ae70e9fc437bf61cf2601
@@ -50,7 +50,7 @@ class Graph
50
50
  @col_leaf = "black"
51
51
  @col_trace = "black"
52
52
  end
53
-
53
+
54
54
  @main_height = img_get_txt_height("l", font, font_size)
55
55
  @sub_size = (font_size * SUBSCRIPT_CONST)
56
56
  @sub_space_width = img_get_txt_width("l", font, @sub_size)
@@ -63,7 +63,7 @@ class Graph
63
63
 
64
64
  gc = Draw.new
65
65
  gc.annotate(background, 0, 0, 0, 0, text) do |gc|
66
- gc.font = font
66
+ gc.font = font
67
67
  gc.pointsize = font_size
68
68
  gc.gravity = CenterGravity
69
69
  gc.stroke = 'none'
@@ -191,23 +191,24 @@ class Graph
191
191
  end
192
192
  return true if !@symmetrize
193
193
 
194
+ @check = []
194
195
  h.times do |i|
195
196
  curlevel = h - i - 1
196
- indent = 0
197
197
  e_arr.each_with_index do |j, idx|
198
198
  if (j.level == curlevel)
199
199
  # Draw a line to the parent element
200
200
  children = @e_list.get_children(j.id)
201
201
 
202
202
  tw = img_get_txt_width(j.content, @font, @font_size)
203
- if children.length > 1
203
+ if children.length > 0
204
204
  left, right = -1, -1
205
- children.each do |child|
205
+ children.each do |child|
206
206
  k = @e_list.get_id(child)
207
- kw = img_get_txt_width(k.content, @font, @font_size)
207
+ kw = img_get_txt_width(k.content, @font, @font_size)
208
208
  left = k.indent + kw / 2 if k.indent + kw / 2 < left or left == -1
209
209
  right = k.indent + kw / 2 if k.indent + kw / 2 > right
210
210
  end
211
+
211
212
  draw_element(left, curlevel, right - left, j.content, j.type)
212
213
  @e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
213
214
 
@@ -215,40 +216,11 @@ class Graph
215
216
  k = @e_list.get_id(child)
216
217
  words = k.content.split(" ")
217
218
  dw = img_get_txt_width(k.content, @font, @font_size)
218
- unless @leafstyle == "nothing" && ETYPE_LEAF == k.type
219
- if (@leafstyle == "triangle" && ETYPE_LEAF == k.type && k.indent == j.indent && words.length > 0)
220
- txt_width = img_get_txt_width(k.content, @font, @font_size)
221
- triangle_to_parent(k.indent, curlevel + 1, dw, txt_width)
222
- elsif (@leafstyle == "auto" && ETYPE_LEAF == k.type && k.indent == j.indent)
223
- if words.length > 1 || k.triangle
224
- txt_width = img_get_txt_width(k.content, @font, @font_size)
225
- triangle_to_parent(k.indent, curlevel + 1, dw, txt_width)
226
- else
227
- line_to_parent(k.indent, curlevel + 1, dw, j.indent, tw)
228
- end
229
- else
230
- line_to_parent(k.indent, curlevel + 1, dw, j.indent, tw)
231
- end
232
- end
233
- end
234
219
 
235
- else
236
- unless children.empty?
237
- k = @e_list.get_id(children[0])
238
- kw = img_get_txt_width(k.content, @font, @font_size)
239
- left = k.indent
240
- right = k.indent + kw
241
- draw_element(left, curlevel, right - left, j.content, j.type)
242
- @e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
220
+ children2 = @e_list.get_children(k.id)
243
221
 
244
- k = @e_list.get_id(children[0])
245
- words = k.content.split(" ")
246
- dw = img_get_txt_width(k.content, @font, @font_size)
247
- unless (@leafstyle == "nothing" && ETYPE_LEAF == k.type)
248
- if (@leafstyle == "triangle" && ETYPE_LEAF == k.type && words.length > 0)
249
- txt_width = img_get_txt_width(k.content, @font, @font_size)
250
- triangle_to_parent(k.indent, curlevel + 1, dw, txt_width)
251
- elsif (@leafstyle == "auto" && ETYPE_LEAF == k.type)
222
+ unless @leafstyle == "nothing" && ETYPE_LEAF == k.type
223
+ if (@leafstyle == "auto" && ETYPE_LEAF == k.type)
252
224
  if words.length > 1 || k.triangle
253
225
  txt_width = img_get_txt_width(k.content, @font, @font_size)
254
226
  triangle_to_parent(k.indent, curlevel + 1, dw, txt_width)
@@ -259,39 +231,41 @@ class Graph
259
231
  line_to_parent(k.indent, curlevel + 1, dw, j.indent, tw)
260
232
  end
261
233
  end
262
-
263
- else
264
- parent = @e_list.get_id(j.parent)
265
- pw = img_get_txt_width(parent.content, @font, @font_size)
266
- pleft = parent.indent
267
- pright = pleft + pw
268
- if curlevel == (h - 1) && e_arr.size == idx + 1
269
- e_arr.select{|l|l.level == curlevel}.each do |l|
270
- lw = img_get_txt_width(l.content, @font, @font_size)
271
- left = l.indent
272
- right = left + lw
273
- @e_list.set_indent(l.id, left + (right - left) / 2 - tw / 2)
274
- draw_element(left, curlevel, right - left, l.content, l.type)
275
- end
276
- break
277
- else
278
- left = j.indent
279
- right = left + tw
280
- if pw > tw
281
- left = pleft
282
- right = pright
283
- end
284
- draw_element(left, curlevel, right - left, j.content, j.type)
285
- @e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
286
- end
287
234
  end
288
235
 
289
236
  end
237
+ elements = e_arr.select do |l|
238
+ l.level == curlevel && @e_list.get_children(l.id).empty?
239
+ end
240
+ process_terminal(elements, j, curlevel, tw)
290
241
  end
291
242
  end
292
243
  end
293
244
  end
294
245
 
246
+
247
+ def process_terminal(elements, j, curlevel, tw)
248
+ # parent = @e_list.get_id(j.parent)
249
+ # return unless parent
250
+ # pw = img_get_txt_width(parent.content, @font, @font_size)
251
+ # pleft = parent.indent
252
+ # pright = pleft + pw
253
+
254
+ elements.each.with_index do |l, idx|
255
+ lw = img_get_txt_width(l.content, @font, @font_size)
256
+ left = l.indent
257
+ right = left + lw
258
+ # if pw > tw
259
+ # left = pleft
260
+ # right = pright
261
+ # end
262
+ unless @check.include? l.id
263
+ draw_element(left, curlevel, right - left, l.content, l.type)
264
+ @check << l.id
265
+ end
266
+ end
267
+ end
268
+
295
269
  # Calculate top position from row (level)
296
270
  def row2px(row)
297
271
  @m[:b_topbot] + @e_height * row + (@m[:v_space] + @font_size) * row
@@ -1,4 +1,4 @@
1
1
  module RSyntaxTree
2
- VERSION = "0.8.4"
2
+ VERSION = "0.8.5"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsyntaxtree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoichiro Hasebe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-01 00:00:00.000000000 Z
11
+ date: 2021-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
@@ -91,7 +91,6 @@ files:
91
91
  - lib/rsyntaxtree/utils.rb
92
92
  - lib/rsyntaxtree/version.rb
93
93
  - rsyntaxtree.gemspec
94
- - syntree.svg
95
94
  homepage: http://github.com/yohasebe/rsyntaxtree
96
95
  licenses:
97
96
  - MIT
data/syntree.svg DELETED
@@ -1,44 +0,0 @@
1
- <?xml version="1.0" standalone="no"?>
2
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
- "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
- <svg width="1847.0" height="992.0" version="1.1" xmlns="http://www.w3.org/2000/svg">
5
- <text style='fill: green; font-size: 64px; ; ;' x='536.0' y='961.0' text-decoration='' font-family='sans-serif'>the</text>
6
- <text style='fill: green; font-size: 64px; ; ;' x='699.0' y='961.0' text-decoration='' font-family='sans-serif'>president</text>
7
- <text style='fill: green; font-size: 64px; ; ;' x='408.0' y='785.0' text-decoration='' font-family='sans-serif'>of</text>
8
- <text style='fill: blue; font-size: 64px; ; ;' x='562.0' y='785.0' text-decoration='' font-family='sans-serif'>D</text>
9
- <line style='stroke:black; stroke-width:2;' x1='586' y1='890' x2='586' y2='806' />
10
- <text style='fill: blue; font-size: 64px; ; ;' x='818.0' y='785.0' text-decoration='' font-family='sans-serif'>N</text>
11
- <line style='stroke:black; stroke-width:2;' x1='843' y1='890' x2='843' y2='806' />
12
- <text style='fill: green; font-size: 64px; ; ;' x='1243.0' y='785.0' text-decoration='' font-family='sans-serif'>blame</text>
13
- <text style='fill: green; font-size: 64px; ; ;' x='1495.0' y='785.0' text-decoration='' font-family='sans-serif'>* himself</text>
14
- <text style='fill: green; font-size: 64px; ; ;' x='10.0' y='609.0' text-decoration='line-through' font-family='sans-serif'>Supporters</text>
15
- <text style='fill: blue; font-size: 64px; ; ;' x='420.5' y='609.0' text-decoration='' font-family='sans-serif'>P</text>
16
- <line style='stroke:black; stroke-width:2;' x1='440' y1='714' x2='440' y2='630' />
17
- <text style='fill: blue; font-size: 64px; ; ;' x='671.0' y='609.0' text-decoration='' font-family='sans-serif'>DP</text>
18
- <line style='stroke:black; stroke-width:2;' x1='586' y1='714' x2='714' y2='630' />
19
- <line style='stroke:black; stroke-width:2;' x1='843' y1='714' x2='714' y2='630' />
20
- <text style='fill: green; font-size: 64px; ; ;' x='1050.0' y='609.0' text-decoration='' font-family='sans-serif'>may</text>
21
- <text style='fill: blue; font-size: 64px; ; ;' x='1317.5' y='609.0' text-decoration='' font-family='sans-serif'>V</text>
22
- <line style='stroke:black; stroke-width:2;' x1='1337' y1='714' x2='1337' y2='630' />
23
- <text style='fill: blue; font-size: 64px; ; ;' x='1570.0' y='609.0' text-decoration='' font-family='sans-serif'>PRN</text>
24
- <polygon style='fill: none; stroke: black; stroke-width:2;' points='1773 714 1495 714 1634 630' />
25
- <text style='fill: blue; font-size: 64px; ; ;' x='152.5' y='433.0' text-decoration='' font-family='sans-serif'>N</text>
26
- <line style='stroke:black; stroke-width:2;' x1='177' y1='538' x2='177' y2='454' />
27
- <text style='fill: blue; font-size: 64px; ; ;' x='538.0' y='433.0' text-decoration='' font-family='sans-serif'>PP</text>
28
- <line style='stroke:black; stroke-width:2;' x1='440' y1='538' x2='577' y2='454' />
29
- <line style='stroke:black; stroke-width:2;' x1='714' y1='538' x2='577' y2='454' />
30
- <text style='fill: blue; font-size: 64px; ; ;' x='1096.5' y='433.0' text-decoration='' font-family='sans-serif'>T</text>
31
- <line style='stroke:black; stroke-width:2;' x1='1115' y1='538' x2='1115' y2='454' />
32
- <text style='fill: blue; font-size: 64px; ; ;' x='1447.0' y='433.0' text-decoration='' font-family='sans-serif'>VP</text>
33
- <line style='stroke:black; stroke-width:2;' x1='1337' y1='538' x2='1486' y2='454' />
34
- <line style='stroke:black; stroke-width:2;' x1='1634' y1='538' x2='1486' y2='454' />
35
- <text style='fill: blue; font-size: 64px; ; ;' x='333.0' y='257.0' text-decoration='' font-family='sans-serif'>NP</text>
36
- <line style='stroke:black; stroke-width:2;' x1='177' y1='362' x2='377' y2='278' />
37
- <line style='stroke:black; stroke-width:2;' x1='577' y1='362' x2='377' y2='278' />
38
- <text style='fill: blue; font-size: 64px; ; ;' x='1275.0' y='257.0' text-decoration='' font-family='sans-serif'>T'</text>
39
- <line style='stroke:black; stroke-width:2;' x1='1115' y1='362' x2='1300' y2='278' />
40
- <line style='stroke:black; stroke-width:2;' x1='1486' y1='362' x2='1300' y2='278' />
41
- <text style='fill: blue; font-size: 64px; ; ;' x='801.0' y='81.0' text-decoration='' font-family='sans-serif'>TP</text>
42
- <line style='stroke:black; stroke-width:2;' x1='377' y1='186' x2='839' y2='102' />
43
- <line style='stroke:black; stroke-width:2;' x1='1300' y1='186' x2='839' y2='102' />
44
- </svg>