willbryant-scruffy 0.2.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) 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 +22 -0
  7. data/lib/scruffy/components/axes.rb +18 -0
  8. data/lib/scruffy/components/background.rb +24 -0
  9. data/lib/scruffy/components/base.rb +57 -0
  10. data/lib/scruffy/components/data_markers.rb +41 -0
  11. data/lib/scruffy/components/graphs.rb +51 -0
  12. data/lib/scruffy/components/grid.rb +54 -0
  13. data/lib/scruffy/components/label.rb +17 -0
  14. data/lib/scruffy/components/legend.rb +147 -0
  15. data/lib/scruffy/components/style_info.rb +22 -0
  16. data/lib/scruffy/components/title.rb +19 -0
  17. data/lib/scruffy/components/value_markers.rb +25 -0
  18. data/lib/scruffy/components/viewport.rb +37 -0
  19. data/lib/scruffy/formatters.rb +233 -0
  20. data/lib/scruffy/graph.rb +205 -0
  21. data/lib/scruffy/graph_state.rb +29 -0
  22. data/lib/scruffy/helpers.rb +13 -0
  23. data/lib/scruffy/helpers/canvas.rb +41 -0
  24. data/lib/scruffy/helpers/layer_container.rb +119 -0
  25. data/lib/scruffy/helpers/marker_helper.rb +25 -0
  26. data/lib/scruffy/helpers/meta.rb +5 -0
  27. data/lib/scruffy/helpers/point_container.rb +99 -0
  28. data/lib/scruffy/layers.rb +28 -0
  29. data/lib/scruffy/layers/all_smiles.rb +137 -0
  30. data/lib/scruffy/layers/area.rb +46 -0
  31. data/lib/scruffy/layers/average.rb +67 -0
  32. data/lib/scruffy/layers/bar.rb +68 -0
  33. data/lib/scruffy/layers/base.rb +211 -0
  34. data/lib/scruffy/layers/box.rb +114 -0
  35. data/lib/scruffy/layers/line.rb +46 -0
  36. data/lib/scruffy/layers/multi.rb +74 -0
  37. data/lib/scruffy/layers/multi_bar.rb +51 -0
  38. data/lib/scruffy/layers/pie.rb +123 -0
  39. data/lib/scruffy/layers/pie_slice.rb +119 -0
  40. data/lib/scruffy/layers/scatter.rb +29 -0
  41. data/lib/scruffy/layers/sparkline_bar.rb +39 -0
  42. data/lib/scruffy/layers/stacked.rb +87 -0
  43. data/lib/scruffy/rasterizers.rb +14 -0
  44. data/lib/scruffy/rasterizers/batik_rasterizer.rb +39 -0
  45. data/lib/scruffy/rasterizers/rmagick_rasterizer.rb +27 -0
  46. data/lib/scruffy/renderers.rb +23 -0
  47. data/lib/scruffy/renderers/axis_legend.rb +41 -0
  48. data/lib/scruffy/renderers/base.rb +95 -0
  49. data/lib/scruffy/renderers/cubed.rb +44 -0
  50. data/lib/scruffy/renderers/cubed3d.rb +53 -0
  51. data/lib/scruffy/renderers/empty.rb +22 -0
  52. data/lib/scruffy/renderers/pie.rb +20 -0
  53. data/lib/scruffy/renderers/reversed.rb +17 -0
  54. data/lib/scruffy/renderers/sparkline.rb +10 -0
  55. data/lib/scruffy/renderers/split.rb +48 -0
  56. data/lib/scruffy/renderers/standard.rb +37 -0
  57. data/lib/scruffy/themes.rb +175 -0
  58. data/lib/scruffy/version.rb +9 -0
  59. data/test/graph_creation_test.rb +286 -0
  60. data/test/test_helper.rb +2 -0
  61. metadata +136 -0
