scruffy 0.2.6 → 0.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/{History.txt → CHANGES.txt} +15 -12
- data/README.txt +25 -25
- data/lib/scruffy.rb +0 -5
- data/lib/scruffy/components.rb +1 -0
- data/lib/scruffy/components/axes.rb +23 -0
- data/lib/scruffy/components/background.rb +3 -3
- data/lib/scruffy/components/base.rb +3 -0
- data/lib/scruffy/components/data_markers.rb +23 -8
- data/lib/scruffy/components/graphs.rb +4 -0
- data/lib/scruffy/components/grid.rb +45 -4
- data/lib/scruffy/components/legend.rb +63 -21
- data/lib/scruffy/components/title.rb +1 -1
- data/lib/scruffy/components/value_markers.rb +9 -16
- data/lib/scruffy/formatters.rb +41 -3
- data/lib/scruffy/graph.rb +27 -11
- data/lib/scruffy/graph_state.rb +5 -0
- data/lib/scruffy/helpers.rb +1 -0
- data/lib/scruffy/helpers/layer_container.rb +28 -4
- data/lib/scruffy/helpers/marker_helper.rb +25 -0
- data/lib/scruffy/helpers/point_container.rb +46 -17
- data/lib/scruffy/layers.rb +6 -1
- data/lib/scruffy/layers/bar.rb +35 -14
- data/lib/scruffy/layers/base.rb +51 -21
- data/lib/scruffy/layers/box.rb +114 -0
- data/lib/scruffy/layers/line.rb +31 -14
- data/lib/scruffy/layers/multi.rb +74 -0
- data/lib/scruffy/layers/multi_area.rb +119 -0
- data/lib/scruffy/layers/multi_bar.rb +51 -0
- data/lib/scruffy/layers/scatter.rb +13 -5
- data/lib/scruffy/layers/stacked.rb +2 -1
- data/lib/scruffy/rasterizers.rb +1 -0
- data/lib/scruffy/rasterizers/mini_magick_rasterizer.rb +24 -0
- data/lib/scruffy/rasterizers/rmagick_rasterizer.rb +8 -2
- data/lib/scruffy/renderers.rb +2 -0
- data/lib/scruffy/renderers/axis_legend.rb +41 -0
- data/lib/scruffy/renderers/base.rb +6 -4
- data/lib/scruffy/renderers/basic.rb +20 -0
- data/lib/scruffy/renderers/standard.rb +7 -6
- data/lib/scruffy/themes.rb +37 -1
- data/lib/scruffy/version.rb +1 -7
- data/spec/output/array.svg +55 -0
- data/spec/output/hash.svg +55 -0
- data/spec/scruffy/graph_spec.rb +4 -4
- data/spec/scruffy/layers/base_spec.rb +15 -10
- metadata +84 -96
- data/CHANGES +0 -104
- data/License.txt +0 -20
- data/MIT-LICENSE +0 -20
- data/Manifest.txt +0 -104
- data/PostInstall.txt +0 -6
- data/README +0 -9
- data/Rakefile +0 -108
- data/config/hoe.rb +0 -78
- data/config/requirements.rb +0 -15
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/script/txt2html +0 -82
- data/setup.rb +0 -1585
- data/spec/scruffy/layers/line_spec.rb +0 -10
- data/tasks/deployment.rake +0 -34
- data/tasks/environment.rake +0 -7
- data/tasks/website.rake +0 -17
- data/test/graph_creation_test.rb +0 -101
- data/test/test_helper.rb +0 -2
- data/website/images/blank.gif.html +0 -7
- data/website/images/graphs/all_smiles.png +0 -0
- data/website/images/graphs/bar_test.png +0 -0
- data/website/images/graphs/bar_test.svg +0 -71
- data/website/images/graphs/line_test.png +0 -0
- data/website/images/graphs/line_test.svg +0 -60
- data/website/images/graphs/multi_test.png +0 -0
- data/website/images/graphs/multi_test.svg +0 -296
- data/website/images/graphs/pie_test.png +0 -0
- data/website/images/graphs/pie_test.svg +0 -40
- data/website/images/graphs/split_test.png +0 -0
- data/website/images/graphs/split_test.svg +0 -295
- data/website/images/graphs/stacking_test.png +0 -0
- data/website/images/graphs/stacking_test.svg +0 -146
- data/website/images/header.png +0 -0
- data/website/images/header_gradient.png +0 -0
- data/website/images/overlay.png +0 -0
- data/website/images/scruffy.png +0 -0
- data/website/index.html +0 -225
- data/website/index.txt +0 -204
- data/website/javascripts/application.js +0 -2
- data/website/javascripts/controls.js +0 -815
- data/website/javascripts/dragdrop.js +0 -913
- data/website/javascripts/effects.js +0 -958
- data/website/javascripts/lightbox.js +0 -437
- data/website/javascripts/prototype.js +0 -2006
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/lightbox.css +0 -27
- data/website/stylesheets/screen.css +0 -147
- data/website/stylesheets/scruffy.css +0 -227
- data/website/template.html.erb +0 -47
data/{History.txt → CHANGES.txt}
RENAMED
@@ -1,17 +1,20 @@
|
|
1
1
|
= Scruffy Changelog
|
2
|
-
== Version 0.2.6
|
3
|
-
(August 23rd, 2009)
|
4
|
-
* Fixed some syntax errors causing problems with Builder
|
5
2
|
|
6
|
-
== Version 0.
|
7
|
-
(
|
8
|
-
*
|
9
|
-
|
3
|
+
== Version 0.3.0.beta1
|
4
|
+
(January 1st, 2011)
|
5
|
+
* Really? 2011? Wow.
|
6
|
+
* Merged in divergent forks from github
|
7
|
+
* Probably broken, but lets get it fixed.
|
10
8
|
|
11
|
-
== Version 0.2.
|
12
|
-
(2008
|
13
|
-
*
|
14
|
-
*
|
9
|
+
== Version 0.2.6
|
10
|
+
(December 12th, 2008)
|
11
|
+
* Forked from the official 0.2.5 release (http://github.com/delano/scruffy/)
|
12
|
+
* Added stroke_width and style attributes to Line
|
13
|
+
* Added toggleable shadow and dots attributes to Line
|
14
|
+
* Changed the default Line to not include shadow or dots and to have a width of 1 pixel.
|
15
|
+
* Added stroke_width for Component::Graph. Default is now 1.
|
16
|
+
* Changed the default theme to one appropriate for hi-res charts
|
17
|
+
* Removed website from release
|
15
18
|
|
16
19
|
== Version 0.2.3
|
17
20
|
(July 4th, 2008)
|
@@ -115,4 +118,4 @@ This is not a public release.
|
|
115
118
|
* Marker transformers: currency, percentages.
|
116
119
|
* Basic Graphs: Area, Bar, Line.
|
117
120
|
* Advanced Graphs: Average, AllSmiles.
|
118
|
-
* Initial documentation.
|
121
|
+
* Initial documentation.
|
data/README.txt
CHANGED
@@ -1,17 +1,37 @@
|
|
1
|
-
= scruffy
|
1
|
+
= scruffy, unofficial release
|
2
|
+
|
3
|
+
This is a fork from based on the official 0.2.5 release. See below for
|
4
|
+
further a longer description.
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
2
7
|
|
3
8
|
* scruffy.rubyforge.org
|
4
9
|
|
5
10
|
Author:: Brasten Sager (brasten@nagilum.com)
|
6
11
|
Date:: July 8, 2008
|
7
|
-
|
8
|
-
== DESCRIPTION:
|
12
|
+
Release:: 0.2.5
|
9
13
|
|
10
14
|
Scruffy is a Ruby library for generating high quality, good looking graphs. It is designed
|
11
15
|
to be easy to use and highly customizable.
|
12
16
|
|
13
17
|
For basic usage instructions, refer to the documentation for Scruffy::Graph.
|
14
18
|
|
19
|
+
|
20
|
+
== FORK DESCRIPTION
|
21
|
+
|
22
|
+
* http://github.com/delano/scruffy/
|
23
|
+
|
24
|
+
Author:: Delano Mandelbaum (delano@solutious.com)
|
25
|
+
Author:: Kalin Harvey
|
26
|
+
Date:: December 12, 2008
|
27
|
+
|
28
|
+
We love scruffy. Our motivation for creating a forking is to make it useful for hi-resolution
|
29
|
+
graphs and charts. We would love to get our changes in to the official release but until
|
30
|
+
that time they will be available at the GitHub URI above.
|
31
|
+
|
32
|
+
CHANGES.txt contains everything we've been up to.
|
33
|
+
|
34
|
+
|
15
35
|
== FEATURES
|
16
36
|
|
17
37
|
* Renders to SVG or bitmap (PNG, JPG)
|
@@ -40,27 +60,7 @@ For basic usage instructions, refer to the documentation for Scruffy::Graph.
|
|
40
60
|
|
41
61
|
* sudo gem install scruffy
|
42
62
|
|
43
|
-
== LICENSE:
|
44
|
-
|
45
|
-
(The MIT License)
|
46
|
-
|
47
|
-
Copyright (c) 2008 Brasten Sager (brasten@nagilum.com)
|
48
63
|
|
49
|
-
|
50
|
-
a copy of this software and associated documentation files (the
|
51
|
-
'Software'), to deal in the Software without restriction, including
|
52
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
53
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
54
|
-
permit persons to whom the Software is furnished to do so, subject to
|
55
|
-
the following conditions:
|
56
|
-
|
57
|
-
The above copyright notice and this permission notice shall be
|
58
|
-
included in all copies or substantial portions of the Software.
|
64
|
+
== LICENSE:
|
59
65
|
|
60
|
-
|
61
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
62
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
63
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
64
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
65
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
66
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
66
|
+
See Licence.txt
|
data/lib/scruffy.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
-
|
4
1
|
# ===Scruffy Graphing Library for Ruby
|
5
2
|
#
|
6
3
|
# Author:: Brasten Sager
|
@@ -14,8 +11,6 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
14
11
|
module Scruffy
|
15
12
|
end
|
16
13
|
|
17
|
-
require 'rubygems'
|
18
|
-
gem 'builder', '>= 2.0'
|
19
14
|
require 'builder'
|
20
15
|
|
21
16
|
require 'scruffy/helpers'
|
data/lib/scruffy/components.rb
CHANGED
@@ -13,6 +13,7 @@ require 'scruffy/components/title'
|
|
13
13
|
require 'scruffy/components/background'
|
14
14
|
require 'scruffy/components/graphs'
|
15
15
|
require 'scruffy/components/grid'
|
16
|
+
require 'scruffy/components/axes'
|
16
17
|
require 'scruffy/components/value_markers'
|
17
18
|
require 'scruffy/components/data_markers'
|
18
19
|
require 'scruffy/components/legend'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Scruffy
|
2
|
+
module Components
|
3
|
+
class Axes < Base
|
4
|
+
include Scruffy::Helpers::Marker
|
5
|
+
|
6
|
+
def draw(svg, bounds, options={})
|
7
|
+
stroke_width = options[:stroke_width]
|
8
|
+
|
9
|
+
colour = options[:theme].grid || options[:theme].marker
|
10
|
+
unless options[:show_x] == false
|
11
|
+
y = (options[:max_value] * bounds[:height])/(options[:max_value] - options[:min_value])
|
12
|
+
svg.line(:x1 => 0, :y1 => y, :x2 => bounds[:width], :y2 => y, :style => "stroke: #{colour.to_s}; stroke-width: #{stroke_width};")
|
13
|
+
end
|
14
|
+
|
15
|
+
unless options[:show_y] == false
|
16
|
+
x = -0.5
|
17
|
+
svg.line(:x1 => x, :y1 => 0, :x2 => x, :y2 => bounds[:height], :style => "stroke: #{colour.to_s}; stroke-width: #{stroke_width};")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -2,12 +2,12 @@ module Scruffy
|
|
2
2
|
module Components
|
3
3
|
class Background < Base
|
4
4
|
def draw(svg, bounds, options={})
|
5
|
-
fill =
|
5
|
+
fill = nil
|
6
6
|
case options[:theme].background
|
7
7
|
when Symbol, String
|
8
8
|
fill = options[:theme].background.to_s
|
9
9
|
when Array
|
10
|
-
fill = "url(#BackgroundGradient)"
|
10
|
+
fill = "url(#BackgroundGradient) #{options[:theme].background[0]}" # the second part is a fallback for Firefox, which does support gradient fills, but unfortunately can't handle url(#fragment) references for SVGs loaded from a data: URI (whereas it does work ok for external images); if we don't specify a solid fallback color it fills black!
|
11
11
|
svg.defs {
|
12
12
|
svg.linearGradient(:id=>'BackgroundGradient', :x1 => '0%', :y1 => '0%', :x2 => '0%', :y2 => '100%') {
|
13
13
|
svg.stop(:offset => '5%', 'stop-color' => options[:theme].background[0])
|
@@ -15,7 +15,7 @@ module Scruffy
|
|
15
15
|
}
|
16
16
|
}
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
# Render background (maybe)
|
20
20
|
svg.rect(:width => bounds[:width], :height => bounds[:height], :x => "0", :y => "0", :fill => fill) unless fill.nil?
|
21
21
|
end
|
@@ -13,11 +13,14 @@ module Scruffy
|
|
13
13
|
attr_accessor :options
|
14
14
|
attr_accessor :visible
|
15
15
|
|
16
|
+
# Options:
|
17
|
+
# stroke_width:: numeric value for width of line (0.1 - 10, default: 1)
|
16
18
|
def initialize(id, options = {})
|
17
19
|
@id = id.to_sym
|
18
20
|
@position = options[:position] || [0, 0]
|
19
21
|
@size = options[:size] || [100, 100]
|
20
22
|
@visible = options[:visible] || true
|
23
|
+
|
21
24
|
@options = options
|
22
25
|
end
|
23
26
|
|
@@ -2,18 +2,33 @@ module Scruffy
|
|
2
2
|
module Components
|
3
3
|
|
4
4
|
class DataMarkers < Base
|
5
|
-
|
5
|
+
|
6
|
+
include Scruffy::Helpers::Marker
|
7
|
+
|
8
|
+
attr_accessor :markers
|
9
|
+
|
6
10
|
def draw(svg, bounds, options={})
|
11
|
+
if options[:calculate_markers] && (options[:point_markers].nil? || options[:point_markers].empty?)
|
12
|
+
markers = (options[:markers] || self.markers) || 5
|
13
|
+
options[:point_markers] = []
|
14
|
+
each_marker(markers, options[:min_key], options[:max_key], bounds[:width], options, :key_formatter) do |label, x|
|
15
|
+
options[:point_markers] << [x, label]
|
16
|
+
end
|
17
|
+
end
|
7
18
|
unless options[:point_markers].nil?
|
8
|
-
|
9
|
-
|
19
|
+
dx = bounds[:width].to_f / (options[:max_key] - options[:min_key] + 1)
|
10
20
|
(0...options[:point_markers].size).map do |idx|
|
11
|
-
x_coord =
|
12
|
-
|
13
|
-
:
|
14
|
-
|
15
|
-
|
21
|
+
x_coord = dx * (options[:point_markers][idx].first - options[:min_key]) + dx/2
|
22
|
+
if options[:point_markers_ticks]
|
23
|
+
svg.line(:x1 => x_coord, :y1 => 0, :x2 => x_coord, :y2 => -3, :style => "stroke:#{(options[:theme].marker || 'white').to_s}; stroke-width:1")
|
24
|
+
end
|
25
|
+
|
26
|
+
svg.text(options[:point_markers][idx].last,
|
27
|
+
:x => 0,
|
28
|
+
:y => 0,
|
29
|
+
'font-size' => options[:theme].marker_font_size || relative(90),
|
16
30
|
'font-family' => options[:theme].font_family,
|
31
|
+
:transform => "translate(#{x_coord},#{bounds[:height]}) rotate(#{options[:point_markers_rotation] || 0})",
|
17
32
|
:fill => (options[:theme].marker || 'white').to_s,
|
18
33
|
'text-anchor' => 'middle') unless options[:point_markers][idx].nil?
|
19
34
|
end
|
@@ -26,9 +26,13 @@ module Scruffy
|
|
26
26
|
layer_options[:index] = idx
|
27
27
|
layer_options[:min_value] = options[:min_value]
|
28
28
|
layer_options[:max_value] = options[:max_value]
|
29
|
+
layer_options[:min_key] = options[:min_key]
|
30
|
+
layer_options[:max_key] = options[:max_key]
|
29
31
|
layer_options[:complexity] = options[:complexity]
|
30
32
|
layer_options[:size] = [bounds[:width], bounds[:height]]
|
31
33
|
layer_options[:color] = layer.preferred_color || layer.color || options[:theme].next_color
|
34
|
+
layer_options[:border] = options[:border]
|
35
|
+
layer_options[:outline] = layer.preferred_outline || layer.outline || options[:theme].next_outline
|
32
36
|
layer_options[:opacity] = opacity_for(idx)
|
33
37
|
layer_options[:theme] = options[:theme]
|
34
38
|
|
@@ -3,14 +3,55 @@ module Scruffy
|
|
3
3
|
class Grid < Base
|
4
4
|
attr_accessor :markers
|
5
5
|
|
6
|
+
include Scruffy::Helpers::Marker
|
7
|
+
|
6
8
|
def draw(svg, bounds, options={})
|
7
9
|
markers = (options[:markers] || self.markers) || 5
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
stroke_width = options[:stroke_width]
|
12
|
+
|
13
|
+
colour = options[:theme].grid || options[:theme].marker
|
14
|
+
|
15
|
+
each_marker(markers, options[:min_value], options[:max_value], bounds[:height], options, :value_formatter) do |label, y|
|
16
|
+
svg.line(:x1 => 0, :y1 => y, :x2 => bounds[:width], :y2 => y, :style => "stroke: #{colour.to_s}; stroke-width: #{stroke_width};")
|
17
|
+
end
|
18
|
+
|
19
|
+
#add a 0 line
|
20
|
+
y = (options[:max_value] * bounds[:height])/(options[:max_value] - options[:min_value])
|
21
|
+
svg.line(:x1 => 0, :y1 => y, :x2 => bounds[:width], :y2 => y, :style => "stroke: #{colour.to_s}; stroke-width: #{stroke_width};")
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class VGrid < Base
|
27
|
+
attr_accessor :markers
|
28
|
+
|
29
|
+
include Scruffy::Helpers::Marker
|
30
|
+
|
31
|
+
def draw(svg, bounds, options={})
|
32
|
+
colour = options[:theme].grid || options[:theme].marker
|
33
|
+
|
34
|
+
if options[:graph].point_markers #get vertical grid lines up with points if there are labels for them
|
35
|
+
point_distance = bounds[:width] / (options[:graph].point_markers.size).to_f
|
36
|
+
stroke_width = options[:stroke_width]
|
37
|
+
(0...options[:graph].point_markers.size).map do |idx|
|
38
|
+
x = point_distance * idx + point_distance/2
|
39
|
+
svg.line(:x1 => x, :y1 => 0, :x2 => x, :y2 => bounds[:height], :style => "stroke: #{colour.to_s}; stroke-width: #{stroke_width};")
|
40
|
+
end
|
41
|
+
#add the far right and far left lines
|
42
|
+
svg.line(:x1 => 0, :y1 => 0, :x2 => 0, :y2 => bounds[:height], :style => "stroke: #{colour.to_s}; stroke-width: #{stroke_width};")
|
43
|
+
svg.line(:x1 => bounds[:width], :y1 => 0, :x2 => bounds[:width], :y2 => bounds[:height], :style => "stroke: #{colour.to_s}; stroke-width: #{stroke_width};")
|
44
|
+
else
|
45
|
+
|
46
|
+
markers = (options[:key_markers] || self.markers) || 5 #options[:point_markers].size#
|
47
|
+
stroke_width = options[:stroke_width]
|
48
|
+
each_marker(markers, options[:min_key], options[:max_key], bounds[:width], options, :key_formatter) do |label, x|
|
49
|
+
svg.line(:x1 => x, :y1 => 0, :x2 => x, :y2 => bounds[:height], :style => "stroke: #{colour.to_s}; stroke-width: #{stroke_width};")
|
50
|
+
end
|
51
|
+
|
12
52
|
end
|
13
53
|
end
|
14
54
|
end
|
15
55
|
end
|
16
|
-
end
|
56
|
+
end
|
57
|
+
|
@@ -1,5 +1,47 @@
|
|
1
1
|
module Scruffy::Components
|
2
|
-
|
2
|
+
|
3
|
+
class XLegend < Base
|
4
|
+
def draw(svg, bounds, options={})
|
5
|
+
if options[:title]
|
6
|
+
svg.text(options[:x_legend],
|
7
|
+
:class => 'title',
|
8
|
+
:x => (bounds[:width] / 2),
|
9
|
+
:y => bounds[:height],
|
10
|
+
'font-size' => options[:theme].legend_font_size || relative(100),
|
11
|
+
'font-family' => options[:theme].font_family,
|
12
|
+
:fill => options[:theme].marker,
|
13
|
+
:stroke => 'none', 'stroke-width' => '0',
|
14
|
+
'text-anchor' => (@options[:text_anchor] || 'middle'))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end #XLegend
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
class YLegend < Base
|
22
|
+
def draw(svg, bounds, options={})
|
23
|
+
if options[:title]
|
24
|
+
svg.text(options[:y_legend],
|
25
|
+
:class => 'title',
|
26
|
+
:x => (0),
|
27
|
+
:y => 0,
|
28
|
+
'font-size' => options[:theme].legend_font_size || relative(100),
|
29
|
+
'font-family' => options[:theme].font_family,
|
30
|
+
:transform => "translate(#{bounds[:width] / 2},#{bounds[:height]/2}) rotate(#{-90})",
|
31
|
+
:fill => options[:theme].marker,
|
32
|
+
:stroke => 'none', 'stroke-width' => '0',
|
33
|
+
'text-anchor' => (@options[:text_anchor] || 'middle'))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end #YLegend
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
3
45
|
class Legend < Base
|
4
46
|
FONT_SIZE = 80
|
5
47
|
|
@@ -11,18 +53,18 @@ module Scruffy::Components
|
|
11
53
|
set_line_height = 0.08 * bounds[:height]
|
12
54
|
@line_height = bounds[:height] / legend_info.length
|
13
55
|
@line_height = set_line_height if @line_height >
|
14
|
-
|
56
|
+
set_line_height
|
15
57
|
else
|
16
58
|
set_line_height = 0.90 * bounds[:height]
|
17
59
|
@line_height = set_line_height
|
18
60
|
end
|
19
|
-
|
61
|
+
|
20
62
|
text_height = @line_height * FONT_SIZE / 100
|
21
63
|
# #TODO how does this related to @points?
|
22
64
|
active_width, points = layout(legend_info, vertical)
|
23
|
-
|
65
|
+
|
24
66
|
offset = (bounds[:width] - active_width) / 2 # Nudge over a bit for true centering
|
25
|
-
|
67
|
+
|
26
68
|
# Render Legend
|
27
69
|
points.each_with_index do |point, idx|
|
28
70
|
if vertical
|
@@ -38,18 +80,18 @@ module Scruffy::Components
|
|
38
80
|
# "#{x} #{y} #{@line_height} #{size}"
|
39
81
|
|
40
82
|
svg.rect(:x => x,
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
83
|
+
:y => y,
|
84
|
+
:width => size,
|
85
|
+
:height => size,
|
86
|
+
:fill => legend_info[idx][:color])
|
87
|
+
|
46
88
|
svg.text(legend_info[idx][:title],
|
47
|
-
|
48
|
-
|
89
|
+
:x => x + @line_height,
|
90
|
+
:y => y + text_height * 0.75,
|
49
91
|
'font-size' => text_height,
|
50
92
|
'font-family' => options[:theme].font_family,
|
51
|
-
|
52
|
-
|
93
|
+
:style => "color: #{options[:theme].marker || 'white'}",
|
94
|
+
:fill => (options[:theme].marker || 'white'))
|
53
95
|
end
|
54
96
|
end # draw
|
55
97
|
|
@@ -60,9 +102,9 @@ module Scruffy::Components
|
|
60
102
|
def relevant_legend_info(layers, categories=(@options[:category] ? [@options[:category]] : @options[:categories]))
|
61
103
|
legend_info = layers.inject([]) do |arr, layer|
|
62
104
|
if categories.nil? ||
|
63
|
-
|
64
|
-
|
65
|
-
|
105
|
+
(categories.include?(layer.options[:category]) ||
|
106
|
+
(layer.options[:categories] && (categories & layer.options[:categories]).size > 0) )
|
107
|
+
|
66
108
|
data = layer.legend_data
|
67
109
|
arr << data if data.is_a?(Hash)
|
68
110
|
arr = arr + data if data.is_a?(Array)
|
@@ -70,7 +112,7 @@ module Scruffy::Components
|
|
70
112
|
arr
|
71
113
|
end
|
72
114
|
end # relevant_legend_info
|
73
|
-
|
115
|
+
|
74
116
|
# Returns an array consisting of the total width needed by the legend
|
75
117
|
# information, as well as an array of @x-coords for each element. If
|
76
118
|
# vertical, then these are @y-coords, and @x is 0
|
@@ -84,7 +126,7 @@ module Scruffy::Components
|
|
84
126
|
longest = longest < cur_length ? cur_length : longest
|
85
127
|
}
|
86
128
|
y_positions = []
|
87
|
-
|
129
|
+
(0..legend_info_array.length - 1).each {|y|
|
88
130
|
y_positions << y * @line_height
|
89
131
|
}
|
90
132
|
[longest, y_positions]
|
@@ -94,12 +136,12 @@ module Scruffy::Components
|
|
94
136
|
enum[1] << enum.first # Add location to points
|
95
137
|
enum[0] += relative(50) # Add room for color box
|
96
138
|
enum[0] += (relative(50) * elem[:title].length) # Add room for text
|
97
|
-
|
139
|
+
|
98
140
|
[enum.first, enum.last]
|
99
141
|
end
|
100
142
|
end
|
101
143
|
end
|
102
|
-
|
144
|
+
|
103
145
|
end # class Legend
|
104
146
|
|
105
147
|
end # Scruffy::Components
|