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
@@ -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,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,177 @@
|
|
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 :grid # Marker color for grid lines, etc.
|
24
|
+
attr_accessor :marker # Marker color for grid lines, values, etc.
|
25
|
+
attr_accessor :font_family # Font family: Not really supported. Maybe in the future.
|
26
|
+
attr_accessor :marker_font_size # Marker Font Size:
|
27
|
+
attr_accessor :title_font_size # Title Font Size:
|
28
|
+
attr_accessor :legend_font_size # Legend Font Size:
|
29
|
+
|
30
|
+
# Returns a new Scruffy::Themes::Base object.
|
31
|
+
#
|
32
|
+
# Hash options:
|
33
|
+
# background:: background color.
|
34
|
+
# colors:: an array of color values to use for graphs.
|
35
|
+
# marker:: color used for grid lines, values, data points, etc.
|
36
|
+
# font_family:: in general, allows you to change the font used in the graph.
|
37
|
+
# This is not yet supported in most graph elements,
|
38
|
+
# and may be deprecated soon anyway.
|
39
|
+
def initialize(descriptor)
|
40
|
+
self.background = descriptor[:background]
|
41
|
+
self.colors = descriptor[:colors]
|
42
|
+
self.outlines = descriptor[:outlines]
|
43
|
+
self.grid = descriptor[:grid]
|
44
|
+
self.marker = descriptor[:marker]
|
45
|
+
self.font_family = descriptor[:font_family]
|
46
|
+
self.marker_font_size = descriptor[:marker_font_size]
|
47
|
+
self.title_font_size = descriptor[:title_font_size]
|
48
|
+
self.legend_font_size = descriptor[:legend_font_size]
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the next available color in the color array.
|
52
|
+
def next_color
|
53
|
+
@previous_color = 0 if @previous_color.nil?
|
54
|
+
@previous_color += 1
|
55
|
+
|
56
|
+
self.colors[(@previous_color-1) % self.colors.size]
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# Returns the next available outline in the outline array.
|
61
|
+
def next_outline
|
62
|
+
@previous_outline = 0 if @previous_outline.nil?
|
63
|
+
@previous_outline += 1
|
64
|
+
if self.outlines.nil?
|
65
|
+
return "#000000"
|
66
|
+
end
|
67
|
+
self.outlines[(@previous_outline-1) % self.outlines.size]
|
68
|
+
end
|
69
|
+
|
70
|
+
# todo: Implement darken function.
|
71
|
+
def darken(color, shift=20); end
|
72
|
+
|
73
|
+
# todo: Implement lighten function.
|
74
|
+
def lighten(color, shift=20); end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
# A basic default theme
|
81
|
+
# 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
|
82
|
+
class Standard < Base
|
83
|
+
def initialize
|
84
|
+
super({
|
85
|
+
:background => ['#FFFFFF', '#FFFFFF'],
|
86
|
+
:marker => '#999999',
|
87
|
+
:colors => %w(#1919B3 #FFB200 #FFFF00 #660099 #E9E9FF #FFF7E6 #FFFFE6 #F7E6FF #0F0F6B #996B00 #999900 #3D005C)
|
88
|
+
})
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Keynote theme, based on Apple's Keynote presentation software.
|
94
|
+
#
|
95
|
+
# Color values used from Gruff's default theme.
|
96
|
+
class Keynote < Base
|
97
|
+
def initialize
|
98
|
+
super({
|
99
|
+
:background => [:black, '#4A465A'],
|
100
|
+
:marker => :white,
|
101
|
+
:colors => %w(#6886B4 #FDD84E #72AE6E #D1695E #8A6EAF #EFAA43 white)
|
102
|
+
})
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Roughly, roughly based on the color scheme of www.mephistoblog.com.
|
107
|
+
class Mephisto < Base
|
108
|
+
def initialize
|
109
|
+
super({
|
110
|
+
:background => ['#101010', '#999977'],
|
111
|
+
:marker => :white,
|
112
|
+
:colors => %w(#DD3300 #66AABB #225533 #992200)
|
113
|
+
})
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Based on the color scheme used by almost every Ruby blogger.
|
119
|
+
class RubyBlog < Base
|
120
|
+
def initialize
|
121
|
+
super({
|
122
|
+
:background => ['#670A0A', '#831515'],
|
123
|
+
:marker => '#DBD1C1',
|
124
|
+
:colors => %w(#007777 #444477 #994444 #77FFBB #D75A20)
|
125
|
+
})
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Inspired by http://www.colorschemer.com/schemes/
|
130
|
+
class Apples < Base
|
131
|
+
def initialize
|
132
|
+
super({
|
133
|
+
:background => ['#3B411F', '#4A465A'],
|
134
|
+
:marker => '#DBD1C1',
|
135
|
+
:colors => %w(#AA3322 #DD3322 #DD6644 #FFEE88 #BBCC66 #779933)
|
136
|
+
})
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Inspired by http://www.colorschemer.com/schemes/
|
141
|
+
class CareBears < Base
|
142
|
+
def initialize
|
143
|
+
super({
|
144
|
+
# Playing with Sky Background
|
145
|
+
# :background => ['#2774B6', '#5EA6D8'],
|
146
|
+
# :marker => :white,
|
147
|
+
:background => [:black, '#4A465A'],
|
148
|
+
:marker => :white,
|
149
|
+
:colors => %w(#FFBBBB #00CC33 #7788BB #EEAA44 #FFDD11 #44BBDD #DD6677)
|
150
|
+
})
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
# Inspired by http://www.colorschemer.com/schemes/
|
156
|
+
class Vitamins < Base
|
157
|
+
def initialize
|
158
|
+
super({
|
159
|
+
:background => [:black, '#4A465A'],
|
160
|
+
:marker => :white,
|
161
|
+
:colors => %w(#CC9933 #FFCC66 #CCCC99 #CCCC33 #99CC33 #3333CC #336699 #6633CC #9999CC #333366)
|
162
|
+
})
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Inspired by http://www.colorschemer.com/schemes/
|
167
|
+
class Tulips < Base
|
168
|
+
def initialize
|
169
|
+
super({
|
170
|
+
:background => ['#670A0A', '#831515'],
|
171
|
+
:marker => '#DBD1C1',
|
172
|
+
:colors => %w(#F2C8CA #BF545E #D2808E #97985C #B3B878 #A24550)
|
173
|
+
})
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
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
|