suranyami-tuftify 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +2 -2
  2. data/lib/tuftify/graph.rb +55 -15
  3. data/tuftify.gemspec +1 -1
  4. metadata +1 -1
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'hoe'
5
5
  require 'echoe'
6
6
  require 'tuftify'
7
7
 
8
- Echoe.new('tuftify', '0.1.1') do |p|
8
+ Echoe.new('tuftify', '0.1.2') do |p|
9
9
  p.description = 'A graphing library.'
10
10
  p.url = 'http://github.com/suranyami/tuftify'
11
11
  p.author = ["David Parry", "Ingrid Anzola"]
@@ -21,6 +21,6 @@ task :sample do
21
21
  (1..10).each {|i| values << [i, rand(100)]}
22
22
  g = Tuftify::Graph.new(500, 300, values)
23
23
  canvas = g.draw
24
- canvas.write('sample.jpg')
24
+ canvas.write('samples/sample.jpg')
25
25
  end
26
26
 
data/lib/tuftify/graph.rb CHANGED
@@ -6,32 +6,72 @@ module Tuftify
6
6
  class Graph
7
7
  include Magick
8
8
  attr_accessor :width, :height, :values
9
+ attr_accessor :font_size, :resolution
10
+ attr_accessor :canvas
9
11
 
10
12
  def initialize(width, height, values = nil)
11
13
  @width = width
12
14
  @height = height
13
15
  @values = values
16
+ @font_size = 9
17
+ @resolution = 72.0
18
+ d = "#{@resolution}x#{@resolution}"
19
+
20
+ @canvas = Magick::Image.new(@width, @height) {
21
+ self.background_color = 'white'
22
+ self.density = d
23
+ }
24
+
25
+ @drawing = Magick::Draw.new
26
+ @drawing.font_family = 'Helvetica'
27
+ @drawing.fill = 'black'
28
+ @drawing.pointsize = 12
29
+ @drawing.gravity = NorthGravity
14
30
  end
15
31
 
16
32
  def draw
17
- canvas = Magick::ImageList.new
18
- canvas.new_image(@width, @height) { self.background_color = 'white'}
19
33
  max_value = @values.collect {|v| v[1]}.max
20
-
21
34
  barwidth = @width / @values.length
22
-
23
- upper_left_x = 0
24
-
35
+ x = 0
36
+ lh = label_height
37
+ draw_height = @height - lh
25
38
  @values.each do |key, value|
26
- rect = Magick::Draw.new
27
- h = @height / max_value * value
28
- rect.fill('white')
29
- rect.stroke('black')
30
- rect.rectangle(upper_left_x, @height, upper_left_x + barwidth, @height - h)
31
- upper_left_x += barwidth
32
- rect.draw(canvas)
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
33
45
  end
34
- return canvas
46
+ @drawing.draw(@canvas)
47
+ return @canvas
48
+ end
49
+
50
+ def label_height
51
+ h = 0
52
+ @values.each {|key, value|
53
+
54
+ m = @drawing.get_type_metrics(key.to_s)
55
+ h = m.height if m.height > h
56
+ }
57
+ return h
35
58
  end
36
59
  end
37
- end
60
+ end
61
+ #
62
+ #
63
+ # if !@labels[index].nil? && @labels_seen[index].nil?
64
+ # y_offset = @graph_bottom + LABEL_MARGIN
65
+ #
66
+ # @d.fill = @font_color
67
+ # @d.font = @font if @font
68
+ # @d.stroke('transparent')
69
+ # @d.font_weight = NormalWeight
70
+ # @d.pointsize = scale_fontsize(@marker_font_size)
71
+ # @d.gravity = NorthGravity
72
+ # @d = @d.annotate_scaled(@base_image,
73
+ # 1.0, 1.0,
74
+ # x_offset, y_offset,
75
+ # @labels[index], @scale)
76
+ # @labels_seen[index] = 1
77
+ # debug { @d.line 0.0, y_offset, @raw_columns, y_offset }
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.1"
5
+ s.version = "0.1.2"
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Parry, Ingrid Anzola