usps_flags 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +22 -11
  3. data/.travis.yml +1 -1
  4. data/Gemfile.lock +5 -2
  5. data/README.md +6 -0
  6. data/lib/usps_flags.rb +35 -44
  7. data/lib/usps_flags/config.rb +89 -87
  8. data/lib/usps_flags/core.rb +44 -42
  9. data/lib/usps_flags/core/ensign.rb +53 -49
  10. data/lib/usps_flags/core/field.rb +96 -92
  11. data/lib/usps_flags/core/footer.rb +9 -5
  12. data/lib/usps_flags/core/headers.rb +58 -48
  13. data/lib/usps_flags/core/icons.rb +11 -7
  14. data/lib/usps_flags/core/icons/anchor.rb +62 -56
  15. data/lib/usps_flags/core/icons/binoculars.rb +21 -15
  16. data/lib/usps_flags/core/icons/lighthouse.rb +28 -22
  17. data/lib/usps_flags/core/icons/star.rb +21 -15
  18. data/lib/usps_flags/core/icons/trident.rb +136 -127
  19. data/lib/usps_flags/core/icons/trident_parts/hashes.rb +62 -55
  20. data/lib/usps_flags/core/icons/trumpet.rb +34 -28
  21. data/lib/usps_flags/core/pennant.rb +50 -46
  22. data/lib/usps_flags/core/trident_spec.rb +135 -131
  23. data/lib/usps_flags/core/trident_specs.rb +11 -7
  24. data/lib/usps_flags/core/trident_specs/base.rb +36 -26
  25. data/lib/usps_flags/core/trident_specs/circle.rb +36 -30
  26. data/lib/usps_flags/core/trident_specs/delta.rb +41 -30
  27. data/lib/usps_flags/core/trident_specs/header.rb +56 -50
  28. data/lib/usps_flags/core/trident_specs/horizontal.rb +80 -0
  29. data/lib/usps_flags/core/trident_specs/long.rb +41 -25
  30. data/lib/usps_flags/core/trident_specs/overlay.rb +40 -0
  31. data/lib/usps_flags/core/trident_specs/short.rb +30 -156
  32. data/lib/usps_flags/core/trident_specs/vertical.rb +108 -0
  33. data/lib/usps_flags/core/tridents.rb +54 -50
  34. data/lib/usps_flags/core/us.rb +40 -44
  35. data/lib/usps_flags/core/wheel.rb +7 -3
  36. data/lib/usps_flags/errors.rb +25 -23
  37. data/lib/usps_flags/generate.rb +111 -107
  38. data/lib/usps_flags/generate/flag.rb +160 -157
  39. data/lib/usps_flags/generate/generator_methods.rb +139 -0
  40. data/lib/usps_flags/generate/helper_methods.rb +88 -0
  41. data/lib/usps_flags/helpers.rb +163 -165
  42. data/lib/usps_flags/helpers/builders.rb +92 -85
  43. data/lib/usps_flags/helpers/spec_arrows.rb +127 -123
  44. data/lib/usps_flags/helpers/valid_flags.rb +45 -41
  45. data/lib/usps_flags/rational.rb +35 -0
  46. data/spec/usps_flags/config_spec.rb +17 -10
  47. data/spec/usps_flags/core_spec.rb +31 -31
  48. data/spec/usps_flags/generate_spec.rb +76 -73
  49. data/spec/usps_flags/helpers_spec.rb +8 -8
  50. data/spec/usps_flags/rational_spec.rb +17 -0
  51. data/spec/usps_flags_spec.rb +19 -21
  52. data/usps_flags.gemspec +7 -6
  53. metadata +34 -10
  54. data/lib/rational.rb +0 -39
  55. data/lib/usps_flags/generate/private.rb +0 -199
  56. data/spec/rational_spec.rb +0 -19
@@ -4,105 +4,112 @@
4
4
  #
5
5
  # These methods should never need to be called directly, except when designing new flags.
6
6
  # @private
