drawio_dsl 0.2.0 → 0.3.0

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: 96f9176e2e3f9b37f0a02f462d075835aae641a43d14dc45c747a1434fcb17df
4
- data.tar.gz: 07ef19170c1721bb9ebe7a58d9cc6d20ca000d620b555941c2e396d83a8b27e0
3
+ metadata.gz: 874e60205978452d6b06bd53855edff255b5b168fb7a80693ac109279381c880
4
+ data.tar.gz: f5073b3be534353987969a4c96c563a1ed5d9dedcb52c09355ef013db0c5a382
5
5
  SHA512:
6
- metadata.gz: ccb338c21e1a14d55e0fb7965c05c014714e37081a1b2f365ea01168017d15327043255a23346dde6c7674419c5458ea9516411240108e5e5c4cb688b9210a9f
7
- data.tar.gz: ab033223b347fa65e1e6e2ddb91d93085276052dd21685d5bd76db0c9cc0f92c1c0a2e5cade339f4e1f7a67569ee42153249d61ec6f15bdb8401e7b52d25d57b
6
+ metadata.gz: 50178f5c6728de3571a1effb263d62b4676f9685e05a59b4b31fb88a1f3b1d3fc4583f13a976c8d67202c3dc4981470073855f10b2c69196051984ae70d06c8a
7
+ data.tar.gz: 5ad8beb7a169b7d3c0b44e887dfb71b6a966d63023986efe319007e0f4fcaf397edd688cfbd3c98f5dc8a6760d55af1eaea3d7b646ed8658fda765c2dd129d0d
@@ -0,0 +1,46 @@
1
+ KManager.action :bootstrap do
2
+ action do
3
+ director = DrawioDsl::Drawio
4
+ .init(k_builder)
5
+ .diagram(theme: :style_01)
6
+ .page('PgMargin-default') do
7
+ grid_layout(wrap_at: 4)
8
+ square(title: 'Page Margin 50, 50 (Default)')
9
+ circle
10
+ square
11
+ circle
12
+ square
13
+ circle
14
+ square
15
+ circle
16
+ end
17
+ .page('PgMargin-0-0', margin_left: 0, margin_top: 0) do
18
+ grid_layout(wrap_at: 4)
19
+ square(title: 'Page Margin 0, 0')
20
+ circle
21
+ square
22
+ circle
23
+ square
24
+ circle
25
+ square
26
+ circle
27
+ end
28
+ .page('PgMargin-90-70', margin_left: 90, margin_top: 70) do
29
+ grid_layout(wrap_at: 4)
30
+ square(title: 'Page Margin 90, 70')
31
+ circle
32
+ square
33
+ circle
34
+ square
35
+ circle
36
+ square
37
+ circle
38
+ end
39
+
40
+ diagram = DrawioDsl::XmlBuilder.new(director.builder.diagram)
41
+
42
+
43
+ File.write('../spec/.samples/drawio/10-page-margin.xml', diagram.build)
44
+ File.write('../spec/.samples/drawio/10-page-margin.drawio', diagram.build)
45
+ end
46
+ end
@@ -0,0 +1,40 @@
1
+ KManager.action :bootstrap do
2
+ action do
3
+
4
+ # KConfig.configuration.drawio.square.w = KConfig.configuration.drawio.square.w / 4
5
+ # KConfig.configuration.drawio.square.h = KConfig.configuration.drawio.square.h / 4
6
+ # KConfig.configuration.drawio.circle.w = KConfig.configuration.drawio.circle.w / 4
7
+ # KConfig.configuration.drawio.circle.h = KConfig.configuration.drawio.circle.h / 4
8
+ # KConfig.configuration.drawio.rectangle.w = KConfig.configuration.drawio.rectangle.w / 4
9
+ # KConfig.configuration.drawio.rectangle.h = KConfig.configuration.drawio.rectangle.h / 4
10
+
11
+ director = DrawioDsl::Drawio
12
+ .init(k_builder)
13
+ .diagram(theme: :style_01)
14
+ .page('Horizontal', margin_left: 0, margin_top: 0) do
15
+ grid_layout(wrap_at: 3, direction: :horizontal)
16
+ circle(title: '01')
17
+ square(title: '02')
18
+ circle(title: '03')
19
+ square(title: '04')
20
+ circle(title: '05')
21
+ square(title: '06')
22
+ circle(title: '07')
23
+ end
24
+ .page('Vertical', margin_left: 0, margin_top: 0) do
25
+ grid_layout(wrap_at: 3, direction: :vertical)
26
+ circle(title: '01')
27
+ square(title: '02')
28
+ circle(title: '03')
29
+ square(title: '04')
30
+ circle(title: '05')
31
+ square(title: '06')
32
+ circle(title: '07')
33
+ end
34
+
35
+ diagram = DrawioDsl::XmlBuilder.new(director.builder.diagram)
36
+
37
+ File.write('../spec/.samples/drawio/15-grid-direction.xml', diagram.build)
38
+ File.write('../spec/.samples/drawio/15-grid-direction.drawio', diagram.build)
39
+ end
40
+ end
@@ -0,0 +1,73 @@
1
+ KManager.action :bootstrap do
2
+ action do
3
+
4
+ # KConfig.configuration.drawio.square.w = KConfig.configuration.drawio.square.w / 4
5
+ # KConfig.configuration.drawio.square.h = KConfig.configuration.drawio.square.h / 4
6
+ # KConfig.configuration.drawio.circle.w = KConfig.configuration.drawio.circle.w / 4
7
+ # KConfig.configuration.drawio.circle.h = KConfig.configuration.drawio.circle.h / 4
8
+ # KConfig.configuration.drawio.rectangle.w = KConfig.configuration.drawio.rectangle.w / 4
9
+ # KConfig.configuration.drawio.rectangle.h = KConfig.configuration.drawio.rectangle.h / 4
10
+
11
+ director = DrawioDsl::Drawio
12
+ .init(k_builder,
13
+ on_exist: :skip, # %i[skip write compare]
14
+ on_action: :queue # %i[queue execute]
15
+ )
16
+ .diagram(theme: :style_01)
17
+ .page('Grid-Center', margin_left: 0, margin_top: 0) do
18
+ grid_layout(wrap_at: 3)
19
+ circle
20
+ square
21
+ circle
22
+ square
23
+ circle
24
+ square
25
+ circle
26
+ end
27
+ .page('Grid-Top', margin_left: 0, margin_top: 0) do
28
+ grid_layout(wrap_at: 3, v_align: :top, h_align: :center)
29
+ circle
30
+ square
31
+ circle
32
+ square
33
+ circle
34
+ square
35
+ circle
36
+ end
37
+ .page('Grid-Bottom', margin_left: 0, margin_top: 0) do
38
+ grid_layout(wrap_at: 3, v_align: :bottom, h_align: :center)
39
+ circle
40
+ square
41
+ circle
42
+ square
43
+ circle
44
+ square
45
+ circle
46
+ end
47
+ .page('Grid-Left', margin_left: 0, margin_top: 0) do
48
+ grid_layout(wrap_at: 3, v_align: :center, h_align: :left)
49
+ circle
50
+ square
51
+ circle
52
+ square
53
+ circle
54
+ square
55
+ circle
56
+ end
57
+ .page('Grid-Right', margin_left: 0, margin_top: 0) do
58
+ grid_layout(wrap_at: 3, v_align: :center, h_align: :right)
59
+ circle
60
+ square
61
+ circle
62
+ square
63
+ circle
64
+ square
65
+ circle
66
+ end
67
+
68
+ diagram = DrawioDsl::XmlBuilder.new(director.builder.diagram)
69
+
70
+ File.write('../spec/.samples/drawio/16-grid-alignment.xml', diagram.build)
71
+ File.write('../spec/.samples/drawio/16-grid-alignment.drawio', diagram.build)
72
+ end
73
+ end
@@ -0,0 +1,64 @@
1
+ KManager.action :bootstrap do
2
+ action do
3
+
4
+ # :rounded, :shadow, :sketch, :glass
5
+ director = DrawioDsl::Drawio
6
+ .init(k_builder)
7
+ .diagram(theme: :style_06)
8
+ .page('Style-Plain', margin_left: 0, margin_top: 0) do
9
+ grid_layout(wrap_at: 4)
10
+ circle
11
+ square
12
+ circle
13
+ square
14
+ circle
15
+ square
16
+ circle
17
+ end
18
+ .page('Style-Shadow', shadow: 1, margin_left: 0, margin_top: 0) do
19
+ grid_layout(wrap_at: 4)
20
+ circle
21
+ square
22
+ circle
23
+ square
24
+ circle
25
+ square
26
+ circle
27
+ end
28
+ .page('Style-Rounded', rounded: 1, margin_left: 0, margin_top: 0) do
29
+ grid_layout(wrap_at: 4)
30
+ circle
31
+ square
32
+ circle
33
+ square
34
+ circle
35
+ square
36
+ circle
37
+ end
38
+ .page('Style-Glass', glass: 1, margin_left: 0, margin_top: 0) do
39
+ grid_layout(wrap_at: 4)
40
+ circle
41
+ square
42
+ circle
43
+ square
44
+ circle
45
+ square
46
+ circle
47
+ end
48
+ .page('Style-Sketch', sketch: 1, margin_left: 0, margin_top: 0) do
49
+ grid_layout(wrap_at: 4)
50
+ circle
51
+ square
52
+ circle
53
+ square
54
+ circle
55
+ square
56
+ circle
57
+ end
58
+
59
+ diagram = DrawioDsl::XmlBuilder.new(director.builder.diagram)
60
+
61
+ File.write('../spec/.samples/drawio/20-styles.xml', diagram.build)
62
+ File.write('../spec/.samples/drawio/20-styles.drawio', diagram.build)
63
+ end
64
+ end
@@ -0,0 +1,21 @@
1
+ KManager.action :bootstrap do
2
+ action do
3
+
4
+ # :rounded, :shadow, :sketch, :glass
5
+ director = DrawioDsl::Drawio
6
+ .init(k_builder)
7
+ .diagram(theme: :style_06)
8
+ .page('Style-Plain', margin_left: 0, margin_top: 0) do
9
+ grid_layout(wrap_at: 5)
10
+
11
+ KConfig.configuration.drawio.themes.keys.each do |theme|
12
+ random(title: theme.to_s, theme: theme)
13
+ end
14
+ end
15
+
16
+ diagram = DrawioDsl::XmlBuilder.new(director.builder.diagram)
17
+
18
+ File.write('../spec/.samples/drawio/25-themes.xml', diagram.build)
19
+ File.write('../spec/.samples/drawio/25-themes.drawio', diagram.build)
20
+ end
21
+ end
data/.rubocop.yml CHANGED
@@ -83,7 +83,8 @@ Metrics/ParameterLists:
83
83
  Layout/EmptyLineBetweenDefs:
