gruff 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,11 @@
1
1
  CHANGELOG
2
2
 
3
+ == 0.2.8
4
+
5
+ * New accumulator bar graph (experimental)
6
+ * Better mini graphs
7
+ * Bug fixes
8
+
3
9
  == 0.2.7
4
10
 
5
11
  * Regenerated Manifest.txt
data/Manifest.txt CHANGED
@@ -30,6 +30,7 @@ lib/gruff.rb
30
30
  lib/gruff/area.rb
31
31
  lib/gruff/bar.rb
32
32
  lib/gruff/bar_conversion.rb
33
+ lib/gruff/accumulator_bar.rb
33
34
  lib/gruff/base.rb
34
35
  lib/gruff/deprecated.rb
35
36
  lib/gruff/line.rb
@@ -48,6 +49,7 @@ lib/gruff/mini/side_bar.rb
48
49
  test/gruff_test_case.rb
49
50
  test/output
50
51
  test/test_area.rb
52
+ test/test_accumulator_bar.rb
51
53
  test/test_bar.rb
52
54
  test/test_base.rb
53
55
  test/test_legend.rb
data/lib/gruff.rb CHANGED
@@ -11,6 +11,7 @@
11
11
  stacked_bar
12
12
  side_stacked_bar
13
13
  side_bar
14
+ accumulator_bar
14
15
 
15
16
  scene
16
17
 
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+
3
+ ##
4
+ # A special bar graph that shows a single dataset as a set of
5
+ # stacked bars. The bottom bar shows the running total and
6
+ # the top bar shows the new value being added to the array.
7
+
8
+ class Gruff::AccumulatorBar < Gruff::StackedBar
9
+
10
+ def draw
11
+ raise(Gruff::IncorrectNumberOfDatasetsException) unless @data.length == 1
12
+
13
+ accumulator_array = []
14
+ index = 0
15
+
16
+ increment_array = @data.first[DATA_VALUES_INDEX].inject([]) {|memo, value|
17
+ memo << ((index > 0) ? (value + memo.max) : value)
18
+ accumulator_array << memo[index] - value
19
+ index += 1
20
+ memo
21
+ }
22
+ data "Accumulator", accumulator_array
23
+
24
+ super
25
+ end
26
+
27
+ end
data/lib/gruff/base.rb CHANGED
@@ -20,7 +20,7 @@ require File.dirname(__FILE__) + '/deprecated'
20
20
 
21
21
  module Gruff
22
22
 
23
- VERSION = '0.2.7'
23
+ VERSION = '0.2.8'
24
24
 
25
25
  class Base
26
26
 
@@ -88,6 +88,9 @@ module Gruff
88
88
  # Message shown when there is no data. Fits up to 20 characters. Defaults to "No Data."
89
89
  attr_accessor :no_data_message
90
90
 
91
+ # The font size of the large title at the top of the graph
92
+ attr_accessor :title_font_size
93
+
91
94
  # Optionally set the size of the font. Based on an 800x600px graph. Default is 20.
92
95
  #
93
96
  # Will be scaled down if graph is smaller than 800px wide.
@@ -102,8 +105,6 @@ module Gruff
102
105
  # The number of horizontal lines shown for reference
103
106
  attr_accessor :marker_count
104
107
 
105
- # The font size of the large title at the top of the graph
106
- attr_accessor :title_font_size
107
108
 
108
109
  # You can manually set a minimum value instead of having the values guessed for you.
109
110
  #
@@ -754,14 +755,26 @@ protected
754
755
  # Creates a @base_image to draw on.
755
756
  #
756
757
  def render_background
757
- if not @theme_options[:background_colors].nil?
758
+ case @theme_options[:background_colors]
759
+ when Array
758
760
  @base_image = render_gradiated_background(*@theme_options[:background_colors])
761
+ when String
762
+ @base_image = render_solid_background(@theme_options[:background_colors])
759
763
  else
760
764
  @base_image = render_image_background(*@theme_options[:background_image])
761
765
  end
762
766
  end
763
767
 
