rsyntaxtree 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/docs/_examples/026.md +1 -1
  3. data/docs/_examples/027.md +1 -1
  4. data/docs/_examples/038.md +31 -0
  5. data/docs/_examples/039.md +14 -0
  6. data/docs/assets/img/000.png +0 -0
  7. data/docs/assets/img/001.png +0 -0
  8. data/docs/assets/img/002.png +0 -0
  9. data/docs/assets/img/003.png +0 -0
  10. data/docs/assets/img/004.png +0 -0
  11. data/docs/assets/img/005.png +0 -0
  12. data/docs/assets/img/006.png +0 -0
  13. data/docs/assets/img/007.png +0 -0
  14. data/docs/assets/img/008.png +0 -0
  15. data/docs/assets/img/009.png +0 -0
  16. data/docs/assets/img/010.png +0 -0
  17. data/docs/assets/img/011.png +0 -0
  18. data/docs/assets/img/012.png +0 -0
  19. data/docs/assets/img/013.png +0 -0
  20. data/docs/assets/img/014.png +0 -0
  21. data/docs/assets/img/015.png +0 -0
  22. data/docs/assets/img/016.png +0 -0
  23. data/docs/assets/img/017.png +0 -0
  24. data/docs/assets/img/018.png +0 -0
  25. data/docs/assets/img/019.png +0 -0
  26. data/docs/assets/img/020.png +0 -0
  27. data/docs/assets/img/021.png +0 -0
  28. data/docs/assets/img/022.png +0 -0
  29. data/docs/assets/img/023.png +0 -0
  30. data/docs/assets/img/024.png +0 -0
  31. data/docs/assets/img/025.png +0 -0
  32. data/docs/assets/img/026.png +0 -0
  33. data/docs/assets/img/027.png +0 -0
  34. data/docs/assets/img/028.png +0 -0
  35. data/docs/assets/img/029.png +0 -0
  36. data/docs/assets/img/030.png +0 -0
  37. data/docs/assets/img/031.png +0 -0
  38. data/docs/assets/img/032.png +0 -0
  39. data/docs/assets/img/033.png +0 -0
  40. data/docs/assets/img/034.png +0 -0
  41. data/docs/assets/img/035.png +0 -0
  42. data/docs/assets/img/036.png +0 -0
  43. data/docs/assets/img/037.png +0 -0
  44. data/docs/assets/img/038.png +0 -0
  45. data/docs/assets/img/039.png +0 -0
  46. data/docs/assets/svg/000.svg +36 -36
  47. data/docs/assets/svg/001.svg +17 -17
  48. data/docs/assets/svg/002.svg +35 -35
  49. data/docs/assets/svg/003.svg +27 -27
  50. data/docs/assets/svg/004.svg +38 -38
  51. data/docs/assets/svg/005.svg +18 -18
  52. data/docs/assets/svg/006.svg +23 -23
  53. data/docs/assets/svg/007.svg +29 -29
  54. data/docs/assets/svg/008.svg +33 -33
  55. data/docs/assets/svg/009.svg +32 -32
  56. data/docs/assets/svg/010.svg +50 -50
  57. data/docs/assets/svg/011.svg +27 -27
  58. data/docs/assets/svg/012.svg +30 -30
  59. data/docs/assets/svg/013.svg +119 -119
  60. data/docs/assets/svg/014.svg +85 -85
  61. data/docs/assets/svg/015.svg +31 -31
  62. data/docs/assets/svg/016.svg +252 -252
  63. data/docs/assets/svg/017.svg +33 -33
  64. data/docs/assets/svg/018.svg +35 -35
  65. data/docs/assets/svg/019.svg +179 -179
  66. data/docs/assets/svg/020.svg +57 -57
  67. data/docs/assets/svg/021.svg +40 -40
  68. data/docs/assets/svg/022.svg +66 -66
  69. data/docs/assets/svg/023.svg +40 -40
  70. data/docs/assets/svg/024.svg +21 -21
  71. data/docs/assets/svg/025.svg +125 -125
  72. data/docs/assets/svg/026.svg +17 -17
  73. data/docs/assets/svg/027.svg +47 -47
  74. data/docs/assets/svg/028.svg +19 -19
  75. data/docs/assets/svg/029.svg +91 -91
  76. data/docs/assets/svg/030.svg +47 -47
  77. data/docs/assets/svg/031.svg +13 -13
  78. data/docs/assets/svg/032.svg +51 -51
  79. data/docs/assets/svg/033.svg +39 -39
  80. data/docs/assets/svg/034.svg +61 -61
  81. data/docs/assets/svg/035.svg +46 -46
  82. data/docs/assets/svg/036.svg +20 -20
  83. data/docs/assets/svg/037.svg +5 -5
  84. data/docs/assets/svg/038.svg +88 -0
  85. data/docs/assets/svg/039.svg +30 -0
  86. data/docs/documentation.md +3 -2
  87. data/docs/documentation_ja.md +2 -2
  88. data/lib/rsyntaxtree/element.rb +12 -7
  89. data/lib/rsyntaxtree/markup_parser.rb +1 -1
  90. data/lib/rsyntaxtree/svg_graph.rb +5 -5
  91. data/lib/rsyntaxtree/version.rb +1 -1
  92. metadata +8 -2
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg width="115.6" height="211.2" viewBox="-20, -20, 135.6, 231.2" version="1.1" xmlns="http://www.w3.org/2000/svg">
4
+ <defs>
5
+ <marker id="arrow" markerUnits="strokeWidth" markerWidth="13.440000000000001" markerHeight="13.440000000000001" viewBox="0 0 13.440000000000001 13.440000000000001" refX="6.720000000000001" refY="0">
6
+ <polyline fill="none" stroke="#CC79A7" stroke-width="1" points="0,13.440000000000001,6.720000000000001,0,13.440000000000001,13.440000000000001" />
7
+ </marker>
8
+ <marker id="arrowBackward" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="13.440000000000001" markerHeight="13.440000000000001" orient="auto">
9
+ <path d="M 0 0 L 10 5 L 0 10 z" fill="#D55E00"/>
10
+ </marker>
11
+ <marker id="arrowForward" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="13.440000000000001" markerHeight="13.440000000000001" orient="auto">
12
+ <path d="M 10 0 L 0 5 L 10 10 z" fill="#D55E00"/>
13
+ </marker>
14
+ <marker id="arrowBothways" viewBox="0 0 30 10" refX="15" refY="5" markerWidth="40.32" markerHeight="40.32" orient="auto">
15
+ <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="#D55E00"/>
16
+ </marker>
17
+ <pattern id="hatchBlack" x="10" y="10" width="10" height="10" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
18
+ <line x1="0" y="0" x2="0" y2="10" stroke="black" stroke-width="4"></line>
19
+ </pattern>
20
+ <pattern id="hatchForNode" x="10" y="10" width="10" height="10" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
21
+ <line x1="0" y="0" x2="0" y2="10" stroke="#0072B2" stroke-width="4"></line>
22
+ </pattern>
23
+ <pattern id="hatchForLeaf" x="10" y="10" width="10" height="10" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
24
+ <line x1="0" y="0" x2="0" y2="10" stroke="#009E73" stroke-width="4"></line>
25
+ </pattern>
26
+ </defs>
27
+ <rect x="-20" y="-20" width="135.6" height="231.2" stroke="none" fill="white" />"
28
+ <text white-space='pre' alignment-baseline='text-top' style='fill: #009E73; font-size: 64px;' x='33.599999999999994' y='132.0'><tspan x='33.599999999999994' y='132.0' style="" text-decoration="" font-family="'Noto Serif', 'Noto Serif JP', OpenMoji, 'OpenMoji Color', 'OpenMoji Black', serif">X</tspan>
29
+ </text>
30
+ </svg>
@@ -133,7 +133,8 @@ You can draw any number of paths of three different types:
133
133
  - Directional (rendered as solid line `----->`)