@@ -0,0 +1,53 @@
1
+ module Scruffy::Renderers
2
+ # ===Scruffy::Renderers::Cubed3d
3
+ #
4
+ # Author:: Brasten Sager
5
+ # Date:: August 17th, 2006
6
+ #
7
+ # A 3-dimensional cube effect.
8
+ class Cubed3d < Empty
9
+ VIEWPORT_SIZE = [25, 45]
10
+ VIEWPORTS = { :top_left => [10, 25],
11
+ :top_right => [55, 25],
12
+ :bottom_left => [10, 65],
13
+ :bottom_right => [55, 65] }
14
+
15
+ # Returns a Cubed instance.
16
+ def define_layout
17
+ super do |components|
18
+ components << Scruffy::Components::Title.new(:title, :position => [5, 2], :size => [90, 7])
19
+
20
+ components << Scruffy::Components::Viewport.new(:one, :position => [10, 50],
21
+ :size => VIEWPORT_SIZE, :skewY => '-25',
22
+ &graph_block(:one))
23
+ components << Scruffy::Components::Viewport.new(:two, :position => [30, 50],
24
+ :size => VIEWPORT_SIZE, :skewY => '-25',
25
+ &graph_block(:two))
26
+ components << Scruffy::Components::Viewport.new(:three, :position => [50, 50],
27
+ :size => VIEWPORT_SIZE, :skewY => '-25',
28
+ &graph_block(:three))
29
+ components << Scruffy::Components::Viewport.new(:four, :position => [70, 50],
30
+ :size => VIEWPORT_SIZE, :skewY => '-25',
31
+ &graph_block(:four))
32
+
33
+
34
+ components << Scruffy::Components::Legend.new(:legend, :position => [5, 13], :size => [90, 5])
35
+ end
36
+ end
37
+
38
+ private
39
+ # Returns a typical graph layout.
40
+ #
41
+ # These are squeezed into viewports.
42
+ def graph_block(graph_filter)
43
+ block = Proc.new { |components|
44
+ components << Scruffy::Components::Grid.new(:grid, :position => [10, 0], :size => [90, 89])
45
+ components << Scruffy::Components::ValueMarkers.new(:value_markers, :position => [0, 2], :size => [8, 89])
46
+ components << Scruffy::Components::DataMarkers.new(:data_markers, :position => [10, 92], :size => [90, 8])
47
+ components << Scruffy::Components::Graphs.new(:graphs, :position => [10, 0], :size => [90, 89], :only => graph_filter)
48
+ }
49
+
50
+ block
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ module Scruffy::Renderers
2
+ # ===Scruffy::Renderers::Empty
3
+ #
4
+ # Author:: Brasten Sager
5
+ # Date:: August 17th, 2006
6
+ #
7
+ # An Empty graph isn't completely empty, it adds a background componenet
8
+ # to itself before handing other all other layout responsibilities to it's
9
+ # subclasses or caller.
10
+ class Empty < Base
11
+
12
+ # Returns a renderer with just a background.
13
+ #
14
+ # If a block is provided, the components array is passed to
15
+ # the block, allowing callers to add components during initialize.
16
+ def define_layout
17
+ self.components << Scruffy::Components::Background.new(:background, :position => [0,0], :size =>[100, 100])
18
+
19
+ yield(self.components) if block_given?
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ module Scruffy::Renderers
2
+ # ===Scruffy::Renderers::Base
3
+ #
4
+ # Author:: A.J. Ostman
5
+ # Date:: August 14th, 2006
6
+ #
7
+ # Provides a more appropriate rendering for Pie Charts.
8
+ # Does not show grid or Data markers, but does add Pie Value Markers.
9
+ class Pie < Base
10
+
11
+ def initialize
12
+ self.components = []
13
+ self.components << Scruffy::Components::Background.new(:background, :position => [0,0], :size =>[100, 100])
14
+ self.components << Scruffy::Components::Graphs.new(:graphs, :position => [-15, 12], :size => [90, 88])
15
+ self.components << Scruffy::Components::Title.new(:title, :position => [5, 2], :size => [90, 7])
16
+ self.components << Scruffy::Components::Legend.new(:legend, :position => [60, 15], :size => [40, 88], :vertical_legend => true)
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,17 @@
1
+ module Scruffy
2
+ module Renderers
3
+ class Reversed < Base
4
+
5
+ def define_layout
6
+ self.components << Scruffy::Components::Background.new(:background, :position => [0,0], :size =>[100, 100])
7
+ self.components << Scruffy::Components::Title.new(:title, :position => [98, 95], :size => [1, 3], :text_anchor => 'end')
8
+ #self.components << Scruffy::Components::Grid.new(:grid, :position => [14, 12], :size => [78.5, 70])
9
+ self.components << Scruffy::Components::ValueMarkers.new(:value_markers, :position => [2, 14], :size => [10, 70])
10
+ self.components << Scruffy::Components::DataMarkers.new(:data_markers, :position => [14, 3.5], :size => [78.5, 4])
11
+ self.components << Scruffy::Components::Graphs.new(:graphs, :position => [14, 12], :size => [78.5, 70])
12
+ self.components << Scruffy::Components::Legend.new(:legend, :position => [3, 90], :size => [55, 6])
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module Scruffy
2
+ module Renderers
3
+ # Experimental, do not use.
4
+ class Sparkline < Base
5
+ def define_layout
6
+ self.components << Scruffy::Components::Graphs.new(:sparkline, :position => [0, 0], :size => [100, 100])
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,48 @@
1
+ module Scruffy
2
+ module Renderers
3
+ # Renderer that splits the graphs up into four other little graphs.
4
+ class Split < Empty
5
+ def define_layout
6
+ super do |components|
7
+ components << Scruffy::Components::Title.new(:title, :position => [5, 2], :size => [90, 7])
8
+ components << Scruffy::Components::Label.new(:label_one, :text => self.options[:split_label] || '',
9
+ :position => [30, 54.5], :size => [40, 3])
10
+
11
+ # Viewports
12
+ components << Scruffy::Components::Viewport.new(:top, :position => [3, 20],
13
+ :size => [90, 30], &graph_block(:top))
14
+ components << Scruffy::Components::Viewport.new(:bottom, :position => [3, 65],
15
+ :size => [90, 30], &graph_block(:bottom))
16
+
17
+ components << Scruffy::Components::Legend.new(:legend, :position => [5, 11], :size => [90, 4])
18
+ end
19
+ end
20
+
21
+ protected
22
+ def labels
23
+ [component(:top).component(:labels), component(:bottom).component(:labels)]
24
+ end
25
+
26
+ def values
27
+ [component(:top).component(:values), component(:bottom).component(:values)]
28
+ end
29
+
30
+ def grids
31
+ [component(:top).component(:grid), component(:bottom).component(:grid)]
32
+ end
33
+
34
+
35
+ private
36
+ def graph_block(graph_filter)
37
+ block = Proc.new { |components|
38
+ components << Scruffy::Components::Grid.new(:grid, :position => [10, 0], :size => [90, 89])
39
+ components << Scruffy::Components::ValueMarkers.new(:values, :position => [0, 2], :size => [8, 89])
40
+ components << Scruffy::Components::DataMarkers.new(:labels, :position => [10, 92], :size => [90, 8])
41
+ components << Scruffy::Components::Graphs.new(:graphs, :position => [10, 0], :size => [90, 89], :only => graph_filter)
42
+ }
43
+
44
+ block
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,37 @@
1
+ module Scruffy::Renderers
2
+ class Standard < Empty
3
+
4
+ def define_layout
5
+ super do |components|
6
+ components << Scruffy::Components::Title.new(:title, :position => [5, 2], :size => [90, 7])
7
+ components << Scruffy::Components::Viewport.new(:view, :position => [2, 26], :size => [90, 66]) do |graph|
8
+ graph << Scruffy::Components::ValueMarkers.new(:values, :position => [0, 2], :size => [8, 89])
9
+ graph << Scruffy::Components::Grid.new(:grid, :position => [10, 0], :size => [90, 89], :stroke_width => 1)
10
+ graph << Scruffy::Components::VGrid.new(:vgrid, :position => [10, 0], :size => [90, 89], :stroke_width => 1)
11
+ graph << Scruffy::Components::DataMarkers.new(:labels, :position => [10, 92], :size => [90, 8])
12
+ graph << Scruffy::Components::Graphs.new(:graphs, :position => [10, 0], :size => [90, 89])
13
+ end
14
+ components << Scruffy::Components::Legend.new(:legend, :position => [5, 13], :size => [90, 6])
15
+ end
16
+ end
17
+
18
+ protected
19
+ def hide_values
20
+ super
21
+ component(:view).position[0] = -10
22
+ component(:view).size[0] = 100
23
+ end
24
+
25
+ def labels
26
+ [component(:view).component(:labels)]
27
+ end
28
+
29
+ def values
30
+ [component(:view).component(:values)]
31
+ end
32
+
33
+ def grids
34
+ [component(:view).component(:grid),component(:view).component(:vgrid)]
35
+ end
36
+ end
37
+ end
@@ -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 = 15
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