7
- class USPSFlags::Helpers::Builders
8
- class << self
9
- # Displays an overlay grid with regularly spaced locator markers.
10
- #
11
- # This is useful for adjusting or creating new SVG data generators, but should not otherwise need to be called.
12
- # @private
13
- def grid(width: USPSFlags::Config::BASE_FLY, height: USPSFlags::Config::BASE_HOIST)
14
- @width = width
15
- @height = height
16
- @stroke_width = @width / 600
17
- "#{circles}#{horizontal_lines}#{vertical_lines}#{diagonal_lines}"
18
- end
7
+ class USPSFlags
8
+ class Helpers
9
+ class Builders
10
+ class << self
11
+ # Displays an overlay grid with regularly spaced locator markers.
12
+ #
13
+ # This is useful for adjusting or creating new SVG data generators, but should not otherwise need to be called.
14
+ # @private
15
+ def grid(width: USPSFlags::Config::BASE_FLY, height: USPSFlags::Config::BASE_HOIST)
16
+ @width = width
17
+ @height = height
18
+ @stroke_width = @width / 600
19
+ "#{circles}#{horizontal_lines}#{vertical_lines}#{diagonal_lines}"
20
+ end
19
21
 
20
- # Displays an overlay indicator of concentric circles and radiating lines.
21
- #
22
- # This is useful for adjusting or creating new SVG data generators, but should not otherwise need to be called.
23
- # @private
24
- def locator
25
- <<~SVG
26
- <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY * 2}" fill="#000000" fill-opacity="0.4" />
27
- <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY}" fill="#333333" fill-opacity="0.4" />
28
- <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 2}" fill="#666666" fill-opacity="0.4" />
29
- <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 4}" fill="#999999" fill-opacity="0.4" />
30
- <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 8}" fill="#CCCCCC" fill-opacity="0.4" />
31
- <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 16}" fill="#FFFFFF" fill-opacity="0.4" />
22
+ # Displays an overlay indicator of concentric circles and radiating lines.
23
+ #
24
+ # This is useful for adjusting or creating new SVG data generators, but should not otherwise need to be called.
25
+ # @private
26
+ def locator
27
+ <<~SVG
28
+ <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY * 2}" fill="#000000" fill-opacity="0.4" />
29
+ <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY}" fill="#333333" fill-opacity="0.4" />
30
+ <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 2}" fill="#666666" fill-opacity="0.4" />
31
+ <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 4}" fill="#999999" fill-opacity="0.4" />
32
+ <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 8}" fill="#CCCCCC" fill-opacity="0.4" />
33
+ <circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 16}" fill="#FFFFFF" fill-opacity="0.4" />
32
34
 
33
- <line x1="-#{USPSFlags::Config::BASE_FLY}" y1="-#{USPSFlags::Config::BASE_HOIST}" x2="#{USPSFlags::Config::BASE_FLY}" y2="#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
34
- <line x1="-#{USPSFlags::Config::BASE_FLY}" y1="#{USPSFlags::Config::BASE_HOIST}" x2="#{USPSFlags::Config::BASE_FLY}" y2="-#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
35
- <line x1="0" y1="#{USPSFlags::Config::BASE_HOIST}" x2="0" y2="-#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
36
- <line x1="-#{USPSFlags::Config::BASE_FLY}" y1="0" x2="#{USPSFlags::Config::BASE_FLY}" y2="0" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
35
+ <line x1="-#{USPSFlags::Config::BASE_FLY}" y1="-#{USPSFlags::Config::BASE_HOIST}" x2="#{USPSFlags::Config::BASE_FLY}" y2="#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
36
+ <line x1="-#{USPSFlags::Config::BASE_FLY}" y1="#{USPSFlags::Config::BASE_HOIST}" x2="#{USPSFlags::Config::BASE_FLY}" y2="-#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
37
+ <line x1="0" y1="#{USPSFlags::Config::BASE_HOIST}" x2="0" y2="-#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
38
+ <line x1="-#{USPSFlags::Config::BASE_FLY}" y1="0" x2="#{USPSFlags::Config::BASE_FLY}" y2="0" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
37
39
 
38
- <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY / 30}" height="#{USPSFlags::Config::BASE_FLY / 30}" fill="#333333" fill-opacity="0.6" />
39
- SVG
40
- end
40
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY / 30}" height="#{USPSFlags::Config::BASE_FLY / 30}" fill="#333333" fill-opacity="0.6" />
41
+ SVG
42
+ end
41
43
 
42
- private
44
+ private
43
45
 
