class Minichart::VerticalBarMeter
Public Class Methods
defaults()
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 4 def defaults meter_defaults.merge width: 50, height: 300 end
Public Instance Methods
build()
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 9 def build draw_bar draw_notches if options[:notches] draw_clipping_indicator if options[:clipping_indicator] and clipping? end
Protected Instance Methods
bar_height()
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 60 def bar_height if mode == :dual clamped_value.abs * height_factor * 0.5 else clamped_value.abs * height_factor end end
draw_bar()
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 17 def draw_bar y1 = y_for 0 y2 = y_for clamped_value y = [y1, y2].min element :rect, x: options[:padding], y: y, height: bar_height, width: options[:width], style: style end
draw_clipping_indicator()
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 38 def draw_clipping_indicator draw_horizontal_line clamped_value, stroke: options[:clipping_indicator_thickness], color: options[:clipping_indicator_color] end
draw_horizontal_line(target_value, color:, stroke:)
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 44 def draw_horizontal_line(target_value, color:, stroke:) y = y_for target_value element :line, x1: options[:padding], x2: options[:width] + options[:padding], y1: y, y2: y, stroke: color, stroke_width: stroke end
draw_notch(notch)
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 33 def draw_notch(notch) draw_horizontal_line notch, stroke: options[:notch_thickness], color: options[:notch_color] end
draw_notches()
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 26 def draw_notches options[:notches].each do |notch| draw_notch notch draw_notch -notch if mode == :dual and notch != 0 end end
half_height()
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 56 def half_height options[:height] * 0.5 end
height_factor()
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 52 def height_factor options[:height] / options[:max].to_f end
y_for(target_value)
click to toggle source
# File lib/minichart/meters/vertical_bar_meter.rb, line 68 def y_for(target_value) result = target_value.abs / options[:max].to_f * options[:height] + options[:padding] case mode when :positive full_height - result when :negative result when :dual options[:height] - (target_value / options[:max].to_f * half_height + half_height) + options[:padding] end end