SvgGrapher documentation

Build svg 1.1 graph using SvgGrapher php5 library by guil.

Table of Contents

Guillaume Luchet, guillaume@geelweb.org.
Copyright © 2007, Guillaume Luchet
BSD License

SvgGrapher documentation

SvgGrapher permit you to create SVG 1.1 graph easily.

License

BSD License

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the name of the Xml2Pdf nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Installation instructions

PEAR install

You can use the package.xml in the source directory

$ sudo pear install /path/to/svggrapher/package.xml
                    

If you have modify the source code you can generate a new package.xml

$ cd path/to/svggrapher
$ php tools/pearReleaser.php
                    


dot deb install

From dor deb package: debian users (or "debian like" like Ubuntu users) can install it using a dot deb package

$ sudo dpkg -i /path/to/svggrapher/SvgGrapher_1.3.deb
                    

If you have modify the source code you can generate a new dot deb package

$ sh /path/to/svggrapher/tools/debianReleaser
                    


from source

download the tar.gz file to install from source code. Extract the content into a directory accessible by your web-server.


End-User documentation

Fisrt step with svgGrapher:

  1. require('svggrapher/SvgGrapher.php');
  2.  
  3. // instantiate the graph
  4. $graph new SvgGrapher();
  5.  
  6. // add curves
  7. $graph->addCurve('c1'array(
  8.     'labels'=> array('jan''feb''mar''mai''jun''jui'),
  9.     'values' => array(7514560809860),
  10.     'legend' => 'my first curve',
  11.     'visual' => 'bar'));
  12. $graph->addCurve('c2'array(
  13.     'labels'=> array('jan''feb''mar''apr'),
  14.     'values' => array(10012014280),
  15.     'legend' => 'curve 2',
  16.     'color' => '#0000FF',
  17.     'visual' => 'line'));
  18.  
  19. // render graph
  20. $graph->genGraph();
  21. $graph->drawSVG();
You can find more examples in the examples directory.

SvgGrapher internals functions

Internals functions are a set of tools and utilities, they are load with SvgGraper class instantiation.

SvgGrapher plugins

SvgGrapher use plugins...

Dataproviders plugins

The main purpose of Dataproviders plugins is get the data, but they can be use to modify data, set curves etc.


Defs plugins

Defs plugins are used to add 'defs' element in the svg. 'defs' element is a container element for references elements. http://www.w3.org/TR/SVG11/struct.html#DefsElement


Scripts plugins

Scripts plugins are used to add js script in the document.


Visuals plugins

Visuals plugins are plugins to define curves renderers. You can add all the curves visuals style than you want.


How to define new plugin ?

The plugins are defined by a php file with a function. The file must be named svgGraper.pluginType.pluginKeyword.php, and the function svgGraper_pluginType_pluginKeyword(). eg the visual plugin function for line representation is named svgGrapher_visual_line and is in a file named svgGrapher.visual.line.php in visuals plugins directory.

The plugins are call using PluginManager class. They can access to SvgGrapher using SvgGrapher::singleton() method.

exemple of plugin who insert a js script in the svg:

  1. /**
  2.  * 
  3.  * @param string $scriptPath path to the script file
  4.  * @return void 
  5.  */
  6. function svgGrapher_script_js($scriptPath{
  7.     // check the params
  8.     if(!is_file($scriptPath{
  9.         throw new Exception('Wrong params for svgGrapher script js plugin,
  10.         $scriptPath must be a valid file path');
  11.     }
  12.     
  13.     // get the script content
  14.     $js implode(''file($scriptPath));
  15.     
  16.     // create script element
  17.     $script new ScriptElement($js);
  18.     
  19.     // get the SvgGrapher instance
  20.     $grapher SvgGrapher::singleton();
  21.  
  22.     // add the script element in the group element svgEcma
  23.     $grapher->svgEcma[$script;
  24. }


How to use plugin ?

To use a plugin call the SvgGrapher::getPlugin() method.

  1. $graph new SvgGrapher();
  2.  
  3. // put the data
  4. PluginManager::execute('dataprovider''myPluginToGetDataAndSetCurves');
  5.  
  6. // insert js script
  7. PluginManager::execute('script''js''path/to/my/script.js');
  8.  
  9. // render
  10. $graph->genGraph();
  11. $graph->drawSVG();


Documentation generated on Tue, 23 Oct 2007 11:31:50 +0200 by phpDocumentor 1.4.0