Class: Scruffy::Components::VGrid

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.



25
26
27
# File 'lib/scruffy/components/grid.rb', line 25

def markers
  @markers
end

Instance Method Details

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/scruffy/components/grid.rb', line 29

def draw(svg, bounds, options={})
  
  if options[:graph].point_markers #get vertical grid lines up with points if there are labels for them
    point_distance = bounds[:width] / (options[:graph].point_markers.size).to_f
    stroke_width = options[:stroke_width]
    (0...options[:graph].point_markers.size).map do |idx| 
      x = point_distance * idx  + point_distance/2
      svg.line(:x1 => x, :y1 => 0, :x2 => x, :y2 => bounds[:height], :style => "stroke: #{options[:theme].marker.to_s}; stroke-width: #{stroke_width};")
    end
    #add the far right and far left lines
    svg.line(:x1 => 0, :y1 => 0, :x2 => 0, :y2 => bounds[:height], :style => "stroke: #{options[:theme].marker.to_s}; stroke-width: #{stroke_width};")
    svg.line(:x1 => bounds[:width], :y1 => 0, :x2 => bounds[:width], :y2 => bounds[:height], :style => "stroke: #{options[:theme].marker.to_s}; stroke-width: #{stroke_width};")
  else
      
    markers =  (options[:key_markers] || self.markers) || 5 #options[:point_markers].size#
    stroke_width = options[:stroke_width]
    each_marker(markers, options[:min_key], options[:max_key], bounds[:width], options, :key_formatter) do |label, x|
      svg.line(:x1 => x, :y1 => 0, :x2 => x, :y2 => bounds[:height], :style => "stroke: #{options[:theme].marker.to_s}; stroke-width: #{stroke_width};")
    end
    
  end
end