tlconnor-scruffy 0.2.17
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +115 -0
- data/LICENCE.txt +20 -0
- data/Manifest.txt +74 -0
- data/README.txt +66 -0
- data/lib/scruffy.rb +30 -0
- data/lib/scruffy/components.rb +22 -0
- data/lib/scruffy/components/axes.rb +23 -0
- data/lib/scruffy/components/background.rb +24 -0
- data/lib/scruffy/components/base.rb +57 -0
- data/lib/scruffy/components/data_markers.rb +41 -0
- data/lib/scruffy/components/graphs.rb +52 -0
- data/lib/scruffy/components/grid.rb +57 -0
- data/lib/scruffy/components/label.rb +17 -0
- data/lib/scruffy/components/legend.rb +147 -0
- data/lib/scruffy/components/style_info.rb +22 -0
- data/lib/scruffy/components/title.rb +19 -0
- data/lib/scruffy/components/value_markers.rb +25 -0
- data/lib/scruffy/components/viewport.rb +37 -0
- data/lib/scruffy/formatters.rb +233 -0
- data/lib/scruffy/graph.rb +205 -0
- data/lib/scruffy/graph_state.rb +29 -0
- data/lib/scruffy/helpers.rb +13 -0
- data/lib/scruffy/helpers/canvas.rb +41 -0
- data/lib/scruffy/helpers/layer_container.rb +119 -0
- data/lib/scruffy/helpers/marker_helper.rb +25 -0
- data/lib/scruffy/helpers/meta.rb +5 -0
- data/lib/scruffy/helpers/point_container.rb +99 -0
- data/lib/scruffy/layers.rb +28 -0
- data/lib/scruffy/layers/all_smiles.rb +137 -0
- data/lib/scruffy/layers/area.rb +46 -0
- data/lib/scruffy/layers/average.rb +67 -0
- data/lib/scruffy/layers/bar.rb +73 -0
- data/lib/scruffy/layers/base.rb +211 -0
- data/lib/scruffy/layers/box.rb +114 -0
- data/lib/scruffy/layers/line.rb +46 -0
- data/lib/scruffy/layers/multi.rb +74 -0
- data/lib/scruffy/layers/multi_bar.rb +51 -0
- data/lib/scruffy/layers/pie.rb +123 -0
- data/lib/scruffy/layers/pie_slice.rb +119 -0
- data/lib/scruffy/layers/scatter.rb +29 -0
- data/lib/scruffy/layers/sparkline_bar.rb +39 -0
- data/lib/scruffy/layers/stacked.rb +87 -0
- data/lib/scruffy/rasterizers.rb +14 -0
- data/lib/scruffy/rasterizers/batik_rasterizer.rb +39 -0
- data/lib/scruffy/rasterizers/mini_magick_rasterizer.rb +24 -0
- data/lib/scruffy/rasterizers/rmagick_rasterizer.rb +27 -0
- data/lib/scruffy/renderers.rb +23 -0
- data/lib/scruffy/renderers/axis_legend.rb +41 -0
- data/lib/scruffy/renderers/base.rb +95 -0
- data/lib/scruffy/renderers/cubed.rb +44 -0
- data/lib/scruffy/renderers/cubed3d.rb +53 -0
- data/lib/scruffy/renderers/empty.rb +22 -0
- data/lib/scruffy/renderers/pie.rb +20 -0
- data/lib/scruffy/renderers/reversed.rb +17 -0
- data/lib/scruffy/renderers/sparkline.rb +10 -0
- data/lib/scruffy/renderers/split.rb +48 -0
- data/lib/scruffy/renderers/standard.rb +37 -0
- data/lib/scruffy/themes.rb +177 -0
- data/lib/scruffy/version.rb +9 -0
- data/test/graph_creation_test.rb +286 -0
- data/test/test_helper.rb +2 -0
- metadata +150 -0
data/CHANGES.txt
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
= Scruffy Changelog
|
2
|
+
|
3
|
+
== Version 0.2.6
|
4
|
+
(December 12th, 2008)
|
5
|
+
* Forked from the official 0.2.5 release (http://github.com/delano/scruffy/)
|
6
|
+
* Added stroke_width and style attributes to Line
|
7
|
+
* Added toggleable shadow and dots attributes to Line
|
8
|
+
* Changed the default Line to not include shadow or dots and to have a width of 1 pixel.
|
9
|
+
* Added stroke_width for Component::Graph. Default is now 1.
|
10
|
+
* Changed the default theme to one appropriate for hi-res charts
|
11
|
+
* Removed website from release
|
12
|
+
|
13
|
+
== Version 0.2.3
|
14
|
+
(July 4th, 2008)
|
15
|
+
* Got pie charts working
|
16
|
+
* Added rough capability for legend to run vertically (better for Pie chart)
|
17
|
+
* Added some checks in the Pie initializer so that you simply pass a Hash of
|
18
|
+
name => values, instead of adding PieSlices in a block.
|
19
|
+
* Added a simplistic unit test that outputs a pie and line chart in PNG & SVG.
|
20
|
+
* Quite a lot of hard-wired values in here. Whole thing needs a spring clean.
|
21
|
+
|
22
|
+
== Version 0.2.2
|
23
|
+
(August 19th, 2006)
|
24
|
+
|
25
|
+
* Removed all font-family and text-rendering attributes from elements.
|
26
|
+
- These were causing issues with Batik and Adobe Viewer. Horrible font problems.
|
27
|
+
* Added require 'builder' to renderers/base.rb
|
28
|
+
* Added minor shadows to most graph types. Adds some depth perception.
|
29
|
+
* Added graph.layout as an alias of renderer. (graph.layout looks nicer).
|
30
|
+
* Added markers, values, grid options.
|
31
|
+
|
32
|
+
== Version 0.2.1
|
33
|
+
(August 18th, 2006)
|
34
|
+
|
35
|
+
* Mostly documentation.
|
36
|
+
* Added Builder 2.0 dependency to gem spec.
|
37
|
+
* Removed minimum size hack in RMagickRasterizer, for now.
|
38
|
+
|
39
|
+
|
40
|
+
== Version 0.2.0
|
41
|
+
(August 14th, 2006)
|
42
|
+
|
43
|
+
- Lots of changes, hold on tight:
|
44
|
+
|
45
|
+
* Redesigned rendering system to a component-based design.
|
46
|
+
All objects on the canvas are components that can be re-arranged via renderers.
|
47
|
+
* Created default renderer for basic Gruff-like layout.
|
48
|
+
* Added Reversed and Cubed renderers to demonstrate the customization abilities (plus, they're cool).
|
49
|
+
* Added Split renderer.
|
50
|
+
* Created Viewport component to help with Cubed.
|
51
|
+
- Viewport lets you scale it's inner components and move around the
|
52
|
+
graph. Its components' sizes and positions are relative to the viewport,
|
53
|
+
not the graph.
|
54
|
+
* Set title to respect marker color if available.
|
55
|
+
* Respects :to option in Graph#render for SVG output to file.
|
56
|
+
* Stacked layer type -- accepts layers which it then uses to create a stacked graph. Such as Bar graphs
|
57
|
+
and Area graphs.
|
58
|
+
* Abstracted out layer_container functionality to helper module (for stacked graph)
|
59
|
+
* Renamed value_transformers to value_formatters.
|
60
|
+
* Refined Value Formatters.
|
61
|
+
- Created default: Number.
|
62
|
+
- Respects float precision
|
63
|
+
- Allows for "auto-precision", which will use the largest precision (up to a customizable limit)
|
64
|
+
necessary to portray the values correctly. ie: 5.1, 6.32, 7.142 becomes '5.100', '6.320', '7.142'
|
65
|
+
* Modified Legend component, Layers, and Graph component to respect categories.
|
66
|
+
- ie: Creating a Bar layer with :category => :sales and a Graph with :category => :qa will result in
|
67
|
+
the Bay layer not being displayed. Allows for more than one Graph viewport on a screen with different
|
68
|
+
layers.
|
69
|
+
* Improved rasterizing at smaller sizes( < 300px) by rasterizing the image at a larger size first, then
|
70
|
+
allowing RMagick to resize the image with specific filtering/blurring. Actually looks better than just
|
71
|
+
rasterizing the SVG at the small size from the beginning.
|
72
|
+
* Fixed Opacity on stacked graphs.
|
73
|
+
* Added Style (invisible) components to allow for CSS styling. (Not recommended, however.)
|
74
|
+
* Added Label component for arbitrary text.
|
75
|
+
* Created Theme object in place of theme hash.
|
76
|
+
|
77
|
+
== Version 0.1.0
|
78
|
+
(August 11th, 2006)
|
79
|
+
|
80
|
+
* First public release!
|
81
|
+
* Legend rendering
|
82
|
+
* Rasterizing graph to multiple image types (graph.render :as => 'PNG')
|
83
|
+
|
84
|
+
== Version 0.0.12
|
85
|
+
(August 10th, 2006)
|
86
|
+
This is not a public release.
|
87
|
+
|
88
|
+
* Rearranged Layers into a better class/module arrangement.
|
89
|
+
|
90
|
+
== Version 0.0.11
|
91
|
+
(August 10th, 2006)
|
92
|
+
This is not a public release.
|
93
|
+
|
94
|
+
* Fixed gem issue.
|
95
|
+
|
96
|
+
== Version 0.0.10
|
97
|
+
(August 10th, 2006)
|
98
|
+
|
99
|
+
This is not a public release.
|
100
|
+
|
101
|
+
|
102
|
+
* Removed bogus changelog.
|
103
|
+
|
104
|
+
|
105
|
+
== Version 0.0.9
|
106
|
+
(August 10th, 2006)
|
107
|
+
|
108
|
+
This is not a public release.
|
109
|
+
|
110
|
+
* Initial release.
|
111
|
+
* Standard renderer.
|
112
|
+
* Marker transformers: currency, percentages.
|
113
|
+
* Basic Graphs: Area, Bar, Line.
|
114
|
+
* Advanced Graphs: Average, AllSmiles.
|
115
|
+
* Initial documentation.
|
data/LICENCE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006 Brasten Sager (brasten@nagilum.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
CHANGES.txt
|
2
|
+
LICENCE.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/scruffy.rb
|
9
|
+
lib/scruffy/components.rb
|
10
|
+
lib/scruffy/components/background.rb
|
11
|
+
lib/scruffy/components/base.rb
|
12
|
+
lib/scruffy/components/data_markers.rb
|
13
|
+
lib/scruffy/components/graphs.rb
|
14
|
+
lib/scruffy/components/grid.rb
|
15
|
+
lib/scruffy/components/label.rb
|
16
|
+
lib/scruffy/components/legend.rb
|
17
|
+
lib/scruffy/components/style_info.rb
|
18
|
+
lib/scruffy/components/title.rb
|
19
|
+
lib/scruffy/components/value_markers.rb
|
20
|
+
lib/scruffy/components/viewport.rb
|
21
|
+
lib/scruffy/formatters.rb
|
22
|
+
lib/scruffy/graph.rb
|
23
|
+
lib/scruffy/graph_state.rb
|
24
|
+
lib/scruffy/helpers.rb
|
25
|
+
lib/scruffy/helpers/canvas.rb
|
26
|
+
lib/scruffy/helpers/layer_container.rb
|
27
|
+
lib/scruffy/helpers/marker_helper.rb
|
28
|
+
lib/scruffy/helpers/meta.rb
|
29
|
+
lib/scruffy/helpers/point_container.rb
|
30
|
+
lib/scruffy/layers.rb
|
31
|
+
lib/scruffy/layers/all_smiles.rb
|
32
|
+
lib/scruffy/layers/area.rb
|
33
|
+
lib/scruffy/layers/average.rb
|
34
|
+
lib/scruffy/layers/bar.rb
|
35
|
+
lib/scruffy/layers/box.rb
|
36
|
+
lib/scruffy/layers/base.rb
|
37
|
+
lib/scruffy/layers/line.rb
|
38
|
+
lib/scruffy/layers/multi.rb
|
39
|
+
lib/scruffy/layers/multi_bar.rb
|
40
|
+
lib/scruffy/layers/pie.rb
|
41
|
+
lib/scruffy/layers/pie_slice.rb
|
42
|
+
lib/scruffy/layers/scatter.rb
|
43
|
+
lib/scruffy/layers/sparkline_bar.rb
|
44
|
+
lib/scruffy/layers/stacked.rb
|
45
|
+
lib/scruffy/rasterizers.rb
|
46
|
+
lib/scruffy/rasterizers/batik_rasterizer.rb
|
47
|
+
lib/scruffy/rasterizers/rmagick_rasterizer.rb
|
48
|
+
lib/scruffy/renderers.rb
|
49
|
+
lib/scruffy/renderers/base.rb
|
50
|
+
lib/scruffy/renderers/cubed.rb
|
51
|
+
lib/scruffy/renderers/cubed3d.rb
|
52
|
+
lib/scruffy/renderers/empty.rb
|
53
|
+
lib/scruffy/renderers/pie.rb
|
54
|
+
lib/scruffy/renderers/reversed.rb
|
55
|
+
lib/scruffy/renderers/sparkline.rb
|
56
|
+
lib/scruffy/renderers/split.rb
|
57
|
+
lib/scruffy/renderers/standard.rb
|
58
|
+
lib/scruffy/renderers/axis_legend.rb
|
59
|
+
lib/scruffy/themes.rb
|
60
|
+
lib/scruffy/version.rb
|
61
|
+
script/console
|
62
|
+
script/destroy
|
63
|
+
script/generate
|
64
|
+
script/txt2html
|
65
|
+
setup.rb
|
66
|
+
spec/scruffy/graph_spec.rb
|
67
|
+
spec/scruffy/layers/base_spec.rb
|
68
|
+
spec/scruffy/layers/line_spec.rb
|
69
|
+
spec/spec_helper.rb
|
70
|
+
tasks/deployment.rake
|
71
|
+
tasks/environment.rake
|
72
|
+
tasks/website.rake
|
73
|
+
test/graph_creation_test.rb
|
74
|
+
test/test_helper.rb
|
data/README.txt
ADDED
@@ -0,0 +1,66 @@
|
|
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:
|
7
|
+
|
8
|
+
* scruffy.rubyforge.org
|
9
|
+
|
10
|
+
Author:: Brasten Sager (brasten@nagilum.com)
|
11
|
+
Date:: July 8, 2008
|
12
|
+
Release:: 0.2.5
|
13
|
+
|
14
|
+
Scruffy is a Ruby library for generating high quality, good looking graphs. It is designed
|
15
|
+
to be easy to use and highly customizable.
|
16
|
+
|
17
|
+
For basic usage instructions, refer to the documentation for Scruffy::Graph.
|
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
|
+
|
35
|
+
== FEATURES
|
36
|
+
|
37
|
+
* Renders to SVG or bitmap (PNG, JPG)
|
38
|
+
|
39
|
+
== PROBLEMS:
|
40
|
+
|
41
|
+
* 0.2.3 version has missing legend text when rendering to bitmap. This is strange because the text is there in the SVG before it goes to RMagick.
|
42
|
+
|
43
|
+
== SYNOPSIS:
|
44
|
+
|
45
|
+
graph = Scruffy::Graph.new
|
46
|
+
graph.title = "Sample Line Graph"
|
47
|
+
graph.renderer = Scruffy::Renderers::Standard.new
|
48
|
+
|
49
|
+
graph.add :line, 'Example', [20, 100, 70, 30, 106]
|
50
|
+
|
51
|
+
graph.render :to => "line_test.svg"
|
52
|
+
graph.render :width => 300, :height => 200,
|
53
|
+
:to => "line_test.png", :as => 'png'
|
54
|
+
|
55
|
+
== REQUIREMENTS:
|
56
|
+
|
57
|
+
* Needs RMagick and Magic installed, if you wish to render to bitmap.
|
58
|
+
|
59
|
+
== INSTALL:
|
60
|
+
|
61
|
+
* sudo gem install scruffy
|
62
|
+
|
63
|
+
|
64
|
+
== LICENSE:
|
65
|
+
|
66
|
+
See Licence.txt
|
data/lib/scruffy.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
# ===Scruffy Graphing Library for Ruby
|
5
|
+
#
|
6
|
+
# Author:: Brasten Sager
|
7
|
+
# Date:: August 5th, 2006
|
8
|
+
#
|
9
|
+
# For information on generating graphs using Scruffy, see the
|
10
|
+
# documentation in Scruffy::Graph.
|
11
|
+
#
|
12
|
+
# For information on creating your own graph types, see the
|
13
|
+
# documentation in Scruffy::Layers::Base.
|
14
|
+
module Scruffy
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
gem 'builder', '>= 2.0'
|
19
|
+
require 'builder'
|
20
|
+
|
21
|
+
require 'scruffy/helpers'
|
22
|
+
require 'scruffy/graph_state'
|
23
|
+
require 'scruffy/graph'
|
24
|
+
require 'scruffy/themes'
|
25
|
+
require 'scruffy/version'
|
26
|
+
require 'scruffy/formatters'
|
27
|
+
require 'scruffy/rasterizers'
|
28
|
+
require 'scruffy/layers'
|
29
|
+
require 'scruffy/components'
|
30
|
+
require 'scruffy/renderers'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# ===Scruffy Components
|
2
|
+
#
|
3
|
+
# Author:: Brasten Sager
|
4
|
+
# Date:: August 16th, 2006
|
5
|
+
#
|
6
|
+
# Components make up the visual elements of a Scruffy graph.
|
7
|
+
#
|
8
|
+
# For examples, see Scruffy::Components::Base.
|
9
|
+
module Scruffy::Components; end
|
10
|
+
|
11
|
+
require 'scruffy/components/base'
|
12
|
+
require 'scruffy/components/title'
|
13
|
+
require 'scruffy/components/background'
|
14
|
+
require 'scruffy/components/graphs'
|
15
|
+
require 'scruffy/components/grid'
|
16
|
+
require 'scruffy/components/axes'
|
17
|
+
require 'scruffy/components/value_markers'
|
18
|
+
require 'scruffy/components/data_markers'
|
19
|
+
require 'scruffy/components/legend'
|
20
|
+
require 'scruffy/components/style_info'
|
21
|
+
require 'scruffy/components/viewport'
|
22
|
+
require 'scruffy/components/label'
|
@@ -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
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Scruffy
|
2
|
+
module Components
|
3
|
+
class Background < Base
|
4
|
+
def draw(svg, bounds, options={})
|
5
|
+
fill = nil
|
6
|
+
case options[:theme].background
|
7
|
+
when Symbol, String
|
8
|
+
fill = options[:theme].background.to_s
|
9
|
+
when Array
|
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
|
+
svg.defs {
|
12
|
+
svg.linearGradient(:id=>'BackgroundGradient', :x1 => '0%', :y1 => '0%', :x2 => '0%', :y2 => '100%') {
|
13
|
+
svg.stop(:offset => '5%', 'stop-color' => options[:theme].background[0])
|
14
|
+
svg.stop(:offset => '95%', 'stop-color' => options[:theme].background[1])
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Render background (maybe)
|
20
|
+
svg.rect(:width => bounds[:width], :height => bounds[:height], :x => "0", :y => "0", :fill => fill) unless fill.nil?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Scruffy
|
2
|
+
module Components
|
3
|
+
# ===Scruffy::Components::Base
|
4
|
+
#
|
5
|
+
# Common attributes for all components, and a standard render method
|
6
|
+
# that calls draw after setting up the drawing transformations.
|
7
|
+
class Base
|
8
|
+
attr_reader :id
|
9
|
+
|
10
|
+
# In terms of percentages: [10, 10] == 10% by 10%
|
11
|
+
attr_accessor :position
|
12
|
+
attr_accessor :size
|
13
|
+
attr_accessor :options
|
14
|
+
attr_accessor :visible
|
15
|
+
|
16
|
+
# Options:
|
17
|
+
# stroke_width:: numeric value for width of line (0.1 - 10, default: 1)
|
18
|
+
def initialize(id, options = {})
|
19
|
+
@id = id.to_sym
|
20
|
+
@position = options[:position] || [0, 0]
|
21
|
+
@size = options[:size] || [100, 100]
|
22
|
+
@visible = options[:visible] || true
|
23
|
+
|
24
|
+
@options = options
|
25
|
+
end
|
26
|
+
|
27
|
+
def render(svg, bounds, options={})
|
28
|
+
if @visible
|
29
|
+
unless bounds.nil?
|
30
|
+
@render_height = bounds[:height]
|
31
|
+
|
32
|
+
svg.g(:id => id.to_s,
|
33
|
+
:transform => "translate(#{bounds.delete(:x)}, #{bounds.delete(:y)})") {
|
34
|
+
|
35
|
+
draw(svg, bounds, options.merge(@options))
|
36
|
+
}
|
37
|
+
else
|
38
|
+
process(svg, options.merge(@options))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def draw(svg, bounds, options={})
|
44
|
+
# Override this if visual component
|
45
|
+
end
|
46
|
+
|
47
|
+
def process(svg, options={})
|
48
|
+
# Override this NOT a visual component
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
def relative(pct)
|
53
|
+
@render_height * ( pct / 100.to_f )
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Scruffy
|
2
|
+
module Components
|
3
|
+
|
4
|
+
class DataMarkers < Base
|
5
|
+
|
6
|
+
include Scruffy::Helpers::Marker
|
7
|
+
|
8
|
+
attr_accessor :markers
|
9
|
+
|
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
|
18
|
+
unless options[:point_markers].nil?
|
19
|
+
dx = bounds[:width].to_f / (options[:max_key] - options[:min_key] + 1)
|
20
|
+
(0...options[:point_markers].size).map do |idx|
|
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),
|
30
|
+
'font-family' => options[:theme].font_family,
|
31
|
+
:transform => "translate(#{x_coord},#{bounds[:height]}) rotate(#{options[:point_markers_rotation] || 0})",
|
32
|
+
:fill => (options[:theme].marker || 'white').to_s,
|
33
|
+
'text-anchor' => 'middle') unless options[:point_markers][idx].nil?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end # draw
|
37
|
+
|
38
|
+
end # class
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|