gruff 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,15 @@
1
1
  CHANGELOG
2
2
 
3
+ == 0.2.6
4
+
5
+ * Fixed missing side_bar.rb in Manifest.txt
6
+
7
+ == 0.2.5
8
+
9
+ * New mini graph types (Experimental)
10
+ * Marker lines can be different color than text labels
11
+ * Theme definition cleanup
12
+
3
13
  == 0.2.4
4
14
 
5
15
  * Added option to hide line numbers
data/Manifest.txt CHANGED
@@ -18,6 +18,7 @@ lib/gruff/scene.rb
18
18
  lib/gruff/side_stacked_bar.rb
19
19
  lib/gruff/spider.rb
20
20
  lib/gruff/stacked_bar.rb
21
+ lib/gruff/side_bar.rb
21
22
 
22
23
  lib/gruff/mini/bar.rb
23
24
  lib/gruff/mini/pie.rb
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.5'
23
+ VERSION = '0.2.6'
24
24
 
25
25
  class Base
26
26
 
@@ -12,8 +12,9 @@ module Gruff
12
12
  @hide_title = true
13
13
  @hide_line_numbers = true
14
14
 
15
- @marker_font_size = 40.0
15
+ @marker_font_size = 40.0
16
16
  super
17
+
17
18
  end
18
19
 
19
20
  end
@@ -0,0 +1,111 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+
3
+ ##
4
+ # EXPERIMENTAL
5
+ #
6
+ # Graph with horizontal bars instead of vertical.
7
+ #
8
+ # TODO SideStackedBar should probably inherit from this
9
+ # to consolidate the line marker drawing.
10
+ class Gruff::SideBar < Gruff::Base
11
+
12
+ # Instead of base class version, draws vertical background lines and label
13
+ def draw_line_markers
14
+
15
+ return if @hide_line_markers
16
+
17
+ # Draw horizontal line markers and annotate with numbers
18
+ @d = @d.stroke(@marker_color)
19
+ @d = @d.stroke_width 1
20
+ number_of_lines = 5
21
+
22
+ # TODO Round maximum marker value to a round number like 100, 0.1, 0.5, etc.
23
+ increment = significant(@maximum_value.to_f / number_of_lines)
24
+ (0..number_of_lines).each do |index|
25
+
26
+ line_diff = (@graph_right - @graph_left) / number_of_lines
27
+ x = @graph_right - (line_diff * index) - 1
28
+ @d = @d.line(x, @graph_bottom, x, @graph_top)
29
+
30
+ diff = index - number_of_lines
31
+ marker_label = diff.abs * increment
32
+
33
+ @d.fill = @marker_color
34
+ @d.font = @font if @font
35
+ @d.stroke = 'transparent'
36
+ @d.pointsize = scale_fontsize(@marker_font_size)
37
+ # @d.gravity = NorthGravity
38
+ @d = @d.annotate_scaled( @base_image,
39
+ 100, 20,
40
+ x - (@marker_font_size/1.5), @graph_bottom + 40,
41
+ marker_label.to_s, @scale)
42
+
43
+ end
44
+ end
45
+
46
+ # Instead of base class version, modified to enable us to draw on the Y axis instead of X
47
+ def draw_label(y_offset, index)
48
+ if !@labels[index].nil? && @labels_seen[index].nil?
49
+ @d.fill = @marker_color
50
+ @d.font = @font if @font
51
+ @d.stroke = 'transparent'
52
+ @d.font_weight = NormalWeight
53
+ @d.pointsize = scale_fontsize(@marker_font_size)
54
+ @d.gravity = CenterGravity
55
+ @d = @d.annotate_scaled(@base_image,
56
+ 1, 1,
57
+ @graph_left / 2, y_offset,
58
+ @labels[index], @scale)
59
+ @labels_seen[index] = 1
60
+ end
61
+ end
62
+
63
+ def draw
64
+ @has_left_labels = true
65
+ super
66
+
67
+ return unless @has_data
68
+
69
+ # Setup spacing.
70
+ #
71
+ # Columns sit stacked.
72
+ spacing_factor = 0.9
73
+
74
+ @bar_width = @graph_height / @column_count.to_f
75
+ @d = @d.stroke_opacity 0.0
76
+ height = Array.new(@column_count, 0)
77
+ length = Array.new(@column_count, @graph_left)
78
+
79
+ @norm_data.each_with_index do |data_row, row_index|
80
+ @d = @d.fill data_row[DATA_COLOR_INDEX]
81
+
82
+ data_row[1].each_with_index do |data_point, point_index|
83
+
84
+ ## using the original calcs from the stacked bar chart to get the difference between
85
+ ## part of the bart chart we wish to stack.
86
+ temp1 = @graph_left + (@graph_width -
87
+ data_point * @graph_width -
88
+ height[point_index]) + 1
89
+ temp2 = @graph_left + @graph_width - height[point_index] - 1
90
+ difference = temp2 - temp1
91
+
92
+ left_x = length[point_index] #+ 1
93
+ left_y = @graph_top + (@bar_width * point_index)
94
+ right_x = left_x + difference
95
+ right_y = left_y + @bar_width * spacing_factor
96
+ length[point_index] += difference
97
+ height[point_index] += (data_point * @graph_width - 2)
98
+
99
+ @d = @d.rectangle(left_x, left_y, right_x, right_y)
100
+
101
+ # Calculate center based on bar_width and current row
102
+ label_center = @graph_top + (@bar_width * point_index) + (@bar_width * spacing_factor / 2.0)
103
+ draw_label(label_center, point_index)
104
+ end
105
+
106
+ end
107
+
108
+ @d.draw(@base_image)
109
+ end
110
+
111
+ end
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
2
 
