Class: Tuftify::GraphLayer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, details, options = {}) ⇒ GraphLayer

Returns a new instance of GraphLayer.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tuftify/graph_layer.rb', line 12

def initialize(data, details, options = {})
  @options = {:title => 'Graph',
    :font_family =>'Helvetica',
    :fill => 'black',
    :pointsize => 12,
    :title_pointsize => 18,
    :categories_pointsize => 12,
    :gravity => NorthGravity,
    :stroke => 'white'
  }
  @height = details[:height]
  @width = details[:width]
  @options = @options.merge options
  @data = data.collect {|i| [i[0], i[1].to_f]}
  @panels = {}
  title = Tuftify::TitlePanel.new(@options.delete(:title), @options[:title_pointsize], details, @options)
  @panels[:title] = title
  barwidth = @width / @data.length
  categories = []
  categories = @data.collect { |value| value[0].to_s} if @options[:categories].nil?
  categories = @options[:categories] unless @options[:categories].nil?

  @panels[:category_axis] = Tuftify::CategoryAxis.new(categories,0,
    @options[:categories_pointsize],details,barwidth,@options)

  @height_graph = @height - (title.height + @panels[:category_axis].height)
  
  @panels[:graph_area] = Tuftify::GraphAreaPanel.new(data, 0, title.height,
    @width, @height_graph, details[:canvas], @options)
 

end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#widthObject

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#drawObject



45
46
47
48
49
# File 'lib/tuftify/graph_layer.rb', line 45

def draw
  @panels[:title].draw
  @panels[:graph_area].draw
  @panels[:category_axis].draw
end