jagthedrummer-scruffy 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGES.txt +115 -0
  2. data/LICENCE.txt +20 -0
  3. data/Manifest.txt +69 -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 +37 -0
  10. data/lib/scruffy/components/graphs.rb +50 -0
  11. data/lib/scruffy/components/grid.rb +36 -0
  12. data/lib/scruffy/components/label.rb +17 -0
  13. data/lib/scruffy/components/legend.rb +105 -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 +24 -0
  17. data/lib/scruffy/components/viewport.rb +37 -0
  18. data/lib/scruffy/formatters.rb +230 -0
  19. data/lib/scruffy/graph.rb +195 -0
  20. data/lib/scruffy/graph_state.rb +25 -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 +117 -0
  24. data/lib/scruffy/helpers/marker_helper.rb +23 -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 +25 -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 +52 -0
  32. data/lib/scruffy/layers/base.rb +202 -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 +22 -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 +156 -0
  53. data/lib/scruffy/version.rb +9 -0
  54. data/test/graph_creation_test.rb +134 -0
  55. data/test/test_helper.rb +2 -0
  56. metadata +129 -0
@@ -0,0 +1,156 @@
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 :marker # Marker color for grid lines, values, etc.
23
+ attr_accessor :font_family # Font family: Not really supported. Maybe in the future.
24
+
25
+ # Returns a new Scruffy::Themes::Base object.
26
+ #
27
+ # Hash options:
28
+ # background:: background color.
29
+ # colors:: an array of color values to use for graphs.
30
+ # marker:: color used for grid lines, values, data points, etc.
31
+ # font_family:: in general, allows you to change the font used in the graph.
32
+ # This is not yet supported in most graph elements,
33
+ # and may be deprecated soon anyway.
34
+ def initialize(descriptor)
35
+ self.background = descriptor[:background]
36
+ self.colors = descriptor[:colors]
37
+ self.marker = descriptor[:marker]
38
+ self.font_family = descriptor[:font_family]
39
+ end
40
+
41
+ # Returns the next available color in the color array.
42
+ def next_color
43
+ @previous_color = 0 if @previous_color.nil?
44
+ @previous_color += 1
45
+
46
+ self.colors[(@previous_color-1) % self.colors.size]
47
+ end
48
+
49
+ # todo: Implement darken function.
50
+ def darken(color, shift=20); end
51
+
52
+ # todo: Implement lighten function.
53
+ def lighten(color, shift=20); end
54
+
55
+ end
56
+
57
+
58
+
59
+ # A basic default theme
60
+ # 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
61
+ class Standard < Base
62
+ def initialize
63
+ super({
64
+ :background => ['#FFFFFF', '#FFFFFF'],
65
+ :marker => '#999999',
66
+ :colors => %w(#1919B3 #FFB200 #FFFF00 #660099 #E9E9FF #FFF7E6 #FFFFE6 #F7E6FF #0F0F6B #996B00 #999900 #3D005C)
67
+ })
68
+
69
+ end
70
+ end
71
+
72
+ # Keynote theme, based on Apple's Keynote presentation software.
73
+ #
74
+ # Color values used from Gruff's default theme.
75
+ class Keynote < Base
76
+ def initialize
77
+ super({
78
+ :background => [:black, '#4A465A'],
79
+ :marker => :white,
80
+ :colors => %w(#6886B4 #FDD84E #72AE6E #D1695E #8A6EAF #EFAA43 white)
81
+ })
82
+ end
83
+ end
84
+
85
+ # Roughly, roughly based on the color scheme of www.mephistoblog.com.
86
+ class Mephisto < Base
87
+ def initialize
88
+ super({
89
+ :background => ['#101010', '#999977'],
90
+ :marker => :white,
91
+ :colors => %w(#DD3300 #66AABB #225533 #992200)
92
+ })
93
+
94
+ end
95
+ end
96
+
97
+ # Based on the color scheme used by almost every Ruby blogger.
98
+ class RubyBlog < Base
99
+ def initialize
100
+ super({
101
+ :background => ['#670A0A', '#831515'],
102
+ :marker => '#DBD1C1',
103
+ :colors => %w(#007777 #444477 #994444 #77FFBB #D75A20)
104
+ })
105
+ end
106
+ end
107
+
108
+ # Inspired by http://www.colorschemer.com/schemes/
109
+ class Apples < Base
110
+ def initialize
111
+ super({
112
+ :background => ['#3B411F', '#4A465A'],
113
+ :marker => '#DBD1C1',
114
+ :colors => %w(#AA3322 #DD3322 #DD6644 #FFEE88 #BBCC66 #779933)
115
+ })
116
+ end
117
+ end
118
+
119
+ # Inspired by http://www.colorschemer.com/schemes/
120
+ class CareBears < Base
121
+ def initialize
122
+ super({
123
+ # Playing with Sky Background
124
+ # :background => ['#2774B6', '#5EA6D8'],
125
+ # :marker => :white,
126
+ :background => [:black, '#4A465A'],
127
+ :marker => :white,
128
+ :colors => %w(#FFBBBB #00CC33 #7788BB #EEAA44 #FFDD11 #44BBDD #DD6677)
129
+ })
130
+ end
131
+ end
132
+
133
+
134
+ # Inspired by http://www.colorschemer.com/schemes/
135
+ class Vitamins < Base
136
+ def initialize
137
+ super({
138
+ :background => [:black, '#4A465A'],
139
+ :marker => :white,
140
+ :colors => %w(#CC9933 #FFCC66 #CCCC99 #CCCC33 #99CC33 #3333CC #336699 #6633CC #9999CC #333366)
141
+ })
142
+ end
143
+ end
144
+
145
+ # Inspired by http://www.colorschemer.com/schemes/
146
+ class Tulips < Base
147
+ def initialize
148
+ super({
149
+ :background => ['#670A0A', '#831515'],
150
+ :marker => '#DBD1C1',
151
+ :colors => %w(#F2C8CA #BF545E #D2808E #97985C #B3B878 #A24550)
152
+ })
153
+ end
154
+ end
155
+
156
+ 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,134 @@
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_bar
55
+ graph = Scruffy::Graph.new
56
+ graph.title = "Sample Bar Graph"
57
+ graph.renderer = Scruffy::Renderers::Standard.new
58
+ graph.add :bar, 'Example', [20, 100, 70, 30, 106]
59
+ graph.render :to => "#{WEBSITE_DIR}/bar_test.svg"
60
+ graph.render :width => 400, :to => "#{WEBSITE_DIR}/bar_test.png", :as => 'png' if $make_png
61
+ end
62
+
63
+ def test_split
64
+ graph = Scruffy::Graph.new
65
+ graph.title = "Long-term Comparisons"
66
+ graph.value_formatter = Scruffy::Formatters::Currency.new(:special_negatives => true, :negative_color => '#ff7777')
67
+ graph.renderer = Scruffy::Renderers::Split.new(:split_label => 'Northeastern (Top) / Central (Bottom)')
68
+
69
+ graph.add :area, 'Jeff', [20, -5, 100, 70, 30, 106, 203, 100, 50, 203, 289, 20], :category => :top
70
+ graph.add :area, 'Jerry', [-10, 70, 20, 102, 201, 26, 30, 106, 203, 100, 50, 39], :category => :top
71
+ graph.add :bar, 'Jack', [30, 0, 49, 29, 100, 203, 70, 20, 102, 201, 26, 130], :category => :bottom
72
+ graph.add :line, 'Brasten', [42, 10, 75, 150, 130, 70, -10, -20, 50, 92, -21, 19], :categories => [:top, :bottom]
73
+ graph.add :line, 'Jim', [-10, -20, 50, 92, -21, 56, 92, 84, 82, 100, 39, 120], :categories => [:top, :bottom]
74
+ graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
75
+
76
+ graph.render :to => "#{WEBSITE_DIR}/split_test.svg"
77
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/split_test.png", :as => 'png' if $make_png
78
+ end
79
+
80
+ def test_stacking
81
+ graph = Scruffy::Graph.new
82
+ graph.title = "Comparative Agent Performance"
83
+ graph.value_formatter = Scruffy::Formatters::Percentage.new(:precision => 0)
84
+ graph.add :stacked do |stacked|
85
+ stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
86
+ stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
87
+ stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
88
+ end
89
+ graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
90
+ graph.render :to => "#{WEBSITE_DIR}/stacking_test.svg"
91
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/stacking_test.png", :as => 'png' if $make_png
92
+ end
93
+
94
+ def test_multi_layered
95
+ graph = Scruffy::Graph.new
96
+ graph.title = "Some Kind of Information"
97
+ graph.renderer = Scruffy::Renderers::Cubed.new
98
+
99
+ graph.add :area, 'Jeff', [20, -5, 100, 70, 30, 106], :categories => [:top_left, :bottom_right]
100
+ graph.add :area, 'Jerry', [-10, 70, 20, 102, 201, 26], :categories => [:bottom_left, :buttom_right]
101
+ graph.add :bar, 'Jack', [30, 0, 49, 29, 100, 203], :categories => [:bottom_left, :top_right]
102
+ graph.add :line, 'Brasten', [42, 10, 75, 150, 130, 70], :categories => [:top_right, :bottom_left]
103
+ graph.add :line, 'Jim', [-10, -20, 50, 92, -21, 56], :categories => [:top_left, :bottom_right]
104
+ graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
105
+ graph.render :to => "#{WEBSITE_DIR}/multi_test.svg"
106
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/multi_test.png", :as => 'png' if $make_png
107
+ end
108
+
109
+ def test_scatter
110
+ graph = Scruffy::Graph.new
111
+ graph.title = "Some Kind of Information"
112
+ graph.renderer = Scruffy::Renderers::Standard.new
113
+
114
+ graph.add :scatter, 'Stephanie', {0 => 0, 1 => 1, 2 => 4, 3 => 9, 4 => 8, 5 => 10, 6 => 12, 7 => 3, 8 => 13}
115
+ graph.add :line, 'Artiom', {-3 => 2, 1.5 => 6, 2 => 4.5, 15 => -4}, :dots => true
116
+ graph.add :scatter, 'Sam', [[-3,15], [1.5,18], [2,9], [15,6]]
117
+ graph.render :to => "#{WEBSITE_DIR}/scatter_test.svg"
118
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/scatter_test.png", :as => 'png' if $make_png
119
+ end
120
+
121
+ def test_scatter_by_date
122
+ graph = Scruffy::Graph.new
123
+ graph.title = "Some Kind of Information"
124
+ graph.renderer = Scruffy::Renderers::Standard.new
125
+ graph.key_formatter = Scruffy::Formatters::Date.new("%H:%M")
126
+ h = {}
127
+ start = Time.local(2009, 1, 20, 12, 0, 0)
128
+ 30.times{|i| h[start + 60*i] = i*i}
129
+
130
+ graph.add :scatter, 'DNI', h
131
+ graph.render :to => "#{WEBSITE_DIR}/scatter_date_test.svg", :calculate_markers => true
132
+ graph.render :width => 500, :to => "#{WEBSITE_DIR}/scatter_date_test.png", :as => 'png' if $make_png
133
+ end
134
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/scruffy'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jagthedrummer-scruffy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.9
5
+ platform: ruby
6
+ authors:
7
+ - Brasten Sager
8
+ - Jeremy Green
9
+ - samhendley
10
+ - delano
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2009-01-22 21:00:00 -08:00
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: builder
20
+ type: :runtime
21
+ version_requirement:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ version:
28
+ description: Scruffy is a Ruby library for generating high quality, good looking graphs. It is designed to be easy to use and highly customizable.
29
+ email:
30
+ - brasten@nagilum.com
31
+ - david.parry@suranyami.com
32
+ executables: []
33
+
34
+ extensions: []
35
+
36
+ extra_rdoc_files: []
37
+
38
+ files:
39
+ - lib/scruffy/rasterizers/rmagick_rasterizer.rb
40
+ - lib/scruffy/rasterizers/batik_rasterizer.rb
41
+ - lib/scruffy/version.rb
42
+ - lib/scruffy/layers/base.rb
43
+ - lib/scruffy/layers/area.rb
44
+ - lib/scruffy/layers/stacked.rb
45
+ - lib/scruffy/layers/pie_slice.rb
46
+ - lib/scruffy/layers/scatter.rb
47
+ - lib/scruffy/layers/bar.rb
48
+ - lib/scruffy/layers/sparkline_bar.rb
49
+ - lib/scruffy/layers/pie.rb
50
+ - lib/scruffy/layers/all_smiles.rb
51
+ - lib/scruffy/layers/average.rb
52
+ - lib/scruffy/layers/line.rb
53
+ - lib/scruffy/rasterizers.rb
54
+ - lib/scruffy/renderers.rb
55
+ - lib/scruffy/themes.rb
56
+ - lib/scruffy/helpers/canvas.rb
57
+ - lib/scruffy/helpers/point_container.rb
58
+ - lib/scruffy/helpers/layer_container.rb
59
+ - lib/scruffy/helpers/meta.rb
60
+ - lib/scruffy/helpers/marker_helper.rb
61
+ - lib/scruffy/components.rb
62
+ - lib/scruffy/graph_state.rb
63
+ - lib/scruffy/components/style_info.rb
64
+ - lib/scruffy/components/value_markers.rb
65
+ - lib/scruffy/components/viewport.rb
66
+ - lib/scruffy/components/base.rb
67
+ - lib/scruffy/components/graphs.rb
68
+ - lib/scruffy/components/background.rb
69
+ - lib/scruffy/components/legend.rb
70
+ - lib/scruffy/components/data_markers.rb
71
+ - lib/scruffy/components/label.rb
72
+ - lib/scruffy/components/grid.rb
73
+ - lib/scruffy/components/title.rb
74
+ - lib/scruffy/graph.rb
75
+ - lib/scruffy/renderers/sparkline.rb
76
+ - lib/scruffy/renderers/base.rb
77
+ - lib/scruffy/renderers/reversed.rb
78
+ - lib/scruffy/renderers/split.rb
79
+ - lib/scruffy/renderers/cubed3d.rb
80
+ - lib/scruffy/renderers/standard.rb
81
+ - lib/scruffy/renderers/pie.rb
82
+ - lib/scruffy/renderers/empty.rb
83
+ - lib/scruffy/renderers/cubed.rb
84
+ - lib/scruffy/formatters.rb
85
+ - lib/scruffy/helpers.rb
86
+ - lib/scruffy/layers.rb
87
+ - lib/scruffy.rb
88
+ - LICENCE.txt
89
+ - README.txt
90
+ - CHANGES.txt
91
+ - Manifest.txt
92
+ has_rdoc: true
93
+ homepage: http://scruffy.rubyforge.org
94
+ licenses:
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --quiet
98
+ - --title
99
+ - scruffy documentation
100
+ - --opname
101
+ - index.html
102
+ - --line-numbers
103
+ - --main
104
+ - README.txt
105
+ - --inline-source
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ version:
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: "0"
119
+ version:
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.3.5
124
+ signing_key:
125
+ specification_version: 2
126
+ summary: A powerful, clean graphing library for Ruby.
127
+ test_files:
128
+ - test/graph_creation_test.rb
129
+ - test/test_helper.rb