44
- def circles
45
- <<~SVG
46
- #{pos_circle(0, 0)}
47
- #{pos_circle(@width, 0)}
48
- #{pos_circle(@width, @height)}
49
- #{pos_circle(0, @height)}
50
- <circle cx="#{@width * 1 / 4}" cy="#{@height / 2}" r="#{@width / 60}" fill="#999999" fill-opacity="0.4" />
51
- <circle cx="#{@width * 3 / 4}" cy="#{@height / 2}" r="#{@width / 60}" fill="#999999" fill-opacity="0.4" />
52
- #{radial_circles}
53
- SVG
54
- end
46
+ def circles
47
+ <<~SVG
48
+ #{pos_circle(0, 0)}
49
+ #{pos_circle(@width, 0)}
50
+ #{pos_circle(@width, @height)}
51
+ #{pos_circle(0, @height)}
52
+ <circle cx="#{@width * 1 / 4}" cy="#{@height / 2}" r="#{@width / 60}" fill="#999999" fill-opacity="0.4" />
53
+ <circle cx="#{@width * 3 / 4}" cy="#{@height / 2}" r="#{@width / 60}" fill="#999999" fill-opacity="0.4" />
54
+ #{radial_circles}
55
+ SVG
56
+ end
55
57
 
56
- def radial_circles
57
- <<~SVG
58
- #{radial_circle(1, @width / 60)}
59
- #{radial_circle(2, @width / 60)}
60
- #{radial_circle(2, @width / 75)}
61
- #{radial_circle(2, @width / 100)}
62
- #{radial_circle(3, @width / 60)}
63
- SVG
64
- end
58
+ def radial_circles
59
+ <<~SVG
60
+ #{radial_circle(1, @width / 60)}
61
+ #{radial_circle(2, @width / 60)}
62
+ #{radial_circle(2, @width / 75)}
63
+ #{radial_circle(2, @width / 100)}
64
+ #{radial_circle(3, @width / 60)}
65
+ SVG
66
+ end
65
67
 
66
- def pos_circle(cx, cy)
67
- <<~SVG
68
- <circle cx="#{cx}" cy="#{cy}" r="#{@width / 60}" fill="#000000" fill-opacity="0.4" />
69
- SVG
70
- end
68
+ def pos_circle(cx, cy)
69
+ <<~SVG
70
+ <circle cx="#{cx}" cy="#{cy}" r="#{@width / 60}" fill="#000000" fill-opacity="0.4" />
71
+ SVG
72
+ end
71
73
 
72
- def radial_circle(index, radius)
73
- <<~SVG
74
- <circle cx="#{@width / 2}" cy="#{@height * index / 4}" r="#{radius}" fill="#999999" fill-opacity="0.4" />
75
- SVG
76
- end
74
+ def radial_circle(index, radius)
75
+ <<~SVG
76
+ <circle cx="#{@width / 2}" cy="#{@height * index / 4}" r="#{radius}" fill="#999999" fill-opacity="0.4" />
77
+ SVG
78
+ end
77
79
 
78
- def horizontal_lines
79
- (0..4).map { |index| horizontal_line(index) }.join
80
- end
80
+ def horizontal_lines
81
+ (0..4).map { |index| horizontal_line(index) }.join
82
+ end
81
83
 
82
- def horizontal_line(index)
83
- <<~SVG
84
- <line x1="0" y1="#{@height * index / 4}" x2="#{@width}" y2="#{@height * index / 4}" stroke="#333333" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
85
- SVG
86
- end
84
+ def horizontal_line(index)
85
+ <<~SVG
86
+ <line x1="0" y1="#{@height * index / 4}" x2="#{@width}" y2="#{@height * index / 4}" stroke="#333333" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
87
+ SVG
88
+ end
87
89
 
88
- def vertical_lines
89
- (0..6).map { |index| vertical_line(index) }.join
90
- end
90
+ def vertical_lines
91
+ (0..6).map { |index| vertical_line(index) }.join
92
+ end
91
93
 
92
- def vertical_line(index)
93
- <<~SVG
94
- <line y1="0" x1="#{@width * index / 6}" y2="#{@height}" x2="#{@width * index / 6}" stroke="#333333" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
95
- SVG
96
- end
94
+ def vertical_line(index)
95
+ <<~SVG
96
+ <line y1="0" x1="#{@width * index / 6}" y2="#{@height}" x2="#{@width * index / 6}" stroke="#333333" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
97
+ SVG
98
+ end
97
99
 
