Class: SVG::Graph::Schedule Deprecated

Inherits:
Graph
  • Object
show all
Defined in:
lib/SVG/Graph/Schedule.rb

Overview

Deprecated.

Removed at 4.0.0

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

www.germane-software/repositories/public/SVG/test/schedule.rb

Notes

The default stylesheet handles up to 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

Since:

  • 0.5.0

Instance Attribute Summary collapse

Attributes inherited from Graph

#add_popups, #font_size, #graph_subtitle, #graph_title, #height, #key, #key_font_size, #key_position, #min_scale_value, #no_css, #rotate_x_labels, #rotate_y_labels, #scale_divisions, #scale_integers, #show_data_values, #show_graph_subtitle, #show_graph_title, #show_x_guidelines, #show_x_labels, #show_x_title, #show_y_guidelines, #show_y_labels, #show_y_title, #stagger_x_labels, #stagger_y_labels, #step_include_first_x_label, #step_x_labels, #style_sheet, #subtitle_font_size, #title_font_size, #width, #x_label_font_size, #x_title, #x_title_font_size, #y_label_font_size, #y_title, #y_title_font_size, #y_title_text_direction

Instance Method Summary collapse

Methods inherited from Graph

#burn, #clear_data, #initialize

Constructor Details

This class inherits a constructor from SVG::Graph::Graph

Instance Attribute Details

#bar_gapObject

Returns the value of attribute bar_gap



118
119
120
# File 'lib/SVG/Graph/Schedule.rb', line 118

def bar_gap
  @bar_gap
end

#min_x_valueObject

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

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

#scale_x_divisionsObject

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

#scale_x_integersObject

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

#timescale_divisionsObject

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

#x_label_formatObject

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

#add_data(data) ⇒ Object

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 discernible 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

#set_defaultsObject

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