rsyntaxtree 1.2.3 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tags +365 -127
- data/Rakefile +1 -76
- data/bin/rsyntaxtree +2 -0
- data/devel/generate_examples.rb +91 -0
- data/docs/_examples/000.md +3 -1
- data/docs/_examples/001.md +2 -0
- data/docs/_examples/002.md +2 -0
- data/docs/_examples/003.md +2 -0
- data/docs/_examples/004.md +2 -0
- data/docs/_examples/005.md +2 -0
- data/docs/_examples/006.md +2 -0
- data/docs/_examples/007.md +2 -0
- data/docs/_examples/008.md +2 -0
- data/docs/_examples/009.md +2 -0
- data/docs/_examples/010.md +2 -0
- data/docs/_examples/011.md +2 -0
- data/docs/_examples/012.md +2 -0
- data/docs/_examples/013.md +2 -0
- data/docs/_examples/014.md +2 -0
- data/docs/_examples/015.md +2 -0
- data/docs/_examples/016.md +2 -0
- data/docs/_examples/017.md +2 -0
- data/docs/_examples/018.md +2 -0
- data/docs/_examples/019.md +2 -0
- data/docs/_examples/020.md +8 -6
- data/docs/_examples/021.md +2 -0
- data/docs/_examples/022.md +2 -0
- data/docs/_examples/023.md +2 -0
- data/docs/_examples/024.md +2 -0
- data/docs/_examples/025.md +2 -0
- data/docs/_examples/026.md +2 -0
- data/docs/_examples/027.md +2 -0
- data/docs/_examples/028.md +2 -0
- data/docs/_examples/029.md +2 -0
- data/docs/_examples/030.md +2 -0
- data/docs/_examples/031.md +2 -0
- data/docs/_examples/032.md +2 -0
- data/docs/_examples/033.md +2 -0
- data/docs/_examples/034.md +2 -0
- data/docs/_examples/035.md +2 -0
- data/docs/_examples/036.md +2 -0
- data/docs/_examples/037.md +8 -5
- data/docs/_examples/038.md +3 -1
- data/docs/_examples/039.md +3 -0
- data/docs/_examples/040.md +63 -0
- data/docs/_examples/041.md +35 -0
- data/docs/_examples/042.md +22 -0
- data/docs/_examples/043.md +40 -0
- data/docs/_examples/044.md +16 -0
- data/docs/_examples/045.md +48 -0
- data/docs/assets/img/000.png +0 -0
- data/docs/assets/img/001.png +0 -0
- data/docs/assets/img/002.png +0 -0
- data/docs/assets/img/003.png +0 -0
- data/docs/assets/img/004.png +0 -0
- data/docs/assets/img/005.png +0 -0
- data/docs/assets/img/006.png +0 -0
- data/docs/assets/img/007.png +0 -0
- data/docs/assets/img/008.png +0 -0
- data/docs/assets/img/009.png +0 -0
- data/docs/assets/img/010.png +0 -0
- data/docs/assets/img/011.png +0 -0
- data/docs/assets/img/012.png +0 -0
- data/docs/assets/img/013.png +0 -0
- data/docs/assets/img/014.png +0 -0
- data/docs/assets/img/014_.png +0 -0
- data/docs/assets/img/015.png +0 -0
- data/docs/assets/img/016.png +0 -0
- data/docs/assets/img/017.png +0 -0
- data/docs/assets/img/018.png +0 -0
- data/docs/assets/img/019.png +0 -0
- data/docs/assets/img/020.png +0 -0
- data/docs/assets/img/021.png +0 -0
- data/docs/assets/img/022.png +0 -0
- data/docs/assets/img/023.png +0 -0
- data/docs/assets/img/024.png +0 -0
- data/docs/assets/img/025.png +0 -0
- data/docs/assets/img/026.png +0 -0
- data/docs/assets/img/027.png +0 -0
- data/docs/assets/img/028.png +0 -0
- data/docs/assets/img/029.png +0 -0
- data/docs/assets/img/030.png +0 -0
- data/docs/assets/img/031.png +0 -0
- data/docs/assets/img/032.png +0 -0
- data/docs/assets/img/033.png +0 -0
- data/docs/assets/img/034.png +0 -0
- data/docs/assets/img/035.png +0 -0
- data/docs/assets/img/036.png +0 -0
- data/docs/assets/img/037.png +0 -0
- data/docs/assets/img/038.png +0 -0
- data/docs/assets/img/039.png +0 -0
- data/docs/assets/img/040.png +0 -0
- data/docs/assets/img/041.png +0 -0
- data/docs/assets/img/042.png +0 -0
- data/docs/assets/img/043.png +0 -0
- data/docs/assets/img/044.png +0 -0
- data/docs/assets/img/045.png +0 -0
- data/docs/assets/svg/000.svg +43 -43
- data/docs/assets/svg/001.svg +22 -22
- data/docs/assets/svg/002.svg +37 -37
- data/docs/assets/svg/003.svg +29 -29
- data/docs/assets/svg/004.svg +40 -40
- data/docs/assets/svg/005.svg +20 -20
- data/docs/assets/svg/006.svg +25 -25
- data/docs/assets/svg/007.svg +31 -31
- data/docs/assets/svg/008.svg +35 -35
- data/docs/assets/svg/009.svg +34 -34
- data/docs/assets/svg/010.svg +55 -55
- data/docs/assets/svg/011.svg +29 -29
- data/docs/assets/svg/012.svg +34 -34
- data/docs/assets/svg/013.svg +140 -140
- data/docs/assets/svg/014.svg +103 -110
- data/docs/assets/svg/015.svg +36 -36
- data/docs/assets/svg/016.svg +380 -380
- data/docs/assets/svg/017.svg +52 -52
- data/docs/assets/svg/018.svg +40 -40
- data/docs/assets/svg/019.svg +204 -234
- data/docs/assets/svg/020.svg +65 -63
- data/docs/assets/svg/021.svg +57 -57
- data/docs/assets/svg/022.svg +102 -102
- data/docs/assets/svg/023.svg +65 -65
- data/docs/assets/svg/024.svg +23 -23
- data/docs/assets/svg/025.svg +144 -144
- data/docs/assets/svg/026.svg +23 -23
- data/docs/assets/svg/027.svg +63 -63
- data/docs/assets/svg/028.svg +24 -24
- data/docs/assets/svg/029.svg +88 -98
- data/docs/assets/svg/030.svg +47 -53
- data/docs/assets/svg/031.svg +15 -15
- data/docs/assets/svg/032.svg +60 -66
- data/docs/assets/svg/033.svg +46 -46
- data/docs/assets/svg/034.svg +58 -67
- data/docs/assets/svg/035.svg +48 -53
- data/docs/assets/svg/036.svg +26 -29
- data/docs/assets/svg/037.svg +35 -55
- data/docs/assets/svg/038.svg +51 -57
- data/docs/assets/svg/039.svg +10 -10
- data/docs/assets/svg/040.svg +120 -0
- data/docs/assets/svg/041.svg +93 -0
- data/docs/assets/svg/042.svg +42 -0
- data/docs/assets/svg/043.svg +304 -0
- data/docs/assets/svg/044.svg +32 -0
- data/docs/assets/svg/045.svg +107 -0
- data/docs/documentation.md +9 -6
- data/docs/documentation_ja.md +9 -5
- data/docs/examples.html +2 -0
- data/fonts/NotoEmoji-Bold.ttf +0 -0
- data/fonts/NotoEmoji-Regular.ttf +0 -0
- data/fonts/OpenMoji-black-glyf.ttf +0 -0
- data/lib/rsyntaxtree/base_graph.rb +7 -6
- data/lib/rsyntaxtree/element.rb +7 -6
- data/lib/rsyntaxtree/svg_graph.rb +57 -53
- data/lib/rsyntaxtree/version.rb +1 -1
- data/lib/rsyntaxtree.rb +10 -5
- data/test/example_verify_test.rb +3 -0
- metadata +25 -4
- data/fonts/OpenMoji-Black.ttf +0 -0
- data/fonts/OpenMoji-Color.ttf +0 -0
data/lib/rsyntaxtree/element.rb
CHANGED
@@ -139,20 +139,21 @@ module RSyntaxTree
|
|
139
139
|
elements_height << height
|
140
140
|
else
|
141
141
|
one_bvm_given = true
|
142
|
-
elements_height << height + @global[:box_vertical_margin]
|
142
|
+
elements_height << height + @global[:box_vertical_margin]
|
143
143
|
end
|
144
144
|
|
145
145
|
e[:width] = width
|
146
146
|
row_width += width
|
147
147
|
end
|
148
148
|
|
149
|
-
total_height +=
|
150
|
-
elements_height.max + @global[:height_connector_to_text] * 2
|
151
|
-
else
|
152
|
-
elements_height.max + @global[:height_connector_to_text]
|
153
|
-
end
|
149
|
+
total_height += elements_height.max
|
154
150
|
content_width += row_width
|
155
151
|
end
|
152
|
+
total_height += if @parent.zero? && @children.empty? && @enclosure != :none
|
153
|
+
@global[:height_connector_to_text] / 4
|
154
|
+
else
|
155
|
+
@global[:height_connector_to_text]
|
156
|
+
end
|
156
157
|
total_width = content_width if total_width < content_width
|
157
158
|
end
|
158
159
|
@content_width = total_width
|
@@ -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:#{
|
31
|
-
@polyline_styles = "<polyline style='stroke:#{@col_line}; stroke-width:#{
|
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:#{
|
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 = {}
|
@@ -40,11 +41,7 @@ module RSyntaxTree
|
|
40
41
|
|
41
42
|
def svg_data
|
42
43
|
metrics = parse_list
|
43
|
-
@height =
|
44
|
-
metrics[:height]
|
45
|
-
else
|
46
|
-
metrics[:height] + @margin * 2
|
47
|
-
end
|
44
|
+
@height = metrics[:height] + @margin * 2
|
48
45
|
@width = metrics[:width] + @margin * 2
|
49
46
|
|
50
47
|
x1 = 0 - @margin
|
@@ -53,25 +50,24 @@ module RSyntaxTree
|
|
53
50
|
y2 = @height + @margin
|
54
51
|
extra_lines = @extra_lines.join("\n")
|
55
52
|
|
56
|
-
|
57
|
-
|
58
|
-
as4 = @global[:h_gap_between_nodes] * 1.2
|
53
|
+
as2 = @global[:h_gap_between_nodes] * 1.0
|
54
|
+
as4 = as2 * 3
|
59
55
|
|
60
56
|
header = <<~HDR
|
61
57
|
<?xml version="1.0" standalone="no"?>
|
62
58
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
63
59
|
<svg width="#{@width}" height="#{@height}" viewBox="#{x1}, #{y1}, #{x2}, #{y2}" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
64
60
|
<defs>
|
65
|
-
<marker id="arrow" markerUnits="
|
66
|
-
<
|
61
|
+
<marker id="arrow" markerUnits="userSpaceOnUse" viewBox="0 0 10 10" refX="10" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
|
62
|
+
<path d="M 0 0 L 10 5 L 0 10" fill="#{@col_extra}"/>
|
67
63
|
</marker>
|
68
|
-
<marker id="arrowBackward" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
|
64
|
+
<marker id="arrowBackward" markerUnits="userSpaceOnUse" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
|
69
65
|
<path d="M 0 0 L 10 5 L 0 10 z" fill="#{@col_extra}"/>
|
70
66
|
</marker>
|
71
|
-
<marker id="arrowForward" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
|
67
|
+
<marker id="arrowForward" markerUnits="userSpaceOnUse" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
|
72
68
|
<path d="M 10 0 L 0 5 L 10 10 z" fill="#{@col_extra}"/>
|
73
69
|
</marker>
|
74
|
-
<marker id="arrowBothways" viewBox="0 0 30 10" refX="15" refY="5" markerWidth="#{as4}" markerHeight="#{
|
70
|
+
<marker id="arrowBothways" markerUnits="userSpaceOnUse" viewBox="0 0 30 10" refX="15" refY="5" markerWidth="#{as4}" markerHeight="#{as2}" orient="auto">
|
75
71
|
<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
72
|
</marker>
|
77
73
|
<pattern id="hatchBlack" x="10" y="10" width="10" height="10" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
|
@@ -99,10 +95,6 @@ module RSyntaxTree
|
|
99
95
|
end
|
100
96
|
end
|
101
97
|
|
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
98
|
def draw_a_path(s_x, s_y, t_x, t_y, target_arrow = :none)
|
107
99
|
x_spacing = @global[:h_gap_between_nodes] * 1.25
|
108
100
|
y_spacing = @global[:height_connector] * 0.75
|
@@ -147,7 +139,6 @@ module RSyntaxTree
|
|
147
139
|
@extra_lines << generate_line(new_s_x, new_y, new_t_x, new_y, @col_path, dashed)
|
148
140
|
@extra_lines << generate_line(new_t_x, new_y, new_t_x, t_y, @col_path, dashed)
|
149
141
|
end
|
150
|
-
|
151
142
|
@height = new_y if new_y > @height
|
152
143
|
end
|
153
144
|
|
@@ -187,9 +178,9 @@ module RSyntaxTree
|
|
187
178
|
y2 = y1
|
188
179
|
case l[:type]
|
189
180
|
when :border
|
190
|
-
stroke_width =
|
181
|
+
stroke_width = @linewidth + LINE_SCALING
|
191
182
|
when :bborder
|
192
|
-
stroke_width =
|
183
|
+
stroke_width = @linewidth + BLINE_SCALING
|
193
184
|
end
|
194
185
|
@extra_lines << "<line style=\"stroke:#{col}; stroke-width:#{stroke_width}; \" x1=\"#{x1}\" y1=\"#{y1}\" x2=\"#{x2}\" y2=\"#{y2}\"></line>"
|
195
186
|
else
|
@@ -226,7 +217,7 @@ module RSyntaxTree
|
|
226
217
|
this_y = text_y
|
227
218
|
end
|
228
219
|
|
229
|
-
style += "font-weight: bold; " if e[:decoration].include?(:bold) || e[:decoration].include?(:bolditalic)
|
220
|
+
style += "font-weight: bold; fill: #{@col_emph}; " if e[:decoration].include?(:bold) || e[:decoration].include?(:bolditalic)
|
230
221
|
style += "font-style: italic; " if e[:decoration].include?(:italic) || e[:decoration].include?(:bolditalic)
|
231
222
|
style += "\""
|
232
223
|
|
@@ -281,9 +272,9 @@ module RSyntaxTree
|
|
281
272
|
enc = nil
|
282
273
|
|
283
274
|
stroke_width = if e[:decoration].include?(:bstroke)
|
284
|
-
|
275
|
+
@linewidth + BLINE_SCALING
|
285
276
|
else
|
286
|
-
|
277
|
+
@linewidth + LINE_SCALING
|
287
278
|
end
|
288
279
|
|
289
280
|
if e[:decoration].include?(:box)
|
@@ -306,12 +297,12 @@ module RSyntaxTree
|
|
306
297
|
@extra_lines << bar
|
307
298
|
|
308
299
|
if e[:decoration].include?(:arrow_to_l)
|
309
|
-
l_arrowhead = "<polyline stroke-linejoin='
|
300
|
+
l_arrowhead = "<polyline stroke-linejoin='round' stroke-linecap='round' fill='none' stroke='#{col}' stroke-width='#{stroke_width}' points='#{x1 + ar_hwidth},#{y1 + ar_hwidth / 2} #{x1 + stroke_width / 2},#{y1} #{x1 + ar_hwidth},#{y1 - ar_hwidth / 2}' />\n"
|
310
301
|
@extra_lines << l_arrowhead
|
311
302
|
end
|
312
303
|
|
313
304
|
if e[:decoration].include?(:arrow_to_r)
|
314
|
-
r_arrowhead = "<polyline stroke-linejoin='
|
305
|
+
r_arrowhead = "<polyline stroke-linejoin='round' stroke-linecap='round' fill='none' stroke='#{col}' stroke-width='#{stroke_width}' points='#{x2 - ar_hwidth},#{y2 - ar_hwidth / 2} #{x2 - stroke_width / 2},#{y2} #{x2 - ar_hwidth},#{y2 + ar_hwidth / 2}' />\n"
|
315
306
|
@extra_lines << r_arrowhead
|
316
307
|
end
|
317
308
|
end
|
@@ -342,32 +333,37 @@ module RSyntaxTree
|
|
342
333
|
end
|
343
334
|
@height = text_y if text_y > @height
|
344
335
|
end
|
336
|
+
|
345
337
|
bc[:y] = bc[:y] + @global[:height_connector_to_text] * 3 / 4
|
346
338
|
bc[:height] = text_y - bc[:y] + @global[:height_connector_to_text]
|
347
339
|
case element.enclosure
|
348
340
|
when :brackets
|
349
|
-
|
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)
|
341
|
+
draw_bracket(bc[:x], bc[:y], bc[:width], bc[:height], col)
|
355
342
|
when :rectangle
|
356
|
-
|
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)
|
343
|
+
draw_rectangle(bc[:x], bc[:y], bc[:width], bc[:height], col)
|
360
344
|
when :brectangle
|
361
|
-
|
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)
|
345
|
+
draw_rectangle(bc[:x], bc[:y], bc[:width], bc[:height], col, true)
|
365
346
|
end
|
366
347
|
|
367
348
|
element.content_height = bc[:height]
|
368
349
|
@tree_data += text_data.sub(/CONTENT/, new_text)
|
369
350
|
end
|
370
351
|
|
352
|
+
def draw_rectangle(x1, y1, width, height, col, bline = false)
|
353
|
+
swidth = bline ? @linewidth + BLINE_SCALING : @linewidth + LINE_SCALING
|
354
|
+
@extra_lines << "<polygon style='stroke:#{col}; stroke-width:#{swidth}; fill:none; stroke-linejoin:round;'
|
355
|
+
points='#{x1},#{y1} #{x1 + width},#{y1} #{x1 + width},#{y1 + height} #{x1},#{y1 + height}' />\n"
|
356
|
+
end
|
357
|
+
|
358
|
+
def draw_bracket(x1, y1, width, height, col, bline = false)
|
359
|
+
swidth = bline ? @linewidth + BLINE_SCALING : @linewidth + LINE_SCALING
|
360
|
+
slwidth = @global[:h_gap_between_nodes] / 2
|
361
|
+
@extra_lines << "<polyline style='stroke:#{col}; stroke-width:#{swidth}; fill:none; stroke-linejoin:round;'
|
362
|
+
points='#{x1 + slwidth},#{y1} #{x1},#{y1} #{x1},#{y1 + height} #{x1 + slwidth},#{y1 + height}' />\n"
|
363
|
+
@extra_lines << "<polyline style='stroke:#{col}; stroke-width:#{swidth}; fill:none; stroke-linejoin:round;'
|
364
|
+
points='#{x1 + width - slwidth},#{y1} #{x1 + width},#{y1} #{x1 + width},#{y1 + height} #{x1 + width - slwidth},#{y1 + height}' />\n"
|
365
|
+
end
|
366
|
+
|
371
367
|
def set_tspan(this_x, this_y, style, decoration, fontstyle, text)
|
372
368
|
text.gsub!(/■+/) do |x|
|
373
369
|
num_spaces = x.size
|
@@ -462,19 +458,27 @@ module RSyntaxTree
|
|
462
458
|
b = v[1]
|
463
459
|
|
464
460
|
if a[:y][:top] > b[:y][:bottom]
|
465
|
-
|
461
|
+
generate_connectors(a[:x][:center], a[:y][:top], b[:x][:center], b[:y][:bottom], @col_extra, false, a[:arrow], b[:arrow])
|
466
462
|
elsif a[:y][:bottom] < b[:y][:top]
|
467
|
-
|
463
|
+
generate_connectors(b[:x][:center], b[:y][:top], a[:x][:center], a[:y][:bottom], @col_extra, false, b[:arrow], a[:arrow])
|
468
464
|
elsif a[:x][:center] < b[:x][:center]
|
469
|
-
|
465
|
+
if a[:y][:top] == b[:y][:top]
|
466
|
+
upper_y = a[:y][:center] < b[:y][:center] ? a[:y][:center] : b[:y][:center]
|
467
|
+
generate_connectors(a[:x][:right], upper_y, b[:x][:left], upper_y, @col_extra, false, a[:arrow], b[:arrow])
|
468
|
+
else
|
469
|
+
generate_connectors(a[:x][:right], a[:y][:center], b[:x][:left], b[:y][:center], @col_extra, false, a[:arrow], b[:arrow])
|
470
|
+
end
|
471
|
+
elsif a[:y][:top] == b[:y][:top]
|
472
|
+
upper_y = a[:y][:center] < b[:y][:center] ? a[:y][:center] : b[:y][:center]
|
473
|
+
generate_connectors(b[:x][:right], upper_y, a[:x][:left], upper_y, @col_extra, false, b[:arrow], a[:arrow])
|
470
474
|
else
|
471
|
-
|
475
|
+
generate_connectors(b[:x][:right], b[:y][:center], a[:x][:left], a[:y][:center], @col_extra, false, b[:arrow], a[:arrow])
|
472
476
|
end
|
473
477
|
end
|
474
478
|
paths.size + line_pool.keys.size
|
475
479
|
end
|
476
480
|
|
477
|
-
def
|
481
|
+
def generate_connectors(x1, y1, x2, y2, col, dashed = false, s_arrow = false, t_arrow = false, bline = false)
|
478
482
|
string = if s_arrow && t_arrow
|
479
483
|
"marker-mid='url(#arrowBothways)' "
|
480
484
|
elsif s_arrow
|
@@ -485,7 +489,7 @@ module RSyntaxTree
|
|
485
489
|
""
|
486
490
|
end
|
487
491
|
dasharray = dashed ? "stroke-dasharray='8 8'" : ""
|
488
|
-
swidth =
|
492
|
+
swidth = bline ? @linewidth + BLINE_SCALING : @linewidth + LINE_SCALING
|
489
493
|
|
490
494
|
if s_arrow || t_arrow
|
491
495
|
x_mid = if x2 > x1
|
@@ -498,22 +502,22 @@ module RSyntaxTree
|
|
498
502
|
else
|
499
503
|
y1 - (y1 - y2) / 2
|
500
504
|
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}/>"
|
505
|
+
@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
506
|
else
|
503
|
-
"<line x1='#{x1}' y1='#{y1}' x2='#{x2}' y2='#{y2}' style='fill: none; stroke: #{col}; stroke-width:#{swidth}' #{dasharray} #{string}/>"
|
507
|
+
@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
508
|
end
|
505
509
|
end
|
506
510
|
|
507
|
-
def generate_line(x1, y1, x2, y2, col, dashed = false, arrow = false,
|
511
|
+
def generate_line(x1, y1, x2, y2, col, dashed = false, arrow = false, bline = false)
|
508
512
|
string = if arrow
|
509
513
|
"marker-end='url(#arrow)' "
|
510
514
|
else
|
511
515
|
""
|
512
516
|
end
|
513
517
|
dasharray = dashed ? "stroke-dasharray='8 8'" : ""
|
514
|
-
swidth =
|
518
|
+
swidth = bline ? @linewidth + BLINE_SCALING : @linewidth + LINE_SCALING
|
515
519
|
|
516
|
-
"<line x1='#{x1}' y1='#{y1}' x2='#{x2}' y2='#{y2}' style='fill: none; stroke: #{col}; stroke-width:#{swidth}' #{dasharray} #{string}/>"
|
520
|
+
"<line x1='#{x1}' y1='#{y1}' x2='#{x2}' y2='#{y2}' style='fill: none; stroke: #{col}; stroke-width:#{swidth}; stroke-linecap:round;' #{dasharray} #{string}/>"
|
517
521
|
end
|
518
522
|
|
519
523
|
# Draw a line between child/parent elements
|
data/lib/rsyntaxtree/version.rb
CHANGED
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
|
@@ -79,7 +83,7 @@ module RSyntaxTree
|
|
79
83
|
fontset[:bolditalic] = FONT_DIR + "/NotoSansMono_SemiCondensed-Bold.ttf"
|
80
84
|
fontset[:math] = FONT_DIR + "/latinmodern-math.otf"
|
81
85
|
fontset[:cjk] = FONT_DIR + "/NotoSansJP-Regular.otf"
|
82
|
-
fontset[:emoji] = FONT_DIR + "/OpenMoji-
|
86
|
+
fontset[:emoji] = FONT_DIR + "/OpenMoji-black-glyf"
|
83
87
|
new_params[:fontstyle] = "mono"
|
84
88
|
when "noto-sans", "sans"
|
85
89
|
fontset[:normal] = FONT_DIR + "/NotoSans-Regular.ttf"
|
@@ -88,7 +92,7 @@ module RSyntaxTree
|
|
88
92
|
fontset[:bolditalic] = FONT_DIR + "/NotoSans-BoldItalic.ttf"
|
89
93
|
fontset[:math] = FONT_DIR + "/NotoSansMath-Regular.ttf"
|
90
94
|
fontset[:cjk] = FONT_DIR + "/NotoSansJP-Regular.otf"
|
91
|
-
fontset[:emoji] = FONT_DIR + "/OpenMoji-
|
95
|
+
fontset[:emoji] = FONT_DIR + "/OpenMoji-black-glyf.ttf"
|
92
96
|
new_params[:fontstyle] = "sans"
|
93
97
|
when "noto-serif", "serif"
|
94
98
|
fontset[:normal] = FONT_DIR + "/NotoSerif-Regular.ttf"
|
@@ -97,7 +101,7 @@ module RSyntaxTree
|
|
97
101
|
fontset[:bolditalic] = FONT_DIR + "/NotoSerif-BoldItalic.ttf"
|
98
102
|
fontset[:math] = FONT_DIR + "/latinmodern-math.otf"
|
99
103
|
fontset[:cjk] = FONT_DIR + "/NotoSerifJP-Regular.otf"
|
100
|
-
fontset[:emoji] = FONT_DIR + "/OpenMoji-
|
104
|
+
fontset[:emoji] = FONT_DIR + "/OpenMoji-black-glyf.ttf"
|
101
105
|
new_params[:fontstyle] = "serif"
|
102
106
|
when "cjk zenhei", "cjk"
|
103
107
|
fontset[:normal] = FONT_DIR + "/wqy-zenhei.ttf"
|
@@ -106,7 +110,7 @@ module RSyntaxTree
|
|
106
110
|
fontset[:bolditalic] = FONT_DIR + "/NotoSans-BoldItalic.ttf"
|
107
111
|
fontset[:math] = FONT_DIR + "/NotoSansMath-Regular.ttf"
|
108
112
|
fontset[:cjk] = FONT_DIR + "/wqy-zenhei.ttf"
|
109
|
-
fontset[:emoji] = FONT_DIR + "/OpenMoji-
|
113
|
+
fontset[:emoji] = FONT_DIR + "/OpenMoji-black-glyf.ttf"
|
110
114
|
new_params[:fontstyle] = "cjk"
|
111
115
|
end
|
112
116
|
else
|
@@ -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",
|
@@ -140,7 +145,7 @@ module RSyntaxTree
|
|
140
145
|
@global[:height_connector_to_text] = single_x_metrics.height / 2.0
|
141
146
|
@global[:single_line_height] = single_x_metrics.height * 2.0
|
142
147
|
@global[:width_half_x] = single_x_metrics.width / 2.0
|
143
|
-
@global[:height_connector] = single_x_metrics.height *
|
148
|
+
@global[:height_connector] = single_x_metrics.height * @params[:vheight]
|
144
149
|
@global[:h_gap_between_nodes] = single_x_metrics.width * 0.8
|
145
150
|
@global[:box_vertical_margin] = single_x_metrics.height * 0.8
|
146
151
|
end
|
data/test/example_verify_test.rb
CHANGED
@@ -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",
|
@@ -48,6 +49,8 @@ class ExampleParserTest < Minitest::Test
|
|
48
49
|
opts[:polyline] = value
|
49
50
|
when "hide_default_connectors"
|
50
51
|
opts[:hide_default_connectors] = value
|
52
|
+
when "connector_height"
|
53
|
+
opts[:vheight] = value
|
51
54
|
when "symmetrization"
|
52
55
|
opts[:symmetrize] = value
|
53
56
|
when "connector"
|
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.
|
4
|
+
version: 1.2.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: 2023-02-
|
11
|
+
date: 2023-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: optimist
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- README.md
|
109
109
|
- Rakefile
|
110
110
|
- bin/rsyntaxtree
|
111
|
+
- devel/generate_examples.rb
|
111
112
|
- docs/.gitignore
|
112
113
|
- docs/404.html
|
113
114
|
- docs/Gemfile
|
@@ -152,6 +153,12 @@ files:
|
|
152
153
|
- docs/_examples/037.md
|
153
154
|
- docs/_examples/038.md
|
154
155
|
- docs/_examples/039.md
|
156
|
+
- docs/_examples/040.md
|
157
|
+
- docs/_examples/041.md
|
158
|
+
- docs/_examples/042.md
|
159
|
+
- docs/_examples/043.md
|
160
|
+
- docs/_examples/044.md
|
161
|
+
- docs/_examples/045.md
|
155
162
|
- docs/_includes/box_and_circle_table.html
|
156
163
|
- docs/_includes/escape_char_table.html
|
157
164
|
- docs/_includes/social_media_links.html
|
@@ -172,6 +179,7 @@ files:
|
|
172
179
|
- docs/assets/img/012.png
|
173
180
|
- docs/assets/img/013.png
|
174
181
|
- docs/assets/img/014.png
|
182
|
+
- docs/assets/img/014_.png
|
175
183
|
- docs/assets/img/015.png
|
176
184
|
- docs/assets/img/016.png
|
177
185
|
- docs/assets/img/017.png
|
@@ -197,6 +205,12 @@ files:
|
|
197
205
|
- docs/assets/img/037.png
|
198
206
|
- docs/assets/img/038.png
|
199
207
|
- docs/assets/img/039.png
|
208
|
+
- docs/assets/img/040.png
|
209
|
+
- docs/assets/img/041.png
|
210
|
+
- docs/assets/img/042.png
|
211
|
+
- docs/assets/img/043.png
|
212
|
+
- docs/assets/img/044.png
|
213
|
+
- docs/assets/img/045.png
|
200
214
|
- docs/assets/img/elements/circle.png
|
201
215
|
- docs/assets/img/elements/circle_abc.png
|
202
216
|
- docs/assets/img/elements/circle_bold.png
|
@@ -253,10 +267,18 @@ files:
|
|
253
267
|
- docs/assets/svg/037.svg
|
254
268
|
- docs/assets/svg/038.svg
|
255
269
|
- docs/assets/svg/039.svg
|
270
|
+
- docs/assets/svg/040.svg
|
271
|
+
- docs/assets/svg/041.svg
|
272
|
+
- docs/assets/svg/042.svg
|
273
|
+
- docs/assets/svg/043.svg
|
274
|
+
- docs/assets/svg/044.svg
|
275
|
+
- docs/assets/svg/045.svg
|
256
276
|
- docs/documentation.md
|
257
277
|
- docs/documentation_ja.md
|
258
278
|
- docs/examples.html
|
259
279
|
- docs/index.html
|
280
|
+
- fonts/NotoEmoji-Bold.ttf
|
281
|
+
- fonts/NotoEmoji-Regular.ttf
|
260
282
|
- fonts/NotoSans-Bold.ttf
|
261
283
|
- fonts/NotoSans-BoldItalic.ttf
|
262
284
|
- fonts/NotoSans-Italic.ttf
|
@@ -272,8 +294,7 @@ files:
|
|
272
294
|
- fonts/NotoSerif-Regular.ttf
|
273
295
|
- fonts/NotoSerifJP-Bold.otf
|
274
296
|
- fonts/NotoSerifJP-Regular.otf
|
275
|
-
- fonts/OpenMoji-
|
276
|
-
- fonts/OpenMoji-Color.ttf
|
297
|
+
- fonts/OpenMoji-black-glyf.ttf
|
277
298
|
- fonts/wqy-zenhei.ttf
|
278
299
|
- img/rsyntaxtree-web-screenshot.png
|
279
300
|
- img/rsyntaxtree.png
|
data/fonts/OpenMoji-Black.ttf
DELETED
Binary file
|
data/fonts/OpenMoji-Color.ttf
DELETED
Binary file
|