suranyami-tuftify 0.1.4 → 0.1.5

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/README CHANGED
@@ -1,4 +1,6 @@
1
1
  = Tuftify
2
2
 
3
- A graphing library.
3
+ A wonderful graphing library.
4
4
 
5
+ A testing from ianzola
6
+ This is a test.
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, values)
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
 
@@ -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, values)
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 'rubygems'
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
- attr_accessor :width, :height, :values
7
+
8
+ attr_accessor :width, :height
9
9
  attr_accessor :font_size, :resolution
10
10
  attr_accessor :canvas
11
-
12
- def initialize(width, height, values = nil)
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
- @drawing = Magick::Draw.new
26
- @drawing.font_family = 'Helvetica'
27
- @drawing.fill = 'black'
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
- max_value = @values.collect {|v| v[1]}.max
34
- barwidth = @width / @values.length
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
- m = @drawing.get_type_metrics(key.to_s)
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
@@ -1,2 +1,5 @@
1
+ require 'rubygems'
2
+ require 'RMagick'
3
+
1
4
  require 'tuftify'
2
5
  require 'tuftify/graph'
data/tuftify.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tuftify}
5
- s.version = "0.1.4"
5
+ s.version = "0.1.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["David Parry, Ingrid Anzola"]
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
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.2.0
77
+ rubygems_version: 1.3.5
77
78
  signing_key:
78
79
  specification_version: 3
79
80
  summary: A graphing library.