Class: SVG::Graph::Graph

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

# SVG::Graph

### Base object for generating SVG Graphs

## Synopsis

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

        def set_defaults
          default = { 'keys' => 'value }
          default.each { |key, value|
            this.config[ key ] = value
          }
        end

        def get_template
          template = 'set the template'
          return template
        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 SVG::Graph::Bar for an example.

Methods

add_data burn clear_data is_valid_config new range_calc

Public Class methods

new( config )

Public Instance methods

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

range_calc(value, range)

Calculate a scaling range and divisions to be aesthetically pleasing

Parameters: | value range
Returns: | [revised range, division size, division precision]

is_valid_config(name)

Returns true if config value exists, is defined and not ’’