764
- # Use with a theme definition method to draw a gradiated (or solid color) background.
768
+ ##
769
+ # Make a new image at the current size with a solid +color+.
770
+
771
+ def render_solid_background(color)
772
+ Image.new(@columns, @rows) {
773
+ self.background_color = color
774
+ }
775
+ end
776
+
777
+ # Use with a theme definition method to draw a gradiated background.
765
778
  def render_gradiated_background(top_color, bottom_color)
766
779
  Image.new(@columns, @rows,
767
780
  GradientFill.new(0, 0, 100, 0, top_color, bottom_color))
@@ -862,6 +875,11 @@ protected
862
875
  total_sum
863
876
  end
864
877
 
878
+ ##
879
+ # Used by StackedBar and child classes.
880
+ #
881
+ # May need to be moved to the StackedBar class.
882
+
865
883
  def get_maximum_by_stack
866
884
  # Get sum of each stack
867
885
  max_hash = {}
@@ -872,7 +890,7 @@ protected
872
890
  end
873
891
  end
874
892
 
875
- @maximum_value = 0
893
+ # @maximum_value = 0
876
894
  max_hash.keys.each do |key|
877
895
  @maximum_value = max_hash[key] if max_hash[key] > @maximum_value
878
896
  end
@@ -915,7 +933,6 @@ private
915
933
  # Start over
916
934
  @color_index = 0
917
935
  return @colors[-1]
918
- #raise(ColorlistExhaustedException, "There are no more colors left to use.")
919
936
  end
920
937
  end
921
938
  end
@@ -961,8 +978,8 @@ private
961
978
 
962
979
  end # Gruff::Base
963
980
 
964
- class ColorlistExhaustedException < StandardError; end
965
-
981
+ class IncorrectNumberOfDatasetsException < StandardError; end
982
+
966
983
  end # Gruff
967
984
 
968
985
 
@@ -14,7 +14,7 @@ module Gruff
14
14
  @hide_title = true
15
15
  @hide_line_numbers = true
16
16
 
17
- @marker_font_size = 40.0
17
+ @marker_font_size = 50.0
18
18
  @minimum_value = 0.0
19
19
  @legend_font_size = 60.0
20
20
 
@@ -13,7 +13,7 @@ module Gruff
13
13
  @hide_title = true
14
14
  @hide_line_numbers = true
15
15
 
16
- @marker_font_size = 40.0
16
+ @marker_font_size = 50.0
17
17
  end
18
18
 
19
19
  end
@@ -32,7 +32,7 @@ class Gruff::SideBar < Gruff::Base
32
32
  marker_label = diff.abs * increment
33
33
 
34
34
  unless @hide_line_numbers
35
- @d.fill = @marker_color
35
+ @d.fill = @font_color
36
36
  @d.font = @font if @font
37
37
  @d.stroke = 'transparent'
38
38
  @d.pointsize = scale_fontsize(@marker_font_size)
@@ -51,7 +51,7 @@ class Gruff::SideBar < Gruff::Base
51
51
 
52
52
  def draw_label(y_offset, index)
53
53
  if !@labels[index].nil? && @labels_seen[index].nil?
54
- @d.fill = @marker_color
54
+ @d.fill = @font_color
55
55
  @d.font = @font if @font
56
56
  @d.stroke = 'transparent'
57
57
  @d.font_weight = NormalWeight
@@ -108,6 +108,7 @@ protected
108
108
  g.title = "My Bar Graph"
109
109
  g.labels = @labels
110
110
 
111
+
111
112
  @datasets.each do |data|
112
113
  g.data(data[0], data[1])
113
114
  end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + "/gruff_test_case"
