rsyntaxtree 1.2.2 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.tags +364 -127
  3. data/Rakefile +3 -0
  4. data/bin/rsyntaxtree +2 -0
  5. data/docs/_examples/000.md +2 -1
  6. data/docs/_examples/001.md +1 -0
  7. data/docs/_examples/002.md +1 -0
  8. data/docs/_examples/003.md +1 -0
  9. data/docs/_examples/004.md +1 -0
  10. data/docs/_examples/005.md +1 -0
  11. data/docs/_examples/006.md +1 -0
  12. data/docs/_examples/007.md +1 -0
  13. data/docs/_examples/008.md +1 -0
  14. data/docs/_examples/009.md +1 -0
  15. data/docs/_examples/010.md +1 -0
  16. data/docs/_examples/011.md +1 -0
  17. data/docs/_examples/012.md +1 -0
  18. data/docs/_examples/013.md +1 -0
  19. data/docs/_examples/014.md +1 -0
  20. data/docs/_examples/015.md +1 -0
  21. data/docs/_examples/016.md +1 -0
  22. data/docs/_examples/017.md +1 -0
  23. data/docs/_examples/018.md +1 -0
  24. data/docs/_examples/019.md +1 -0
  25. data/docs/_examples/020.md +7 -6
  26. data/docs/_examples/021.md +1 -0
  27. data/docs/_examples/022.md +1 -0
  28. data/docs/_examples/023.md +1 -0
  29. data/docs/_examples/024.md +1 -0
  30. data/docs/_examples/025.md +1 -0
  31. data/docs/_examples/026.md +2 -1
  32. data/docs/_examples/027.md +2 -1
  33. data/docs/_examples/028.md +1 -0
  34. data/docs/_examples/029.md +1 -0
  35. data/docs/_examples/030.md +1 -0
  36. data/docs/_examples/031.md +1 -0
  37. data/docs/_examples/032.md +1 -0
  38. data/docs/_examples/033.md +1 -0
  39. data/docs/_examples/034.md +1 -0
  40. data/docs/_examples/035.md +1 -0
  41. data/docs/_examples/036.md +1 -0
  42. data/docs/_examples/037.md +1 -0
  43. data/docs/_examples/038.md +32 -0
  44. data/docs/_examples/039.md +16 -0
  45. data/docs/_examples/040.md +62 -0
  46. data/docs/_examples/041.md +34 -0
  47. data/docs/assets/img/000.png +0 -0
  48. data/docs/assets/img/001.png +0 -0
  49. data/docs/assets/img/002.png +0 -0
  50. data/docs/assets/img/003.png +0 -0
  51. data/docs/assets/img/004.png +0 -0
  52. data/docs/assets/img/005.png +0 -0
  53. data/docs/assets/img/006.png +0 -0
  54. data/docs/assets/img/007.png +0 -0
  55. data/docs/assets/img/008.png +0 -0
  56. data/docs/assets/img/009.png +0 -0
  57. data/docs/assets/img/010.png +0 -0
  58. data/docs/assets/img/011.png +0 -0
  59. data/docs/assets/img/012.png +0 -0
  60. data/docs/assets/img/013.png +0 -0
  61. data/docs/assets/img/014.png +0 -0
  62. data/docs/assets/img/015.png +0 -0
  63. data/docs/assets/img/016.png +0 -0
  64. data/docs/assets/img/017.png +0 -0
  65. data/docs/assets/img/018.png +0 -0
  66. data/docs/assets/img/019.png +0 -0
  67. data/docs/assets/img/020.png +0 -0
  68. data/docs/assets/img/021.png +0 -0
  69. data/docs/assets/img/022.png +0 -0
  70. data/docs/assets/img/023.png +0 -0
  71. data/docs/assets/img/024.png +0 -0
  72. data/docs/assets/img/025.png +0 -0
  73. data/docs/assets/img/026.png +0 -0
  74. data/docs/assets/img/027.png +0 -0
  75. data/docs/assets/img/028.png +0 -0
  76. data/docs/assets/img/029.png +0 -0
  77. data/docs/assets/img/030.png +0 -0
  78. data/docs/assets/img/031.png +0 -0
  79. data/docs/assets/img/032.png +0 -0
  80. data/docs/assets/img/033.png +0 -0
  81. data/docs/assets/img/034.png +0 -0
  82. data/docs/assets/img/035.png +0 -0
  83. data/docs/assets/img/036.png +0 -0
  84. data/docs/assets/img/037.png +0 -0
  85. data/docs/assets/img/038.png +0 -0
  86. data/docs/assets/img/039.png +0 -0
  87. data/docs/assets/img/040.png +0 -0
  88. data/docs/assets/img/041.png +0 -0
  89. data/docs/assets/svg/000.svg +43 -43
  90. data/docs/assets/svg/001.svg +22 -22
  91. data/docs/assets/svg/002.svg +38 -38
  92. data/docs/assets/svg/003.svg +30 -30
  93. data/docs/assets/svg/004.svg +41 -41
  94. data/docs/assets/svg/005.svg +21 -21
  95. data/docs/assets/svg/006.svg +26 -26
  96. data/docs/assets/svg/007.svg +32 -32
  97. data/docs/assets/svg/008.svg +36 -36
  98. data/docs/assets/svg/009.svg +35 -35
  99. data/docs/assets/svg/010.svg +55 -55
  100. data/docs/assets/svg/011.svg +30 -30
  101. data/docs/assets/svg/012.svg +33 -33
  102. data/docs/assets/svg/013.svg +141 -141
  103. data/docs/assets/svg/014.svg +103 -110
  104. data/docs/assets/svg/015.svg +36 -36
  105. data/docs/assets/svg/016.svg +381 -381
  106. data/docs/assets/svg/017.svg +52 -52
  107. data/docs/assets/svg/018.svg +40 -40
  108. data/docs/assets/svg/019.svg +203 -233
  109. data/docs/assets/svg/020.svg +65 -63
  110. data/docs/assets/svg/021.svg +58 -58
  111. data/docs/assets/svg/022.svg +103 -103
  112. data/docs/assets/svg/023.svg +66 -66
  113. data/docs/assets/svg/024.svg +24 -24
  114. data/docs/assets/svg/025.svg +145 -145
  115. data/docs/assets/svg/026.svg +24 -24
  116. data/docs/assets/svg/027.svg +64 -64
  117. data/docs/assets/svg/028.svg +24 -24
  118. data/docs/assets/svg/029.svg +89 -99
  119. data/docs/assets/svg/030.svg +48 -54
  120. data/docs/assets/svg/031.svg +16 -16
  121. data/docs/assets/svg/032.svg +60 -66
  122. data/docs/assets/svg/033.svg +46 -46
  123. data/docs/assets/svg/034.svg +59 -68
  124. data/docs/assets/svg/035.svg +49 -54
  125. data/docs/assets/svg/036.svg +26 -29
  126. data/docs/assets/svg/037.svg +24 -25
  127. data/docs/assets/svg/038.svg +82 -0
  128. data/docs/assets/svg/039.svg +30 -0
  129. data/docs/assets/svg/040.svg +120 -0
  130. data/docs/assets/svg/041.svg +93 -0
  131. data/docs/documentation.md +10 -5
  132. data/docs/documentation_ja.md +9 -5
  133. data/docs/examples.html +2 -0
  134. data/lib/rsyntaxtree/base_graph.rb +7 -6
  135. data/lib/rsyntaxtree/element.rb +14 -7
  136. data/lib/rsyntaxtree/markup_parser.rb +1 -1
  137. data/lib/rsyntaxtree/svg_graph.rb +54 -51
  138. data/lib/rsyntaxtree/version.rb +1 -1
  139. data/lib/rsyntaxtree.rb +5 -0
  140. data/test/example_verify_test.rb +1 -0
  141. metadata +15 -3