134
134
  - Bidirectional (rendered as solid line `<----->`)
135
135
 
136
- Each path is distinguished by a unique ID number. The ID is specified by putting a plus sign and a number (e.g. `+7`) at the end of the node text. If a greater-than sign is placed between the plus sign and the number (e.g. `+>7`), an arrowhead will appear at the end of the path.
136
+ Each path is distinguished by a unique ID number. The ID is specified by putting a plus sign and a number (e.g. `+7`) at the end of the node text. If a greater-than or less-than sign is placed between the plus sign and the number (e.g. `+>7` or `+<7`), an arrowhead will appear at the end of the path. Note that it makes no difference whether `+>` or `+<` is used. The arrow is always directed to the element with one of these ID symbols.
137
+
137
138
 
138
139
  A node can have any number of IDs. The same ID must appear in the text of the *two* nodes between which the path is rendered. The same ID number cannot appear in more than two places.
139
140
 
@@ -145,7 +146,7 @@ You can also add extra connector between nodes in the same fasion as you draw pa
145
146
  - Directional (rendered as solid line `--▶--`)
146
147
  - Bidirectional (rendered as solid line `-◀-▶-`)
147
148
 
148
- Each additional connectors is distinguished by an ID number. The ID is specified by putting a a number after a sequence of a plus and a minus symbols (e.g. `+-8`) at the end of the node text. If a greater-than sign is placed between the minus sign and the number (e.g. `+->8`), an arrowhead will appear at the end of the connector.
149
+ Each additional connectors is distinguished by an ID number. The ID is specified by putting a a number after a sequence of a plus and a minus symbols (e.g. `+-8`) at the end of the node text. If a greater-than sign is placed between the minus sign and the number (e.g. `+->8`), an arrowhead will appear at the end of the connector. Note that it makes no difference whether `+->` or `+-<` is used. The arrow is always directed to the element with one of these ID symbols.
149
150
 
