srawlins-scruffy 0.2.9

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.
Files changed (56) hide show
  1. data/CHANGES.txt +115 -0
  2. data/LICENCE.txt +20 -0
  3. data/Manifest.txt +74 -0
  4. data/README.txt +66 -0
  5. data/lib/scruffy.rb +30 -0
  6. data/lib/scruffy/components.rb +21 -0
  7. data/lib/scruffy/components/background.rb +24 -0
  8. data/lib/scruffy/components/base.rb +57 -0
  9. data/lib/scruffy/components/data_markers.rb +42 -0
  10. data/lib/scruffy/components/graphs.rb +51 -0
  11. data/lib/scruffy/components/grid.rb +54 -0
  12. data/lib/scruffy/components/label.rb +17 -0
  13. data/lib/scruffy/components/legend.rb +147 -0
  14. data/lib/scruffy/components/style_info.rb +22 -0
  15. data/lib/scruffy/components/title.rb +19 -0
  16. data/lib/scruffy/components/value_markers.rb +25 -0
  17. data/lib/scruffy/components/viewport.rb +37 -0
  18. data/lib/scruffy/formatters.rb +230 -0
  19. data/lib/scruffy/graph.rb +205 -0
  20. data/lib/scruffy/graph_state.rb +29 -0
  21. data/lib/scruffy/helpers.rb +13 -0
  22. data/lib/scruffy/helpers/canvas.rb +41 -0
  23. data/lib/scruffy/helpers/layer_container.rb +119 -0
  24. data/lib/scruffy/helpers/marker_helper.rb +25 -0
  25. data/lib/scruffy/helpers/meta.rb +5 -0
  26. data/lib/scruffy/helpers/point_container.rb +99 -0
  27. data/lib/scruffy/layers.rb +28 -0
  28. data/lib/scruffy/layers/all_smiles.rb +137 -0
  29. data/lib/scruffy/layers/area.rb +46 -0
  30. data/lib/scruffy/layers/average.rb +67 -0
  31. data/lib/scruffy/layers/bar.rb +68 -0
  32. data/lib/scruffy/layers/base.rb +211 -0
  33. data/lib/scruffy/layers/line.rb +46 -0
  34. data/lib/scruffy/layers/pie.rb +123 -0
  35. data/lib/scruffy/layers/pie_slice.rb +119 -0
  36. data/lib/scruffy/layers/scatter.rb +29 -0
  37. data/lib/scruffy/layers/sparkline_bar.rb +39 -0
  38. data/lib/scruffy/layers/stacked.rb +87 -0
  39. data/lib/scruffy/rasterizers.rb +14 -0
  40. data/lib/scruffy/rasterizers/batik_rasterizer.rb +39 -0
  41. data/lib/scruffy/rasterizers/rmagick_rasterizer.rb +27 -0
  42. data/lib/scruffy/renderers.rb +24 -0
  43. data/lib/scruffy/renderers/base.rb +95 -0
  44. data/lib/scruffy/renderers/cubed.rb +44 -0
  45. data/lib/scruffy/renderers/cubed3d.rb +53 -0
  46. data/lib/scruffy/renderers/empty.rb +22 -0
  47. data/lib/scruffy/renderers/pie.rb +20 -0
  48. data/lib/scruffy/renderers/reversed.rb +17 -0
  49. data/lib/scruffy/renderers/sparkline.rb +10 -0
  50. data/lib/scruffy/renderers/split.rb +48 -0
  51. data/lib/scruffy/renderers/standard.rb +37 -0
  52. data/lib/scruffy/themes.rb +175 -0
  53. data/lib/scruffy/version.rb +9 -0
  54. data/test/graph_creation_test.rb +286 -0
  55. data/test/test_helper.rb +2 -0
  56. metadata +132 -0