@@ -22,15 +22,16 @@ module RSyntaxTree
22
22
  @extra_lines = []
23
23
  @fontset = params[:fontset]
24
24
  @fontsize = params[:fontsize]
25
+ @linewidth = params[:linewidth]
25
26
  @transparent = params[:transparent]
26
27
  @color = params[:color]
27
28
  @fontstyle = params[:fontstyle]
28
29
  @margin = params[:margin].to_i
29
30
  @polyline = params[:polyline]
30
- @line_styles = "<line style='stroke:#{@col_line}; stroke-width:#{FONT_SCALING};' x1='X1' y1='Y1' x2='X2' y2='Y2' />\n"
31
- @polyline_styles = "<polyline style='stroke:#{@col_line}; stroke-width:#{FONT_SCALING}; fill:none;'
31
+ @line_styles = "<line style='stroke:#{@col_line}; stroke-width:#{@linewidth + LINE_SCALING}; stroke-linecap:round;' x1='X1' y1='Y1' x2='X2' y2='Y2' />\n"
32
+ @polyline_styles = "<polyline style='stroke:#{@col_line}; stroke-width:#{@linewidth + LINE_SCALING}; fill:none; stroke-linejoin:round;'
32
33
  points='CHIX CHIY MIDX1 MIDY1 MIDX2 MIDY2 PARX PARY' />\n"
