suranyami-tuftify 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -2,6 +2,13 @@ CHANGELOG
2
2
  init.rb
3
3
  lib/playing_around.rb
4
4
  lib/tuftify/graph.rb
5
+ lib/tuftify/graph_layer.rb
6
+ lib/tuftify/graph_area_panel.rb
7
+ lib/tuftify/bar_graph.rb
8
+ lib/tuftify/category_axis.rb
9
+ lib/tuftify/data_ppoint.rb
10
+ lib/tuftify/panel.rb
11
+ lib/tuftify/title_panel.rb
5
12
  lib/tuftify.rb
6
13
  Manifest
7
14
  Rakefile
@@ -0,0 +1,30 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Tuttify
5
+ class BarGraph < Graph
6
+ def initialize
7
+
8
+ end
9
+
10
+ def draw
11
+ max_value = @values.collect {|v| v[1]}.max
12
+ barwidth = @width / @values.length
13
+ x = 0
14
+ lh = label_height
15
+ draw_height = @height - lh
16
+ @values.each do |key, value|
17
+ h = draw_height / max_value * value
18
+ @drawing.fill('black')
19
+ @drawing.stroke('white')
20
+ @drawing.rectangle(x, draw_height, x + barwidth, draw_height - h)
21
+ @drawing.annotate(@canvas, barwidth, lh, x, draw_height, key.to_s)
22
+ x += barwidth
23
+ end
24
+ @drawing.draw(@canvas)
25
+ return @canvas
26
+ end
27
+
28
+
29
+ end
30
+ end
@@ -0,0 +1,58 @@
1
+ require 'jcode'
2
+
3
+ module Tuftify
4
+ class CategoryAxis < Tuftify::Panel
5
+ def initialize(categories,x_orig,height,details,barwidth,options)
6
+
7
+ @categories = categories
8
+
9
+ super x_orig, details[:height]-height, details[:width], height, details[:canvas], options
10
+ @drawing.pointsize = @options[:categories_pointsize]
11
+ @label_height = label_height
12
+ @height = @label_height
13
+ @y = details[:height] - @height
14
+ @barwidth = barwidth
15
+
16
+ end
17
+
18
+ def draw
19
+ x = @x
20
+ @drawing.fill_opacity(0)
21
+
22
+ @categories.each do |category|
23
+
24
+ @drawing.annotate(@canvas, @barwidth, @label_height, x, @y, category){
25
+ self.rotation = 315
26
+ self.gravity = Magick::CenterGravity
27
+ }
28
+
29
+ # @drawing.stroke('red')
30
+ # @drawing.stroke_width(3)
31
+ # @drawing.rectangle(x,@y,@barwidth,@y+@label_height)
32
+ # @drawing.draw(@canvas)
33
+ x += @barwidth
34
+ end
35
+
36
+ end
37
+
38
+ def label_height
39
+ h = 0
40
+ l = ""
41
+ x = ""
42
+ @categories.each {|label|
43
+
44
+ m = label.length
45
+ l = label if m > h
46
+ h = m if m > h
47
+
48
+ }
49
+
50
+ l.each_char { |c| x << "#{c}\n" }
51
+ h = @drawing.get_multiline_type_metrics(x)
52
+
53
+ return h.height
54
+ end
55
+
56
+
57
+ end
58
+ end
@@ -0,0 +1,15 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Tuftify
5
+ class DataPoint
6
+
7
+ attr_accesor :label
8
+ attr_accesor :value
9
+ attr_accesor :rectangle
10
+
11
+ def initialize
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,61 @@
1
+ require 'tuftify/graph_layer'
2
+
3
+ module Tuftify
4
+ # Basic Graph class.
5
+ class Graph
6
+ include Magick
7
+
8
+ attr_accessor :width, :height
9
+ attr_accessor :font_size, :resolution
10
+ attr_accessor :canvas
11
+ attr_accessor :title
12
+
13
+
14
+ def initialize(width, height)
15
+ @width = width
16
+ @height = height
17
+ @font_size = 9
18
+ @resolution = 72.0
19
+ d = "#{@resolution}x#{@resolution}"
20
+
21
+ @canvas = Magick::Image.new(@width, @height) {
22
+ self.background_color = 'white'
23
+ self.density = d
24
+ }
25
+
26
+ @details = {:canvas => @canvas, :height => height, :width => width}
27
+
28
+ @graph_layer = []
29
+ end
30
+
31
+ def add_layer(data, options = {})
32
+ @graph_layer << Tuftify::GraphLayer.new(data, @details, options)
33
+ end
34
+
35
+ def draw
36
+ @graph_layer.each do |layer|
37
+ layer.draw
38
+ end
39
+
40
+ return @canvas
41
+ end
42
+
43
+ end
44
+ end
45
+ #
46
+ #
47
+ # if !@labels[index].nil? && @labels_seen[index].nil?
48
+ # y_offset = @graph_bottom + LABEL_MARGIN
49
+ #
50
+ # @d.fill = @font_color
51
+ # @d.font = @font if @font
52
+ # @d.stroke('transparent')
53
+ # @d.font_weight = NormalWeight
54
+ # @d.pointsize = scale_fontsize(@marker_font_size)
55
+ # @d.gravity = NorthGravity
56
+ # @d = @d.annotate_scaled(@base_image,
57
+ # 1.0, 1.0,
58
+ # x_offset, y_offset,
59
+ # @labels[index], @scale)
60
+ # @labels_seen[index] = 1
61
+ # debug { @d.line 0.0, y_offset, @raw_columns, y_offset }
@@ -0,0 +1,32 @@
1
+ require 'tuftify/panel'
2
+
3
+ module Tuftify
4
+ class GraphAreaPanel < Tuftify::Panel
5
+ def initialize(data, x_orig, y_orig, width, height, canvas, options)
6
+ super x_orig, y_orig, width, height, canvas, options
7
+ @data = data
8
+ end
9
+
10
+ def draw
11
+ max_value = @data.collect {|v| v[1]}.max
12
+ scaling = @height.to_f / max_value
13
+ barwidth = @width / @data.length
14
+ x = @x
15
+
16
+
17
+ @data.each do |key, value|
18
+ h = scaling * value
19
+ @drawing.fill(@options[:fill])
20
+ @drawing.stroke(@options[:stroke])
21
+ @drawing.rectangle(x, @y + @height, x + barwidth, @y + @height - h)
22
+ x += barwidth
23
+ end
24
+ @drawing.draw @canvas
25
+
26
+ # @drawing.stroke("red")
27
+ # @drawing.stroke_width(3)
28
+ # @drawing.line(@x,@y + @height,@width,@y + @height)
29
+ # @drawing.draw @canvas
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,71 @@
1
+ require 'tuftify/title_panel'
2
+ require 'tuftify/graph_area_panel'
3
+ require 'tuftify/category_axis'
4
+
5
+ module Tuftify
6
+ class GraphLayer
7
+ include Magick
8
+
9
+ attr_accessor :options
10
+ attr_accessor :height, :width
11
+
12
+ def initialize(data, details, options = {})
13
+ @options = {:title => 'Graph',
14
+ :font_family =>'Helvetica',
15
+ :fill => 'black',
16
+ :pointsize => 12,
17
+ :title_pointsize => 18,
18
+ :categories_pointsize => 12,
19
+ :gravity => NorthGravity,
20
+ :stroke => 'white'
21
+ }
22
+ @height = details[:height]
23
+ @width = details[:width]
24
+ @options = @options.merge options
25
+ @data = data.collect {|i| [i[0], i[1].to_f]}
26
+ @panels = {}
27
+ title = Tuftify::TitlePanel.new(@options.delete(:title), @options[:title_pointsize], details, @options)
28
+ @panels[:title] = title
29
+ barwidth = @width / @data.length
30
+ categories = []
31
+ categories = @data.collect { |value| value[0].to_s} if @options[:categories].nil?
32
+ categories = @options[:categories] unless @options[:categories].nil?
33
+
34
+ @panels[:category_axis] = Tuftify::CategoryAxis.new(categories,0,
35
+ @options[:categories_pointsize],details,barwidth,@options)
36
+
37
+ @height_graph = @height - (title.height + @panels[:category_axis].height)
38
+
39
+ @panels[:graph_area] = Tuftify::GraphAreaPanel.new(data, 0, title.height,
40
+ @width, @height_graph, details[:canvas], @options)
41
+
42
+
43
+ end
44
+
45
+ def draw
46
+ @panels[:title].draw
47
+ @panels[:graph_area].draw
48
+ @panels[:category_axis].draw
49
+ end
50
+
51
+ # def draw_line
52
+ # max_value = @data.collect {|v| v[1]}.max
53
+ # barwidth = width / @data.length
54
+ # x = 0
55
+ # lh = label_height
56
+ # draw_height = height - lh
57
+ # @data.each do |key, value|
58
+ # h = draw_height / max_value * value
59
+ # @drawing.fill('black')
60
+ # @drawing.stroke('white')
61
+ # @drawing.rectangle(x, draw_height, x + barwidth, draw_height - h)
62
+ # # @drawing.annotate(@canvas, barwidth, lh, x, draw_height, key.to_s)
63
+ # x += barwidth
64
+ # end
65
+ #
66
+ # return @drawing
67
+ #
68
+ # end
69
+
70
+ end
71
+ end
@@ -0,0 +1,27 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module Tuftify
5
+ class Panel
6
+ attr_accessor :x, :y
7
+ attr_accessor :width, :height
8
+ attr_accessor :canvas
9
+
10
+ def initialize(x, y, width, height, canvas, options = {})
11
+ @x, @y = x, y
12
+ @width, @height = width, height
13
+ @canvas = canvas
14
+ @options = options.clone
15
+
16
+ @drawing = Magick::Draw.new
17
+ @drawing.font_family = @options[:font_family]
18
+ @drawing.fill = @options[:fill]
19
+ @drawing.pointsize = @options[:pointsize]
20
+ @drawing.gravity = @options[:gravity]
21
+ end
22
+
23
+ def draw
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ require 'tuftify/panel'
2
+
3
+ module Tuftify
4
+ class TitlePanel < Tuftify::Panel
5
+ def initialize(title, height, details, options)
6
+ @title = title
7
+ super 0, 0, details[:width], height, details[:canvas], options
8
+ @drawing.pointsize = @options[:title_pointsize]
9
+ end
10
+
11
+ def draw
12
+ @drawing.fill_opacity(0)
13
+ @drawing.stroke('red')
14
+ @drawing.stroke_width(3)
15
+ #@drawing.rectangle(@x,@y,@width,@height+@y)
16
+
17
+ @drawing.annotate(@canvas, @width, @height, 0, 0, @title)
18
+
19
+ @drawing.draw(@canvas)
20
+ end
21
+ end
22
+ end
data/tuftify.gemspec CHANGED
@@ -2,15 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tuftify}
5
- s.version = "0.1.7"
5
+ s.version = "0.1.8"
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"]
9
9
  s.date = %q{2009-06-09}
