class Minichart::HorizontalBarMeter
Public Class Methods
defaults()
click to toggle source
# File lib/minichart/meters/horizontal_bar_meter.rb, line 4 def defaults meter_defaults.merge width: 300, height: 50 end
Public Instance Methods
build()
click to toggle source
# File lib/minichart/meters/horizontal_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_width()
click to toggle source
# File lib/minichart/meters/horizontal_bar_meter.rb, line 60 def bar_width if mode == :dual clamped_value.abs * width_factor * 0.5 else clamped_value.abs * width_factor end end
draw_bar()
click to toggle source
# File lib/minichart/meters/horizontal_bar_meter.rb, line 17 def draw_bar x1 = x_for 0 x2 = x_for clamped_value x = [x1, x2].min element :rect, x: x, y: options[:padding], height: options[:height], width: bar_width, style: style end
draw_clipping_indicator()
click to toggle source
# File lib/minichart/meters/horizontal_bar_meter.rb, line 38 def draw_clipping_indicator draw_vertical_line clamped_value, stroke: options[:clipping_indicator_thickness], color: options[:clipping_indicator_color] end
draw_notch(notch)
click to toggle source
# File lib/minichart/meters/horizontal_bar_meter.rb, line 33 def draw_notch(notch) draw_vertical_line notch, stroke: options[:notch_thickness], color: options[:notch_color] end
draw_notches()
click to toggle source
# File lib/minichart/meters/horizontal_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
draw_vertical_line(target_value, color:, stroke:)
click to toggle source
# File lib/minichart/meters/horizontal_bar_meter.rb, line 44 def draw_vertical_line(target_value, color:, stroke:) x = x_for target_value element :line, x1: x, x2: x, y1: options[:padding], y2: options[:height] + options[:padding], stroke: color, stroke_width: stroke end
half_width()
click to toggle source
# File lib/minichart/meters/horizontal_bar_meter.rb, line 56 def half_width options[:width] * 0.5 end
width_factor()
click to toggle source
# File lib/minichart/meters/horizontal_bar_meter.rb, line 52 def width_factor options[:width] / options[:max].to_f end
x_for(target_value)
click to toggle source
# File lib/minichart/meters/horizontal_bar_meter.rb, line 68 def x_for(target_value) result = target_value.abs / options[:max].to_f * options[:width] + options[:padding] case mode when :positive result when :negative full_width - result when :dual target_value / options[:max].to_f * half_width + half_width + options[:padding] end end