33
- @polygon_styles = "<polygon style='fill: none; stroke: black; stroke-width:#{FONT_SCALING};' points='X1 Y1 X2 Y2 X3 Y3' />\n"
34
+ @polygon_styles = "<polygon style='fill: none; stroke: black; stroke-width:#{@linewidth + LINE_SCALING}; stroke-linejoin:round;' points='X1 Y1 X2 Y2 X3 Y3' />\n"
34
35
  @text_styles = "<text white-space='pre' alignment-baseline='text-top' style='fill: COLOR; font-size: fontsize' x='X_VALUE' y='Y_VALUE'>CONTENT</text>\n"
35
36
  @tree_data = String.new
36
37
  @visited_x = {}
@@ -53,25 +54,28 @@ module RSyntaxTree
53
54
  y2 = @height + @margin
54
55
  extra_lines = @extra_lines.join("\n")
55
56
 
56
- as = @global[:h_gap_between_nodes] / 4 * 0.8
57
- as2 = @global[:h_gap_between_nodes] / 2 * 0.8
58
- as4 = @global[:h_gap_between_nodes] * 1.2
57
+ # as = @global[:h_gap_between_nodes] / 4 * 0.8
58
+ # as2 = @global[:h_gap_between_nodes] / 2 * 0.8
59
+ # as4 = @global[:h_gap_between_nodes] * 1.2
60
+
61
+ as2 = @global[:h_gap_between_nodes] * 1.0
62
+ as4 = as2 * 3
59
63
 
60
64
  header = <<~HDR
61
65
  <?xml version="1.0" standalone="no"?>
62
66
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
63
67
  <svg width="#{@width}" height="#{@height}" viewBox="#{x1}, #{y1}, #{x2}, #{y2}" version="1.1" xmlns="http://www.w3.org/2000/svg">
64
68
  <defs>
65
- <marker id="arrow" markerUnits="strokeWidth" markerWidth="#{as2}" markerHeight="#{as2}" viewBox="0 0 #{as2} #{as2}" refX="#{as}" refY="0">
66
- <polyline fill="none" stroke="#{@col_path}" stroke-width="1" points="0,#{as2},#{as},0,#{as2},#{as2}" />
69
+ <marker id="arrow" markerUnits="userSpaceOnUse" viewBox="0 0 10 10" refX="10" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
70
+ <path d="M 0 0 L 10 5 L 0 10" fill="#{@col_extra}"/>
67
71
  </marker>
68
- <marker id="arrowForward" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto-start-reverse">
72
+ <marker id="arrowBackward" markerUnits="userSpaceOnUse" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
69
73
  <path d="M 0 0 L 10 5 L 0 10 z" fill="#{@col_extra}"/>
70
74
  </marker>
