gruff 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +9 -2
- data/lib/gruff.rb +6 -4
- data/lib/gruff/bar.rb +47 -2
- data/lib/gruff/base.rb +12 -7
- data/rakefile +1 -1
- data/test/bar_test.rb +76 -0
- data/test/line_test.rb +1 -1
- metadata +3 -15
- data/test/output/line_37signals.png +0 -0
- data/test/output/line_37signals_small.png +0 -0
- data/test/output/line_font.png +0 -0
- data/test/output/line_keynote.png +0 -0
- data/test/output/line_keynote_small.png +0 -0
- data/test/output/line_large.png +0 -0
- data/test/output/line_many.png +0 -0
- data/test/output/line_odeo.png +0 -0
- data/test/output/line_odeo_small.png +0 -0
- data/test/output/line_rails_keynote.png +0 -0
- data/test/output/line_rails_keynote_small.png +0 -0
- data/test/output/line_small.png +0 -0
- data/test/output/similar_high_end_values.png +0 -0
data/CHANGELOG
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
|
3
|
+
== 0.0.2
|
4
|
+
|
5
|
+
* Fixed to_blob (thanks to Carlos Villela)
|
6
|
+
* Added bar graphs (initial functionality...will be enhanced)
|
7
|
+
* Removed rendered test output from gem
|
8
|
+
|
9
|
+
|
3
10
|
== 0.0.1
|
4
11
|
|
5
|
-
Initial release.
|
6
|
-
Line graphs only. Other graph styles coming soon.
|
12
|
+
* Initial release.
|
13
|
+
* Line graphs only. Other graph styles coming soon.
|
data/lib/gruff.rb
CHANGED
data/lib/gruff/bar.rb
CHANGED
@@ -4,11 +4,56 @@ require 'gruff/base'
|
|
4
4
|
module Gruff
|
5
5
|
class Bar < Base
|
6
6
|
|
7
|
-
# TODO Not yet implemented.
|
8
7
|
def draw
|
9
8
|
super
|
10
9
|
|
11
|
-
|
10
|
+
# Setup spacing.
|
11
|
+
#
|
12
|
+
# Columns sit side-by-side.
|
13
|
+
@bar_width = @graph_width / (@column_count * @data.length).to_f
|
14
|
+
|
15
|
+
@d = @d.stroke_opacity 0.0
|
16
|
+
|
17
|
+
@norm_data.each_with_index do |data_row, row_index|
|
18
|
+
@d = @d.fill current_color
|
19
|
+
|
20
|
+
data_row[1].each_with_index do |data_point, point_index|
|
21
|
+
# Use incremented x and scaled y
|
22
|
+
left_x = @graph_left + (@bar_width * (row_index + point_index + ((@data.length - 1) * point_index)))
|
23
|
+
left_y = @graph_top + (@graph_height - data_point * @graph_height)
|
24
|
+
right_x = left_x + @bar_width
|
25
|
+
right_y = @graph_top + @graph_height - 1
|
26
|
+
|
27
|
+
@d = @d.rectangle(left_x, left_y, right_x, right_y)
|
28
|
+
|
29
|
+
# TODO Calculate center based on bar_width and current row
|
30
|
+
#draw_label(left_x, index)
|
31
|
+
end
|
32
|
+
|
33
|
+
increment_color()
|
34
|
+
end
|
35
|
+
|
36
|
+
@d.draw(@base_image)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Draws column labels below graph, centered under entire block
|
42
|
+
def draw_label(x_offset, index)
|
43
|
+
# TODO
|
44
|
+
if !@labels[index].nil? && @labels_seen[index].nil?
|
45
|
+
@d.fill = @marker_color
|
46
|
+
@d.font = @font
|
47
|
+
@d.stroke = 'transparent'
|
48
|
+
@d.font_weight = NormalWeight
|
49
|
+
@d.pointsize = scale_fontsize(@marker_pointsize)
|
50
|
+
@d.gravity = CenterGravity
|
51
|
+
@d = @d.annotate_scaled(@base_image,
|
52
|
+
1, 1,
|
53
|
+
x_offset, @raw_rows - 80,
|
54
|
+
@labels[index], @scale)
|
55
|
+
@labels_seen[index] = 1
|
56
|
+
end
|
12
57
|
end
|
13
58
|
|
14
59
|
end
|
data/lib/gruff/base.rb
CHANGED
@@ -7,12 +7,15 @@
|
|
7
7
|
#
|
8
8
|
#
|
9
9
|
|
10
|
-
|
11
|
-
require '
|
10
|
+
begin
|
11
|
+
require 'rmagick'
|
12
|
+
rescue LoadError
|
13
|
+
require 'RMagick' # capitalized on Windows
|
14
|
+
end
|
12
15
|
|
13
16
|
module Gruff
|
14
17
|
|
15
|
-
VERSION = '0.0.
|
18
|
+
VERSION = '0.0.2'
|
16
19
|
|
17
20
|
class Base
|
18
21
|
|
@@ -172,10 +175,12 @@ module Gruff
|
|
172
175
|
@base_image.write(filename)
|
173
176
|
end
|
174
177
|
|
175
|
-
#
|
176
|
-
def to_blob(
|
178
|
+
# Return the graph as a rendered binary blob.
|
179
|
+
def to_blob(fileformat='PNG')
|
177
180
|
draw()
|
178
|
-
|
181
|
+
return @base_image.to_blob do
|
182
|
+
self.format=fileformat
|
183
|
+
end
|
179
184
|
end
|
180
185
|
|
181
186
|
protected
|
@@ -217,7 +222,7 @@ protected
|
|
217
222
|
# Draws horizontal background lines and labels
|
218
223
|
def draw_line_markers
|
219
224
|
@graph_left = 130.0
|
220
|
-
@graph_right = @raw_columns - 100.0
|
225
|
+
@graph_right = @raw_columns - 100.0 # TODO Make wider
|
221
226
|
@graph_top = 150.0
|
222
227
|
@graph_bottom = @raw_rows - 110.0
|
223
228
|
@graph_height = @graph_bottom - @graph_top
|
data/rakefile
CHANGED
@@ -61,7 +61,7 @@ spec = Gem::Specification.new do |s|
|
|
61
61
|
|
62
62
|
s.files = [ "rakefile", "README", "CHANGELOG", "MIT-LICENSE" ]
|
63
63
|
s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
64
|
-
s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
64
|
+
s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) || item.include?("\.png") }
|
65
65
|
end
|
66
66
|
|
67
67
|
Rake::GemPackageTask.new(spec) do |p|
|
data/test/bar_test.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift(File.dirname(__FILE__) + "/../lib/")
|
4
|
+
#$:.unshift File.dirname(__FILE__) + "/fixtures/helpers"
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'gruff'
|
8
|
+
|
9
|
+
class TestGruffBar < Test::Unit::TestCase
|
10
|
+
|
11
|
+
# TODO Delete old output files once when starting tests
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@datasets = [
|
15
|
+
[:Jimmy, [25, 36, 86, 39]],
|
16
|
+
[:Charles, [80, 54, 67, 54]],
|
17
|
+
[:Julie, [22, 29, 35, 38]],
|
18
|
+
#[:Jane, [95, 95, 95, 90, 85, 80, 88, 100]],
|
19
|
+
#[:Philip, [90, 34, 23, 12, 78, 89, 98, 88]],
|
20
|
+
#["Arthur", [5, 10, 13, 11, 6, 16, 22, 32]],
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_bar_graph
|
25
|
+
g = Gruff::Bar.new
|
26
|
+
g.title = "Visual Multi-Line Bar Graph Test"
|
27
|
+
g.labels = {
|
28
|
+
0 => '5/6',
|
29
|
+
2 => '5/15',
|
30
|
+
4 => '5/24',
|
31
|
+
6 => '5/30',
|
32
|
+
}
|
33
|
+
@datasets.each do |data|
|
34
|
+
g.data(data[0], data[1])
|
35
|
+
end
|
36
|
+
|
37
|
+
g.write("test/output/bar_keynote.png")
|
38
|
+
|
39
|
+
g.theme_37signals
|
40
|
+
g.write("test/output/bar_37signals.png")
|
41
|
+
|
42
|
+
g.theme_rails_keynote
|
43
|
+
g.write("test/output/bar_rails_keynote.png")
|
44
|
+
|
45
|
+
g.theme_odeo
|
46
|
+
g.write("test/output/bar_odeo.png")
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def test_bar_graph_small
|
51
|
+
g = Gruff::Bar.new(400)
|
52
|
+
g.title = "Visual Multi-Line Bar Graph Test"
|
53
|
+
g.labels = {
|
54
|
+
0 => '5/6',
|
55
|
+
2 => '5/15',
|
56
|
+
4 => '5/24',
|
57
|
+
6 => '5/30',
|
58
|
+
}
|
59
|
+
@datasets.each do |data|
|
60
|
+
g.data(data[0], data[1])
|
61
|
+
end
|
62
|
+
|
63
|
+
g.write("test/output/bar_keynote_small.png")
|
64
|
+
|
65
|
+
g.theme_37signals
|
66
|
+
g.write("test/output/bar_37signals_small.png")
|
67
|
+
|
68
|
+
g.theme_rails_keynote
|
69
|
+
g.write("test/output/bar_rails_keynote_small.png")
|
70
|
+
|
71
|
+
g.theme_odeo
|
72
|
+
g.write("test/output/bar_odeo_small.png")
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end
|
data/test/line_test.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: gruff
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2005-10-
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2005-10-26 00:00:00 -07:00
|
8
8
|
summary: Beautiful graphs for one or multiple datasets.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -40,21 +40,9 @@ files:
|
|
40
40
|
- lib/gruff/base.rb
|
41
41
|
- lib/gruff/line.rb
|
42
42
|
- lib/gruff/pie.rb
|
43
|
+
- test/bar_test.rb
|
43
44
|
- test/line_test.rb
|
44
45
|
- test/output
|
45
|
-
- test/output/line_37signals.png
|
46
|
-
- test/output/line_37signals_small.png
|
47
|
-
- test/output/line_font.png
|
48
|
-
- test/output/line_keynote.png
|
49
|
-
- test/output/line_keynote_small.png
|
50
|
-
- test/output/line_large.png
|
51
|
-
- test/output/line_many.png
|
52
|
-
- test/output/line_odeo.png
|
53
|
-
- test/output/line_odeo_small.png
|
54
|
-
- test/output/line_rails_keynote.png
|
55
|
-
- test/output/line_rails_keynote_small.png
|
56
|
-
- test/output/line_small.png
|
57
|
-
- test/output/similar_high_end_values.png
|
58
46
|
test_files: []
|
59
47
|
rdoc_options: []
|
60
48
|
extra_rdoc_files: []
|
Binary file
|
Binary file
|
data/test/output/line_font.png
DELETED
Binary file
|
Binary file
|
Binary file
|
data/test/output/line_large.png
DELETED
Binary file
|
data/test/output/line_many.png
DELETED
Binary file
|
data/test/output/line_odeo.png
DELETED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/output/line_small.png
DELETED
Binary file
|
Binary file
|