Class: Tuftify::Graph

Inherits:
Object
  • Object
show all
Includes:
Magick
Defined in:
lib/tuftify/graph.rb

Overview

Basic Graph class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height) ⇒ Graph

Returns a new instance of Graph.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tuftify/graph.rb', line 14

def initialize(width, height)
  @width = width
  @height = height
  @font_size = 9
  @resolution = 72.0
  d = "#{@resolution}x#{@resolution}"
  
  @canvas = Magick::Image.new(@width, @height) {
    self.background_color = 'white'
    self.density = d
  }

  @details = {:canvas => @canvas, :height => height, :width => width}

  @graph_layer = []
end

Instance Attribute Details

#canvasObject

Returns the value of attribute canvas.


10
11
12
# File 'lib/tuftify/graph.rb', line 10

def canvas
  @canvas
end

#font_sizeObject

Returns the value of attribute font_size.


9
10
11
# File 'lib/tuftify/graph.rb', line 9

def font_size
  @font_size
end

#heightObject

Returns the value of attribute height.


8
9
10
# File 'lib/tuftify/graph.rb', line 8

def height
  @height
end

#resolutionObject

Returns the value of attribute resolution.


9
10
11
# File 'lib/tuftify/graph.rb', line 9

def resolution
  @resolution
end

#titleObject

Returns the value of attribute title.


11
12
13
# File 'lib/tuftify/graph.rb', line 11

def title
  @title
end

#widthObject

Returns the value of attribute width.


8
9
10
# File 'lib/tuftify/graph.rb', line 8

def width
  @width
end

Instance Method Details

#add_layer(data, options = {}) ⇒ Object


31
32
33
# File 'lib/tuftify/graph.rb', line 31

def add_layer(data, options = {})
  @graph_layer << Tuftify::GraphLayer.new(data, @details, options)
end

#drawObject


35
36
37
38
39
40
41
# File 'lib/tuftify/graph.rb', line 35

def draw
  @graph_layer.each do |layer|
    layer.draw
  end

  return @canvas
end