71
- <marker id="arrowBackward" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
72
- <path d="M 0 0 L 10 5 L 0 10 z" fill="#{@col_extra}"/>
75
+ <marker id="arrowForward" markerUnits="userSpaceOnUse" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
76
+ <path d="M 10 0 L 0 5 L 10 10 z" fill="#{@col_extra}"/>
73
77
  </marker>
74
- <marker id="arrowBothways" viewBox="0 0 30 10" refX="15" refY="5" markerWidth="#{as4}" markerHeight="#{as4}" orient="auto">
78
+ <marker id="arrowBothways" markerUnits="userSpaceOnUse" viewBox="0 0 30 10" refX="15" refY="5" markerWidth="#{as4}" markerHeight="#{as2}" orient="auto">
75
79
  <path d="M 0 5 L 10 0 L 10 5 L 20 5 L 20 0 L 30 5 L 20 10 L 20 5 L 10 5 L 10 10 z" fill="#{@col_extra}"/>
76
80
  </marker>
77
81
  <pattern id="hatchBlack" x="10" y="10" width="10" height="10" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
@@ -99,10 +103,6 @@ module RSyntaxTree
99
103
  end
100
104
  end
101
105
 
102
- def draw_direct_line(s_x, s_y, t_x, t_y, s_arrow = false, t_arrow = false)
103
- @extra_lines << generate_connector(s_x, s_y, t_x, t_y, @col_extra, false, s_arrow, t_arrow)
104
- end
105
-
106
106
  def draw_a_path(s_x, s_y, t_x, t_y, target_arrow = :none)
107
107
  x_spacing = @global[:h_gap_between_nodes] * 1.25
108
108
  y_spacing = @global[:height_connector] * 0.75
@@ -147,7 +147,6 @@ module RSyntaxTree
147
147
  @extra_lines << generate_line(new_s_x, new_y, new_t_x, new_y, @col_path, dashed)
148
148
  @extra_lines << generate_line(new_t_x, new_y, new_t_x, t_y, @col_path, dashed)
149
149
  end
150
-
151
150
  @height = new_y if new_y > @height
152
151
  end
153
152
 
@@ -187,9 +186,9 @@ module RSyntaxTree
187
186
  y2 = y1
188
187
  case l[:type]
189
188
  when :border
190
- stroke_width = FONT_SCALING
189
+ stroke_width = @linewidth + LINE_SCALING
191
190
  when :bborder
192
- stroke_width = FONT_SCALING * 2
191
+ stroke_width = @linewidth + BLINE_SCALING
193
192
  end
194
193
  @extra_lines << "<line style=\"stroke:#{col}; stroke-width:#{stroke_width}; \" x1=\"#{x1}\" y1=\"#{y1}\" x2=\"#{x2}\" y2=\"#{y2}\"></line>"
195
194
  else
@@ -226,7 +225,7 @@ module RSyntaxTree
226
225
  this_y = text_y
227
226
  end
228
227
 
229
- style += "font-weight: bold; " if e[:decoration].include?(:bold) || e[:decoration].include?(:bolditalic)
228
+ style += "font-weight: bold; fill: #{@col_emph}; " if e[:decoration].include?(:bold) || e[:decoration].include?(:bolditalic)
230
229
  style += "font-style: italic; " if e[:decoration].include?(:italic) || e[:decoration].include?(:bolditalic)
231
230
  style += "\""
232
231
 
@@ -281,9 +280,9 @@ module RSyntaxTree
281
280
  enc = nil
282
281
 
283
282
  stroke_width = if e[:decoration].include?(:bstroke)
284
- FONT_SCALING * 2.5
283
+ @linewidth + BLINE_SCALING
285
284
  else
286
- FONT_SCALING
285
+ @linewidth + LINE_SCALING
287
286
  end
288
287
 
289
288
  if e[:decoration].include?(:box)
@@ -306,12 +305,12 @@ module RSyntaxTree
306
305
  @extra_lines << bar
307
306
 
