Module: Charts::Renderer::RvgRenderer

Defined in:
lib/charts/renderer/rvg_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rvgObject (readonly)

Returns the value of attribute rvg.



4
5
6
# File 'lib/charts/renderer/rvg_renderer.rb', line 4

def rvg
  @rvg
end

Instance Method Details

#canvas(style) ⇒ Object



40
41
42
43
44
45
# File 'lib/charts/renderer/rvg_renderer.rb', line 40

def canvas(style)
  style.delete(:class)
  rvg.rvg(chart.width, chart.height) do |canvas|
    yield(canvas).styles(style)
  end
end

#circle(cx, cy, radius, style) ⇒ Object



24
25
26
# File 'lib/charts/renderer/rvg_renderer.rb', line 24

def circle(cx, cy, radius, style)
  canvas(style) { |c| c.circle radius, cx, cy }
end

#line(x1, y1, x2, y2, style) ⇒ Object



20
21
22
# File 'lib/charts/renderer/rvg_renderer.rb', line 20

def line(x1, y1, x2, y2, style)
  canvas(style) { |c| c.line x1, y1, x2, y2 }
end

#path(d, style) ⇒ Object



32
33
34
# File 'lib/charts/renderer/rvg_renderer.rb', line 32

def path(d, style)
  canvas(style) { |c| c.path d }
end

#pre_drawObject



6
7
8
9
10
# File 'lib/charts/renderer/rvg_renderer.rb', line 6

def pre_draw
  @rvg = Magick::RVG.new(chart.width, chart.height) do |canvas|
    canvas.background_fill = 'white'
  end
end


12
13
14
# File 'lib/charts/renderer/rvg_renderer.rb', line 12

def print
  rvg.draw.to_blob { |attrs| attrs.format = 'PNG' }
end

#rect(x, y, width, height, style) ⇒ Object



28
29
30
# File 'lib/charts/renderer/rvg_renderer.rb', line 28

def rect(x, y, width, height, style)
  canvas(style) { |c| c.rect width, height, x, y }
end

#save(filename) ⇒ Object



16
17
18
# File 'lib/charts/renderer/rvg_renderer.rb', line 16

def save(filename)
  rvg.draw.write filename
end

#text(text, x, y, style = {}) ⇒ Object



36
37
38
# File 'lib/charts/renderer/rvg_renderer.rb', line 36

def text(text, x, y, style = {})
  canvas(font_style.merge(style)) { |c| c.text x, y, text }
end