Class: SVG::Graph::Schedule
Overview
For creating SVG plots of scalar temporal data
Synopsis
require 'SVG/Graph/Schedule' # Data sets are label, start, end tripples. data1 = [ "Housesitting", "6/17/04", "6/19/04", "Summer Session", "6/15/04", "8/15/04", ] graph = SVG::Graph::Schedule.new( { :width => 640, :height => 480, :graph_title => title, :show_graph_title => true, :no_css => true, :scale_x_integers => true, :scale_y_integers => true, :min_x_value => 0, :min_y_value => 0, :show_data_labels => true, :show_x_guidelines => true, :show_x_title => true, :x_title => "Time", :stagger_x_labels => true, :stagger_y_labels => true, :x_label_format => "%m/%d/%y", }) graph.add_data({ :data => data1, :title => 'Data', }) print graph.burn()
Description
Produces a graph of temporal scalar data.
Examples
http://www.germane-software/repositories/public/SVG/test/schedule.rb
Notes
The default stylesheet handles upto 10 data sets, if you use more you must create your own stylesheet and add the additional settings for the extra data sets. You will know if you go over 10 data sets as they will have no style and be in black.
Note that multiple data sets within the same chart can differ in length, and that the data in the datasets needn’t be in order; they will be ordered by the plot along the X-axis.
The dates must be parseable by ParseDate, but otherwise can be any order of magnitude (seconds within the hour, or years)
See also
- SVG::Graph::Graph
- SVG::Graph::BarHorizontal
- SVG::Graph::Bar
- SVG::Graph::Line
- SVG::Graph::Pie
- SVG::Graph::Plot
- SVG::Graph::TimeSeries
Author
Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
Copyright 2004 Sean E. Russell This software is available under the Ruby license[LICENSE.txt]
Constant Summary
Constants inherited from Graph
Instance Attribute Summary
-
- (Object) bar_gap
Returns the value of attribute bar_gap.
-
- (Object) min_x_value
Returns the value of attribute min_x_value.
-
- (Object) popup_format
The formatting used for the popups.
-
- (Object) scale_x_divisions
Returns the value of attribute scale_x_divisions.
-
- (Object) scale_x_integers
Returns the value of attribute scale_x_integers.
-
- (Object) timescale_divisions
Use this to set the spacing between dates on the axis.
-
- (Object) x_label_format
The format string use do format the X axis labels.
Instance Method Summary
-
- (Object) add_data(data)
Add data to the plot.
-
- (Object) set_defaults
In addition to the defaults set by Graph::initialize and Plot::set_defaults, sets:
- x_label_format
- ’%Y-%m-%d %H:%M:%S’
- popup_format
- ’%Y-%m-%d %H:%M:%S’.
Methods inherited from Graph
#burn, #clear_data, #initialize
Constructor Details
This class inherits a constructor from SVG::Graph::Graph
Instance Attribute Details
- (Object) bar_gap
Returns the value of attribute bar_gap
118 119 120 |
# File 'lib/SVG/Graph/Schedule.rb', line 118 def end |
- (Object) min_x_value
Returns the value of attribute min_x_value
115 116 117 |
# File 'lib/SVG/Graph/Schedule.rb', line 115 def min_x_value @min_x_value end |
- (Object) popup_format
The formatting used for the popups. See x_label_format
114 115 116 |
# File 'lib/SVG/Graph/Schedule.rb', line 114 def popup_format @popup_format end |
- (Object) scale_x_divisions
Returns the value of attribute scale_x_divisions
116 117 118 |
# File 'lib/SVG/Graph/Schedule.rb', line 116 def scale_x_divisions @scale_x_divisions end |
- (Object) scale_x_integers
Returns the value of attribute scale_x_integers
117 118 119 |
# File 'lib/SVG/Graph/Schedule.rb', line 117 def scale_x_integers @scale_x_integers end |
- (Object) timescale_divisions
Use this to set the spacing between dates on the axis. The value must be of the form "\d+ ?(days|weeks|months|years|hours|minutes|seconds)?"
EG:
graph.timescale_divisions = "2 weeks"
will cause the chart to try to divide the X axis up into segments of two week periods.
112 113 114 |
# File 'lib/SVG/Graph/Schedule.rb', line 112 def timescale_divisions @timescale_divisions end |
- (Object) x_label_format
The format string use do format the X axis labels. See Time::strformat
101 102 103 |
# File 'lib/SVG/Graph/Schedule.rb', line 101 def x_label_format @x_label_format end |
Instance Method Details
- (Object) add_data(data)
Add data to the plot.
# A data set with 1 point: Lunch from 12:30 to 14:00 d1 = [ "Lunch", "12:30", "14:00" ] # A data set with 2 points: "Cats" runs from 5/11/03 to 7/15/04, and # "Henry V" runs from 6/12/03 to 8/20/03 d2 = [ "Cats", "5/11/03", "7/15/04", "Henry V", "6/12/03", "8/20/03" ] graph.add_data( :data => d1, :title => 'Meetings' ) graph.add_data( :data => d2, :title => 'Plays' )
Note that the data must be in time,value pairs, and that the date format may be any date that is parseable by ParseDate. Also note that, in this example, we’re mixing scales; the data from d1 will probably not be discernable if both data sets are plotted on the same graph, since d1 is too granular.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/SVG/Graph/Schedule.rb', line 143 def add_data data @data = [] unless @data raise "No data provided by #{conf.inspect}" unless data[:data] and data[:data].kind_of? Array raise "Data supplied must be title,from,to tripples! "+ "The data provided contained an odd set of "+ "data points" unless data[:data].length % 3 == 0 return if data[:data].length == 0 y = [] x_start = [] x_end = [] data[:data].each_index {|i| im3 = i%3 if im3 == 0 y << data[:data][i] else arr = ParseDate.parsedate( data[:data][i] ) t = Time.local( *arr[0,6].compact ) (im3 == 1 ? x_start : x_end) << t.to_i end } sort( x_start, x_end, y ) @data = [x_start, x_end, y ] end |
- (Object) set_defaults
In addition to the defaults set by Graph::initialize and Plot::set_defaults, sets:
- x_label_format
- ’%Y-%m-%d %H:%M:%S’
- popup_format
- ’%Y-%m-%d %H:%M:%S’
89 90 91 92 93 94 95 96 97 |
# File 'lib/SVG/Graph/Schedule.rb', line 89 def set_defaults init_with( :x_label_format => '%Y-%m-%d %H:%M:%S', :popup_format => '%Y-%m-%d %H:%M:%S', :scale_x_divisions => false, :scale_x_integers => false, :bar_gap => true ) end |