308
307
  if e[:decoration].include?(:arrow_to_l)
309
- l_arrowhead = "<polyline stroke-linejoin='bevel' fill='none' stroke='#{col}' stroke-width='#{stroke_width}' points='#{x1 + ar_hwidth},#{y1 + ar_hwidth / 2} #{x1},#{y1} #{x1 + ar_hwidth},#{y1 - ar_hwidth / 2}' />\n"
308
+ l_arrowhead = "<polyline stroke-linejoin='round' fill='none' stroke='#{col}' stroke-width='#{stroke_width}' points='#{x1 + ar_hwidth},#{y1 + ar_hwidth / 2} #{x1},#{y1} #{x1 + ar_hwidth},#{y1 - ar_hwidth / 2}' />\n"
310
309
  @extra_lines << l_arrowhead
311
310
  end
312
311
 
313
312
  if e[:decoration].include?(:arrow_to_r)
314
- r_arrowhead = "<polyline stroke-linejoin='bevel' fill='none' stroke='#{col}' stroke-width='#{stroke_width}' points='#{x2 - ar_hwidth},#{y2 - ar_hwidth / 2} #{x2},#{y2} #{x2 - ar_hwidth},#{y2 + ar_hwidth / 2}' />\n"
313
+ r_arrowhead = "<polyline stroke-linejoin='round' fill='none' stroke='#{col}' stroke-width='#{stroke_width}' points='#{x2 - ar_hwidth},#{y2 - ar_hwidth / 2} #{x2},#{y2} #{x2 - ar_hwidth},#{y2 + ar_hwidth / 2}' />\n"
315
314
  @extra_lines << r_arrowhead
316
315
  end
317
316
  end
@@ -346,28 +345,32 @@ module RSyntaxTree
346
345
  bc[:height] = text_y - bc[:y] + @global[:height_connector_to_text]
347
346
  case element.enclosure
348
347
  when :brackets
349
- @extra_lines << generate_line(bc[:x], bc[:y], bc[:x] + @global[:h_gap_between_nodes] / 2, bc[:y], col)
350
- @extra_lines << generate_line(bc[:x], bc[:y], bc[:x], bc[:y] + bc[:height], col)
351
- @extra_lines << generate_line(bc[:x], bc[:y] + bc[:height], bc[:x] + @global[:h_gap_between_nodes] / 2, bc[:y] + bc[:height], col)
352
- @extra_lines << generate_line(bc[:x] + bc[:width], bc[:y], bc[:x] + bc[:width] - @global[:h_gap_between_nodes] / 2, bc[:y], col)
353
- @extra_lines << generate_line(bc[:x] + bc[:width], bc[:y], bc[:x] + bc[:width], bc[:y] + bc[:height], col)
354
- @extra_lines << generate_line(bc[:x] + bc[:width], bc[:y] + bc[:height], bc[:x] + bc[:width] - @global[:h_gap_between_nodes] / 2, bc[:y] + bc[:height], col)
348
+ draw_bracket(bc[:x], bc[:y], bc[:width], bc[:height], col)
355
349
  when :rectangle
356
- @extra_lines << generate_line(bc[:x], bc[:y], bc[:x] + bc[:width], bc[:y], col)
357
- @extra_lines << generate_line(bc[:x], bc[:y], bc[:x], bc[:y] + bc[:height], col)
358
- @extra_lines << generate_line(bc[:x] + bc[:width], bc[:y], bc[:x] + bc[:width], bc[:y] + bc[:height], col)
359
- @extra_lines << generate_line(bc[:x], bc[:y] + bc[:height], bc[:x] + bc[:width], bc[:y] + bc[:height], col)
350
+ draw_rectangle(bc[:x], bc[:y], bc[:width], bc[:height], col)
360
351
  when :brectangle