10
10
  s.description = %q{A graphing library.}
11
11
  s.email = %q{ingrid.anzola@kinesis.org}
12
- s.extra_rdoc_files = ["CHANGELOG", "lib/playing_around.rb", "lib/tuftify.rb", "README", "README.rdoc"] + Dir["lib/tuftify/*.rb"]
13
- s.files = ["CHANGELOG", "init.rb", "lib/playing_around.rb", "lib/tuftify.rb", "Manifest", "Rakefile", "README", "README.rdoc", "tuftify.gemspec"] + Dir["lib/tuftify/*.rb"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/playing_around.rb", "lib/tuftify/graph.rb","lib/tuftify/bar_graph.rb","lib/tuftify/graph_layer.rb","lib/tuftify/category_axis.rb",
13
+ "lib/tuftify/data_point.rb","lib/tuftify/panel.rb","lib/tuftify/title_panel.rb","lib/tuftify/graph_area_panel.rb","lib/tuftify.rb", "README", "README.rdoc"]
14
+ s.files = ["CHANGELOG", "init.rb", "lib/playing_around.rb", "lib/tuftify/graph.rb","lib/tuftify/bar_graph.rb","lib/tuftify/graph_layer.rb","lib/tuftify/category_axis.rb",
15
+ "lib/tuftify/data_point.rb","lib/tuftify/panel.rb","lib/tuftify/title_panel.rb","lib/tuftify/graph_area_panel.rb","lib/tuftify.rb", "Manifest", "Rakefile", "README", "README.rdoc", "tuftify.gemspec"]
14
16
  s.homepage = %q{http://github.com/suranyami/tuftify}
15
17
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tuftify", "--main", "README"]
16
18
  s.require_paths = ["lib"]
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.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Parry, Ingrid Anzola
@@ -31,6 +31,14 @@ extensions: []
31
31
  extra_rdoc_files:
32
32
  - CHANGELOG
33
33
  - lib/playing_around.rb
34
+ - lib/tuftify/graph.rb
35
+ - lib/tuftify/bar_graph.rb
36
+ - lib/tuftify/graph_layer.rb
37
+ - lib/tuftify/category_axis.rb
38
+ - lib/tuftify/data_point.rb
39
+ - lib/tuftify/panel.rb
40
+ - lib/tuftify/title_panel.rb
41
+ - lib/tuftify/graph_area_panel.rb
34
42
  - lib/tuftify.rb
35
43
  - README
36
44
  - README.rdoc
@@ -38,6 +46,14 @@ files:
38
46
  - CHANGELOG
39
47
  - init.rb
40
48
  - lib/playing_around.rb
49
+ - lib/tuftify/graph.rb
50
+ - lib/tuftify/bar_graph.rb
51
+ - lib/tuftify/graph_layer.rb
52
+ - lib/tuftify/category_axis.rb
53
+ - lib/tuftify/data_point.rb
54
+ - lib/tuftify/panel.rb
55
+ - lib/tuftify/title_panel.rb
56
+ - lib/tuftify/graph_area_panel.rb
41
57
  - lib/tuftify.rb
42
58
  - Manifest
43
59
  - Rakefile