class Minichart::HorizontalStatusLeds
Public Class Methods
defaults()
click to toggle source
# File lib/minichart/leds/horizontal_status_leds.rb, line 4 def defaults leds_defaults.merge width: 300, height: 50 end
Public Instance Methods
build()
click to toggle source
# File lib/minichart/leds/horizontal_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_options(value, i)
click to toggle source
# File lib/minichart/leds/horizontal_status_leds.rb, line 21 def bar_options(value, i) color = if value == 0 or !value :neutral_color elsif value > 0 :positive_color else :negative_color end { x: (options[:padding] + i * bar_width), y: options[:padding], width: bar_width, height: options[:height], style: { opacity: opacity(value), fill: options[color], stroke_width: options[:stroke], stroke: options[:background] } } end
bar_width()
click to toggle source
# File lib/minichart/leds/horizontal_status_leds.rb, line 17 def bar_width @bar_width ||= options[:width] / data.size.to_f end