2
+
3
+ class TestGruffAccumulatorBar < GruffTestCase
4
+
5
+ # TODO Delete old output files once when starting tests
6
+
7
+ def setup
8
+ @datasets = [
9
+ (1..20).to_a.map { rand(10) }
10
+ ]
11
+ end
12
+
13
+ def test_accumulator
14
+ g = Gruff::AccumulatorBar.new 500
15
+ g.title = "Your Savings"
16
+ g.hide_legend = true
17
+
18
+ # g.font = File.expand_path(File.dirname(__FILE__) + "/../assets/fonts/ATMA____.TTF")
19
+
20
+ g.marker_font_size = 18
21
+
22
+ g.theme = {
23
+ :colors => ['#aedaa9', '#12a702'], # 3077a9 blue, aedaa9 light green
24
+ :marker_color => '#dddddd',
25
+ :font_color => 'black',
26
+ :background_colors => "white"
27
+ # :background_image => File.expand_path(File.dirname(__FILE__) + "/../assets/backgrounds/43things.png")
28
+ }
29
+
30
+ # Attempt at negative numbers
31
+ # g.data 'Savings', (1..20).to_a.map { rand(10) * (rand(2) > 0 ? 1 : -1) }
32
+ g.data 'Savings', (1..12).to_a.map { rand(100) }
33
+ g.labels = (0..11).to_a.inject({}) {|memo, index| {index => '12-26'}.merge(memo)}
34
+
35
+ g.maximum_value = 1000
36
+ g.minimum_value = 0
37
+
38
+ g.write("test/output/accum_bar.png")
39
+ end
40
+
41
+ def test_too_many_args
42
+ assert_raise(Gruff::IncorrectNumberOfDatasetsException) {
43
+ g = Gruff::AccumulatorBar.new
44
+ g.data 'First', [1,1,1]
45
+ g.data 'Too Many', [1,1,1]
46
+ g.write("test/output/_SHOULD_NOT_ACTUALLY_BE_WRITTEN.png")
47
+ }
48
+ end
49
+
50
+ end
data/test/test_bar.rb CHANGED
@@ -132,33 +132,6 @@ class TestGruffBar < GruffTestCase
132
132
  g.write("test/output/bar_x_y_labels.png")
133
133
  end
134
134
 
135
- def test_fireball
136
- g = Gruff::Bar.new
137
- g.title = "Daring Fireball-type Accumulation Graph"
138
- g.hide_line_numbers = true
139
-
140
- running_totals = []
141
- new_additions = []
142
-
143
- (0..19).each do |i|
144
- add = rand(10)
145
- case i
146
- when 0
147
- running_totals << 0
148
- new_additions << add
149
- else
150
- running_totals << new_additions[i-1]
151
- new_additions << running_totals[i-1] + add
152
- end
153
- end
154
-
155
- g.data '1', running_totals
156
- g.data '2', new_additions
157
-
158
- g.write("test/output/bar_fireball.png")
159
- end
160
-
161
-
162
135
  def test_wide_graph
163
136
  g = setup_basic_graph('800x400')
164
137
  g.title = "Wide Graph"
data/test/test_line.rb CHANGED
@@ -13,7 +13,7 @@ class TestGruffLine < GruffTestCase
13
13
 
14
14
  def test_one_value
15
15
  g = Gruff::Line.new
16
- g.title = "One Value Graph Test"
16
+ g.title = "One Value"
17
17
  g.labels = {
18
18
  0 => '1',
19
19
  1 => '2'
@@ -25,7 +25,7 @@ class TestGruffLine < GruffTestCase
25
25
 
26
26
  def test_one_value_array
27
27
  g = Gruff::Line.new
28
- g.title = "One Value Graph Test"
28
+ g.title = "One Value in an Array"
29
29
  g.labels = {
30
30
  0 => '1',
31
31
  1 => '2'
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: gruff
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.7
7
- date: 2006-11-03 00:00:00 -08:00
6
+ version: 0.2.8
7
+ date: 2006-11-06 00:00:00 -08:00
8
8
  summary: Beautiful graphs for one or multiple datasets.
9
9
  require_paths:
10
10
  - lib
@@ -62,6 +62,7 @@ files:
62
62
  - lib/gruff/area.rb
63
63
  - lib/gruff/bar.rb
64
64
  - lib/gruff/bar_conversion.rb
65
+ - lib/gruff/accumulator_bar.rb
65
66
  - lib/gruff/base.rb
66
67
  - lib/gruff/deprecated.rb
67
68
  - lib/gruff/line.rb
@@ -80,6 +81,7 @@ files:
80
81
  - test/gruff_test_case.rb
81
82
  - test/output
82
83
  - test/test_area.rb
84
+ - test/test_accumulator_bar.rb
83
85
  - test/test_bar.rb
84
86
  - test/test_base.rb
85
87
  - test/test_legend.rb