Class: Scruffy::Components::Grid

Inherits:
Base
  • Object
show all
Includes:
Helpers::Marker
Defined in:
lib/scruffy/components/grid.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#id, #options, #position, #size, #visible

Instance Method Summary collapse

Methods included from Helpers::Marker

#each_marker

Methods inherited from Base

#initialize, #process, #render

Constructor Details

This class inherits a constructor from Scruffy::Components::Base

Instance Attribute Details

#markersObject

Returns the value of attribute markers.



4
5
6
# File 'lib/scruffy/components/grid.rb', line 4

def markers
  @markers
end

Instance Method Details

#draw(svg, bounds, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/scruffy/components/grid.rb', line 8

def draw(svg, bounds, options={})
  markers = (options[:markers] || self.markers) || 5
  
  stroke_width = options[:stroke_width]
  
  each_marker(markers, options[:min_value], options[:max_value], bounds[:height], options, :value_formatter) do |label, y|
    svg.line(:x1 => 0, :y1 => y, :x2 => bounds[:width], :y2 => y, :style => "stroke: #{options[:theme].marker.to_s}; stroke-width: #{stroke_width};")
  end
  
  #add a 0 line
  y = (options[:max_value] * bounds[:height])/(options[:max_value] - options[:min_value])
  svg.line(:x1 => 0, :y1 => y, :x2 => bounds[:width], :y2 => y, :style => "stroke: #{options[:theme].marker.to_s}; stroke-width: #{stroke_width};")
  
end