Class: TimeFlot
- Inherits:
-
Flot
- Object
- Flot
- TimeFlot
- Defined in:
- lib/time_flot.rb
Overview
TimeFlot
The TimeFlot class provides for a graph of values over time. See Flot for more details.
Usage:
TimeFlot.new('graph') do |f|
f.
f.grid :hoverable => true
f.selection :mode => "xy"
f.filter {|collection| collection.select {|j| j.entry_date < Date.parse("7/8/2007") }}
f.series_for("Stress", @journals, :x => :entry_date, :y => :stress_rating)
f.series_for("Hours of Sleep", @journals, :x => :entry_date, :y => :hours_of_sleep)
f.series_for("Restful Night?", @journals, :x => :entry_date, :y => lambda {|record| record.restful_night ? 5 : 0 }, :options => {:points => {:show => true}, :bars => {:show => false}})
end
Constant Summary collapse
- JS_TIME_MULTIPLIER =
1000
- BAR_WIDTH =
1.day * JS_TIME_MULTIPLIER
Instance Method Summary collapse
-
#bars(opts = {:show => true, :barWidth => BAR_WIDTH, :align => "center"}) ⇒ Object
Sets the default width to one day…
-
#initialize(time_axis = :xaxis, &block) ⇒ TimeFlot
constructor
Create a new TimeFlot object with a default time_axis of :xaxis TimeFlot.new do |tf| tf.bars # default width is equal to 1 day tf.series_for(“Temperature”, @temps, :x => :created_on, :y => :temperature) end.
- #series(label, d, opts = {}) ⇒ Object
Constructor Details
#initialize(time_axis = :xaxis, &block) ⇒ TimeFlot
Create a new TimeFlot object with a default time_axis of :xaxis
TimeFlot.new do |tf|
tf. # default width is equal to 1 day
tf.series_for("Temperature", @temps, :x => :created_on, :y => :temperature)
end
35 36 37 38 39 |
# File 'lib/time_flot.rb', line 35 def initialize(time_axis = :xaxis, &block) @options ||= {} time_axis(time_axis) super(nil, {}, &block) end |
Instance Method Details
#bars(opts = {:show => true, :barWidth => BAR_WIDTH, :align => "center"}) ⇒ Object
Sets the default width to one day… different set of defaults from Flot#bar
43 44 45 |
# File 'lib/time_flot.rb', line 43 def (opts = {:show => true, :barWidth => BAR_WIDTH, :align => "center"}) @options[:bars] = opts end |