Class SVG::Graph::Graph
In: temp/Graph/Graph.rb
Parent: Object

SVG::Graph

0.3.0

Base object for generating SVG Graphs

Synopsis

  module SVG::Graph::Graph_Type
    include SVG::Graph

    def set_defaults
      init_with( { :key => 'value' } )
    end
    def _init
      # any testing you want to do
    end
  end

In your script…

  require 'SVG/Graph/Graph_Type'

  width = 500
  height = 300
  fields = %w{ field_1 field_2 field_3 )
  graph = SVG::Graph::Graph_Type.new( {
    :fields => fields,
    # ... other config options
    :height => height
  })

  data = [ 23, 56, 32 ]
  graph.add_data( {
    :data => data,
    :title => 'Sales 2002'
  })

  config_value = graph.config_option
  graph.config_option = config_value
  graph.compress = true

  print "Content-type: image/svg+xml\r\n"
  print graph.burn

Description

This package should be used as a base for creating SVG graphs.

See

Methods
add_data    burn    clear_data    init_with    new   
Attributes
font_size  [RW] 

Set the font size (in points) of the data point labels

graph_subtitle  [RW] 

What the subtitle on the graph should be.

graph_title  [RW] 

What the title on the graph should be.

height  [RW] 

Set the height of the graph box, this is the total height of the SVG box created - not the graph it self which auto scales to fix the space.

key  [RW] 

Whether to show a key, defaults to false, set to true if you want to show it.

key_font_size  [RW] 

Set the key font size

key_position  [RW] 

Where the key should be positioned, defaults to :right, set to :bottom if you want to move it.

min_scale_value  [RW] 

The point at which the Y axis starts, defaults to ‘0’, if set to nil it will default to the minimum data value.

rotate_x_labels  [RW] 

This turns the X axis labels by 90 degrees. Default it false, to turn on set to true.

rotate_y_labels  [RW] 

This turns the Y axis labels by 90 degrees. Default it false, to turn on set to true.

scale_divisions  [RW] 

This defines the gap between markers on the Y axis, default is a 10th of the max_value, e.g. you will have 10 markers on the Y axis. NOTE: do not set this too low - you are limited to 999 markers, after that the graph won’t generate.

scale_integers  [RW] 

Ensures only whole numbers are used as the scale divisions. Default it false, to turn on set to true. This has no effect if scale divisions are less than 1.

show_data_values  [RW] 

(Bool) Show the value of each element of data on the graph

show_graph_subtitle  [RW] 

Whether to show a subtitle on the graph, defaults to false, set to true to show.

show_graph_title  [RW] 

Whether to show a title on the graph, defaults to false, set to true to show.

show_x_guidelines  [RW] 

Show guidelines for the X axis

show_x_labels  [RW] 

Whether to show labels on the X axis or not, defaults to true, set to false if you want to turn them off.

show_x_title  [RW] 

Whether to show the title under the X axis labels, default is false, set to true to show.

show_y_guidelines  [RW] 

Show guidelines for the Y axis

show_y_labels  [RW] 

Whether to show labels on the Y axis or not, defaults to true, set to false if you want to turn them off.

show_y_title  [RW] 

Whether to show the title under the Y axis labels, default is false, set to true to show.

stagger_x_labels  [RW] 

This puts the labels at alternative levels so if they are long field names they will not overlap so easily. Default it false, to turn on set to true.

style_sheet  [RW] 

Set the path to an external stylesheet, set to ’’ if you want to revert back to using the defaut internal version.

To create an external stylesheet create a graph using the default internal version and copy the stylesheet section to an external file and edit from there.

subtitle_font_size  [RW] 

Set the subtitle font size

title_font_size  [RW] 

Set the title font size

width  [RW] 

Set the width of the graph box, this is the total width of the SVG box created - not the graph it self which auto scales to fix the space.

x_label_font_size  [RW] 

Set the font size of the X axis labels

x_title  [RW] 

What the title under X axis should be, e.g. ‘Months’.

x_title_font_size  [RW] 

Set the font size of the X axis title

y_label_font_size  [RW] 

Set the font size of the Y axis labels

y_title  [RW] 

What the title under Y axis should be, e.g. ‘Sales in thousands’.

y_title_font_size  [RW] 

Set the font size of the Y axis title

y_title_text_direction  [RW] 

Aligns writing mode for Y axis label. Defaults to :bt (Bottom to Top). Change to :tb (Top to Bottom) to reverse.

Included modules
REXML
Public Class methods
new( config )

Initialize the graph object with the graph settings. You won’t instantiate this class directly; see the subclass for options.

Public Instance methods
init_with(config)

Overwrite configuration options with supplied options. Used by subclasses.

add_data(conf)

This method allows you do add data to the graph object. It can be called several times to add more data sets in.

  data_sales_02 = [12, 45, 21];

  graph.add_data({
    :data => data_sales_02,
    :title => 'Sales 2002'
  })
clear_data()

This method removes all data from the object so that you can reuse it to create a new graph but with the same config options.

  graph.clear_data
burn()

This method processes the template with the data and config which has been set and returns the resulting SVG.

This method will croak unless at least one data set has been added to the graph object.

  print graph.burn