3
3
  require 'test/unit'
4
4
  require 'gruff'
5
- require 'test_timer'
5
+ # require 'test_timer'
6
6
 
7
7
  class GruffTestCase < Test::Unit::TestCase
8
8
 
@@ -9,10 +9,24 @@ class TestMiniBar < GruffTestCase
9
9
  write_test_file g, 'mini_bar.png'
10
10
  end
11
11
 
12
- def test_simple_bar_wide_dataset
13
- setup_wide_dataset
14
- g = setup_basic_graph(Gruff::Mini::Bar, 200)
15
- write_test_file g, 'mini_bar_wide_data.png'
16
- end
12
+ # def test_simple_bar_wide_dataset
13
+ # setup_wide_dataset
14
+ # g = setup_basic_graph(Gruff::Mini::Bar, 200)
15
+ # write_test_file g, 'mini_bar_wide_data.png'
16
+ # end
17
+ #
18
+ # def test_code_sample
19
+ # g = Gruff::Mini::Bar.new(200)
20
+ # g.data "Jim", [200, 500, 400]
21
+ # g.labels = { 0 => 'This Month', 1 => 'Average', 2 => 'Overall'}
22
+ # g.write "mini_bar_one_color.png"
23
+ #
24
+ # g = Gruff::Mini::Bar.new(200)
25
+ # g.data "Car", 200
26
+ # g.data "Food", 500
27
+ # g.data "Art", 1000
28
+ # g.data "Music", 16
29
+ # g.write "mini_bar_many_colors.png"
30
+ # end
17
31
 
18
32
  end
@@ -8,4 +8,13 @@ class TestMiniPie < GruffTestCase
8
8
  write_test_file g, 'mini_pie.png'
9
9
  end
10
10
 
11
+ # def test_code_sample
12
+ # g = Gruff::Mini::Pie.new(200)
13
+ # g.data "Car", 200
14
+ # g.data "Food", 500
15
+ # g.data "Art", 1000
16
+ # g.data "Music", 16
17
+ # g.write "mini_pie.png"
18
+ # end
19
+
11
20
  end
@@ -4,7 +4,6 @@ require File.dirname(__FILE__) + "/gruff_test_case"
4
4
  class TestSimpleSideBar < GruffTestCase
5
5
 
6
6
  def test_simple_side_bar
7
- @datasets = (1..5).map {|n| ['Auto', rand(11)]}
8
7
  g = setup_basic_graph(Gruff::Mini::SideBar, 200)
9
8
  write_test_file g, 'mini_side_bar.png'
10
9
  end
metadata CHANGED
@@ -3,7 +3,7 @@ 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.5
6
+ version: 0.2.6
7
7
  date: 2006-10-26 00:00:00 -07:00
8
8
  summary: Beautiful graphs for one or multiple datasets.
9
9
  require_paths:
@@ -49,6 +49,7 @@ files:
49
49
  - lib/gruff/side_stacked_bar.rb
50
50
  - lib/gruff/spider.rb
51
51
  - lib/gruff/stacked_bar.rb
52
+ - lib/gruff/side_bar.rb
52
53
  - lib/gruff/mini/bar.rb
53
54
  - lib/gruff/mini/pie.rb
54
55
  - lib/gruff/mini/side_bar.rb