98
- def diagonal_lines
99
- "#{diagonal_line(2, 1, 3, 2)}#{diagonal_line(3, 2, 2, 3)}#{diagonal_line(2, 3, 1, 2)}#{diagonal_line(1, 2, 2, 1)}"
100
- end
100
+ def diagonal_lines
101
+ diagonal_line(2, 1, 3, 2) +
102
+ diagonal_line(3, 2, 2, 3) +
103
+ diagonal_line(2, 3, 1, 2) +
104
+ diagonal_line(1, 2, 2, 1)
105
+ end
101
106
 
102
- def diagonal_line(a, b, c, d)
103
- <<~SVG
104
- <line x1="#{@width * a / 4}" y1="#{@height * b / 4}" x2="#{@width * c / 4}" y2="#{@height * d / 4}" stroke="#999999" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
105
- SVG
107
+ def diagonal_line(a, b, c, d)
108
+ <<~SVG
109
+ <line x1="#{@width * a / 4}" y1="#{@height * b / 4}" x2="#{@width * c / 4}" y2="#{@height * d / 4}" stroke="#999999" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
110
+ SVG
111
+ end
112
+ end
106
113
  end
107
114
  end
108
115
  end
@@ -4,130 +4,134 @@
4
4
  #
5
5
  # These methods should never need to be called directly.
6
6
  # @private