361
- @extra_lines << generate_line(bc[:x], bc[:y], bc[:x] + bc[:width], bc[:y], col, false, false, 2)
362
- @extra_lines << generate_line(bc[:x], bc[:y], bc[:x], bc[:y] + bc[:height], col, false, false, 2)
363
- @extra_lines << generate_line(bc[:x] + bc[:width], bc[:y], bc[:x] + bc[:width], bc[:y] + bc[:height], col, false, false, 2)
364
- @extra_lines << generate_line(bc[:x], bc[:y] + bc[:height], bc[:x] + bc[:width], bc[:y] + bc[:height], col, false, false, 2)
352
+ draw_rectangle(bc[:x], bc[:y], bc[:width], bc[:height], col, true)
365
353
  end
366
354
 
367
355
  element.content_height = bc[:height]
368
356
  @tree_data += text_data.sub(/CONTENT/, new_text)
369
357
  end
370
358
 
359
+ def draw_rectangle(x1, y1, width, height, col, bline = false)
360
+ swidth = bline ? @linewidth + BLINE_SCALING : @linewidth + LINE_SCALING
361
+ @extra_lines << "<polygon style='stroke:#{col}; stroke-width:#{swidth}; fill:none; stroke-linejoin:round;'
362
+ points='#{x1},#{y1} #{x1 + width},#{y1} #{x1 + width},#{y1 + height} #{x1},#{y1 + height}' />\n"
363
+ end
364
+
365
+ def draw_bracket(x1, y1, width, height, col, bline = false)
366
+ swidth = bline ? @linewidth + BLINE_SCALING : @linewidth + LINE_SCALING
367
+ slwidth = @global[:h_gap_between_nodes] / 2
368
+ @extra_lines << "<polyline style='stroke:#{col}; stroke-width:#{swidth}; fill:none; stroke-linejoin:round;'
369
+ points='#{x1 + slwidth},#{y1} #{x1},#{y1} #{x1},#{y1 + height} #{x1 + slwidth},#{y1 + height}' />\n"
370
+ @extra_lines << "<polyline style='stroke:#{col}; stroke-width:#{swidth}; fill:none; stroke-linejoin:round;'
371
+ points='#{x1 + width - slwidth},#{y1} #{x1 + width},#{y1} #{x1 + width},#{y1 + height} #{x1 + width - slwidth},#{y1 + height}' />\n"
372
+ end
373
+
371
374
  def set_tspan(this_x, this_y, style, decoration, fontstyle, text)
372
375
  text.gsub!(/■+/) do |x|
373
376
  num_spaces = x.size
@@ -396,7 +399,7 @@ module RSyntaxTree
396
399
  y1 = element.vertical_indent + element.content_height + @global[:height_connector_to_text]
397
400
  et = element.path
398
401
  et.each do |tr|
399
- if /\A-(>)?(\d+)\z/ =~ tr
402
+ if /\A-(>|<)?(\d+)\z/ =~ tr
400
403
  arrow = $1
401
404
  tr = $2
402
405
  if line_pool[tr]
@@ -405,7 +408,7 @@ module RSyntaxTree
405
408
  line_pool[tr] = [{ x: { left: x0, center: x1, right: x2 }, y: { top: y0, center: y0 + (y1 - y0) / 2, bottom: y1 }, arrow: arrow }]
406
409
  end
407
410
  line_flags << tr
408
- elsif /\A>(\d+)\z/ =~ tr
411
+ elsif /\A(?:>|<)(\d+)\z/ =~ tr
409
412
  tr = $1
410
413
  if path_pool_target[tr]
411
414
  path_pool_target[tr] << [x1, y1]
@@ -462,19 +465,19 @@ module RSyntaxTree
462
465
  b = v[1]
463
466
 
464
467
  if a[:y][:top] > b[:y][:bottom]
465
- draw_direct_line(a[:x][:center], a[:y][:top], b[:x][:center], b[:y][:bottom], a[:arrow], b[:arrow])
468
+ generate_connectors(a[:x][:center], a[:y][:top], b[:x][:center], b[:y][:bottom], @col_extra, false, a[:arrow], b[:arrow])
466
469
  elsif a[:y][:bottom] < b[:y][:top]
