class Scruffy::Layers::SparklineBar

Experimental, do not use.

Public Instance Methods

draw(svg, coords, options = {}) click to toggle source
# File lib/scruffy/layers/sparkline_bar.rb, line 6
def draw(svg, coords, options = {})
  zero_point = @height / 2.0

  coords.each do |coord|
    x, y, bar_height = (coord.first-(@bar_width * 0.5)), coord.last, (height - coord.last)

    bar_color = (y > zero_point) ? 'black' : 'red'
    bar_height = (bar_height - zero_point)
    
    #y = (bar_height < 0) ? 

    # svg.rect( :x => x, :y => zero_point, :width => @bar_width, :height => , 
    #           :fill => bar_color, :stroke => 'none', 'style' => "opacity: #{opacity}" )
  end
end

Protected Instance Methods

generate_coordinates(options = {}) click to toggle source
# File lib/scruffy/layers/sparkline_bar.rb, line 23
def generate_coordinates(options = {})
  @bar_width = (width / points.size) * 0.9
  options[:point_distance] = (width - (width / points.size)) / (points.size - 1).to_f

  #TODO iteration by index on points.  Needs to change
  coords = (0...points.size).map do |idx| 
    x_coord = (options[:point_distance] * idx) + (width / points.size * 0.5)

    relative_percent = ((points[idx] == min_value) ? 0 : ((points[idx] - min_value) / (max_value - min_value).to_f))
    y_coord = (height - (height * relative_percent))
    [x_coord, y_coord]
  end
  coords
end