7
- class USPSFlags::Helpers::SpecArrows
8
- class << self
9
- # Creates a vertical arrow for the trident spec sheet.
10
- #
11
- # This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
12
- # @private
13
- def vertical(x, top, bottom, **options)
14
- options = defaults.merge(options)
15
-
16
- load_common_config(options[:fly])
17
- label, label_fraction = get_labels(bottom, top)
18
- options = options.merge(x: x, top: top, bottom: bottom, label: label, label_fraction: label_fraction)
19
-
20
- vertical_svg_group(options)
21
- end
22
-
23
- # Creates a horizontal arrow for the trident spec sheet.
24
- #
25
- # This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
26
- # @private
27
- def horizontal(y, left, right, **options)
28
- options = defaults(:h).merge(options)
29
-
30
- load_common_config(options[:fly])
31
- label, label_fraction = get_labels(right, left)
32
- options = options.merge(y: y, left: left, right: right, label: label, label_fraction: label_fraction)
33
-
34
- horizontal_svg_group(options)
35
- end
36
-
37
- private
38
-
39
- def defaults(mode = :v)
40
- {
41
- pointer_top: nil, pointer_bottom: nil, pointer_left: nil, pointer_right: nil, fly: nil,
42
- unit: nil, label_offset: (USPSFlags::Config::BASE_FLY / (mode == :v ? 120 : 45)),
43
- label_offset_x: 0, label_offset_y: 0, label_align: (mode == :v ? 'left' : 'middle')
44
- }
45
- end
46
-
47
- def vertical_svg_group(options)
48
- svg = +''
49
- svg << arrow_pointer(options) unless options[:pointer_top].nil?
50
- svg << arrow_pointer(options) unless options[:pointer_bottom].nil?
51
- svg << vertical_svg(options)
52
- svg
53
- end
54
-
55
- def vertical_svg(options)
56
- <<~SVG
57
- <path d="#{vertical_svg_path(options)}" fill="none" />
58
- <g>
59
- <style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
60
- #{vertical_svg_text(options)}
61
- </g>
62
- SVG
63
- end
64
-
65
- def vertical_svg_path(options)
66
- <<~SVG
67
- M#{options[:x]} #{options[:top]} l #{@arrow_size} #{@arrow_size} M#{options[:x]} #{options[:top]} l -#{@arrow_size} #{@arrow_size} M#{options[:x]} #{options[:top]} l 0 #{options[:bottom] - options[:top]} l #{@arrow_size} -#{@arrow_size} M#{options[:x]} #{options[:bottom]} l -#{@arrow_size} -#{@arrow_size}" stroke="#{@color}" stroke-width="#{@stroke_width}
68
- SVG
69
- end
70
-
71
- def vertical_svg_text(options)
72
- <<~SVG
73
- <text x="#{options[:x] + options[:label_offset]}" y="#{(options[:top] + options[:bottom]) / 2 + (USPSFlags::Config::BASE_HOIST / 150) + options[:label_offset_y]}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{options[:label_align]}">#{options[:label]} <tspan>#{options[:label_fraction]}</tspan> #{options[:unit]}</text>
74
- SVG
75
- end
76
-
77
- def horizontal_svg_group(options)
78
- svg = +''
79
- svg << arrow_pointer(options) unless options[:pointer_left].nil?
80
- svg << arrow_pointer(options) unless options[:pointer_right].nil?
81
- svg << horizontal_svg(options)
82
- svg
83
- end
84
-
85
- def horizontal_svg(options)
86
- <<~SVG
87
- <path d="#{horizontal_svg_path(options)}" stroke="#{@color}" stroke-width="#{@stroke_width}" fill="none" />
88
- <g>
89
- <style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
90
- #{horizontal_svg_text(options)}
91
- </g>
92
- SVG
93
- end
94
-
95
- def horizontal_svg_path(options)
96
- <<~SVG
97
- M#{options[:left]} #{options[:y]} l #{@arrow_size} #{@arrow_size} M#{options[:left]} #{options[:y]} l #{@arrow_size} -#{@arrow_size} M#{options[:left]} #{options[:y]} l #{options[:right] - options[:left]} 0 l -#{@arrow_size} -#{@arrow_size} M#{options[:right]} #{options[:y]} l -#{@arrow_size} #{@arrow_size}
98
- SVG
99
- end
100
-
101
- def horizontal_svg_text(options)
102
- <<~SVG
103
- <text x="#{(options[:left] + options[:right]) / 2 + options[:label_offset_x]}" y="#{options[:y] + options[:label_offset]}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{options[:label_align]}">#{options[:label]} <tspan>#{options[:label_fraction]}</tspan> #{options[:unit]}</text>
104
- SVG
105
- end
106
-
107
- def load_common_config(fly)
108
- @color = '#CCCCCC'
109
- @stroke_width = (USPSFlags::Config::BASE_FLY / 600)
110
- @stroke_dash = '10, 10'
111
- @font_size = (USPSFlags::Config::BASE_FLY / 60)
112
- @arrow_size = (USPSFlags::Config::BASE_FLY / 120)
113
- @fly = fly || USPSFlags::Config::BASE_FLY
114
- end
115
-
116
- def arrow_pointer(options)
117
- <<~SVG
118
- <line x1="#{options[:x1]}" y1="#{options[:y1]}" x2="#{options[:x2]}" y2="#{options[:y2]}" stroke="#{@color}" stroke-width="#{@stroke_width}" stroke-dasharray="#{@stroke_dash}" />
119
- SVG
120
- end
121
-
122
- def get_labels(a, b)
123
- label = (a - b) * Rational(@fly, USPSFlags::Config::BASE_FLY)
124
- if label == label.to_i
125
- label = label.to_i
126
- label_fraction = ''
127
- else
128
- label, label_fraction = label.to_simplified_a
7
+ class USPSFlags
8
+ class Helpers
9
+ class SpecArrows
10
+ class << self
11
+ # Creates a vertical arrow for the trident spec sheet.
12
+ #
13
+ # This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
14
+ # @private
15
+ def vertical(x, top, bottom, **options)
16
+ options = defaults.merge(options)
17
+
18
+ load_common_config(options[:fly])
19
+ label, label_fraction = get_labels(bottom, top)
20
+ options = options.merge(x: x, top: top, bottom: bottom, label: label, label_fraction: label_fraction)
21
+
22
+ vertical_svg_group(options)
23
+ end
24
+
25
+ # Creates a horizontal arrow for the trident spec sheet.
26
+ #
27
+ # This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
28
+ # @private
29
+ def horizontal(y, left, right, **options)
30
+ options = defaults(:h).merge(options)
31
+
32
+ load_common_config(options[:fly])
33
+ label, label_fraction = get_labels(right, left)
34
+ options = options.merge(y: y, left: left, right: right, label: label, label_fraction: label_fraction)
35
+
36
+ horizontal_svg_group(options)
37
+ end
38
+
39
+ private
40
+
41
+ def defaults(mode = :v)
42
+ {
43
+ pointer_top: nil, pointer_bottom: nil, pointer_left: nil, pointer_right: nil, fly: nil,
44
+ unit: nil, label_offset: (USPSFlags::Config::BASE_FLY / (mode == :v ? 120 : 45)),
45
+ label_offset_x: 0, label_offset_y: 0, label_align: (mode == :v ? 'left' : 'middle')
46
+ }
47
+ end
48
+
49
+ def vertical_svg_group(options)
50
+ svg = +''
51
+ svg << arrow_pointer(options) unless options[:pointer_top].nil?
52
+ svg << arrow_pointer(options) unless options[:pointer_bottom].nil?
53
+ svg << vertical_svg(options)
54
+ svg
55
+ end
56
+
57
+ def vertical_svg(options)
58
+ <<~SVG
59
+ <path d="#{vertical_svg_path(options)}" fill="none" />
60
+ <g>
61
+ <style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
62
+ #{vertical_svg_text(options)}
63
+ </g>
64
+ SVG
65
+ end
66
+
67
+ def vertical_svg_path(options)
68
+ <<~SVG
69
+ M#{options[:x]} #{options[:top]} l #{@arrow_size} #{@arrow_size} M#{options[:x]} #{options[:top]} l -#{@arrow_size} #{@arrow_size} M#{options[:x]} #{options[:top]} l 0 #{options[:bottom] - options[:top]} l #{@arrow_size} -#{@arrow_size} M#{options[:x]} #{options[:bottom]} l -#{@arrow_size} -#{@arrow_size}" stroke="#{@color}" stroke-width="#{@stroke_width}
70
+ SVG
71
+ end
72
+
73
+ def vertical_svg_text(options)
74
+ <<~SVG
75
+ <text x="#{options[:x] + options[:label_offset]}" y="#{(options[:top] + options[:bottom]) / 2 + (USPSFlags::Config::BASE_HOIST / 150) + options[:label_offset_y]}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{options[:label_align]}">#{options[:label]} <tspan>#{options[:label_fraction]}</tspan> #{options[:unit]}</text>
76
+ SVG
77
+ end
78
+
79
+ def horizontal_svg_group(options)
80
+ svg = +''
81
+ svg << arrow_pointer(options) unless options[:pointer_left].nil?
82
+ svg << arrow_pointer(options) unless options[:pointer_right].nil?
83
+ svg << horizontal_svg(options)
84
+ svg
85
+ end
86
+
87
+ def horizontal_svg(options)
88
+ <<~SVG
89
+ <path d="#{horizontal_svg_path(options)}" stroke="#{@color}" stroke-width="#{@stroke_width}" fill="none" />
90
+ <g>
91
+ <style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
92
+ #{horizontal_svg_text(options)}
93
+ </g>
94
+ SVG
95
+ end
96
+
97
+ def horizontal_svg_path(options)
98
+ <<~SVG
99
+ M#{options[:left]} #{options[:y]} l #{@arrow_size} #{@arrow_size} M#{options[:left]} #{options[:y]} l #{@arrow_size} -#{@arrow_size} M#{options[:left]} #{options[:y]} l #{options[:right] - options[:left]} 0 l -#{@arrow_size} -#{@arrow_size} M#{options[:right]} #{options[:y]} l -#{@arrow_size} #{@arrow_size}
100
+ SVG
101
+ end
102
+
103
+ def horizontal_svg_text(options)
104
+ <<~SVG
105
+ <text x="#{(options[:left] + options[:right]) / 2 + options[:label_offset_x]}" y="#{options[:y] + options[:label_offset]}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{options[:label_align]}">#{options[:label]} <tspan>#{options[:label_fraction]}</tspan> #{options[:unit]}</text>
106
+ SVG
107
+ end
108
+
109
+ def load_common_config(fly)
110
+ @color = '#CCCCCC'
111
+ @stroke_width = (USPSFlags::Config::BASE_FLY / 600)
112
+ @stroke_dash = '10, 10'
113
+ @font_size = (USPSFlags::Config::BASE_FLY / 60)
114
+ @arrow_size = (USPSFlags::Config::BASE_FLY / 120)
115
+ @fly = fly || USPSFlags::Config::BASE_FLY
116
+ end
117
+
118
+ def arrow_pointer(options)
119
+ <<~SVG
120
+ <line x1="#{options[:x1]}" y1="#{options[:y1]}" x2="#{options[:x2]}" y2="#{options[:y2]}" stroke="#{@color}" stroke-width="#{@stroke_width}" stroke-dasharray="#{@stroke_dash}" />
121
+ SVG
122
+ end
123
+
124
+ def get_labels(a, b)
125
+ label = (a - b) * Rational(@fly, USPSFlags::Config::BASE_FLY)
126
+ if label == label.to_i
127
+ label = label.to_i
128
+ label_fraction = ''
129
+ else
130
+ label, label_fraction = USPSFlags::Rational.new(label).to_simplified_a
131
+ end
132
+ [label, label_fraction]
133
+ end
129
134
  end
130
- [label, label_fraction]
131
135
  end
132
136
  end
133
137
  end