150
151
  A node can have any number of IDs. The same ID must appear in the text of the *two* nodes between which the additional connector is rendered. The same ID number cannot appear in more than two places.
151
152
 
@@ -144,7 +144,7 @@ SVG形式を用いる場合,期待通りの表示を得るためには,ご
144
144
  - 両方向の矢印のあるパス(`<----->`)
145
145
 
146
146
  樹形図の中でパスを表示したいとき,パスの両端を数字のIDで指定します.数字をプラス(`+`)記号と共にノードのテキストの最後で指定してください(例:`+7`).
147
- プラス記号とID番号の間に `>` 記号を入れると(例:`+>7`),パスの終端に矢印が付きます.
147
+ プラス記号とID番号の間に `>` 記号を入れると(例:`+>7`),パスの終端に矢印が付きます.その際、`+>` と `+<` のどちらを用いるかで結果は変わりません。矢印の先は常にこれらのいずれかを用いたIDが指定された要素に向けられます。
148
148
 
149
149
  IDにはどのような数字を用いても構いませんが,必ず **2箇所** で同じIDを指定することが必要です.同じIDを3箇所以上で指定することはできません.
150
150
 
@@ -152,7 +152,7 @@ IDにはどのような数字を用いても構いませんが,必ず **2箇
152
152
 
153
153
  パスの指定と類似した方式でノードからノードへのコネクターを追加することができます.追加的なコネクターは直線で描画されます(`polyline`にはなりません).追加的なコネクターを描画する際,デフォルトのコネクターを非表示(透明)にしたいときには `Hide default connectors`オプションをオンにすると良いでしょう.
154
154
 
155
- 追加のコネクターは数字のIDで指定します,プラスとマイナスを連続させた(`+-`)後にIDを指定してください(例:`+-8`).マイナス記号とID番号の間に `>` 記号を入れると(例:`+->8`),コネクターの終端に矢印が付きます.
155
+ 追加のコネクターは数字のIDで指定します,プラスとマイナスを連続させた(`+-`)後にIDを指定してください(例:`+-8`).マイナス記号とID番号の間に `>` 記号を入れると(例:`+->8`),コネクターの終端に矢印が付きます.その際、`+->` と `+-<` のどちらを用いるかで結果は変わりません。矢印の先は常にこれらのいずれかを用いたIDが指定された要素に向けられます。
156
156
 
157
157
  - 方向(矢印)のないコネクター(`-----`)
158
158
  - 方向(矢印)のあるコネクター(`--▶--`)
@@ -27,7 +27,7 @@ module RSyntaxTree
27
27
  @vertical_indent = 0 # Drawing offset
28
28
  content = content.strip
29
29
 
30
- @path = if /.+?\^?((?:\+-?>?\d+)+)\^?\z/m =~ content
30
+ @path = if /.+?\^?((?:\+-?>?<?\d+)+)\^?\z/m =~ content
31
31
  $1.sub(/\A\+/, "").split("+")
32
32
  else
33
33
  []
@@ -57,6 +57,7 @@ module RSyntaxTree
57
57
  def setup
58
58
  total_width = 0
59
59
  total_height = 0
60
+ one_bvm_given = false
60
61
  @content.each do |content|
61
62
  content_width = 0
62
63
  case content[:type]
@@ -88,6 +89,7 @@ module RSyntaxTree
88
89
  end
89
90
 
90
91
  standard_metrics = FontMetrics.get_metrics('X', @fontset[:normal], fontsize, :normal, :normal)
92
+
91
93
  height = standard_metrics.height
92
94
  if /\A[<>]+\z/ =~ text
93
95
  width = standard_metrics.width * text.size / 2
@@ -132,17 +134,20 @@ module RSyntaxTree
132
134
  end
133
135
 
134
136
  e[:height] = height
135
- elements_height << height + @global[:box_vertical_margin] / 2
137
+
138
+ if one_bvm_given
139
+ elements_height << height
140
+ else
141
+ one_bvm_given = true
142
+ elements_height << height + @global[:box_vertical_margin] / 2
143
+ end
136
144
 
137
145
  e[:width] = width
138
146
  row_width += width
139
147
  end
140
148
 