467
- draw_direct_line(b[:x][:center], b[:y][:top], a[:x][:center], a[:y][:bottom], b[:arrow], a[:arrow])
470
+ generate_connectors(b[:x][:center], b[:y][:top], a[:x][:center], a[:y][:bottom], @col_extra, false, b[:arrow], a[:arrow])
468
471
  elsif a[:x][:center] < b[:x][:center]
469
- draw_direct_line(a[:x][:right], a[:y][:center], b[:x][:left], b[:y][:center], a[:arrow], b[:arrow])
472
+ generate_connectors(a[:x][:right], a[:y][:center], b[:x][:left], b[:y][:center], @col_extra, false, a[:arrow], b[:arrow])
470
473
  else
471
- draw_direct_line(b[:x][:right], b[:y][:center], a[:x][:left], a[:y][:center], b[:arrow], a[:arrow])
474
+ generate_connectors(b[:x][:right], b[:y][:center], a[:x][:left], a[:y][:center], @col_extra, false, b[:arrow], a[:arrow])
472
475
  end
473
476
  end
474
477
  paths.size + line_pool.keys.size
475
478
  end
476
479
 
477
- def generate_connector(x1, y1, x2, y2, col, dashed = false, s_arrow = false, t_arrow = false, stroke_width = 1)
480
+ def generate_connectors(x1, y1, x2, y2, col, dashed = false, s_arrow = false, t_arrow = false, bline = false)
478
481
  string = if s_arrow && t_arrow
479
482
  "marker-mid='url(#arrowBothways)' "
480
483
  elsif s_arrow
@@ -485,7 +488,7 @@ module RSyntaxTree
485
488
  ""
486
489
  end
487
490
  dasharray = dashed ? "stroke-dasharray='8 8'" : ""
488
- swidth = FONT_SCALING * stroke_width
491
+ swidth = bline ? @linewidth + BLINE_SCALING : @linewidth + LINE_SCALING
489
492
 
490
493
  if s_arrow || t_arrow
491
494
  x_mid = if x2 > x1
@@ -498,22 +501,22 @@ module RSyntaxTree
498
501
  else
499
502
  y1 - (y1 - y2) / 2
500
503
  end
501
- "<path d='M#{x1},#{y1} L#{x_mid},#{y_mid} L#{x2}, #{y2}' style='fill: none; stroke: #{col}; stroke-width:#{swidth}' #{dasharray} #{string}/>"
504
+ @extra_lines << "<path d='M#{x1},#{y1} L#{x_mid},#{y_mid} L#{x2}, #{y2}' style='fill: none; stroke: #{col}; stroke-width:#{swidth}; stroke-linecap:round;' #{dasharray} #{string}/>"
502
505
  else
503
- "<line x1='#{x1}' y1='#{y1}' x2='#{x2}' y2='#{y2}' style='fill: none; stroke: #{col}; stroke-width:#{swidth}' #{dasharray} #{string}/>"
506
+ @extra_lines << "<line x1='#{x1}' y1='#{y1}' x2='#{x2}' y2='#{y2}' style='fill: none; stroke: #{col}; stroke-width:#{swidth}; stroke-linecap:round;' #{dasharray} #{string}/>"
504
507
  end
505
508
  end
506
509
 
507
- def generate_line(x1, y1, x2, y2, col, dashed = false, arrow = false, stroke_width = 1)
510
+ def generate_line(x1, y1, x2, y2, col, dashed = false, arrow = false, bline = false)
508
511
  string = if arrow
509
512
  "marker-end='url(#arrow)' "
510
513
  else
511
514
  ""
512
515
  end
513
516
  dasharray = dashed ? "stroke-dasharray='8 8'" : ""
514
- swidth = FONT_SCALING * stroke_width
517
+ swidth = bline ? @linewidth + BLINE_SCALING : @linewidth + LINE_SCALING
515
518
 
