ramhoj-scruffy 0.2.6 → 0.2.7
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.
@@ -2,7 +2,7 @@ module Scruffy::Components
|
|
2
2
|
|
3
3
|
class Legend < Base
|
4
4
|
FONT_SIZE = 80
|
5
|
-
|
5
|
+
|
6
6
|
def draw(svg, bounds, options={})
|
7
7
|
vertical = options[:vertical_legend]
|
8
8
|
legend_info = relevant_legend_info(options[:layers])
|
@@ -34,28 +34,28 @@ module Scruffy::Components
|
|
34
34
|
y = 0
|
35
35
|
size = relative(50)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# "#{x} #{y} #{@line_height} #{size}"
|
39
|
-
|
40
|
-
svg.rect(:x => x,
|
41
|
-
:y => y,
|
42
|
-
:width => size,
|
39
|
+
|
40
|
+
svg.rect(:x => x,
|
41
|
+
:y => y,
|
42
|
+
:width => size,
|
43
43
|
:height => size,
|
44
44
|
:fill => legend_info[idx][:color])
|
45
45
|
|
46
|
-
svg.text(legend_info[idx][:title],
|
47
|
-
:x => x + @line_height,
|
46
|
+
svg.text(legend_info[idx][:title],
|
47
|
+
:x => x + @line_height,
|
48
48
|
:y => y + text_height * 0.75,
|
49
|
-
'font-size' => text_height,
|
49
|
+
'font-size' => text_height,
|
50
50
|
'font-family' => options[:theme].font_family,
|
51
51
|
:style => "color: #{options[:theme].marker || 'white'}",
|
52
52
|
:fill => (options[:theme].marker || 'white'))
|
53
53
|
end
|
54
54
|
end # draw
|
55
|
-
|
55
|
+
|
56
56
|
protected
|
57
57
|
# Collects Legend Info from the provided Layers.
|
58
|
-
#
|
58
|
+
#
|
59
59
|
# Automatically filters by legend's categories.
|
60
60
|
def relevant_legend_info(layers, categories=(@options[:category] ? [@options[:category]] : @options[:categories]))
|
61
61
|
legend_info = layers.inject([]) do |arr, layer|
|
@@ -70,11 +70,11 @@ module Scruffy::Components
|
|
70
70
|
arr
|
71
71
|
end
|
72
72
|
end # relevant_legend_info
|
73
|
-
|
73
|
+
|
74
74
|
# Returns an array consisting of the total width needed by the legend
|
75
75
|
# information, as well as an array of @x-coords for each element. If
|
76
76
|
# vertical, then these are @y-coords, and @x is 0
|
77
|
-
#
|
77
|
+
#
|
78
78
|
# ie: [200, [0, 50, 100, 150]]
|
79
79
|
def layout(legend_info_array, vertical = false)
|
80
80
|
if vertical
|
@@ -96,10 +96,10 @@ module Scruffy::Components
|
|
96
96
|
enum[0] += (relative(50) * elem[:title].length) # Add room for text
|
97
97
|
|
98
98
|
[enum.first, enum.last]
|
99
|
-
end
|
99
|
+
end
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
end # class Legend
|
104
|
-
|
105
|
-
end # Scruffy::Components
|
104
|
+
|
105
|
+
end # Scruffy::Components
|
@@ -10,7 +10,13 @@ module Scruffy::Rasterizers
|
|
10
10
|
def rasterize(svg, options={})
|
11
11
|
# I know this seems weird, I'm open to suggestions.
|
12
12
|
# I didn't want RMagick required unless absolutely necessary.
|
13
|
-
|
13
|
+
unless defined? Magick
|
14
|
+
begin
|
15
|
+
require 'rmagick'
|
16
|
+
rescue LoadError
|
17
|
+
require 'RMagick'
|
18
|
+
end
|
19
|
+
end
|
14
20
|
|
15
21
|
image = Magick::Image::from_blob(svg)[0]
|
16
22
|
|
@@ -24,4 +30,4 @@ module Scruffy::Rasterizers
|
|
24
30
|
image.to_blob { self.format = options[:as] }
|
25
31
|
end
|
26
32
|
end
|
27
|
-
end
|
33
|
+
end
|
data/lib/scruffy/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 7
|
9
|
+
version: 0.2.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jonas Nicklas
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-13 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|