class Minichart::Meter

Base class for charts with a single value

Public Class Methods

meter_defaults() click to toggle source
# File lib/minichart/meters/meter.rb, line 6
def meter_defaults
  @meter_defaults ||= {
    max: 100,
    notches: [],
    notch_thickness: 4,
    notch_color: 'black',
    clipping_indicator: false,
    clipping_indicator_thickness: 4,
    clipping_indicator_color: 'yellow',
    padding: 2,
  }
end

Protected Instance Methods

clamped_value() click to toggle source
# File lib/minichart/meters/meter.rb, line 44
def clamped_value
  case mode
  when :positive
    value.clamp 0, options[:max]
  when :negative
    value.clamp -options[:max], 0
  when :dual
    value.clamp -options[:max], options[:max]
  end
end
clipping?() click to toggle source
# File lib/minichart/meters/meter.rb, line 26
def clipping?
  value > options[:max] || value < -options[:max]
end
mode() click to toggle source
# File lib/minichart/meters/meter.rb, line 30
def mode
  @mode ||= mode!
end
mode!() click to toggle source
# File lib/minichart/meters/meter.rb, line 34
def mode!
  options[:mode] ||= :auto

  if options[:mode] == :auto
    value >= 0 ? :positive : :negative
  else
    options[:mode].to_sym
  end
end
style() click to toggle source
# File lib/minichart/meters/meter.rb, line 55
def style
  {
    fill: options[:color],
    stroke_width: options[:stroke],
    stroke: options[:background]
  }
end
value() click to toggle source
# File lib/minichart/meters/meter.rb, line 22
def value
  data
end