dudegl 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/compose/arms.rb +51 -4
- data/lib/compose/body.rb +14 -14
- data/lib/compose/limbs.rb +3 -2
- data/lib/diff_params.rb +144 -0
- data/lib/dudegl.rb +21 -7
- data/lib/limbs/arm.rb +27 -26
- data/lib/limbs/leg.rb +3 -4
- data/lib/limbs/limb.rb +16 -3
- data/lib/render.rb +8 -4
- data/lib/utils.rb +50 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b805c21a8942542341dbd1b2acf7c532aeabd85c595f301f0c0e6818cb6aebd3
|
4
|
+
data.tar.gz: 11759902d63ae4308573cce8a8a17d4c12a4eb6f3913e4719e4811378184400a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2496e62b966bccbbfa3413b1f7895e1380eff5d75cbe8563ce9e9fedade4c65b73f7ee2ca5a38f10cd98166e3f26a552363c638cd074d473d4eac78e1b8ade1
|
7
|
+
data.tar.gz: 02afdc8b0225d67eee097552c43b9c26fb696f2a33fbd90f26c54afd5377014aa0d9cd477e552eee79b9084c5b08f3d93f54018a7d796837487d708d03a53fd2
|
data/lib/compose/arms.rb
CHANGED
@@ -9,13 +9,36 @@ class Arms < Limbs
|
|
9
9
|
super
|
10
10
|
divide_arms
|
11
11
|
|
12
|
-
@left_arms_num.times
|
13
|
-
|
12
|
+
@left_arms_num.times { |i| draw_arms_on_side(@left_arms[i], i, :left) }
|
13
|
+
@right_arms_num.times { |i| draw_arms_on_side(@right_arms[i], i, :right) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def draw_arms_on_side(side_arms, i, body_side)
|
17
|
+
body_side == :left ? body_x = @body.body_left_x : body_x = @body.body_right_x
|
18
|
+
|
19
|
+
if arm_size_changed?(side_arms[:length])
|
20
|
+
side_arms_initial = side_arms.dup
|
21
|
+
side_arms[:length] = side_arms[:length].first
|
22
|
+
side_arms[:name] = change_arm_name_param(side_arms[:name], 1)
|
23
|
+
@limbs << Arm.new(side_arms, body_x, hy(i), body_side: body_side, body_color: @body_color)
|
24
|
+
|
25
|
+
side_arms = side_arms_initial
|
26
|
+
side_arms[:name] = change_arm_name_param(side_arms[:name], -1)
|
27
|
+
side_arms[:length] = side_arms[:length].first - side_arms[:length].last
|
28
|
+
@limbs << Arm.new(side_arms, body_x, hy_same_arm(i), body_side: body_side, body_color: @body_color)
|
29
|
+
else
|
30
|
+
side_arms[:length] = arm_length_value(side_arms[:length])
|
31
|
+
@limbs << Arm.new(side_arms, body_x, hy(i), body_side: body_side, body_color: @body_color)
|
14
32
|
end
|
33
|
+
end
|
15
34
|
|
16
|
-
|
17
|
-
|
35
|
+
def change_arm_name_param(name, param)
|
36
|
+
if name.class == Array
|
37
|
+
name[1] = param
|
38
|
+
return name
|
18
39
|
end
|
40
|
+
|
41
|
+
return [name, value]
|
19
42
|
end
|
20
43
|
|
21
44
|
def draw_parameters
|
@@ -38,4 +61,28 @@ class Arms < Limbs
|
|
38
61
|
def hy(i)
|
39
62
|
(1.05 * @body.body_left_top_y + i * @arms_step).round
|
40
63
|
end
|
64
|
+
|
65
|
+
def hy_same_arm(i)
|
66
|
+
(1.05 * @body.body_left_top_y + (i + 1) * 0.5 * @arms_step).round
|
67
|
+
end
|
68
|
+
|
69
|
+
def arm_length_value(item)
|
70
|
+
return item.first if item.class == Array
|
71
|
+
return item
|
72
|
+
end
|
73
|
+
|
74
|
+
def arm_size_changed?(length_params)
|
75
|
+
if length_params.class == Array
|
76
|
+
current_length = length_params.first
|
77
|
+
delta = length_params.last
|
78
|
+
|
79
|
+
current_length_short = current_length <= Config::METHOD_LENGTH_OK_MAX
|
80
|
+
previous_length_short = current_length - delta <= Config::METHOD_LENGTH_OK_MAX
|
81
|
+
changed = (current_length_short != previous_length_short)
|
82
|
+
|
83
|
+
return changed
|
84
|
+
end
|
85
|
+
|
86
|
+
return false
|
87
|
+
end
|
41
88
|
end
|
data/lib/compose/body.rb
CHANGED
@@ -5,17 +5,19 @@ class Body
|
|
5
5
|
include Utils
|
6
6
|
|
7
7
|
attr_reader :body_right_x, :body_right_top_y,
|
8
|
-
:body_left_x, :body_left_top_y, :draw_data
|
8
|
+
:body_left_x, :body_left_top_y, :draw_data, :color
|
9
9
|
|
10
|
-
def initialize(name, offsets)
|
10
|
+
def initialize(name, offsets, renamed = [])
|
11
11
|
@name = name
|
12
12
|
@draw_data = []
|
13
13
|
@offset_x = offsets[:offset_x]
|
14
14
|
@offset_y = offsets[:offset_y]
|
15
|
+
@renamed = renamed
|
15
16
|
draw_body
|
16
17
|
end
|
17
18
|
|
18
19
|
def draw_body
|
20
|
+
@dude_name, @color = process_item(@name)
|
19
21
|
# head center
|
20
22
|
head_center_x = 0.5 * Config::DUDE_FRAME_SIZE + @offset_x
|
21
23
|
head_center_y = 0.3 * Config::DUDE_FRAME_SIZE + @offset_y
|
@@ -27,25 +29,23 @@ class Body
|
|
27
29
|
Config::HEAD_RADIUS,
|
28
30
|
Config::BODY_CENTER - Config::SLIM_FACTOR)
|
29
31
|
|
30
|
-
@draw_data <<
|
31
|
-
circle: {
|
32
|
-
cx: head_center_x,
|
33
|
-
cy: head_center_y,
|
34
|
-
r: Config::HEAD_RADIUS
|
35
|
-
}
|
36
|
-
}
|
32
|
+
@draw_data << draw_circle(head_center_x, head_center_y, Config::HEAD_RADIUS, @color)
|
37
33
|
|
38
34
|
@draw_data << draw_line(@body_right_x, @body_right_top_y,
|
39
|
-
@body_right_x, @body_right_top_y + Config::BODY_LENGTH)
|
35
|
+
@body_right_x, @body_right_top_y + Config::BODY_LENGTH, @color)
|
40
36
|
# left part of a body
|
41
37
|
@draw_data << draw_line(@body_left_x, @body_left_top_y,
|
42
|
-
@body_left_x, @body_left_top_y + Config::BODY_LENGTH)
|
38
|
+
@body_left_x, @body_left_top_y + Config::BODY_LENGTH, @color)
|
43
39
|
# bottom
|
44
40
|
@draw_data << draw_line(@body_right_x, @body_right_top_y + Config::BODY_LENGTH,
|
45
|
-
@body_left_x, @body_left_top_y + Config::BODY_LENGTH)
|
41
|
+
@body_left_x, @body_left_top_y + Config::BODY_LENGTH, @color)
|
46
42
|
|
47
|
-
@draw_data << draw_caption(@
|
43
|
+
@draw_data << draw_caption(@dude_name, head_center_x - Config::HEAD_RADIUS,
|
48
44
|
head_center_y - 1.1 * Config::HEAD_RADIUS,
|
49
|
-
|
45
|
+
14, :lr, @color)
|
46
|
+
end
|
47
|
+
|
48
|
+
def changed?
|
49
|
+
return true if @color == :green || @color == :red
|
50
50
|
end
|
51
51
|
end
|
data/lib/compose/limbs.rb
CHANGED
@@ -3,10 +3,11 @@ require_relative '../config'
|
|
3
3
|
class Limbs
|
4
4
|
attr_reader :limbs
|
5
5
|
|
6
|
-
def initialize(params, body)
|
6
|
+
def initialize(params, body, opts = {})
|
7
7
|
@params = params
|
8
8
|
@body = body
|
9
9
|
@limbs = []
|
10
|
+
opts.key?(:body_color) ? @body_color = opts[:body_color] : @body_color = nil
|
10
11
|
|
11
12
|
draw_parameters
|
12
13
|
draw if @limbs_num.positive?
|
@@ -17,7 +18,7 @@ class Limbs
|
|
17
18
|
def draw; end
|
18
19
|
|
19
20
|
def draw_parameters
|
20
|
-
@params_methods = @params[:methods]
|
21
|
+
@params_methods = @params[:methods]
|
21
22
|
@limbs_num = @params_methods.size
|
22
23
|
return true if @limbs_num == 0
|
23
24
|
end
|
data/lib/diff_params.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# require 'byebug'
|
2
|
+
|
3
|
+
class DiffParams
|
4
|
+
class << self
|
5
|
+
def call(params_list, renamed = nil)
|
6
|
+
@params_list1 = params_list.first
|
7
|
+
@params_list2 = params_list.last
|
8
|
+
@renamed = renamed
|
9
|
+
@diff_params = []
|
10
|
+
|
11
|
+
manage_renamed if !renamed.nil?
|
12
|
+
compare_params_lists
|
13
|
+
|
14
|
+
@diff_params#.flatten!
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def compare_params_lists
|
20
|
+
new_params_names,
|
21
|
+
removed_params_names,
|
22
|
+
unchanged_params_names = items_diff(@params_list1, @params_list2)
|
23
|
+
|
24
|
+
@diff_params << label_items(@params_list2, new_params_names, 1)
|
25
|
+
@diff_params << label_items(@params_list1, removed_params_names, -1)
|
26
|
+
|
27
|
+
unchanged_params_names.each do |params_name|
|
28
|
+
@diff = { name: params_name, :methods=> [] }
|
29
|
+
@params1 = find_item(@params_list1, params_name)
|
30
|
+
@params2 = find_item(@params_list2, params_name)
|
31
|
+
|
32
|
+
compare
|
33
|
+
|
34
|
+
@diff[:name] = [@diff[:name], 0]
|
35
|
+
@diff_params << @diff
|
36
|
+
end
|
37
|
+
remove_empty_params
|
38
|
+
end
|
39
|
+
|
40
|
+
def label_params(params, label)
|
41
|
+
params[:name] = [params[:name], label]
|
42
|
+
end
|
43
|
+
|
44
|
+
def compare
|
45
|
+
new_methods_names,
|
46
|
+
removed_methods_names,
|
47
|
+
unchanged_methods_names = items_diff(@params1[:methods], @params2[:methods])
|
48
|
+
|
49
|
+
new_methods = label_items(@params2[:methods], new_methods_names, 1)
|
50
|
+
removed_methods = label_items(@params1[:methods], removed_methods_names, -1)
|
51
|
+
|
52
|
+
@diff[:methods] << new_methods
|
53
|
+
@diff[:methods] << removed_methods
|
54
|
+
process_unchanged_methods(unchanged_methods_names)
|
55
|
+
|
56
|
+
remove_empty_methods
|
57
|
+
@diff[:methods].flatten!
|
58
|
+
end
|
59
|
+
|
60
|
+
# returns hash with method2 params and diff (e.g. args2 - args1)
|
61
|
+
def compare_methods(method1, method2)
|
62
|
+
args_diff = method2[:args] - method1[:args]
|
63
|
+
length_diff = method2[:length] - method1[:length]
|
64
|
+
conditions_diff = method2[:conditions] - method1[:conditions]
|
65
|
+
{ name: [method1[:name], 0],
|
66
|
+
args: [method2[:args], args_diff],
|
67
|
+
length: [method2[:length], length_diff],
|
68
|
+
conditions: [method2[:conditions], conditions_diff] }
|
69
|
+
end
|
70
|
+
|
71
|
+
def items_diff(items1, items2)
|
72
|
+
items_names1 = items_names(items1)
|
73
|
+
items_names2 = items_names(items2)
|
74
|
+
|
75
|
+
new_items = items_names2 - items_names1
|
76
|
+
removed_items = items_names1 - items_names2
|
77
|
+
unchanged_items = items_names2 - new_items
|
78
|
+
|
79
|
+
[new_items, removed_items, unchanged_items]
|
80
|
+
end
|
81
|
+
|
82
|
+
def items_names(items)
|
83
|
+
items.map { |item| item[:name] }
|
84
|
+
end
|
85
|
+
|
86
|
+
def find_item(items, name)
|
87
|
+
item = items.select { |item| item[:name] == name }
|
88
|
+
item.first unless item.nil?
|
89
|
+
end
|
90
|
+
|
91
|
+
# 0 - unchanged, -1 - removed, 1 - new
|
92
|
+
def label_item(items, item_name, label)
|
93
|
+
item = find_item(items, item_name)
|
94
|
+
item[:name] = [item[:name], label]
|
95
|
+
item
|
96
|
+
end
|
97
|
+
|
98
|
+
def label_items(items, items_names, label)
|
99
|
+
items_names.map { |item_name| label_item(items, item_name, label) }
|
100
|
+
end
|
101
|
+
|
102
|
+
def process_unchanged_methods(unchanged_methods_names)
|
103
|
+
unchanged_methods_names.each do |method_name|
|
104
|
+
method1 = find_item(@params1[:methods], method_name)
|
105
|
+
method2 = find_item(@params2[:methods], method_name)
|
106
|
+
@diff[:methods] << compare_methods(method1, method2)
|
107
|
+
end
|
108
|
+
|
109
|
+
unchanged_methods = label_items(@params1[:methods], unchanged_methods_names, 0)
|
110
|
+
end
|
111
|
+
|
112
|
+
def remove_empty_methods
|
113
|
+
@diff[:methods].select! { |item| item != [] }
|
114
|
+
end
|
115
|
+
|
116
|
+
def remove_empty_params
|
117
|
+
@diff_params.select! { |item| item != [] }
|
118
|
+
end
|
119
|
+
|
120
|
+
def manage_renamed
|
121
|
+
@renamed.each do |names|
|
122
|
+
rename_items(@params_list1, names, :old)
|
123
|
+
rename_items(@params_list2, names, :new)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def renamed_name(names)
|
128
|
+
"#{names[:old_name]} > #{names[:new_name]}"
|
129
|
+
end
|
130
|
+
|
131
|
+
def rename_old_item(param_list, names)
|
132
|
+
param_list[:name] = renamed_name(names) if param_list[:name] == names[:old_name]
|
133
|
+
end
|
134
|
+
|
135
|
+
def rename_new_item(param_list, names)
|
136
|
+
param_list[:name] = renamed_name(names) if param_list[:name] == names[:new_name]
|
137
|
+
end
|
138
|
+
|
139
|
+
def rename_items(params_list, names, type)
|
140
|
+
return params_list.each { |item| rename_old_item(item, names) } if type == :old
|
141
|
+
return params_list.each { |item| rename_new_item(item, names) } if type == :new
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/lib/dudegl.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
|
-
require 'byebug'
|
1
|
+
# require 'byebug'
|
2
2
|
# require all filder from current dir and subdirectories
|
3
3
|
Dir[File.dirname(__FILE__) + '/**/*.rb'].each {|file| require_relative file }
|
4
4
|
|
5
5
|
class DudeGl
|
6
|
-
def initialize(params_list,
|
7
|
-
|
6
|
+
def initialize(params_list, opts = {})
|
7
|
+
opts.key?(:dudes_per_row_max) ? dudes_per_row_max = opts[:dudes_per_row_max] : dudes_per_row_max = nil
|
8
|
+
opts.key?(:renamed) ? @renamed = opts[:renamed] : @renamed = nil
|
9
|
+
|
10
|
+
if opts.key?(:diff) && opts[:diff] == true
|
11
|
+
@params_list = DiffParams.call(params_list, @renamed)
|
12
|
+
else
|
13
|
+
@params_list = params_list
|
14
|
+
end
|
8
15
|
@dudes = []
|
16
|
+
|
9
17
|
@locations = DudesLocation.new(@params_list, dudes_per_row_max)
|
10
18
|
|
11
19
|
build_dudes
|
@@ -21,6 +29,10 @@ class DudeGl
|
|
21
29
|
File.open("images/#{file_name}.svg", 'w') { |file| file.write(@svg.contents) }
|
22
30
|
end
|
23
31
|
|
32
|
+
def save_to_string
|
33
|
+
@svg.contents
|
34
|
+
end
|
35
|
+
|
24
36
|
private
|
25
37
|
|
26
38
|
def build_dudes
|
@@ -28,13 +40,15 @@ class DudeGl
|
|
28
40
|
end
|
29
41
|
|
30
42
|
def build_dude(params, index)
|
31
|
-
|
43
|
+
params = params.first if params.class == Array
|
44
|
+
body = Body.new(params[:name], offsets = @locations.offsets[index], @renamed)
|
32
45
|
|
33
|
-
|
46
|
+
body.changed? ? body_color = body.color : body_color = nil
|
47
|
+
# draw all methods as arms, keep legs for something else...
|
48
|
+
arms = Arms.new(params, body, body_color: body_color).limbs
|
34
49
|
arms_draw_params = arms.map { |arm| arm.draw_data }
|
35
50
|
|
36
|
-
|
37
|
-
legs_draw_params = legs.map { |leg| leg.draw_data }
|
51
|
+
legs_draw_params = []
|
38
52
|
|
39
53
|
(body.draw_data + arms_draw_params + legs_draw_params).flatten
|
40
54
|
end
|
data/lib/limbs/arm.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
require_relative 'limb'
|
2
2
|
|
3
3
|
class Arm < Limb
|
4
|
-
attr_reader :body_side
|
5
|
-
|
6
|
-
def initialize(params, x0, y0, body_side)
|
7
|
-
@body_side = body_side
|
8
|
-
super(params, x0, y0)
|
9
|
-
end
|
10
4
|
|
11
5
|
private
|
12
6
|
|
@@ -14,19 +8,27 @@ class Arm < Limb
|
|
14
8
|
super
|
15
9
|
@end_x = @x0 + @limb_length
|
16
10
|
|
17
|
-
|
11
|
+
@condition_colors = process_item_set(@params[:conditions])
|
12
|
+
@conditions = @condition_colors.size
|
13
|
+
@condition_colors = set_additional_colors(@conditions, @condition_colors)
|
14
|
+
|
15
|
+
if @conditions.positive?
|
18
16
|
draw_conditions
|
19
17
|
else
|
20
|
-
@draw_data << draw_line(@x0, @y0, @x0 + @limb_length, @y0)
|
18
|
+
@draw_data << draw_line(@x0, @y0, @x0 + @limb_length, @y0, @color_limb)
|
21
19
|
end
|
22
20
|
|
23
|
-
@draw_data << draw_caption(@
|
24
|
-
|
21
|
+
@draw_data << draw_caption(@name, (@end_x - 20).round, (@y0 - 10).round, 10, :lr, @color_limb)
|
22
|
+
|
23
|
+
@color_fingers = process_item_set(@params[:args])
|
24
|
+
@args = @color_fingers.size
|
25
|
+
@color_fingers = set_additional_colors(@args, @color_fingers)
|
26
|
+
draw_fingers
|
25
27
|
end
|
26
28
|
|
27
29
|
def draw_conditions
|
28
|
-
@lines_num = @
|
29
|
-
@line_length = ((@limb_length.abs - @
|
30
|
+
@lines_num = @conditions + 1
|
31
|
+
@line_length = ((@limb_length.abs - @conditions * Config::ELLIPSE_LENGTH) / @lines_num).round
|
30
32
|
|
31
33
|
@x1 = @x0 + @line_length * orientation
|
32
34
|
|
@@ -34,39 +36,38 @@ class Arm < Limb
|
|
34
36
|
end
|
35
37
|
|
36
38
|
def draw_condition(i)
|
37
|
-
@draw_data << draw_line(@x0, @y0, @x1, @y0)
|
39
|
+
@draw_data << draw_line(@x0, @y0, @x1, @y0, @color_limb)
|
38
40
|
|
39
|
-
@draw_data <<
|
40
|
-
|
41
|
-
|
42
|
-
ry: (Config::ELLIPSE_LENGTH / 4).round }} if i < @lines_num - 1
|
41
|
+
@draw_data << draw_ellipse(cx = (@x1 + Config::ELLIPSE_LENGTH * orientation / 2), cy = @y0,
|
42
|
+
rx = (Config::ELLIPSE_LENGTH / 2),
|
43
|
+
ry = (Config::ELLIPSE_LENGTH / 4), @condition_colors[i]) if i < @lines_num - 1
|
43
44
|
|
44
45
|
@x0 += (@line_length + Config::ELLIPSE_LENGTH) * orientation
|
45
46
|
@x1 = @x0 + @line_length * orientation
|
46
47
|
end
|
47
48
|
|
48
|
-
def draw_fingers
|
49
|
-
if body_side == :left
|
49
|
+
def draw_fingers
|
50
|
+
if @opts[:body_side] == :left
|
50
51
|
finger_angle_start = Config::FINGER_ANGLE_START
|
51
52
|
finger_angle_end = finger_angle_start + Config::FINGERS_RANGE
|
52
|
-
finger_angle_step = calc_fingers_range
|
53
|
+
finger_angle_step = calc_fingers_range
|
53
54
|
else
|
54
55
|
finger_angle_start = - Config::FINGER_ANGLE_START + Math::PI
|
55
56
|
finger_angle_end = finger_angle_start - Config::FINGERS_RANGE
|
56
|
-
finger_angle_step = - calc_fingers_range
|
57
|
+
finger_angle_step = - calc_fingers_range
|
57
58
|
end
|
58
59
|
|
59
|
-
|
60
|
+
@args.times do |i|
|
60
61
|
finger_end_x, finger_end_y = circle_rotate(end_x, end_y, Config::FINGER_LENGTH,
|
61
62
|
finger_angle_start + finger_angle_step * i)
|
62
63
|
|
63
|
-
@draw_data << draw_line(end_x, end_y, finger_end_x, finger_end_y)
|
64
|
+
@draw_data << draw_line(end_x, end_y, finger_end_x, finger_end_y, @color_fingers[i])
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
67
|
-
def calc_fingers_range
|
68
|
-
return
|
69
|
-
return
|
68
|
+
def calc_fingers_range
|
69
|
+
return Config::FINGERS_RANGE / (@args - 1).to_f if @args > 1
|
70
|
+
return Config::FINGERS_RANGE / @args.to_f if @args == 1
|
70
71
|
return 0
|
71
72
|
end
|
72
73
|
end
|
data/lib/limbs/leg.rb
CHANGED
@@ -30,10 +30,9 @@ class Leg < Limb
|
|
30
30
|
def draw_condition(i)
|
31
31
|
@draw_data << draw_line(@x0, @y0, @x0, @y1)
|
32
32
|
|
33
|
-
@draw_data <<
|
34
|
-
|
35
|
-
|
36
|
-
}} if i < @lines_num - 1
|
33
|
+
@draw_data << draw_ellipse(cx = @x0, cy = (@y1 + Config::ELLIPSE_LENGTH / 2),
|
34
|
+
rx = (Config::ELLIPSE_LENGTH / 4),
|
35
|
+
ry = (Config::ELLIPSE_LENGTH / 2)) if i < @lines_num - 1
|
37
36
|
|
38
37
|
@y0 += @line_length + Config::ELLIPSE_LENGTH
|
39
38
|
@y1 = @y0 + @line_length
|
data/lib/limbs/limb.rb
CHANGED
@@ -5,11 +5,15 @@ class Limb
|
|
5
5
|
|
6
6
|
attr_reader :end_x, :end_y, :draw_data
|
7
7
|
|
8
|
-
def initialize(params, x0, y0)
|
8
|
+
def initialize(params, x0, y0, opts = {})
|
9
9
|
@params = params
|
10
10
|
@x0 = x0
|
11
11
|
@end_y = @y0 = y0
|
12
12
|
@draw_data = []
|
13
|
+
@opts = opts
|
14
|
+
@name, @color_limb = process_item(params[:name])
|
15
|
+
body_color = apply_body_color(@opts[:body_color]) if @opts.key?(:body_color)
|
16
|
+
@color_limb = body_color unless body_color.nil? || body_color == :black
|
13
17
|
|
14
18
|
draw
|
15
19
|
end
|
@@ -25,9 +29,18 @@ class Limb
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def orientation
|
28
|
-
return 1 if @body_side.nil?
|
29
|
-
@body_side == :left ? -1 : 1
|
32
|
+
return 1 if @opts[:body_side].nil?
|
33
|
+
@opts[:body_side] == :left ? -1 : 1
|
30
34
|
end
|
31
35
|
|
32
36
|
def draw_conditions; end
|
37
|
+
|
38
|
+
def set_additional_colors(items, value)
|
39
|
+
return [@color_limb] * items if @color_limb == :green || @color_limb == :red
|
40
|
+
return value
|
41
|
+
end
|
42
|
+
|
43
|
+
def apply_body_color(body_color)
|
44
|
+
return body_color if body_color == :green || body_color == :red
|
45
|
+
end
|
33
46
|
end
|
data/lib/render.rb
CHANGED
@@ -3,8 +3,12 @@ require_relative 'config'
|
|
3
3
|
class Render
|
4
4
|
attr_reader :contents
|
5
5
|
|
6
|
+
HEADER = %Q[<?xml version="1.0" standalone="no"?>
|
7
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">]
|
8
|
+
|
6
9
|
def initialize(elements, width = Config::DUDE_FRAME_SIZE, height = Config::DUDE_FRAME_SIZE)
|
7
10
|
code = []
|
11
|
+
code << HEADER
|
8
12
|
code << %Q[<svg width="#{width}" height="#{height}" style="background:white" xmlns="http://www.w3.org/2000/svg">]
|
9
13
|
elements.each { |element| code << hash_to_svg(element) }
|
10
14
|
code << %Q[</svg>]
|
@@ -24,7 +28,7 @@ class Render
|
|
24
28
|
<line x1="#{params[:x1]}" y1="#{params[:y1]}"
|
25
29
|
x2="#{params[:x2]}"
|
26
30
|
y2="#{params[:y2]}"
|
27
|
-
style="stroke:
|
31
|
+
style="stroke:#{params[:color]}; stroke-width:1"/>
|
28
32
|
LINE
|
29
33
|
end
|
30
34
|
|
@@ -33,7 +37,7 @@ class Render
|
|
33
37
|
<circle cx="#{params[:cx]}"
|
34
38
|
cy="#{params[:cy]}"
|
35
39
|
r="#{params[:r]}"
|
36
|
-
fill="white" style="stroke:
|
40
|
+
fill="white" style="stroke:#{params[:color].to_s}; stroke-width:1"/>
|
37
41
|
CIRCLE
|
38
42
|
end
|
39
43
|
|
@@ -43,7 +47,7 @@ class Render
|
|
43
47
|
cy="#{params[:cy]}"
|
44
48
|
rx="#{params[:rx]}"
|
45
49
|
ry="#{params[:ry]}"
|
46
|
-
style="stroke:
|
50
|
+
style="stroke:#{params[:color].to_s}; stroke-width:1" fill="white"/>
|
47
51
|
ELLIPSE
|
48
52
|
end
|
49
53
|
|
@@ -52,7 +56,7 @@ class Render
|
|
52
56
|
<text x="#{params[:x]}"
|
53
57
|
y="#{params[:y]}"
|
54
58
|
font-family="arial" font-size="#{params[:font_size]}"
|
55
|
-
fill="
|
59
|
+
fill="#{params[:color].to_s}" style="writing-mode:
|
56
60
|
#{params[:orientation].to_s}">#{params[:caption]}</text>
|
57
61
|
TEXT
|
58
62
|
end
|
data/lib/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# require_relative 'config'
|
2
|
+
|
1
3
|
module Utils
|
2
4
|
def circle_rotate(center_x, center_y, r, rotation)
|
3
5
|
x_rotated = center_x + r * Math.cos(rotation)
|
@@ -5,11 +7,55 @@ module Utils
|
|
5
7
|
return [x_rotated, y_rotated]
|
6
8
|
end
|
7
9
|
|
8
|
-
def draw_line(x1, y1, x2, y2)
|
9
|
-
{ line: { x1: x1, y1: y1, x2: x2, y2: y2 } }
|
10
|
+
def draw_line(x1, y1, x2, y2, color = :black)
|
11
|
+
{ line: { x1: x1, y1: y1, x2: x2, y2: y2, color: color } }
|
12
|
+
end
|
13
|
+
|
14
|
+
def draw_caption(caption, x, y, font_size = 9, orientation = :lr, color = :black)
|
15
|
+
{ text: { x: x, y: y, caption: caption, font_size: font_size, orientation: orientation, color: color } }
|
16
|
+
end
|
17
|
+
|
18
|
+
def draw_circle(head_center_x, head_center_y, r, color = :black)
|
19
|
+
{ circle: { cx: head_center_x, cy: head_center_y, r: r, color: color } }
|
20
|
+
end
|
21
|
+
|
22
|
+
def draw_ellipse(cx, cy, rx, ry, color = :black)
|
23
|
+
{ ellipse: { cx: cx, cy: cy, rx: rx, ry: ry, color: color } }
|
10
24
|
end
|
11
25
|
|
12
|
-
def
|
13
|
-
|
26
|
+
def set_color(color_id)
|
27
|
+
return :red if color_id == -1
|
28
|
+
return :green if color_id == 1
|
29
|
+
return :black
|
30
|
+
end
|
31
|
+
|
32
|
+
def process_item(item)
|
33
|
+
# for item like ['new_method', 1]
|
34
|
+
if item.class == Array
|
35
|
+
name = item.first
|
36
|
+
color = set_color(item.last)
|
37
|
+
|
38
|
+
return [name, color]
|
39
|
+
end
|
40
|
+
# 'new_method'
|
41
|
+
return [item, :black]
|
42
|
+
end
|
43
|
+
|
44
|
+
def process_item_set(item)
|
45
|
+
return [:black] * item unless item.class == Array
|
46
|
+
|
47
|
+
current_num = item.first
|
48
|
+
delta = item.last
|
49
|
+
return [:black] * current_num if delta == 0
|
50
|
+
|
51
|
+
if delta > 0
|
52
|
+
colors_changed = [:green] * delta
|
53
|
+
colors_unchanged = [:black] * (current_num - delta)
|
54
|
+
elsif delta < 0
|
55
|
+
colors_changed = [:red] * delta.abs
|
56
|
+
colors_unchanged = [:black] * current_num
|
57
|
+
end
|
58
|
+
|
59
|
+
return colors_changed + colors_unchanged
|
14
60
|
end
|
15
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dudegl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Khramtsov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-02-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: 'Anthropomorphic UML: visualization of code and OOP concepts in a form
|
15
15
|
of human body.'
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/compose/legs.rb
|
26
26
|
- lib/compose/limbs.rb
|
27
27
|
- lib/config.rb
|
28
|
+
- lib/diff_params.rb
|
28
29
|
- lib/dudegl.rb
|
29
30
|
- lib/limbs/arm.rb
|
30
31
|
- lib/limbs/leg.rb
|