Class: GerbilCharts::Models::RoundTimeRange
- Defined in:
- lib/gerbilcharts/models/round_time_range.rb
Overview
rounded time range - Rounds the max to a nice preset
This class allows for labels at clean intervals instead of
"Jan 17 2008 11:27:92"
Constant Summary
Constants inherited from Presets
Presets::PRESETS, Presets::PRESET_LABEL_POS, Presets::PRESET_VAL_POS, Presets::TIMEPRESETS, Presets::UNITPRESETS
Instance Attribute Summary collapse
-
#ldelta ⇒ Object
readonly
label delta seconds (eg label every = 2 hrs).
-
#rdelta ⇒ Object
readonly
range delta seconds (eg chart span = 6 hrs).
Attributes inherited from RawRange
Instance Method Summary collapse
-
#each_label ⇒ Object
provide labels Yields two items (value - seconds since Jan 1 1970, string label).
-
#each_tick(tpl) ⇒ Object
provide ticks (per label interval) note the tpl is not used !.
-
#format_min_value ⇒ Object
format min value completely.
-
#initialize(raw_range) ⇒ RoundTimeRange
constructor
given a raw range, we calculate a round range.
Methods inherited from RawRange
#delta, #format_value, #invalid?, #min_max, #reset, #scale_factor, #to_s, #update, #update_r, #zeromin
Methods inherited from Presets
#format_suffix, #format_timeval
Constructor Details
#initialize(raw_range) ⇒ RoundTimeRange
given a raw range, we calculate a round range
18 19 20 21 22 23 24 25 26 |
# File 'lib/gerbilcharts/models/round_time_range.rb', line 18 def initialize(raw_range) super() @rdelta,@ldelta=round_delta(raw_range.delta) @rmin=raw_range.rmin # this can be rdelta or ldelta for wider or tighter #@rmax=round_max(raw_range.rmax,@rdelta) @rmax=round_max(raw_range.rmax,@ldelta) end |
Instance Attribute Details
#ldelta ⇒ Object (readonly)
label delta seconds (eg label every = 2 hrs)
14 15 16 |
# File 'lib/gerbilcharts/models/round_time_range.rb', line 14 def ldelta @ldelta end |
#rdelta ⇒ Object (readonly)
range delta seconds (eg chart span = 6 hrs)
15 16 17 |
# File 'lib/gerbilcharts/models/round_time_range.rb', line 15 def rdelta @rdelta end |
Instance Method Details
#each_label ⇒ Object
provide labels Yields two items (value - seconds since Jan 1 1970, string label)
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gerbilcharts/models/round_time_range.rb', line 30 def each_label raise "Range not aligned with presets (call round range first)" if not @ldelta return if @ldelta == 0 v = get_label_start_time while (v<=@rmax) do yield v, format_timeval(v,@rdelta) v = v+@ldelta end end |
#each_tick(tpl) ⇒ Object
provide ticks (per label interval) note the tpl is not used !
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gerbilcharts/models/round_time_range.rb', line 46 def each_tick(tpl) raise "Range not aligned with presets (call round range first)" if not @ldelta return if @ldelta == 0 subtick_delta = ideal_subtick_interval(@ldelta) v = get_label_start_time while (v<=@rmax) do yield v v = v+subtick_delta end end |
#format_min_value ⇒ Object
format min value completely
63 64 65 66 |
# File 'lib/gerbilcharts/models/round_time_range.rb', line 63 def format_min_value t = Time.at(@rmin).getlocal return t.to_s end |