84
84
  Exclude:
85
85
  - "**/spec/**/*"
86
-
86
+ Style/Documentation:
87
+ Enabled: false
87
88
  Lint/AmbiguousBlockAssociation:
88
89
  Exclude:
89
90
  - "**/spec/**/*"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [0.2.0](https://github.com/klueless-io/drawio_dsl/compare/v0.1.0...v0.2.0) (2022-03-04)
2
+
3
+
4
+ ### Features
5
+
6
+ * update drawio with grid layout engine ([cc5dc51](https://github.com/klueless-io/drawio_dsl/commit/cc5dc51debfd902a815df704fa2dd77f39f498c7))
7
+
1
8
  # [0.1.0](https://github.com/klueless-io/drawio_dsl/compare/v0.0.1...v0.1.0) (2022-03-02)
2
9
 
3
10
 
@@ -32,10 +32,13 @@ module DrawioDsl
32
32
  attr_accessor :circle
33
33
  attr_accessor :process
34
34
  attr_accessor :ellipse
35
- attr_accessor :triangle
36
- attr_accessor :parallelogram
35
+ attr_accessor :diamond
37
36
  attr_accessor :hexagon
38
37
 
38
+ # <mxCell id="6" value="" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="TqO-B">
39
+ # <mxGeometry x="-496" y="115" width="80" height="80" as="geometry"/>
40
+ # </mxCell>
41
+
39
42
  def initialize
40
43
  @base_style = BaseStyle.new(white_space: :wrap, html: 1, rounded: nil, shadow: nil, sketch: nil, glass: nil)
41
44
 
@@ -45,7 +48,8 @@ module DrawioDsl
45
48
  @circle = ShapeDefaults.new(:circle , 0, 0, 160, 160, 'ellipse')
46
49
  @process = ShapeDefaults.new(:process , 0, 0, 200, 120, 'shape=process')
47
50
  @ellipse = ShapeDefaults.new(:ellipse , 0, 0, 200, 120, 'ellipse')
48
- @triangle = ShapeDefaults.new(:triangle , 0, 0, 160, 160, 'rhombus')
51
+ @diamond = ShapeDefaults.new(:diamond , 0, 0, 160, 160, 'rhombus')
52
+ @hexagon = ShapeDefaults.new(:hexagon , 0, 0, 200, 120, 'shape=hexagon')
49
53
 
50
54
  @themes = {}
51
55
  add_themes
@@ -90,26 +94,26 @@ module DrawioDsl
90
94
  add_theme(:style_21 , fill_color: '#647687', stroke_color: '#314354', font_color: '#ffffff')
91
95
  add_theme(:style_22 , fill_color: '#76608a', stroke_color: '#432D57', font_color: '#ffffff')
92
96
  add_theme(:style_23 , fill_color: '#a0522d', stroke_color: '#6D1F00', font_color: '#ffffff')
93
- add_theme(:style_24 , fill_color: '#fad7ac', stroke_color: '#b46504')
94
- add_theme(:style_25 , fill_color: '#fad9d5', stroke_color: '#ae4132')
95
- add_theme(:style_26 , fill_color: '#b0e3e6', stroke_color: '#0e8088')
96
- add_theme(:style_27 , fill_color: '#b1ddf0', stroke_color: '#10739e')
97
- add_theme(:style_28 , fill_color: '#d0cee2', stroke_color: '#56517e')
98
- add_theme(:style_29 , fill_color: '#bac8d3', stroke_color: '#23445d')
99
- add_theme(:style_30 , fill_color: '#f5f5f5', stroke_color: '#666666', gradient: '#b3b3b3')
100
- add_theme(:style_31 , fill_color: '#dae8fc', stroke_color: '#6c8ebf', gradient: '#7ea6e0')
101
- add_theme(:style_32 , fill_color: '#d5e8d4', stroke_color: '#82b366', gradient: '#97d077')
102
- add_theme(:style_33 , fill_color: '#ffcd28', stroke_color: '#d79b00', gradient: '#ffa500')
103
- add_theme(:style_34 , fill_color: '#fff2cc', stroke_color: '#d6b656', gradient: '#ffd966')
104
- add_theme(:style_35 , fill_color: '#f8cecc', stroke_color: '#b85450', gradient: '#ea6b66')
105
- add_theme(:style_36 , fill_color: '#e6d0de', stroke_color: '#996185', gradient: '#d5739d')
106
- add_theme(:style_37 , fill_color: '#eeeeee', stroke_color: '#36393d')
107
- add_theme(:style_38 , fill_color: '#f9f7ed', stroke_color: '#36393d')
108
- add_theme(:style_39 , fill_color: '#ffcc99', stroke_color: '#36393d')
109
- add_theme(:style_40 , fill_color: '#cce5ff', stroke_color: '#36393d')
110
- add_theme(:style_41 , fill_color: '#ffff88', stroke_color: '#36393d')
111
- add_theme(:style_42 , fill_color: '#cdeb8b', stroke_color: '#36393d')
112
- add_theme(:style_43 , fill_color: '#ffcccc', stroke_color: '#36393d')
97
+ add_theme(:style_24 , fill_color: '#fad7ac', stroke_color: '#b46504', font_color: '#333333')
98
+ add_theme(:style_25 , fill_color: '#fad9d5', stroke_color: '#ae4132', font_color: '#333333')
99
+ add_theme(:style_26 , fill_color: '#b0e3e6', stroke_color: '#0e8088', font_color: '#000000')
100
+ add_theme(:style_27 , fill_color: '#b1ddf0', stroke_color: '#10739e', font_color: '#000000')
101
+ add_theme(:style_28 , fill_color: '#d0cee2', stroke_color: '#56517e', font_color: '#000000')
102
+ add_theme(:style_29 , fill_color: '#bac8d3', stroke_color: '#23445d', font_color: '#000000')
103
+ add_theme(:style_30 , fill_color: '#f5f5f5', stroke_color: '#666666', font_color: '#000000', gradient: '#b3b3b3')
104
+ add_theme(:style_31 , fill_color: '#dae8fc', stroke_color: '#6c8ebf', font_color: '#000000', gradient: '#7ea6e0')
105
+ add_theme(:style_32 , fill_color: '#d5e8d4', stroke_color: '#82b366', font_color: '#000000', gradient: '#97d077')
106
+ add_theme(:style_33 , fill_color: '#ffcd28', stroke_color: '#d79b00', font_color: '#000000', gradient: '#ffa500')
107
+ add_theme(:style_34 , fill_color: '#fff2cc', stroke_color: '#d6b656', font_color: '#000000', gradient: '#ffd966')
108
+ add_theme(:style_35 , fill_color: '#f8cecc', stroke_color: '#b85450', font_color: '#000000', gradient: '#ea6b66')
109
+ add_theme(:style_36 , fill_color: '#e6d0de', stroke_color: '#996185', font_color: '#000000', gradient: '#d5739d')
110
+ add_theme(:style_37 , fill_color: '#eeeeee', stroke_color: '#36393d', font_color: '#000000')
111
+ add_theme(:style_38 , fill_color: '#f9f7ed', stroke_color: '#36393d', font_color: '#000000')
112
+ add_theme(:style_39 , fill_color: '#ffcc99', stroke_color: '#36393d', font_color: '#000000')
113
+ add_theme(:style_40 , fill_color: '#cce5ff', stroke_color: '#36393d', font_color: '#000000')
114
+ add_theme(:style_41 , fill_color: '#ffff88', stroke_color: '#36393d', font_color: '#000000')
115
+ add_theme(:style_42 , fill_color: '#cdeb8b', stroke_color: '#36393d', font_color: '#000000')
116
+ add_theme(:style_43 , fill_color: '#ffcccc', stroke_color: '#36393d', font_color: '#000000')
113
117
  end
114
118
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
115
119
  end
@@ -109,6 +109,16 @@ module DrawioDsl
109
109
  add_shape(ellipse)
110
110
  end
111
111
 
112
+ def add_diamond(**opts)
113
+ diamond = DrawioDsl::Schema::Diamond.new(current_page, **opts)
114
+ add_shape(diamond)
115
+ end
116
+
117
+ def add_hexagon(**opts)
118
+ add_hexagon = DrawioDsl::Schema::Hexagon.new(current_page, **opts)
119
+ add_shape(add_hexagon)
120
+ end
121
+
112
122
  def debug
113
123
  puts JSON.pretty_generate(actions)
114
124
  puts JSON.pretty_generate(diagram.to_h)
@@ -15,6 +15,8 @@ module DrawioDsl
15
15
  page = DrawioDsl::DrawioPage.new(self, **opts.merge(name: name))
16
16
  page.instance_eval(&block) if block_given?
17
17
 
18
+ layout = DrawioDsl::LayoutEngine.new(builder.current_page)
19
+ layout.call
18
20
  self
19
21
  end
20
22
 
@@ -54,6 +56,27 @@ module DrawioDsl
54
56
  builder.add_flex_layout(**opts)
55
57
  end
56
58
 
59
+ # rubocop:disable Metrics/CyclomaticComplexity
60
+ def random(**opts)
61
+ case rand(7)
62
+ when 0
63
+ square(**opts)
64
+ when 1
65
+ rectangle(**opts)
66
+ when 2
67
+ circle(**opts)
68
+ when 3
69
+ process(**opts)
70
+ when 4
71
+ ellipse(**opts)
72
+ when 5
73
+ diamond(**opts)
74
+ when 6
75
+ hexagon(**opts)
76
+ end
77
+ end
78
+ # rubocop:enable Metrics/CyclomaticComplexity
79
+
57
80
  def square(**opts)
58
81
  builder.add_square(**opts)
59
82
  end
@@ -74,6 +97,14 @@ module DrawioDsl
74
97
  builder.add_ellipse(**opts)
75
98
  end
76
99
 
100
+ def diamond(**opts)
101
+ builder.add_diamond(**opts)
102
+ end
103
+
104
+ def hexagon(**opts)
105
+ builder.add_hexagon(**opts)
106
+ end
107
+
77
108
  private
78
109
 
79
110
  def current_shape
@@ -9,38 +9,26 @@ module DrawioDsl
9
9
  # Elements will be placed on the page in the order they are added.
10
10
  # Row/column flow objects will hold information about horizontal and vertical element padding
11
11
  class LayoutEngine
12
- attr_reader :diagram
12
+ attr_reader :page
13
13
 
14
14
  attr_reader :current_page
15
15
  attr_reader :current_layout
16
- attr_reader :page_margin_top
17
- attr_reader :page_margin_left
18
- attr_reader :x
19
- attr_reader :y
20
16
 
21
- def initialize(diagram)
22
- @diagram = diagram
23
- @x = 0
24
- @y = 0
25
- end
26
-
27
- def call
28
- diagram.pages.each do |page|
29
- focus_on_page(page)
17
+ # attr_reader :page_margin_top
18
+ # attr_reader :page_margin_left
19
+ # attr_reader :x
20
+ # attr_reader :y
30
21
 
31
- apply_layout_to_page(page)
32
- end
22
+ def initialize(page)
23
+ @page = page
24
+ # @x = 0
25
+ # @y = 0
33
26
  end
34
27
 
35
- private
36
-
37
- def focus_on_page(page)
38
- @current_page = page
28
+ def call
39
29
  page.position_x = page.margin_left
40
30
  page.position_y = page.margin_top
41
- end
42
31
 
43
- def apply_layout_to_page(page)
44
32
  page.nodes.each do |node|
45
33
  case node.classification
46
34
  when :layout_rule
@@ -48,12 +36,8 @@ module DrawioDsl
48
36
  when :shape
49
37
  current_layout.position_shape(node)
50
38
  end
51
- node.debug(format: :row)
39
+ # node.debug(format: :row)
52
40
  end
53
41
  end
54
-
55
- def define_layout_rule(layout_rule)
56
- layout_rule.debug
57
- end
58
42
  end
59
43
  end
@@ -358,8 +358,8 @@ module DrawioDsl
358
358
 
359
359
  # rubocop:disable Metrics/AbcSize
360
360
  def horizontal_shape_alignment(shape)
361
- return page.position_x + ((grid_size - shape.w) / 2) if h_align == :left
362
- return page.position_x + (grid_size - shape.x) if v_align == :right
361
+ return page.position_x + ((grid_size - shape.w) / 2) if h_align == :center
362
+ return page.position_x + (grid_size - shape.w) if h_align == :right
363
363
 
364
364
  page.position_x
365
365
  end
@@ -367,35 +367,37 @@ module DrawioDsl
367
367
 
368
368
  # rubocop:disable Metrics/AbcSize
369
369
  def vertical_shape_alignment(shape)
370
- return page.position_y + ((grid_size - shape.h) / 2) if v_align == :middle
371
- return page.position_y + (grid_size - shape.h) if v_align == :bottom
370
+ return page.position_y + ((grid_size - shape.h) / 2) if v_align == :center || v_align == :middle
371
+ return page.position_y + (grid_size - shape.h) if v_align == :bottom
372
372
 
373
373
  page.position_y
374
374
  end
375
375
  # rubocop:enable Metrics/AbcSize
376
376
 
377
377
  def move_cell_horizontally
378
- if cell_no >= wrap_at
379
- # Flow down to the next row
380
- page.position_x = anchor_x
381
- page.position_y += grid_size
382
- @cell_no = 1
383
- else
378
+ if cell_no < wrap_at
384
379
  page.position_x += grid_size
385
380
  @cell_no += 1
381
+ return
386
382
  end
383
+
384
+ # Flow down to the next row
385
+ page.position_x = anchor_x
386
+ page.position_y += grid_size
387
+ @cell_no = 1
387
388
  end
388
389
 
389
390
  def move_cell_vertically
390
- if cell_no >= wrap_at
391
- # Flow right to the next column
392
- page.position_y = anchor_y
393
- page.position_x += grid_size
394
- @cell_no = 0
395
- else
391
+ if cell_no < wrap_at
396
392
  page.position_y += grid_size
397
393
  @cell_no += 1
394
+ return
398
395
  end
396
+
397
+ # Flow right to the next column
398
+ page.position_y = anchor_y
399
+ page.position_x += grid_size
400
+ @cell_no = 1
399
401
  end
400
402
  end
401
403
 
@@ -492,7 +494,7 @@ module DrawioDsl
492
494
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
493
495
  def apply_defaults(args, shape_defaults)
494
496
  @theme = args[:theme] || page.theme # KConfig.configuration.drawio.themes.sample
495
- theme_palette = KConfig.configuration.drawio.palette(page.theme)
497
+ theme_palette = KConfig.configuration.drawio.palette(theme)
496
498
  @title = args[:title] || ''
497
499
 
498
500
  @white_space = args[:white_space] || page.style.white_space # wrap or nil
@@ -555,7 +557,6 @@ module DrawioDsl
555
557
  end
556
558
  end
557
559
 
558
- # Graphical shape in the form of a square
559
560
  class Square < Shape
560
561
  def initialize(page, **args)
561
562
  super(page, **args)
@@ -564,7 +565,6 @@ module DrawioDsl
564
565
  end
565
566
  end
566
567
 
567
- # Graphical shape in the form of a rectangle
568
568
  class Rectangle < Shape
569
569
  def initialize(page, **args)
570
570
  super(page, **args)
@@ -573,7 +573,6 @@ module DrawioDsl
573
573
  end
574
574
  end
575
575
 
576
- # Graphical shape in the form of a circle
577
576
  class Circle < Shape
578
577
  def initialize(page, **args)
579
578
  super(page, **args)
@@ -582,7 +581,6 @@ module DrawioDsl
582
581
  end
583
582
  end
584
583
 
585
- # Graphical shape in the form of an rectangle with to vertical lines
586
584
  class Process < Shape
587
585
  def initialize(page, **args)
588
586
  super(page, **args)
@@ -591,7 +589,6 @@ module DrawioDsl
591
589
  end
592
590
  end
593
591
 
594
- # Graphical shape in the form of an ellipse
595
592
  class Ellipse < Shape
596
593
  def initialize(page, **args)
597
594
  super(page, **args)
@@ -599,6 +596,22 @@ module DrawioDsl
599
596
  apply_defaults(args, KConfig.configuration.drawio.ellipse)
600
597
  end
601
598
  end
599
+
600
+ class Diamond < Shape
601
+ def initialize(page, **args)
602
+ super(page, **args)
603
+
604
+ apply_defaults(args, KConfig.configuration.drawio.diamond)
605
+ end
606
+ end
607
+
608
+ class Hexagon < Shape
609
+ def initialize(page, **args)
610
+ super(page, **args)
611
+
612
+ apply_defaults(args, KConfig.configuration.drawio.hexagon)
613
+ end
614
+ end
602
615
  end
603
616
  end
604
617
  # dx="800" dy="583" background="#FFFACD" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DrawioDsl
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "drawio_dsl",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "drawio_dsl",
9
- "version": "0.2.0",
9
+ "version": "0.3.0",
10
10
  "devDependencies": {
11
11
  "@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
12
12
  "@semantic-release/changelog": "^6.0.1",
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drawio_dsl",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "DrawIO DSL can build DrawIO diagrams using a Domain Specific Language",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drawio_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
@@ -76,7 +76,11 @@ files:
76
76
  - ".builders/_.rb"
77
77
  - ".builders/boot.rb"
78
78
  - ".builders/generators/01-bootstrap.rb"
79
- - ".builders/generators/10-layout.rb"
79
+ - ".builders/generators/10-page-margin.rb"
80
+ - ".builders/generators/15-grid-direction.rb"
81
+ - ".builders/generators/16-grid-alignment.rb"
82
+ - ".builders/generators/20-styles.rb"
83
+ - ".builders/generators/25-themes.rb"
80
84
  - ".releaserc.json"
81
85
  - ".rspec"
82
86
  - ".rubocop.yml"
@@ -94,7 +98,6 @@ files:
94
98
  - lib/drawio_dsl/configuration.rb
95
99
  - lib/drawio_dsl/dom_builder.rb
96
100
  - lib/drawio_dsl/drawio.rb
97
- - lib/drawio_dsl/drawio_dsl-OLD.x
98
101
  - lib/drawio_dsl/layout_engine.rb
99
102
  - lib/drawio_dsl/schema.rb
100
103
  - lib/drawio_dsl/version.rb
@@ -1,34 +0,0 @@
1
- KManager.action :bootstrap do
2
- action do
3
- director = DrawioDsl::Drawio
4
- .init(k_builder,
5
- on_exist: :skip, # %i[skip write compare]
6
- on_action: :queue # %i[queue execute]
7
- )
8
- .diagram(theme: :style_01)
9
- .page('Grid-Right', page_shadow: 1) do
10
- grid_layout(wrap_at: 3)
11
- square(title: 'Square')
12
- rectangle(title: 'Rectangle')
13
- rectangle(title: 'Rectangle (Rounded)', rounded: 1)
14
- circle(title: 'Circle')
15
- process(title: 'Process')
16
- ellipse(title: 'Ellipse')
17
- end
18
-
19
- diagram = DrawioDsl::XmlBuilder.new(director.builder.diagram)
20
-
21
-
22
- File.write('../spec/.samples/drawio/10-layout.xml', diagram.build)
23
- File.write('../spec/.samples/drawio/10-layout.drawio', diagram.build)
24
- end
25
- end
26
-
27
- KManager.opts.app_name = 'drawio_dsl'
28
- KManager.opts.sleep = 2
29
- KManager.opts.reboot_on_kill = 0
30
- KManager.opts.reboot_sleep = 4
31
- KManager.opts.exception_style = :short
32
- KManager.opts.show.time_taken = true
33
- KManager.opts.show.finished = true
34
- KManager.opts.show.finished_message = 'FINISHED :)'
@@ -1,335 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module KDirector
4
- module Dsls
5
- class DrawioXmlBuilder
6
- include KLog::Logging
7
-
8
- attr_reader :host
9
- attr_reader :pages
10
-
11
- attr_reader :current_id
12
- attr_reader :row_index
13
- attr_reader :row_offset
14
-
15
- def initialize(opts, dom)
16
- @host = opts[:host] || SecureRandom.alphanumeric(4)
17
- @pages = dom[:pages] || []
18
- # puts JSON.pretty_generate(dom)
19
-
20
- @current_id = 10
21
- @row_index = 0
22
- @row_offset = 0
23
- end
24
-
25
- def build
26
- xml_builder = Nokogiri::XML::Builder.new do |xml|
27
- xml.mxfile(host: host) do
28
- page_index = 0
29
- pages.each do |page|
30
- build_page(xml, page, page_index)
31
- page_index += 1
32
- end
33
- end
34
- end
35
-
36
- xml_builder.to_xml.sub('<?xml version="1.0"?>', '').strip
37
- end
38
-
39
- private
40
-
41
- def next_id
42
- result = @current_id
43
- @current_id += 1
44
- result
45
- end
46
-
47
- def next_row
48
- @row_index += 150
49
- end
50
-
51
- def current_row_index
52
- row_index + row_offset
53
- end
54
-
55
- def reset_row
56
- @row_index = 0
57
- end
58
-
59
- def random_text
60
- return '' if rand(5) == 1
61
-
62
- words = %w[
63
- substantial
64
- humor
65
- jeans
66
- hover
67
- encouraging
68
- glue
69
- used
70
- statuesque
71
- umbrella
72
- vigorous
73
- horses
74
- outgoing
75
- ]
76
-
77
- # return a random word
78
- words.sample
79
- end
80
-
81
- def element_color
82
- element_colors = %w[
83
- fillColor=#d0cee2;strokeColor=#56517e;fontColor=#333333;
84
- fillColor=#FFCCCC;strokeColor=#36393D;fontColor=#333333;
85
- fillColor=#CDEB8B;strokeColor=#36393D;fontColor=#333333;
86
- fillColor=#FFFF88;strokeColor=#36393D;fontColor=#333333;
87
- fillColor=#CCE5FF;strokeColor=#36393D;fontColor=#333333;
88
- fillColor=#FFCC99;strokeColor=#36393D;fontColor=#333333;
89
- fillColor=#F9F7ED;strokeColor=#36393D;fontColor=#333333;
90
- fillColor=#EEEEEE;strokeColor=#36393D;fontColor=#333333;
91
- fillColor=#BAC8D3;strokeColor=#23445D;fontColor=#333333;
92
- fillColor=#D0CEE2;strokeColor=#56517E;fontColor=#333333;
93
- fillColor=#B1DDF0;strokeColor=#10739E;fontColor=#333333;
94
- fillColor=#B0E3E6;strokeColor=#0E8088;fontColor=#333333;
95
- fillColor=#FAD9D5;strokeColor=#AE4132;fontColor=#333333;
96
- ]
97
-
98
- # return a random color
99
- element_colors.sample
100
- # nil
101
- end
102
-
103
- def build_page(xml, page, page_index)
104
- page_id = SecureRandom.alphanumeric(3).to_s
105
- @row_offset = 50 # Random.rand(350)
106
-
107
- xml.diagram(id: page_id, name: page[:name]) do
108
- size_ratio = Random.rand(0.5..3.0)
109
- size_ratio = 2
110
-
111
- reset_row
112
-
113
- grid = 1
114
- element_style = ''
115
-
116
- case page_index
117
- when 1
118
- element_style = 'sketch=1'
119
- grid = 0
120
- when 2
121
- element_style = 'shadow=1'
122
- when 3
123
- element_style = 'sketch=1;shadow=1'
124
- grid = 0
125
- end
126
-
127
- # background = "##{SecureRandom.hex(3)}"
128
- background = '#FFFACD'
129
- # background = nil
130
-
131
- # background="#FF99CC" backgroundImage="{&quot;src&quot;:&quot;data:page/id,AKs&quot;}" math="0" shadow="1"
132
- xml.mxGraphModel(dx: 800, dy: 583, background: background, grid: grid, gridSize: 10, guides: 1, tooltips: 1, connect: 1, arrows: 1, fold: 1, page: page_index, pageScale: 1, pageWidth: 1169,
133
- pageHeight: 827, math: 0, shadow: 0) do
134
- xml.root do
135
- xml.mxCell(id: "#{page_id}-0")
136
- xml.mxCell(id: "#{page_id}-1", parent: "#{page_id}-0")
137
-
138
- # ------ Row 1 ------
139
-
140
- # Square
141
- xml.mxCell(id: "#{page_id}-#{next_id}", parent: "#{page_id}-1", value: random_text, style: "whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}", vertex: '1') do
142
- xml.mxGeometry(x: size_ratio * 50 , y: size_ratio * current_row_index, width: size_ratio * 80, height: size_ratio * 80, as: 'geometry')
143
- end
144
- # Rectangle
145
- xml.mxCell(id: "#{page_id}-#{next_id}", parent: "#{page_id}-1", value: random_text, style: "rounded=0;whiteSpace=wrap;html=1;#{element_style};#{element_color}", vertex: '1') do
146
- xml.mxGeometry(x: size_ratio * 170 , y: size_ratio * current_row_index, width: size_ratio * 120, height: size_ratio * 60, as: 'geometry')
147
- end
148
- # Rectangle - Rounded
149
- xml.mxCell(id: "#{page_id}-#{next_id}", parent: "#{page_id}-1", value: random_text, style: "rounded=1;whiteSpace=wrap;html=1;#{element_style};#{element_color}", vertex: '1') do
150
- xml.mxGeometry(x: size_ratio * 330 , y: size_ratio * current_row_index, width: size_ratio * 120, height: size_ratio * 60, as: 'geometry')
151
- end
152
-
153
- # ------ Row 2 ------
154
-
155
- next_row
156
-
157
- # Circle
158
- xml.mxCell(id: "#{page_id}-#{next_id}", parent: "#{page_id}-1", value: random_text, style: "ellipse;whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}",
159
- vertex: '1') do
160
- xml.mxGeometry(x: size_ratio * 50 , y: size_ratio * current_row_index, width: size_ratio * 80, height: size_ratio * 80, as: 'geometry')
161
- end
162
-
163
- # Process
164
- xml.mxCell(id: "#{page_id}-#{next_id}", parent: "#{page_id}-1", value: random_text,
165
- style: "shape=process;whiteSpace=wrap;html=1;aspect=fixed;backgroundOutline=1;#{element_style};#{element_color}", vertex: '1') do
166
- xml.mxGeometry(x: size_ratio * 170 , y: size_ratio * current_row_index, width: size_ratio * 120, height: size_ratio * 80, as: 'geometry')
167
- end
168
-
169
- # Ellipse
170
- xml.mxCell(id: "#{page_id}-#{next_id}", parent: "#{page_id}-1", value: random_text, style: "ellipse;whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}",
171
- vertex: '1') do
172
- xml.mxGeometry(x: size_ratio * 330 , y: size_ratio * current_row_index, width: size_ratio * 120, height: size_ratio * 80, as: 'geometry')
173
- end
174
-
175
- # ------ Row 3 ------
176
-
177
- next_row
178
-
179
- # Rhombus
180
- xml.mxCell(id: "#{page_id}-#{next_id}", parent: "#{page_id}-1", value: random_text, style: "rhombus;whiteSpace=wrap;html=1;#{element_style};#{element_color}", vertex: '1') do
181
- xml.mxGeometry(x: size_ratio * 50 , y: size_ratio * current_row_index, width: size_ratio * 80, height: size_ratio * 80, as: 'geometry')
182
- end
183
-
184
- # Parallelogram
185
- xml.mxCell(id: "#{page_id}-#{next_id}", parent: "#{page_id}-1", value: random_text,
186
- style: "shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;#{element_style};#{element_color}", vertex: '1') do
187
- xml.mxGeometry(x: size_ratio * 170 , y: size_ratio * current_row_index, width: size_ratio * 120, height: size_ratio * 60, as: 'geometry')
188
- end
189
-
190
- # Hexagon
191
- xml.mxCell(id: "#{page_id}-#{next_id}", parent: "#{page_id}-1", value: random_text,
192
- style: "shape=hexagon;perimeter=hexagonPerimeter2;whiteSpace=wrap;html=1;fixedSize=1;#{element_style};#{element_color}", vertex: '1') do
193
- xml.mxGeometry(x: size_ratio * 330 , y: size_ratio * current_row_index, width: size_ratio * 120, height: size_ratio * 80, as: 'geometry')
194
- end
195
- end
196
- end
197
- end
198
- end
199
- end
200
-
201
- # DrawioDsl is a DSL for draw-io diagrams.
202
- class DrawioDsl < KDirector::Directors::BaseDirector
203
- def default_template_base_folder
204
- 'drawio'
205
- end
206
-
207
- def page(name = nil, **opts, &block)
208
- page = KDirector::Dsls::DrawioPage.new(self, **opts.merge(name: name))
209
- page.instance_eval(&block) if block_given?
210
-
211
- self
212
- end
213
-
214
- def create_diagram(name = nil, **opts)
215
- xml_builder = DrawioXmlBuilder.new(opts, builder.dom)
216
- add_file(name, content: xml_builder.build)
217
- play_actions
218
-
219
- self
220
- end
221
- end
222
-
223
- class DrawioPage < KDirector::Directors::ChildDirector
224
- attr_reader :name
225
- attr_reader :data
226
-
227
- def initialize(parent, **opts)
228
- super(parent, **opts)
229
- @name = opts[:name] || SecureRandom.alphanumeric(4)
230
- @data = { name: name, elements: [] }
231
-
232
- parent.builder.add(:pages, value: data) # , **repo_info_hash(**defaults))
233
- end
234
-
235
- def element(name = nil, **opts) # , &block)
236
- data[:elements] << opts.merge(name: name)
237
- end
238
-
239
- def square(_name = nil, **opts)
240
- # style = "whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}"
241
- style = 'whiteSpace=wrap;html=1;aspect=fixed'
242
-
243
- # available params
244
- # x, :y, :width, :height, :value
245
- element(:square, **opts.merge(style: style))
246
- end
247
-
248
- def rectangle(_name = nil, **opts)
249
- # style = "whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}"
250
- style = 'whiteSpace=wrap;html=1'
251
-
252
- # available params
253
- # x, :y, :width, :height, :value, :rounded
254
- element(:square, **opts.merge(style: style))
255
- end
256
-
257
- def circle(_name = nil, **opts)
258
- # style = "whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}"
259
- style = 'whiteSpace=wrap;html=1;aspect=fixed'
260
-
261
- # available params
262
- # x, :y, :width, :height, :value
263
- element(:circle, **opts.merge(style: style))
264
- end
265
-
266
- def process(_name = nil, **opts)
267
- # style = "whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}"
268
- style = 'whiteSpace=wrap;html=1;aspect=fixed'
269
-
270
- # available params
271
- # x, :y, :width, :height, :value
272
-
273
- element(:process, **opts.merge(style: style))
274
- end
275
-
276
- def ellipse(_name = nil, **opts)
277
- # style = "whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}"
278
- style = 'whiteSpace=wrap;html=1;aspect=fixed'
279
-
280
- # available params
281
- # x, :y, :width, :height, :value
282
-
283
- element(:ellipse, **opts.merge(style: style))
284
- end
285
-
286
- def interface(_name = nil, **opts)
287
- # style = "whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}"
288
- style = 'whiteSpace=wrap;html=1;aspect=fixed'
289
-
290
- # available params
291
- # x, :y, :width, :height, :value
292
-
293
- element(:ellipse, **opts.merge(style: style))
294
- end
295
-
296
- def object(_name = nil, **opts)
297
- # style = "whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}"
298
- style = 'whiteSpace=wrap;html=1;aspect=fixed'
299
-
300
- # available params
301
- # x, :y, :width, :height, :value
302
-
303
- element(:ellipse, **opts.merge(style: style))
304
- end
305
-
306
- def component(_name = nil, **opts)
307
- # style = "whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}"
308
- style = 'whiteSpace=wrap;html=1;aspect=fixed'
309
-
310
- # available params
311
- # x, :y, :width, :height, :value
312
-
313
- element(:ellipse, **opts.merge(style: style))
314
- end
315
-
316
- def package(_name = nil, **opts)
317
- # style = "whiteSpace=wrap;html=1;aspect=fixed;#{element_style};#{element_color}"
318
- style = 'whiteSpace=wrap;html=1;aspect=fixed'
319
-
320
- # available params
321
- # x, :y, :width, :height, :value
322
-
323
- element(:ellipse, **opts.merge(style: style))
324
- end
325
-
326
- def lines(name = nil, **opts); end
327
- def enum(name = nil, **opts); end
328
- def box(name = nil, **opts); end
329
- def down(name = nil, **opts); end
330
- def right(name = nil, **opts); end
331
- def left(name = nil, **opts); end
332
- def up(name = nil, **opts); end
333
- end
334
- end
335
- end