class GerbilCharts::Models::Presets

Presets base class for all ranges

Preset values for ranges. So we do not scale charts arbitrarily and the label values are neat and clean

Constants

PRESETS
PRESET_LABEL_POS
PRESET_VAL_POS
TIMEPRESETS
UNITPRESETS

Public Instance Methods

format_suffix(raw_value) click to toggle source

Formats a number with a units suffix

So a number like 11899833 = 11.90 M
# File lib/gerbilcharts/models/presets.rb, line 70
def format_suffix raw_value
  return "0" if raw_value == 0
  UNITPRESETS.each do |unit|
        if raw_value.abs  >= unit[0]
          retval = raw_value  / unit[0]
          sout=format("%.1f%s", retval, unit[1])
          sout.gsub! "\.0",""
          return sout
        end
  end
  return raw_value.to_s
end
format_timeval( tvsec, interval) click to toggle source

Formats a time value : based on available interval

tvsec = seconds since Jan 1 1970
interval = desired window in seconds
# File lib/gerbilcharts/models/presets.rb, line 86
def format_timeval ( tvsec, interval)   
  t = Time.at(tvsec).getlocal

  if t.hour + t.min == 0 
  return t.strftime("%b-%d") 
  end

  if interval < 60 
    return t.strftime("%M:%S")
  elsif interval < 300
    return t.strftime("%M:%S")
  elsif interval < 3600
    return t.strftime("%H:%M")
  elsif interval < 86400
    return t.strftime("%H:%M")
  elsif interval < 259200
    return t.strftime("%H:%M")
  elsif interval < 604800
    return t.strftime("%b-%d")
  elsif interval < 2419200
    return t.strftime("%b-%d")
  else
    return t.strftime("%b")
  end
end