suranyami-tuftify 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -1
- data/Rakefile +5 -3
- data/lib/playing_around.rb +3 -2
- data/lib/tuftify/graph.rb +18 -34
- data/lib/tuftify.rb +3 -0
- data/tuftify.gemspec +1 -1
- metadata +3 -2
data/README
CHANGED
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rake'
|
|
3
3
|
$:.unshift(File.dirname(__FILE__) + "/lib")
|
4
4
|
require 'hoe'
|
5
5
|
require 'echoe'
|
6
|
-
require 'tuftify'
|
6
|
+
require 'lib/tuftify'
|
7
7
|
|
8
8
|
Echoe.new('tuftify', '0.1.4') do |p|
|
9
9
|
p.description = 'A graphing library.'
|
@@ -18,9 +18,11 @@ end
|
|
18
18
|
desc "Generate a sample file, to test that it's working."
|
19
19
|
task :sample do
|
20
20
|
values = []
|
21
|
-
(1..10).each {|i| values << [i, rand(100)]}
|
22
|
-
g = Tuftify::Graph.new(500, 300
|
21
|
+
(1..10).each {|i| values << ["key #{i}", rand(100)]}
|
22
|
+
g = Tuftify::Graph.new(500, 300)
|
23
|
+
g.add_layer(values)
|
23
24
|
canvas = g.draw
|
25
|
+
FileUtils.mkdir 'samples' if !File..directory?('samples')
|
24
26
|
canvas.write('samples/sample.jpg')
|
25
27
|
end
|
26
28
|
|
data/lib/playing_around.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'RMagick'
|
3
|
-
require 'graph'
|
3
|
+
require 'tuftify/graph'
|
4
4
|
|
5
5
|
include Magick
|
6
6
|
|
7
7
|
values = []
|
8
8
|
(1..10).each {|i| values << [i, rand(100)]}
|
9
9
|
|
10
|
-
g = Graph.new(500, 300
|
10
|
+
g = Tuftify::Graph.new(500, 300)
|
11
|
+
g.add_layer(values,{:categories => ['uno','dos','tres','cuatro','cinco','seis','siete','ocho','nueve','diez']})
|
11
12
|
canvas = g.draw
|
12
13
|
|
13
14
|
canvas.write('rectangle.jpg')
|
data/lib/tuftify/graph.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
require '
|
2
|
-
require 'RMagick'
|
1
|
+
require 'tuftify/graph_layer'
|
3
2
|
|
4
3
|
module Tuftify
|
5
4
|
# Basic Graph class.
|
6
5
|
class Graph
|
7
6
|
include Magick
|
8
|
-
|
7
|
+
|
8
|
+
attr_accessor :width, :height
|
9
9
|
attr_accessor :font_size, :resolution
|
10
10
|
attr_accessor :canvas
|
11
|
-
|
12
|
-
|
11
|
+
attr_accessor :title
|
12
|
+
|
13
|
+
|
14
|
+
def initialize(width, height)
|
13
15
|
@width = width
|
14
16
|
@height = height
|
15
|
-
@values = values
|
16
17
|
@font_size = 9
|
17
18
|
@resolution = 72.0
|
18
19
|
d = "#{@resolution}x#{@resolution}"
|
@@ -22,40 +23,23 @@ module Tuftify
|
|
22
23
|
self.density = d
|
23
24
|
}
|
24
25
|
|
25
|
-
@
|
26
|
-
|
27
|
-
@
|
28
|
-
@drawing.pointsize = 12
|
29
|
-
@drawing.gravity = NorthGravity
|
26
|
+
@details = {:canvas => @canvas, :height => height, :width => width}
|
27
|
+
|
28
|
+
@graph_layer = []
|
30
29
|
end
|
31
30
|
|
31
|
+
def add_layer(data, options = {})
|
32
|
+
@graph_layer << Tuftify::GraphLayer.new(data, @details, options)
|
33
|
+
end
|
34
|
+
|
32
35
|
def draw
|
33
|
-
|
34
|
-
|
35
|
-
x = 0
|
36
|
-
lh = label_height
|
37
|
-
draw_height = @height - lh
|
38
|
-
@values.each do |key, value|
|
39
|
-
h = draw_height / max_value * value
|
40
|
-
@drawing.fill('black')
|
41
|
-
@drawing.stroke('white')
|
42
|
-
@drawing.rectangle(x, draw_height, x + barwidth, draw_height - h)
|
43
|
-
@drawing.annotate(@canvas, barwidth, lh, x, draw_height, key.to_s)
|
44
|
-
x += barwidth
|
36
|
+
@graph_layer.each do |layer|
|
37
|
+
layer.draw
|
45
38
|
end
|
46
|
-
@drawing.draw(@canvas)
|
47
|
-
return @canvas
|
48
|
-
end
|
49
|
-
|
50
|
-
def label_height
|
51
|
-
h = 0
|
52
|
-
@values.each {|key, value|
|
53
39
|
|
54
|
-
|
55
|
-
h = m.height if m.height > h
|
56
|
-
}
|
57
|
-
return h
|
40
|
+
return @canvas
|
58
41
|
end
|
42
|
+
|
59
43
|
end
|
60
44
|
end
|
61
45
|
#
|
data/lib/tuftify.rb
CHANGED
data/tuftify.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: suranyami-tuftify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Parry, Ingrid Anzola
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- tuftify.gemspec
|
49
49
|
has_rdoc: false
|
50
50
|
homepage: http://github.com/suranyami/tuftify
|
51
|
+
licenses:
|
51
52
|
post_install_message:
|
52
53
|
rdoc_options:
|
53
54
|
- --line-numbers
|
@@ -73,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
74
|
requirements: []
|
74
75
|
|
75
76
|
rubyforge_project: tuftify
|
76
|
-
rubygems_version: 1.
|
77
|
+
rubygems_version: 1.3.5
|
77
78
|
signing_key:
|
78
79
|
specification_version: 3
|
79
80
|
summary: A graphing library.
|