516
- "<line x1='#{x1}' y1='#{y1}' x2='#{x2}' y2='#{y2}' style='fill: none; stroke: #{col}; stroke-width:#{swidth}' #{dasharray} #{string}/>"
519
+ "<line x1='#{x1}' y1='#{y1}' x2='#{x2}' y2='#{y2}' style='fill: none; stroke: #{col}; stroke-width:#{swidth}; stroke-linecap:round;' #{dasharray} #{string}/>"
517
520
  end
518
521
 
519
522
  # Draw a line between child/parent elements
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSyntaxTree
4
- VERSION = "1.2.2"
4
+ VERSION = "1.2.4"
5
5
  end
data/lib/rsyntaxtree.rb CHANGED
@@ -13,6 +13,8 @@ ETYPE_NODE = 1
13
13
  ETYPE_LEAF = 2
14
14
  SUBSCRIPT_CONST = 0.7
15
15
  FONT_SCALING = 2
16
+ LINE_SCALING = 2
17
+ BLINE_SCALING = 5
16
18
  WHITESPACE_BLOCK = "■"
17
19
 
18
20
  class RSTError < StandardError
@@ -66,6 +68,8 @@ module RSyntaxTree
66
68
  end
67
69
  when :fontsize
68
70
  new_params[key] = value.to_i * FONT_SCALING
71
+ when :linewidth
72
+ new_params[key] = value.to_i
69
73
  when :margin
70
74
  new_params[key] = value.to_i * FONT_SCALING * 5
71
75
  when :vheight
@@ -120,6 +124,7 @@ module RSyntaxTree
120
124
  color: "modern",
121
125
  transparent: false,
122
126
  fontsize: 16,
127
+ linewidth: 2,
123
128
  format: "png",
124
129
  leafstyle: "auto",
125
130
  filename: "syntree",
@@ -20,6 +20,7 @@ class ExampleParserTest < Minitest::Test
20
20
  leafstyle: "auto",
21
21
  fontstyle: "sans",
22
22
  fontsize: 16,
23
+ linewidth: 1,
23
24
  margin: 1,
24
25
  vheight: 2.0,
25
26
  color: "on",
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: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoichiro Hasebe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-02 00:00:00.000000000 Z
11
+ date: 2023-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: optimist
@@ -150,6 +150,10 @@ files:
150
150
  - docs/_examples/035.md
151
151
  - docs/_examples/036.md
152
152
  - docs/_examples/037.md
153
+ - docs/_examples/038.md
154
+ - docs/_examples/039.md
155
+ - docs/_examples/040.md
156
+ - docs/_examples/041.md
153
157
  - docs/_includes/box_and_circle_table.html
154
158
  - docs/_includes/escape_char_table.html
155
159
  - docs/_includes/social_media_links.html
@@ -193,6 +197,10 @@ files:
193
197
  - docs/assets/img/035.png
194
198
  - docs/assets/img/036.png
195
199
  - docs/assets/img/037.png
200
+ - docs/assets/img/038.png
201
+ - docs/assets/img/039.png
202
+ - docs/assets/img/040.png
203
+ - docs/assets/img/041.png
196
204
  - docs/assets/img/elements/circle.png
197
205
  - docs/assets/img/elements/circle_abc.png
198
206
  - docs/assets/img/elements/circle_bold.png
@@ -247,6 +255,10 @@ files:
247
255
  - docs/assets/svg/035.svg
248
256
  - docs/assets/svg/036.svg
249
257
  - docs/assets/svg/037.svg
258
+ - docs/assets/svg/038.svg
259
+ - docs/assets/svg/039.svg
260
+ - docs/assets/svg/040.svg
261
+ - docs/assets/svg/041.svg
250
262
  - docs/documentation.md
251
263
  - docs/documentation_ja.md
252
264
  - docs/examples.html
@@ -304,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
304
316
  - !ruby/object:Gem::Version
305
317
  version: '0'
306
318
  requirements: []
307
- rubygems_version: 3.4.1
319
+ rubygems_version: 3.4.2
308
320
  signing_key:
309
321
  specification_version: 4
310
322
  summary: RSyntaxTree is a graphical syntax tree generator written in Ruby