@@ -0,0 +1,175 @@
1
+ # ===Scruffy Themes
2
+ #
3
+ # Author:: Brasten Sager & A.J. Ostman
4
+ # Date:: August 27th, 2006
5
+ #
6
+ # Scruffy Themes allow you to alter the colors and appearances of
7
+ # your graph.
8
+ module Scruffy::Themes
9
+
10
+ # ==Scruffy::Themes::Base
11
+ #
12
+ # Author:: Brasten Sager & A.J. Ostman
13
+ # Date:: August 27th, 2006
14
+ #
15
+ # The base theme class. Most themes can be constructed simply
16
+ # by instantiating a new Base object with a hash of color values.
17
+ #
18
+ # See Scruffy::Themes::Base#instantiate for examples.
19
+ class Base
20
+ attr_accessor :background # Background color or array of two colors
21
+ attr_accessor :colors # Array of colors for data graphs
22
+ attr_accessor :outlines # Array of colors for outlines of elements for data graphs
23
+ attr_accessor :marker # Marker color for grid lines, values, etc.
24
+ attr_accessor :font_family # Font family: Not really supported. Maybe in the future.
25
+ attr_accessor :marker_font_size # Marker Font Size:
26
+ attr_accessor :title_font_size # Title Font Size:
27
+ attr_accessor :legend_font_size # Legend Font Size:
28
+
29
+ # Returns a new Scruffy::Themes::Base object.
30
+ #
31
+ # Hash options:
32
+ # background:: background color.
33
+ # colors:: an array of color values to use for graphs.
34
+ # marker:: color used for grid lines, values, data points, etc.
35
+ # font_family:: in general, allows you to change the font used in the graph.
36
+ # This is not yet supported in most graph elements,
37
+ # and may be deprecated soon anyway.
38
+ def initialize(descriptor)
39
+ self.background = descriptor[:background]
40
+ self.colors = descriptor[:colors]
41
+ self.outlines = descriptor[:outlines]
42
+ self.marker = descriptor[:marker]
43
+ self.font_family = descriptor[:font_family]
44
+ self.marker_font_size = descriptor[:marker_font_size]
45
+ self.title_font_size = descriptor[:title_font_size]
46
+ self.legend_font_size = descriptor[:legend_font_size]
47
+ end
48
+
49
+ # Returns the next available color in the color array.
50
+ def next_color
51
+ @previous_color = 0 if @previous_color.nil?
52
+ @previous_color += 1
53
+
54
+ self.colors[(@previous_color-1) % self.colors.size]
55
+ end
56
+
57
+
58
+ # Returns the next available outline in the outline array.
59
+ def next_outline
60
+ @previous_outline = 0 if @previous_outline.nil?
61
+ @previous_outline += 1
62
+ if self.outlines.nil?
63
+ return "#000000"
64
+ end
65
+ self.outlines[(@previous_outline-1) % self.outlines.size]
66
+ end
67
+
68
+ # todo: Implement darken function.
69
+ def darken(color, shift=20); end
70
+
71
+ # todo: Implement lighten function.
72
+ def lighten(color, shift=20); end
73
+
74
+ end
75
+
76
+
77
+
78
+ # A basic default theme
79
+ # Based on http://www.wellstyled.com/tools/colorscheme2/index-en.html?tetrad;50;0;255;1;-1;1;-0.6;0.1;1;0.6;1;1;-1;1;-0.6;0.1;1;0.6;1;1;-1;1;-0.6;0.1;1;0.6;1;1;-1;1;-0.6;0.1;1;0.6;1;0
80
+ class Standard < Base
81
+ def initialize
82
+ super({
83
+ :background => ['#FFFFFF', '#FFFFFF'],
84
+ :marker => '#999999',
85
+ :colors => %w(#1919B3 #FFB200 #FFFF00 #660099 #E9E9FF #FFF7E6 #FFFFE6 #F7E6FF #0F0F6B #996B00 #999900 #3D005C)
86
+ })
87
+
88
+ end
89
+ end
90
+
91
+ # Keynote theme, based on Apple's Keynote presentation software.
92
+ #
93
+ # Color values used from Gruff's default theme.
94
+ class Keynote < Base
95
+ def initialize
96
+ super({
97
+ :background => [:black, '#4A465A'],
98
+ :marker => :white,
99
+ :colors => %w(#6886B4 #FDD84E #72AE6E #D1695E #8A6EAF #EFAA43 white)
100
+ })
101
+ end
102
+ end
103
+
104
+ # Roughly, roughly based on the color scheme of www.mephistoblog.com.
105
+ class Mephisto < Base
106
+ def initialize
107
+ super({
108
+ :background => ['#101010', '#999977'],
109
+ :marker => :white,
110
+ :colors => %w(#DD3300 #66AABB #225533 #992200)
111
+ })
112
+
113
+ end
114
+ end
115
+
116
+ # Based on the color scheme used by almost every Ruby blogger.
117
+ class RubyBlog < Base
118
+ def initialize
119
+ super({
120
+ :background => ['#670A0A', '#831515'],
121
+ :marker => '#DBD1C1',
122
+ :colors => %w(#007777 #444477 #994444 #77FFBB #D75A20)
123
+ })
124
+ end
125
+ end
126
+
127
+ # Inspired by http://www.colorschemer.com/schemes/
128
+ class Apples < Base
129
+ def initialize
130
+ super({
131
+ :background => ['#3B411F', '#4A465A'],
132
+ :marker => '#DBD1C1',
133
+ :colors => %w(#AA3322 #DD3322 #DD6644 #FFEE88 #BBCC66 #779933)
134
+ })
135
+ end
136
+ end
137
+
138
+ # Inspired by http://www.colorschemer.com/schemes/
139
+ class CareBears < Base
140
+ def initialize
141
+ super({
142
+ # Playing with Sky Background
143
+ # :background => ['#2774B6', '#5EA6D8'],
144
+ # :marker => :white,
145
+ :background => [:black, '#4A465A'],
146
+ :marker => :white,
147
+ :colors => %w(#FFBBBB #00CC33 #7788BB #EEAA44 #FFDD11 #44BBDD #DD6677)
148
+ })
149
+ end
150
+ end
151
+
152
+
153
+ # Inspired by http://www.colorschemer.com/schemes/
154
+ class Vitamins < Base
155
+ def initialize
156
+ super({
157
+ :background => [:black, '#4A465A'],
158
+ :marker => :white,
159
+ :colors => %w(#CC9933 #FFCC66 #CCCC99 #CCCC33 #99CC33 #3333CC #336699 #6633CC #9999CC #333366)
160
+ })
161
+ end
162
+ end
163
+
164
+ # Inspired by http://www.colorschemer.com/schemes/
165
+ class Tulips < Base
166
+ def initialize
167
+ super({
168
+ :background => ['#670A0A', '#831515'],
169
+ :marker => '#DBD1C1',
170
+ :colors => %w(#F2C8CA #BF545E #D2808E #97985C #B3B878 #A24550)
171
+ })
172
+ end
173
+ end
174
+
175
+ end
@@ -0,0 +1,9 @@
1
+ module Scruffy
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 2
5
+ TINY = 9
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,286 @@
1
+ require 'test/unit'
2
+ require 'test_helper'
3
+
4
+ class SimpleTheme < Scruffy::Themes::Base
5
+ def initialize
6
+ super({
7
+ :background => [:white, :white],
8
+ :marker => :black,
9
+ :colors => %w(blue green red orange yellow purple pink),
10
+ :stroke_color => 'white'
11
+ })
12
+ end
13
+ end
14
+
15
+ $make_png = true
16
+ begin
17
+ require 'RMagick'
18
+ rescue LoadError
19
+ $make_png = nil
20
+ end
21
+
22
+ class GraphCreationTest < Test::Unit::TestCase
23
+ BASE_DIR = File.dirname(__FILE__)
24
+ WEBSITE_DIR = BASE_DIR + "/../website/images/graphs"
25
+
26
+ def test_create_pie
27
+ graph = Scruffy::Graph.new
28
+ graph.title = "Favourite Snacks"
29
+ graph.renderer = Scruffy::Renderers::Pie.new
30
+
31
+ graph.add :pie, '', {
32
+ 'Apple' => 20,
33
+ 'Banana' => 100,
34
+ 'Orange' => 70,
35
+ 'Taco' => 30
36
+ }
37
+
38
+ graph.render :to => "#{WEBSITE_DIR}/pie_test.svg"
39
+ graph.render :width => 400, :to => "#{WEBSITE_DIR}/pie_test.png", :as => 'png' if $make_png
40
+ end
41
+
42
+ def test_create_line
43
+ graph = Scruffy::Graph.new
44
+ graph.title = "Sample Line Graph"
45
+ graph.renderer = Scruffy::Renderers::Standard.new
46
+
47
+ graph.add :line, 'Example', [20, 100, 70, 30, 106]
48
+
49
+ graph.render :to => "#{WEBSITE_DIR}/line_test.svg"
50
+ graph.render :width => 400, :to => "#{WEBSITE_DIR}/line_test.png", :as => 'png' if $make_png
51
+ end
52
+
53
+
54
+ def test_create_line_with_negatives
55
+ graph = Scruffy::Graph.new
56
+ graph.title = "Sample Line Graph"
57
+ graph.renderer = Scruffy::Renderers::Standard.new
58
+
59
+ graph.add :line, 'Example', [-20, 100, -70, -30, 106]
60
+ theme = Scruffy::Themes::Base.new :background=>"#ffffff", :marker=>"#444444",
61
+ :colors=>["#4f83bf","#be514e","#a1ba5e","#82649a"],
62
+ :title_font_size => 30, :marker_font_size=>10
63
+ graph.render :to => "#{WEBSITE_DIR}/line_test_with_negatives.svg",:theme=>theme
64
+ graph.render :width => 400, :to => "#{WEBSITE_DIR}/line_test_with_negatives.png",:theme=>theme, :as => 'png' if $make_png
65
+ end
66
+
67
+
68
+ def test_create_negative_line
69
+ graph = Scruffy::Graph.new
70
+ graph.title = "Sample Line Graph"
71
+ graph.renderer = Scruffy::Renderers::Standard.new
72
+
73
+ graph.add :line, 'Example', [-20, -100, -70, -30, -106]
74
+ theme = Scruffy::Themes::Apples.new
75
+ graph.render :to => "#{WEBSITE_DIR}/negative_line_test.svg",:theme=>theme
76
+ graph.render :width => 600,:theme=>theme, :to => "#{WEBSITE_DIR}/negative_line_test.png", :as => 'png' if $make_png
77
+ end
78
+
79
+ def test_create_small_value_line
80
+ graph = Scruffy::Graph.new
81
+ graph.title = "Sample Line Graph"
82
+ graph.renderer = Scruffy::Renderers::Standard.new
83
+ graph.value_formatter = Scruffy::Formatters::Number.new(:precision => 1)
84
+ graph.add :line, 'Example', [0.2,0.5,0.1,0.9,0.8,1.2,0.05,1]
85
+
86
+ graph.render :to => "#{WEBSITE_DIR}/small_value_line_test.svg"
87
+ graph.render :width => 400, :to => "#{WEBSITE_DIR}/small_value_line_test.png", :as => 'png' if $make_png
88
+ end
89
+
90
+
91
+ def test_create_bar
92
+ graph = Scruffy::Graph.new
93
+ graph.title = "Sample Bar Graph"
94
+ graph.renderer = Scruffy::Renderers::Standard.new
95
+ graph.add :bar, 'Example', [20, 100, 70, 30, 106]
96
+ graph.render :to => "#{WEBSITE_DIR}/bar_test.svg"
97
+ graph.render :width => 400, :to => "#{WEBSITE_DIR}/bar_test.png", :as => 'png' if $make_png
98
+ end
99
+
100
+
101
+
102
+
103
+ def test_create_bar_with_negatives
104
+ graph = Scruffy::Graph.new
105
+ graph.title = "Sample Bar Graph"
106
+ graph.renderer = Scruffy::Renderers::Standard.new
107
+ graph.add :bar, 'Example', [20, 100,-10, 70, 30, -40, 106]
108
+ graph.render :to => "#{WEBSITE_DIR}/negative_bar_test.svg"
109
+ graph.render :width => 400, :to => "#{WEBSITE_DIR}/negative_bar_test.png", :as => 'png' if $make_png
110
+ end
111
+
112
+
113
+ def test_create_bar_with_all_negatives
114
+ graph = Scruffy::Graph.new
115
+ graph.title = "Sample Bar Graph"
116
+ graph.renderer = Scruffy::Renderers::Standard.new
117
+ graph.add :bar, 'Example', [-20, -100,-10, -70, -30, -40, -106]
118
+
119
+ theme = Scruffy::Themes::Base.new :background=>"#ffffff", :marker=>"#444444",
120
+ :colors=>["#ff0000","#00ff00","#0000ff","#cccccc"],
121
+ :title_font_size => 30, :marker_font_size=>10
122
+
123
+ graph.render :to => "#{WEBSITE_DIR}/all_negative_bar_test.svg",:theme=>theme
124
+ graph.render :width => 400,:theme=>theme, :to => "#{WEBSITE_DIR}/all_negative_bar_test.png", :as => 'png' if $make_png
125
+ end
126
+
127
+
128
+ def test_split
129
+ graph = Scruffy::Graph.new
130
+ graph.title = "Long-term Comparisons"
131
+ graph.value_formatter = Scruffy::Formatters::Currency.new(:special_negatives => true, :negative_color => '#ff7777')
132
+ graph.renderer = Scruffy::Renderers::Split.new(:split_label => 'Northeastern (Top) / Central (Bottom)')
133
+
134
+ graph.add :area, 'Jeff', [20, -5, 100, 70, 30, 106, 203, 100, 50, 203, 289, 20], :category => :top
135
+ graph.add :area, 'Jerry', [-10, 70, 20, 102, 201, 26, 30, 106, 203, 100, 50, 39], :category => :top
136
+ graph.add :bar, 'Jack', [30, 0, 49, 29, 100, 203, 70, 20, 102, 201, 26, 130], :category => :bottom
137
+ graph.add :line, 'Brasten', [42, 10, 75, 150, 130, 70, -10, -20, 50, 92, -21, 19], :categories => [:top, :bottom]
138
+ graph.add :line, 'Jim', [-10, -20, 50, 92, -21, 56, 92, 84, 82, 100, 39, 120], :categories => [:top, :bottom]
139
+ graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
140
+
141
+ graph.render :to => "#{WEBSITE_DIR}/split_test.svg"
142
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/split_test.png", :as => 'png' if $make_png
143
+ end
144
+
145
+ def test_stacking
146
+ graph = Scruffy::Graph.new
147
+ graph.title = "Comparative Agent Performance"
148
+ graph.value_formatter = Scruffy::Formatters::Percentage.new(:precision => 0)
149
+ graph.add :stacked do |stacked|
150
+ stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
151
+ stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
152
+ stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
153
+ end
154
+ graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
155
+ graph.render :to => "#{WEBSITE_DIR}/stacking_test.svg"
156
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/stacking_test.png", :as => 'png' if $make_png
157
+ end
158
+
159
+
160
+ def test_reg_multi_bar
161
+ graph = Scruffy::Graph.new
162
+ graph.title = "Comparative Agent Performance"
163
+ graph.value_formatter = Scruffy::Formatters::Percentage.new(:precision => 0)
164
+ #graph.add :multi do |multi|
165
+ graph.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
166
+ graph.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
167
+ graph.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
168
+ #end
169
+ graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
170
+ graph.render :to => "#{WEBSITE_DIR}/reg_multi_bar_test.svg"
171
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/reg_multi_bar_test.png", :as => 'png' if $make_png
172
+ end
173
+
174
+ def test_multi_bar
175
+ graph = Scruffy::Graph.new
176
+ graph.title = "Comparative Agent Performance"
177
+ graph.value_formatter = Scruffy::Formatters::Percentage.new(:precision => 0)
178
+ graph.add :multi do |multi|
179
+ multi.add :multi_bar, 'Jack', [30, 60, 49, 29, 100, 120]
180
+ multi.add :multi_bar, 'Jill', [120, 240, 0, 100, 140, 20]
181
+ multi.add :multi_bar, 'Hill', [10, 10, 90, 20, 40, 10]
182
+ multi.add :multi_bar, 'Bob', [-10, -20, -30, -40, -50, -60]
183
+ end
184
+ graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
185
+ graph.point_markers_ticks = true
186
+ theme = Scruffy::Themes::Base.new :background=>"#ffffff", :marker=>"#444444",
187
+ :colors=>["#cccccc","#ff0000","#00ff00","#0000ff"],
188
+ :title_font_size => 30, :marker_font_size=>10
189
+
190
+ graph.render :to => "#{WEBSITE_DIR}/multi_bar_test.svg",:theme=>theme
191
+
192
+ graph.render :width => 900,:theme=>theme, :to => "#{WEBSITE_DIR}/multi_bar_test.png", :as => 'png' if $make_png
193
+ end
194
+
195
+
196
+ def test_box_plot
197
+ graph = Scruffy::Graph.new()
198
+ graph.title = "Box Plot Test"
199
+ graph.x_legend = "Time in Seconds"
200
+ graph.y_legend = "Inces of Rain"
201
+ graph.value_formatter = Scruffy::Formatters::Percentage.new(:precision => 0)
202
+ graph.add :box, "Test Data", [
203
+ [10,8,6.2,4,2],
204
+ [12,9,8.2,4.2,3.5],
205
+ [10,8,5.3,4,2],
206
+ [12,9,8.2,4.2,3.5],
207
+ [10,8,6.6,4,2],
208
+ [12,9,8.2,4.2,3.5]
209
+ ]
210
+
211
+ graph.point_markers = ['Jan', 'Feb','Jan', 'Feb','Jan', 'Feb']
212
+ graph.point_markers_ticks = true
213
+ graph.renderer = Scruffy::Renderers::AxisLegend.new
214
+
215
+ theme = Scruffy::Themes::Base.new :background=>"#ffffff", :marker=>"#aaaaaa",
216
+ :colors=>["#4f83bf","#be514e","#a1ba5e","#82649a"],
217
+ :legend_font_size=>30,
218
+ :title_font_size=>40,
219
+ :marker_font_size=>20,
220
+ :outlines=>["#be514e","#a1ba5e","#82649a","#4f83bf"]
221
+ graph.render :to => "#{WEBSITE_DIR}/box_plot_test.svg",:padding=>:padded,:theme=>theme,:key_markers=>8
222
+ graph.render :size => [600,540],:theme=>theme,:key_markers=>7, :to => "#{WEBSITE_DIR}/box_plot_test.png", :as => 'png',:padding=>:padded if $make_png
223
+ end
224
+
225
+
226
+
227
+ def test_rotated_point_markers
228
+ graph = Scruffy::Graph.new({:point_markers_rotation=>30}) #
229
+ graph.title = "Comparative Agent Performance"
230
+ graph.value_formatter = Scruffy::Formatters::Percentage.new(:precision => 0)
231
+ graph.add :stacked do |stacked|
232
+ stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
233
+ stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
234
+ stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
235
+ end
236
+ graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
237
+ graph.point_markers_ticks = true
238
+ #Rotation was set when the graph was created
239
+ #You can also do something like this
240
+ #graph.point_markers_rotation = 90
241
+ graph.render :to => "#{WEBSITE_DIR}/rotated_point_markers_test.svg"
242
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/rotated_point_markers_test.png", :as => 'png' if $make_png
243
+ end
244
+
245
+
246
+ def test_multi_layered
247
+ graph = Scruffy::Graph.new
248
+ graph.title = "Some Kind of Information"
249
+ graph.renderer = Scruffy::Renderers::Cubed.new
250
+
251
+ graph.add :area, 'Jeff', [20, -5, 100, 70, 30, 106], :categories => [:top_left, :bottom_right]
252
+ graph.add :area, 'Jerry', [-10, 70, 20, 102, 201, 26], :categories => [:bottom_left, :buttom_right]
253
+ graph.add :bar, 'Jack', [30, 0, 49, 29, 100, 203], :categories => [:bottom_left, :top_right]
254
+ graph.add :line, 'Brasten', [42, 10, 75, 150, 130, 70], :categories => [:top_right, :bottom_left]
255
+ graph.add :line, 'Jim', [-10, -20, 50, 92, -21, 56], :categories => [:top_left, :bottom_right]
256
+ graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
257
+ graph.render :to => "#{WEBSITE_DIR}/multi_test.svg"
258
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/multi_test.png", :as => 'png' if $make_png
259
+ end
260
+
261
+ def test_scatter
262
+ graph = Scruffy::Graph.new
263
+ graph.title = "Some Kind of Information"
264
+ graph.renderer = Scruffy::Renderers::Standard.new
265
+
266
+ graph.add :scatter, 'Stephanie', {0 => 0, 1 => 1, 2 => 4, 3 => 9, 4 => 8, 5 => 10, 6 => 12, 7 => 3, 8 => 13}
267
+ graph.add :line, 'Artiom', {-3 => 2, 1.5 => 6, 2 => 4.5, 15 => -4}, :dots => true
268
+ graph.add :scatter, 'Sam', [[-3,15], [1.5,18], [2,9], [15,6]]
269
+ graph.render :to => "#{WEBSITE_DIR}/scatter_test.svg"
270
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/scatter_test.png", :as => 'png' if $make_png
271
+ end
272
+
273
+ def test_scatter_by_date
274
+ graph = Scruffy::Graph.new
275
+ graph.title = "Some Kind of Information"
276
+ graph.renderer = Scruffy::Renderers::Standard.new
277
+ graph.key_formatter = Scruffy::Formatters::Date.new("%H:%M")
278
+ h = {}
279
+ start = Time.local(2009, 1, 20, 12, 0, 0)
280
+ 30.times{|i| h[start + 60*i] = i*i}
281
+
282
+ graph.add :scatter, 'DNI', h
283
+ graph.render :to => "#{WEBSITE_DIR}/scatter_date_test.svg", :calculate_markers => true
284
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/scatter_date_test.png", :as => 'png' if $make_png
285
+ end
286
+ end