Class: Tuftify::CategoryAxis

Inherits:
Panel
  • Object
show all
Defined in:
lib/tuftify/category_axis.rb

Instance Attribute Summary

Attributes inherited from Panel

#canvas, #height, #width, #x, #y

Instance Method Summary collapse

Constructor Details

#initialize(categories, x_orig, height, details, barwidth, options) ⇒ CategoryAxis

Returns a new instance of CategoryAxis.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/tuftify/category_axis.rb', line 5

def initialize(categories,x_orig,height,details,barwidth,options)

  @categories = categories
  
  super x_orig, details[:height]-height, details[:width], height, details[:canvas], options
  @drawing.pointsize = @options[:categories_pointsize]
  @label_height = label_height
  @height = @label_height
  @y = details[:height] - @height
  @barwidth = barwidth    
  
end

Instance Method Details

#drawObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tuftify/category_axis.rb', line 18

def draw
  x = @x    
  @drawing.fill_opacity(0)

  @categories.each do |category|

    @drawing.annotate(@canvas, @barwidth, @label_height, x, @y, category){
      self.rotation = 315
      self.gravity = Magick::CenterGravity
    }

#        @drawing.stroke('red')
#        @drawing.stroke_width(3)
#        @drawing.rectangle(x,@y,@barwidth,@y+@label_height)
#        @drawing.draw(@canvas)
    x += @barwidth
  end

end

#label_heightObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tuftify/category_axis.rb', line 38

def label_height
  h = 0
  l = ""
  x = ""
  @categories.each {|label|

    m = label.length
    l = label if m > h
    h = m if m > h
    
  }

  l.each_char { |c| x << "#{c}\n" }
  h = @drawing.get_multiline_type_metrics(x)

  return h.height
end