141
- total_height += if @parent.zero? && @children.empty?
142
- # tree without parent node
143
- elements_height.max
144
- # elsif @enclosure != :none && @children.empty?
145
- # elements_height.max
149
+ total_height += if @parent.zero? && @children.empty? && @enclosure == :none
150
+ elements_height.max + @global[:height_connector_to_text] * 2
146
151
  else
147
152
  elements_height.max + @global[:height_connector_to_text]
148
153
  end
@@ -13,7 +13,7 @@ class MarkupParser < Parslet::Parser
13
13
  rule(:brackets) { str('#') }
14
14
  rule(:triangle) { str('^') }
15
15
 
16
- rule(:path) { (str('+') >> str('-').maybe >> str('>').maybe >> match('\d').repeat(1)).as(:path) }
16
+ rule(:path) { (str('+') >> str('-').maybe >> (str('>') | str('<')).maybe >> match('\d').repeat(1)).as(:path) }
17
17
  rule(:escaped) { str('\\') >> match('[#<>{}\\^+*_=~\|\n\-]').as(:chr) }
18
18
  rule(:non_escaped) { ((match('[#<>{}\\^+*_=~\|\-]') | str('\\n')).absent? >> any).as(:chr) }
19
19
  rule(:text) { (escaped | non_escaped).repeat(1).as(:text) }
@@ -65,12 +65,12 @@ module RSyntaxTree
65
65
  <marker id="arrow" markerUnits="strokeWidth" markerWidth="#{as2}" markerHeight="#{as2}" viewBox="0 0 #{as2} #{as2}" refX="#{as}" refY="0">
66
66
  <polyline fill="none" stroke="#{@col_path}" stroke-width="1" points="0,#{as2},#{as},0,#{as2},#{as2}" />
67
67
  </marker>
68
- <marker id="arrowForward" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto-start-reverse">
69
- <path d="M 0 0 L 10 5 L 0 10 z" fill="#{@col_extra}"/>
70
- </marker>
71
68
  <marker id="arrowBackward" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
72
69
  <path d="M 0 0 L 10 5 L 0 10 z" fill="#{@col_extra}"/>
73
70
  </marker>
71
+ <marker id="arrowForward" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="#{as2}" markerHeight="#{as2}" orient="auto">
72
+ <path d="M 10 0 L 0 5 L 10 10 z" fill="#{@col_extra}"/>
73
+ </marker>
74
74
  <marker id="arrowBothways" viewBox="0 0 30 10" refX="15" refY="5" markerWidth="#{as4}" markerHeight="#{as4}" orient="auto">
75
75
  <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
76
  </marker>
@@ -396,7 +396,7 @@ module RSyntaxTree
396
396
  y1 = element.vertical_indent + element.content_height + @global[:height_connector_to_text]
397
397
  et = element.path
398
398
  et.each do |tr|
399
- if /\A-(>)?(\d+)\z/ =~ tr
399
+ if /\A-(>|<)?(\d+)\z/ =~ tr
400
400
  arrow = $1
401
401
  tr = $2
402
402
  if line_pool[tr]
@@ -405,7 +405,7 @@ module RSyntaxTree
405
405
  line_pool[tr] = [{ x: { left: x0, center: x1, right: x2 }, y: { top: y0, center: y0 + (y1 - y0) / 2, bottom: y1 }, arrow: arrow }]
406
406
  end
407
407
  line_flags << tr
408
- elsif /\A>(\d+)\z/ =~ tr
408
+ elsif /\A(?:>|<)(\d+)\z/ =~ tr
409
409
  tr = $1
410
410
  if path_pool_target[tr]
411
411
  path_pool_target[tr] << [x1, y1]
@@ -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.3"
5
5
  end
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.3
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-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: optimist
@@ -150,6 +150,8 @@ 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
153
155
  - docs/_includes/box_and_circle_table.html
154
156
  - docs/_includes/escape_char_table.html
155
157
  - docs/_includes/social_media_links.html
@@ -193,6 +195,8 @@ files:
193
195
  - docs/assets/img/035.png
194
196
  - docs/assets/img/036.png
195
197
  - docs/assets/img/037.png
198
+ - docs/assets/img/038.png
199
+ - docs/assets/img/039.png
196
200
  - docs/assets/img/elements/circle.png
197
201
  - docs/assets/img/elements/circle_abc.png
198
202
  - docs/assets/img/elements/circle_bold.png
@@ -247,6 +251,8 @@ files:
247
251
  - docs/assets/svg/035.svg
248
252
  - docs/assets/svg/036.svg
249
253
  - docs/assets/svg/037.svg
254
+ - docs/assets/svg/038.svg
255
+ - docs/assets/svg/039.svg
250
256
  - docs/documentation.md
251
257
  - docs/documentation_ja.md
252
258
  - docs/examples.html