class Prawn::Chart::Grid

Prawn::Chart::Grid represents the area whcih your data will be plotted. It is drawn before your data is plotted and serves to mark where the axes of your plot will be and to give an indication of scale.

Attributes

document[RW]
height[RW]
point[RW]
spacing[RW]
width[RW]

Public Class Methods

new(grid_x_start, grid_y_start, grid_width, grid_height, spacing, document, theme) click to toggle source
# File lib/prawn/graph/grid.rb, line 12
def initialize(grid_x_start, grid_y_start, grid_width, grid_height, spacing, document, theme)
  @point = [grid_x_start, grid_y_start]
  @width = grid_width
  @height = grid_height
  @spacing = spacing
  @document = document
  @theme = theme
end

Public Instance Methods

draw() click to toggle source

Draws the Grid on the specified Prawn::Document

# File lib/prawn/graph/grid.rb, line 26
def draw
  @document.stroke_color @theme.marker_colour
  if @theme.stroke_grid_markers?
    (@height / @spacing).times do |x|
      offset = @spacing * (x + 1)
      @document.move_to [@point.first, (@point.last + offset)]
      @document.line_width(0.5)
      @document.stroke_line_to([(@point.first + @width), (@point.last + offset)])
    end
  end
  @document.move_to @point
  @document.line_width(2)
  @document.stroke_line_to([@point.first, @point.last + @height])
  @document.move_to @point
  @document.line_width(2)
  @document.stroke_line_to([(@point.first + @width), @point.last])
  @document.move_to @point.first, (@point.last + height)
  @document.stroke_color '000000'
  @document.line_width(1)
  @document.move_to @point
end
start_x() click to toggle source
# File lib/prawn/graph/grid.rb, line 21
def start_x; @point.first; end
start_y() click to toggle source
# File lib/prawn/graph/grid.rb, line 22
def start_y; @point.last; end