class Minichart::VerticalStatusLeds
Public Class Methods
defaults()
click to toggle source
# File lib/minichart/leds/vertical_status_leds.rb, line 4 def defaults leds_defaults.merge width: 50, height: 300 end
Public Instance Methods
build()
click to toggle source
# File lib/minichart/leds/vertical_status_leds.rb, line 9 def build data.each_with_index do |value, i| element :rect, bar_options(value, i) end end
Protected Instance Methods
bar_height()
click to toggle source
# File lib/minichart/leds/vertical_status_leds.rb, line 21 def bar_height @bar_height ||= options[:height] / points.to_f end
bar_options(value, i)
click to toggle source
# File lib/minichart/leds/vertical_status_leds.rb, line 25 def bar_options(value, i) y = options[:padding] + (points - i - 1) * bar_height color = if value == 0 or !value :neutral_color elsif value > 0 :positive_color else :negative_color end { x: options[:padding], y: y, width: options[:width], height: bar_height, style: { opacity: opacity(value), fill: options[color], stroke_width: options[:stroke], stroke: options[:background] } } end
points()
click to toggle source
# File lib/minichart/leds/vertical_status_leds.rb, line 17 def points @points ||= data.size end