Class: Ruport::Formatter::PDF

Inherits:
Object
  • Object
show all
Defined in:
lib/ruport/util/graph/gruff.rb

Direct Known Subclasses

Controller::Invoice::PDF

Instance Method Summary collapse

Instance Method Details

#draw_graph(graph, opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruport/util/graph/gruff.rb', line 41

def draw_graph(graph, opts={})
  x = opts.delete(:x)
  y = opts.delete(:y)
  width = opts.delete(:width)
  height = opts.delete(:height)
  g = graph.as(:jpg, opts)
  info = ::PDF::Writer::Graphics::ImageInfo.new(g)
  
  # reduce the size of the image until it fits into the requested box
  img_width, img_height =
    fit_image_in_box(info.width,width,info.height,height)
  
  # if the image is smaller than the box, calculate the white space buffer
  x, y = add_white_space(x,y,img_width,width,img_height,height)
  
  pdf_writer.add_image(g, x, y, img_width, img_height) 
end