scruffy 0.0.10 → 0.0.11
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.
- data/CHANGES +11 -1
- data/Rakefile +0 -6
- data/lib/scruffy/graph.rb +24 -11
- data/lib/scruffy/version.rb +1 -1
- data/lib/scruffy.rb +1 -0
- data/spec/graph_spec.rb +74 -0
- metadata +2 -2
data/CHANGES
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
= Scruffy Changelog
|
2
2
|
|
3
|
+
Version 0.1.0 will be the first release for general use.
|
4
|
+
|
5
|
+
== Version 0.0.11
|
6
|
+
(August 10th, 2006)
|
7
|
+
This is not a public release.
|
8
|
+
|
9
|
+
* Fixed gem issue.
|
10
|
+
|
3
11
|
== Version 0.0.10
|
4
12
|
(August 10th, 2006)
|
5
13
|
|
6
14
|
This is not a public release.
|
7
|
-
|
15
|
+
|
8
16
|
|
9
17
|
* Removed bogus changelog.
|
10
18
|
|
@@ -12,6 +20,8 @@ Version 0.1.0 will be the first release for general use.
|
|
12
20
|
== Version 0.0.9
|
13
21
|
(August 10th, 2006)
|
14
22
|
|
23
|
+
This is not a public release.
|
24
|
+
|
15
25
|
* Initial release.
|
16
26
|
* Standard renderer.
|
17
27
|
* Marker transformers: currency, percentages.
|
data/Rakefile
CHANGED
@@ -60,13 +60,7 @@ spec = Gem::Specification.new do |s|
|
|
60
60
|
EOF
|
61
61
|
|
62
62
|
s.files = PKG_FILES.to_a
|
63
|
-
s.require_path = 'lib'
|
64
|
-
|
65
63
|
s.has_rdoc = true
|
66
|
-
|
67
|
-
#s.test_files = Dir.glob('test/*_test.rb')
|
68
|
-
s.require_path = 'lib'
|
69
|
-
s.autorequire = 'scruffy'
|
70
64
|
s.rubyforge_project = "scruffy"
|
71
65
|
end
|
72
66
|
|
data/lib/scruffy/graph.rb
CHANGED
@@ -78,9 +78,10 @@ module Scruffy
|
|
78
78
|
attr_accessor :layers
|
79
79
|
attr_accessor :default_type
|
80
80
|
attr_accessor :point_markers
|
81
|
-
attr_accessor :renderer
|
82
81
|
attr_accessor :marker_transformer
|
83
82
|
|
83
|
+
attr_reader :renderer # Writer defined below
|
84
|
+
|
84
85
|
# Returns a new Graph. You can optionally pass in a default graph type and an options hash.
|
85
86
|
#
|
86
87
|
# Graph.new # New graph
|
@@ -90,21 +91,27 @@ module Scruffy
|
|
90
91
|
# Options:
|
91
92
|
#
|
92
93
|
# title:: Graph's title
|
93
|
-
# theme::
|
94
|
+
# theme:: A theme hash to use when rendering graph
|
95
|
+
# layers:: An array of GraphLayers for this graph to use
|
96
|
+
# default_type:: A symbol indicating the default type of GraphLayer for this graph
|
94
97
|
# renderer:: Sets the renderer to use when rendering graph
|
95
98
|
# marker_transformer:: Sets a transformer used to modify marker values prior to rendering
|
96
99
|
# point_markers:: Sets the x-axis marker values
|
97
100
|
def initialize(*args)
|
98
|
-
|
99
|
-
options
|
101
|
+
self.default_type = args.shift if args.first.is_a?(Symbol)
|
102
|
+
options = args.shift.dup if args.first.is_a?(Hash)
|
103
|
+
raise ArgumentError, "The arguments provided are not supported." if args.size > 0
|
104
|
+
|
100
105
|
options ||= {}
|
106
|
+
self.theme = Scruffy::Theme::KEYNOTE
|
107
|
+
self.layers = []
|
108
|
+
self.renderer = Scruffy::StandardRenderer.new
|
109
|
+
|
110
|
+
%w(title theme layers default_type renderer marker_transformer point_markers).each do |arg|
|
111
|
+
self.send("#{arg}=".to_sym, options.delete(arg.to_sym)) unless options[arg.to_sym].nil?
|
112
|
+
end
|
101
113
|
|
102
|
-
|
103
|
-
@theme = options[:theme] || Scruffy::Theme::KEYNOTE
|
104
|
-
@layers = []
|
105
|
-
@renderer = options[:renderer] || Scruffy::StandardRenderer.new
|
106
|
-
@marker_transformer = options[:marker_transformer]
|
107
|
-
@point_markers = options[:point_markers]
|
114
|
+
raise ArgumentError, "Some options provided are not supported: #{options.keys.join(' ')}." if options.size > 0
|
108
115
|
end
|
109
116
|
|
110
117
|
# Renders the graph in it's current state to an SVG object.
|
@@ -122,7 +129,7 @@ module Scruffy
|
|
122
129
|
options[:marker_transformer] ||= @marker_transformer
|
123
130
|
options[:point_markers] ||= @point_markers
|
124
131
|
|
125
|
-
|
132
|
+
self.renderer.render( options.merge({:size => size, :title => title,
|
126
133
|
:layers => layers, :min_value => (options[:min_value] || bottom_value), :max_value => (options[:max_value] || top_value) } ) )
|
127
134
|
end
|
128
135
|
|
@@ -161,6 +168,12 @@ module Scruffy
|
|
161
168
|
|
162
169
|
alias :add :<<
|
163
170
|
|
171
|
+
def renderer=(val)
|
172
|
+
raise ArgumentError, "Renderer must include a #render(options) method." unless (val.respond_to?(:render) && val.method(:render).arity.abs > 0)
|
173
|
+
|
174
|
+
@renderer = val
|
175
|
+
end
|
176
|
+
|
164
177
|
protected
|
165
178
|
def to_camelcase(type) # :nodoc:
|
166
179
|
type.split('_').map { |e| e.capitalize }.join('')
|
data/lib/scruffy/version.rb
CHANGED
data/lib/scruffy.rb
CHANGED
data/spec/graph_spec.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
require 'lib/scruffy'
|
2
2
|
|
3
|
+
module CustomRenderers
|
4
|
+
def blank_renderer
|
5
|
+
object = Object.new
|
6
|
+
object.instance_eval { class << self;self;end }.instance_eval { define_method :render do |options|
|
7
|
+
puts "Rendering"
|
8
|
+
end
|
9
|
+
}
|
10
|
+
object
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
3
14
|
context "A new Scruffy::Graph" do
|
15
|
+
include CustomRenderers
|
16
|
+
|
4
17
|
setup do
|
5
18
|
@graph = Scruffy::Graph.new
|
6
19
|
end
|
@@ -53,4 +66,65 @@ context "A new Scruffy::Graph" do
|
|
53
66
|
@graph.point_markers = markers
|
54
67
|
@graph.point_markers.should_equal markers
|
55
68
|
end
|
69
|
+
|
70
|
+
specify "should accept a new renderer" do
|
71
|
+
renderer = blank_renderer
|
72
|
+
@graph.renderer = renderer
|
73
|
+
@graph.renderer.should_equal renderer
|
74
|
+
end
|
75
|
+
|
76
|
+
specify "should not accept renderers with missing #render methods" do
|
77
|
+
lambda { @graph.renderer = 1 }.should_raise ArgumentError
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "A Scruffy::Graph's initialization block" do
|
82
|
+
include CustomRenderers
|
83
|
+
|
84
|
+
specify "should accept just a default_type Symbol" do
|
85
|
+
lambda { Scruffy::Graph.new(:line) }.should_not_raise
|
86
|
+
end
|
87
|
+
|
88
|
+
specify "should accept just an options hash" do
|
89
|
+
lambda { Scruffy::Graph.new({:title => "My Title"}) }.should_not_raise
|
90
|
+
lambda { Scruffy::Graph.new(:title => "My Title", :theme => Scruffy::Theme::KEYNOTE) }.should_not_raise
|
91
|
+
end
|
92
|
+
|
93
|
+
specify "should accept both a default_type and options hash" do
|
94
|
+
lambda {
|
95
|
+
Scruffy::Graph.new(:line, {:title => "My Title"})
|
96
|
+
Scruffy::Graph.new(:line, :title => "My Title")
|
97
|
+
}.should_not_raise
|
98
|
+
end
|
99
|
+
|
100
|
+
specify "should reject any invalid argument combination" do
|
101
|
+
lambda { Scruffy::Graph.new({:title => "My Title"}, :line) }.should_raise ArgumentError
|
102
|
+
lambda { Scruffy::Graph.new(:line, {:title => "My Title"}, "Any additional arguments.") }.should_raise ArgumentError
|
103
|
+
lambda { Scruffy::Graph.new(:line, "Any additional arguments.") }.should_raise ArgumentError
|
104
|
+
end
|
105
|
+
|
106
|
+
specify "should reject any options that are not supported" do
|
107
|
+
lambda { Scruffy::Graph.new(:title => "My Title", :some_key => "Some Value") }.should_raise ArgumentError
|
108
|
+
end
|
109
|
+
|
110
|
+
specify "should successfully save all valid options" do
|
111
|
+
options = {:title => "My Title",
|
112
|
+
:theme => {:background => [:black],
|
113
|
+
:colors => [:red => 'red', :yellow => 'yellow']},
|
114
|
+
:layers => [ Scruffy::LineLayer.new(:points => [100, 200, 300]) ],
|
115
|
+
:default_type => :average,
|
116
|
+
:renderer => blank_renderer,
|
117
|
+
:marker_transformer => Scruffy::Transformer::Currency.new,
|
118
|
+
:point_markers => ['One Hundred', 'Two Hundred', 'Three Hundred']}
|
119
|
+
|
120
|
+
@graph = Scruffy::Graph.new(options)
|
121
|
+
|
122
|
+
@graph.title.should_equal options[:title]
|
123
|
+
@graph.theme.should_equal options[:theme]
|
124
|
+
@graph.layers.should_equal options[:layers]
|
125
|
+
@graph.default_type.should_equal options[:default_type]
|
126
|
+
@graph.renderer.should_equal options[:renderer]
|
127
|
+
@graph.marker_transformer.should_equal options[:marker_transformer]
|
128
|
+
@graph.point_markers.should_equal options[:point_markers]
|
129
|
+
end
|
56
130
|
end
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: scruffy
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
6
|
+
version: 0.0.11
|
7
7
|
date: 2006-08-10 00:00:00 -07:00
|
8
8
|
summary: A powerful, clean graphing library for Ruby.
|
9
9
|
require_paths:
|
@@ -12,7 +12,7 @@ email: brasten@nagilum.com
|
|
12
12
|
homepage: http://scruffy.rubyforge.org
|
13
13
|
rubyforge_project: scruffy
|
14
14
|
description: Scruffy is a Ruby library for generating powerful graphs. It is based on SVG, allowing for powerful, clean code, as well as a good foundation for future features.
|
15
|
-
autorequire:
|
15
|
+
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
18
18
|
has_rdoc: true
|