home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Image / Graph.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  27.1 KB  |  851 lines

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * Image_Graph - Main class for the graph creation.
  7.  *
  8.  * PHP versions 4 and 5
  9.  *
  10.  * LICENSE: This library is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU Lesser General Public License as published by
  12.  * the Free Software Foundation; either version 2.1 of the License, or (at your
  13.  * option) any later version. This library is distributed in the hope that it
  14.  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  15.  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
  16.  * General Public License for more details. You should have received a copy of
  17.  * the GNU Lesser General Public License along with this library; if not, write
  18.  * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19.  * 02111-1307 USA
  20.  *
  21.  * @category   Images
  22.  * @package    Image_Graph
  23.  * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  24.  * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  25.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  26.  * @version    CVS: $Id: Graph.php,v 1.58 2005/11/27 18:48:05 nosey Exp $
  27.  * @link       http://pear.php.net/package/Image_Graph
  28.  */
  29.  
  30.  
  31. /**
  32.  * Include PEAR.php
  33.  */
  34. require_once 'PEAR.php';
  35.  
  36. /**
  37.  * Include file Image/Graph/Element.php
  38.  */
  39. require_once 'Image/Graph/Element.php';
  40.  
  41. /**
  42.  * Include file Image/Graph/Constants.php
  43.  */
  44. require_once 'Image/Graph/Constants.php';
  45.  
  46. /**
  47.  * Main class for the graph creation.
  48.  *
  49.  * This is the main class, it manages the canvas and performs the final output
  50.  * by sequentialy making the elements output their results. The final output is
  51.  * handled using the {@link Image_Canvas} classes which makes it possible
  52.  * to use different engines (fx GD, PDFlib, libswf, etc) for output to several
  53.  * formats with a non-intersecting API.
  54.  *
  55.  * This class also handles coordinates and the correct managment of setting the
  56.  * correct coordinates on child elements.
  57.  *
  58.  * @category   Images
  59.  * @package    Image_Graph
  60.  * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  61.  * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  62.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  63.  * @version    Release: 0.7.2
  64.  * @link       http://pear.php.net/package/Image_Graph
  65.  */
  66. class Image_Graph extends Image_Graph_Element
  67. {
  68.  
  69.     /**
  70.      * Show generation time on graph
  71.      * @var bool
  72.      * @access private
  73.      */
  74.     var $_showTime = false;
  75.  
  76.     /**
  77.      * Display errors on the canvas
  78.      * @var boolean
  79.      * @access private
  80.      */
  81.     var $_displayErrors = false;
  82.  
  83.     /**
  84.      * Image_Graph [Constructor].
  85.      *
  86.      * If passing the 3 parameters they are defined as follows:'
  87.      * 
  88.      * Fx.:
  89.      * 
  90.      * $Graph =& new Image_Graph(400, 300);
  91.      * 
  92.      * or using the factory method:
  93.      * 
  94.      * $Graph =& Image_Graph::factory('graph', array(400, 300));
  95.      * 
  96.      * This causes a 'png' canvas to be created by default. 
  97.      * 
  98.      * Otherwise use a single parameter either as an associated array or passing
  99.      * the canvas along to the constructor:
  100.      *
  101.      * 1) Create a new canvas with the following parameters:
  102.      *
  103.      * 'canvas' - The canvas type, can be any of 'gd', 'jpg', 'png' or 'svg'
  104.      * (more to come) - if omitted the default is 'gd'
  105.      *
  106.      * 'width' - The width of the graph
  107.      *
  108.      * 'height' - The height of the graph
  109.      * 
  110.      * An example of this usage:
  111.      * 
  112.      * $Graph =& Image_Graph::factory('graph', array(array('width' => 400,
  113.      * 'height' => 300, 'canvas' => 'jpg')));
  114.      * 
  115.      * NB! In th∩s case remember the "double" array (see {@link Image_Graph::
  116.      * factory()})
  117.      * 
  118.      * 2) Use the canvas specified, pass a valid Image_Canvas as
  119.      * parameter. Remember to pass by reference, i. e. &$canvas, fx.:
  120.      *
  121.      * $Graph =& new Image_Graph($Canvas);
  122.      *
  123.      * or using the factory method:
  124.      *
  125.      * $Graph =& Image_Graph::factory('graph', $Canvas));
  126.      *
  127.      * @param mixed $params The width of the graph, an indexed array
  128.      * describing a new canvas or a valid {@link Image_Canvas} object
  129.      * @param int $height The height of the graph in pixels
  130.      * @param bool $createTransparent Specifies whether the graph should be
  131.      *   created with a transparent background (fx for PNG's - note: transparent
  132.      *   PNG's is not supported by Internet Explorer!)
  133.      */
  134.     function Image_Graph($params, $height = false, $createTransparent = false)
  135.     {
  136.         parent::Image_Graph_Element();
  137.  
  138.         $this->setFont(Image_Graph::factory('Image_Graph_Font'));
  139.  
  140.         if (defined('IMAGE_GRAPH_DEFAULT_CANVAS_TYPE')) {
  141.             $canvasType = IMAGE_GRAPH_DEFAULT_CANVAS_TYPE;
  142.         } else {
  143.             $canvasType = 'png'; // use GD as default, if nothing else is specified
  144.         }
  145.  
  146.         if (is_array($params)) {
  147.             if (isset($params['canvas'])) {
  148.                 $canvasType = $params['canvas'];
  149.             }
  150.  
  151.             $width = 0;
  152.             $height = 0;
  153.  
  154.             if (isset($params['width'])) {
  155.                 $width = $params['width'];
  156.             }
  157.  
  158.             if (isset($params['height'])) {
  159.                 $height = $params['height'];
  160.             }
  161.         } elseif (is_a($params, 'Image_Canvas')) {
  162.             $this->_canvas =& $params;
  163.             $width = $this->_canvas->getWidth();
  164.             $height = $this->_canvas->getHeight();
  165.         } elseif (is_numeric($params)) {
  166.             $width = $params;
  167.         }
  168.  
  169.         if ($this->_canvas == null) {
  170.             include_once 'Image/Canvas.php';
  171.             $this->_canvas =&
  172.                 Image_Canvas::factory(
  173.                     $canvasType,
  174.                     array('width' => $width, 'height' => $height)
  175.                 );
  176.         }
  177.  
  178.         $this->_setCoords(0, 0, $width - 1, $height - 1);
  179.     }
  180.  
  181.     /**
  182.      * Gets the canvas for this graph.
  183.      *
  184.      * The canvas is set by either passing it to the constructor {@link
  185.      * Image_Graph::ImageGraph()} or using the {@link Image_Graph::setCanvas()}
  186.      * method.
  187.      *
  188.      * @return Image_Canvas The canvas used by this graph
  189.      * @access private
  190.      * @since 0.3.0dev2
  191.      */
  192.     function &_getCanvas()
  193.     {
  194.         return $this->_canvas;
  195.     }
  196.  
  197.     /**
  198.      * Sets the canvas for this graph.
  199.      *
  200.      * Calling this method makes this graph use the newly specified canvas for
  201.      * handling output. This method should be called whenever multiple
  202.      * 'outputs' are required. Invoke this method after calls to {@link
  203.      * Image_Graph:: done()} has been performed, to switch canvass.
  204.      *
  205.      * @param Image_Canvas $canvas The new canvas
  206.      * @return Image_Canvas The new canvas
  207.      * @since 0.3.0dev2
  208.      */
  209.     function &setCanvas(&$canvas)
  210.     {
  211.         if (!is_a($this->_canvas, 'Image_Canvas')) {
  212.             return $this->_error('The canvas introduced is not an Image_Canvas object');
  213.         }
  214.         
  215.         $this->_canvas =& $canvas;
  216.         $this->_setCoords(
  217.             0,
  218.             0,
  219.             $this->_canvas->getWidth() - 1,
  220.             $this->_canvas->getHeight() - 1
  221.         );
  222.         return $this->_canvas;
  223.     }
  224.  
  225.     /**
  226.      * Gets a very precise timestamp
  227.      *
  228.      * @return The number of seconds to a lot of decimals
  229.      * @access private
  230.      */
  231.     function _getMicroTime()
  232.     {
  233.         list($usec, $sec) = explode(' ', microtime()); 
  234.         return ((float)$usec + (float)$sec); 
  235.     }
  236.  
  237.     /**
  238.      * Gets the width of this graph.
  239.      *
  240.      * The width is returned as 'defined' by the canvas.
  241.      *
  242.      * @return int the width of this graph
  243.      */
  244.     function width()
  245.     {
  246.         return $this->_canvas->getWidth();
  247.     }
  248.  
  249.     /**
  250.      * Gets the height of this graph.
  251.      *
  252.      * The height is returned as 'defined' by the canvas.
  253.      *
  254.      * @return int the height of this graph
  255.      */
  256.     function height()
  257.     {
  258.         return $this->_canvas->getHeight();
  259.     }
  260.  
  261.     /**
  262.      * Enables displaying of errors on the output.
  263.      *
  264.      * Use this method to enforce errors to be displayed on the output. Calling
  265.      * this method makes PHP uses this graphs error handler as default {@link
  266.      * Image_Graph::_default_error_handler()}.
  267.      */
  268.     function displayErrors()
  269.     {
  270.         $this->_displayErrors = true;
  271.         set_error_handler(array(&$this, '_default_error_handler'));
  272.     }
  273.  
  274.     /**
  275.      * Sets the log method for this graph.
  276.      *
  277.      * Use this method to enable logging. This causes any errors caught
  278.      * by either the error handler {@see Image_Graph::displayErrors()}
  279.      * or explicitly by calling {@link Image_Graph_Common::_error()} be
  280.      * logged using the specified logging method.
  281.      *
  282.      * If a filename is specified as log method, a Log object is created (using
  283.      * the 'file' handler), with a handle of 'Image_Graph Error Log'.
  284.      *
  285.      * Logging requires {@link Log}.
  286.      *
  287.      * @param mixed $log The log method, either a Log object or filename to log
  288.      * to
  289.      * @since 0.3.0dev2
  290.      */
  291.     function setLog($log)
  292.     {
  293.     }
  294.  
  295.     /**
  296.      * Factory method to create Image_Graph objects.
  297.      *
  298.      * Used for 'lazy including', i.e. loading only what is necessary, when it
  299.      * is necessary. If only one parameter is required for the constructor of
  300.      * the class simply pass this parameter as the $params parameter, unless the
  301.      * parameter is an array or a reference to a value, in that case you must
  302.      * 'enclose' the parameter in an array. Similar if the constructor takes
  303.      * more than one parameter specify the parameters in an array, i.e
  304.      *
  305.      * Image_Graph::factory('MyClass', array($param1, $param2, &$param3));
  306.      *
  307.      * Variables that need to be passed by reference *must* have the &
  308.      * before the variable, i.e:
  309.      *
  310.      * Image_Graph::factory('line', &$Dataset);
  311.      *
  312.      * or
  313.      *
  314.      * Image_graph::factory('bar', array(array(&$Dataset1, &$Dataset2),
  315.      * 'stacked'));
  316.      *
  317.      * Class name can be either of the following:
  318.      *
  319.      * 1 The 'real' Image_Graph class name, i.e. Image_Graph_Plotarea or
  320.      * Image_Graph_Plot_Line
  321.      *
  322.      * 2 Short class name (leave out Image_Graph) and retain case, i.e.
  323.      * Plotarea, Plot_Line *not* plot_line
  324.      *
  325.      * 3 Class name 'alias', the following are supported:
  326.      *
  327.      * 'graph' = Image_Graph
  328.      *
  329.      * 'plotarea' = Image_Graph_Plotarea
  330.      *
  331.      * 'line' = Image_Graph_Plot_Line
  332.      *
  333.      * 'area' = Image_Graph_Plot_Area
  334.      *
  335.      * 'bar' = Image_Graph_Plot_Bar
  336.      *
  337.      * 'pie' = Image_Graph_Plot_Pie
  338.      *
  339.      * 'radar' = Image_Graph_Plot_Radar
  340.      *
  341.      * 'step' = Image_Graph_Plot_Step
  342.      *
  343.      * 'impulse' = Image_Graph_Plot_Impulse
  344.      *
  345.      * 'dot' or 'scatter' = Image_Graph_Plot_Dot
  346.      *
  347.      * 'smooth_line' = Image_Graph_Plot_Smoothed_Line
  348.      *
  349.      * 'smooth_area' = Image_Graph_Plot_Smoothed_Area
  350.  
  351.      * 'dataset' = Image_Graph_Dataset_Trivial
  352.      *
  353.      * 'random' = Image_Graph_Dataset_Random
  354.      *
  355.      * 'function' = Image_Graph_Dataset_Function
  356.      *
  357.      * 'vector' = Image_Graph_Dataset_VectorFunction
  358.      *
  359.      * 'category' = Image_Graph_Axis_Category
  360.      *
  361.      * 'axis' = Image_Graph_Axis
  362.      *
  363.      * 'axis_log' = Image_Graph_Axis_Logarithmic
  364.      *
  365.      * 'title' = Image_Graph_Title
  366.      *
  367.      * 'line_grid' = Image_Graph_Grid_Lines
  368.      *
  369.      * 'bar_grid' = Image_Graph_Grid_Bars
  370.      *
  371.      * 'polar_grid' = Image_Graph_Grid_Polar
  372.      *
  373.      * 'legend' = Image_Graph_Legend
  374.      *
  375.      * 'font' = Image_Graph_Font
  376.      *
  377.      * 'ttf_font' = Image_Graph_Font
  378.      * 
  379.      * 'Image_Graph_Font_TTF' = Image_Graph_Font (to maintain BC with Image_Graph_Font_TTF)
  380.      *
  381.      * 'gradient' = Image_Graph_Fill_Gradient
  382.      *
  383.      * 'icon_marker' = Image_Graph_Marker_Icon
  384.      *
  385.      * 'value_marker' = Image_Graph_Marker_Value
  386.      *
  387.      * @param string $class The class for the new object
  388.      * @param mixed $params The paramaters to pass to the constructor
  389.      * @return object A new object for the class
  390.      * @static
  391.      */
  392.     function &factory($class, $params = null)
  393.     {
  394.         static $Image_Graph_classAliases = array(
  395.             'graph'          => 'Image_Graph',
  396.             'plotarea'       => 'Image_Graph_Plotarea',            
  397.  
  398.             'line'           => 'Image_Graph_Plot_Line',
  399.             'area'           => 'Image_Graph_Plot_Area',
  400.             'bar'            => 'Image_Graph_Plot_Bar',
  401.             'smooth_line'    => 'Image_Graph_Plot_Smoothed_Line',
  402.             'smooth_area'    => 'Image_Graph_Plot_Smoothed_Area',
  403.             'pie'            => 'Image_Graph_Plot_Pie',
  404.             'radar'          => 'Image_Graph_Plot_Radar',
  405.             'step'           => 'Image_Graph_Plot_Step',
  406.             'impulse'        => 'Image_Graph_Plot_Impulse',
  407.             'dot'            => 'Image_Graph_Plot_Dot',
  408.             'scatter'        => 'Image_Graph_Plot_Dot',
  409.  
  410.             'dataset'        => 'Image_Graph_Dataset_Trivial',
  411.             'random'         => 'Image_Graph_Dataset_Random',
  412.             'function'       => 'Image_Graph_Dataset_Function',
  413.             'vector'         => 'Image_Graph_Dataset_VectorFunction',
  414.  
  415.             'category'       => 'Image_Graph_Axis_Category',
  416.             'axis'           => 'Image_Graph_Axis',
  417.             'axis_log'       => 'Image_Graph_Axis_Logarithmic',
  418.  
  419.             'title'          => 'Image_Graph_Title',
  420.  
  421.             'line_grid'      => 'Image_Graph_Grid_Lines',
  422.             'bar_grid'       => 'Image_Graph_Grid_Bars',
  423.             'polar_grid'     => 'Image_Graph_Grid_Polar',
  424.  
  425.             'legend'         => 'Image_Graph_Legend',
  426.             'font'             => 'Image_Graph_Font',
  427.             'ttf_font'       => 'Image_Graph_Font',
  428.             'Image_Graph_Font_TTF' => 'Image_Graph_Font', // BC with Image_Graph_Font_TTF
  429.             'gradient'       => 'Image_Graph_Fill_Gradient',
  430.  
  431.             'icon_marker'    => 'Image_Graph_Marker_Icon',
  432.             'value_marker'   => 'Image_Graph_Marker_Value'
  433.         );
  434.                                 
  435.         if (substr($class, 0, 11) != 'Image_Graph') {
  436.             if (isset($Image_Graph_classAliases[$class])) {
  437.                 $class = $Image_Graph_classAliases[$class];
  438.             } else {
  439.                 $class = 'Image_Graph_' . $class;
  440.             }
  441.         }
  442.  
  443.         include_once str_replace('_', '/', $class) . '.php';
  444.  
  445.         $obj = null;
  446.  
  447.         if (is_array($params)) {
  448.             switch (count($params)) {
  449.             case 1:
  450.                 $obj =& new $class(
  451.                     $params[0]
  452.                 );
  453.                 break;
  454.  
  455.             case 2:
  456.                 $obj =& new $class(
  457.                     $params[0],
  458.                     $params[1]
  459.                 );
  460.                 break;
  461.  
  462.             case 3:
  463.                 $obj =& new $class(
  464.                     $params[0],
  465.                     $params[1],
  466.                     $params[2]
  467.                 );
  468.                 break;
  469.  
  470.             case 4:
  471.                 $obj =& new $class(
  472.                     $params[0],
  473.                     $params[1],
  474.                     $params[2],
  475.                     $params[3]
  476.                 );
  477.                 break;
  478.  
  479.             case 5:
  480.                 $obj =& new $class(
  481.                     $params[0],
  482.                     $params[1],
  483.                     $params[2],
  484.                     $params[3],
  485.                     $params[4]
  486.                 );
  487.                 break;
  488.  
  489.             case 6:
  490.                 $obj =& new $class(
  491.                     $params[0],
  492.                     $params[1],
  493.                     $params[2],
  494.                     $params[3],
  495.                     $params[4],
  496.                     $params[5]
  497.                 );
  498.                 break;
  499.  
  500.             case 7:
  501.                 $obj =& new $class(
  502.                     $params[0],
  503.                     $params[1],
  504.                     $params[2],
  505.                     $params[3],
  506.                     $params[4],
  507.                     $params[5],
  508.                     $params[6]
  509.                 );
  510.                 break;
  511.  
  512.             case 8:
  513.                 $obj =& new $class(
  514.                     $params[0],
  515.                     $params[1],
  516.                     $params[2],
  517.                     $params[3],
  518.                     $params[4],
  519.                     $params[5],
  520.                     $params[6],
  521.                     $params[7]
  522.                 );
  523.                 break;
  524.  
  525.             case 9:
  526.                 $obj =& new $class(
  527.                     $params[0],
  528.                     $params[1],
  529.                     $params[2],
  530.                     $params[3],
  531.                     $params[4],
  532.                     $params[5],
  533.                     $params[6],
  534.                     $params[7],
  535.                     $params[8]
  536.                 );
  537.                 break;
  538.  
  539.             case 10:
  540.                 $obj =& new $class(
  541.                     $params[0],
  542.                     $params[1],
  543.                     $params[2],
  544.                     $params[3],
  545.                     $params[4],
  546.                     $params[5],
  547.                     $params[6],
  548.                     $params[7],
  549.                     $params[8],
  550.                     $params[9]
  551.                 );
  552.                 break;
  553.  
  554.             default:
  555.                 $obj =& new $class();
  556.                 break;
  557.  
  558.             }
  559.         } else {
  560.             if ($params == null) {
  561.                 $obj =& new $class();
  562.             } else {
  563.                 $obj =& new $class($params);
  564.             }
  565.         }
  566.         return $obj;
  567.     }
  568.  
  569.     /**
  570.      * Factory method to create layouts.
  571.      *
  572.      * This method is used for easy creation, since using {@link Image_Graph::
  573.      * factory()} does not work with passing newly created objects from
  574.      * Image_Graph::factory() as reference, this is something that is
  575.      * fortunately fixed in PHP5. Also used for 'lazy including', i.e. loading
  576.      * only what is necessary, when it is necessary.
  577.      *
  578.      * Use {@link Image_Graph::horizontal()} or {@link Image_Graph::vertical()}
  579.      * instead for easier access.
  580.      *
  581.      * @param mixed $layout The type of layout, can be either 'Vertical'
  582.      *   or 'Horizontal' (case sensitive)
  583.      * @param Image_Graph_Element $part1 The 1st part of the layout
  584.      * @param Image_Graph_Element $part2 The 2nd part of the layout
  585.      * @param int $percentage The percentage of the layout to split at
  586.      * @return Image_Graph_Layout The newly created layout object
  587.      * @static
  588.      */
  589.     function &layoutFactory($layout, &$part1, &$part2, $percentage = 50)
  590.     {
  591.         if (($layout != 'Vertical') && ($layout != 'Horizontal')) {
  592.             return $this->_error('Layouts must be either \'Horizontal\' or \'Vertical\'');
  593.         }
  594.         
  595.         if (!(is_a($part1, 'Image_Graph_Element'))) {
  596.             return $this->_error('Part 1 is not a valid Image_Graph element');
  597.         }
  598.         
  599.         if (!(is_a($part2, 'Image_Graph_Element'))) {
  600.             return $this->_error('Part 2 is not a valid Image_Graph element');
  601.         }
  602.         
  603.         if ((!is_numeric($percentage)) || ($percentage < 0) || ($percentage > 100)) {
  604.             return $this->_error('Percentage has to be a number between 0 and 100');
  605.         }
  606.         
  607.         include_once "Image/Graph/Layout/$layout.php";
  608.         $class = "Image_Graph_Layout_$layout";
  609.         $obj =& new $class($part1, $part2, $percentage);
  610.         return $obj;
  611.     }
  612.  
  613.     /**
  614.      * Factory method to create horizontal layout.
  615.      *
  616.      * See {@link Image_Graph::layoutFactory()}
  617.      *
  618.      * @param Image_Graph_Element $part1 The 1st (left) part of the layout
  619.      * @param Image_Graph_Element $part2 The 2nd (right) part of the layout
  620.      * @param int $percentage The percentage of the layout to split at
  621.      *   (percentage of total height from the left side)
  622.      * @return Image_Graph_Layout The newly created layout object
  623.      * @static
  624.      */
  625.     function &horizontal(&$part1, &$part2, $percentage = 50)
  626.     {
  627.         $obj =& Image_Graph::layoutFactory('Horizontal', $part1, $part2, $percentage);
  628.         return $obj;
  629.     }
  630.  
  631.     /**
  632.      * Factory method to create vertical layout.
  633.      *
  634.      * See {@link Image_Graph::layoutFactory()}
  635.      *
  636.      * @param Image_Graph_Element $part1 The 1st (top) part of the layout
  637.      * @param Image_Graph_Element $part2 The 2nd (bottom) part of the layout
  638.      * @param int $percentage The percentage of the layout to split at
  639.      *   (percentage of total width from the top edge)
  640.      * @return Image_Graph_Layout The newly created layout object
  641.      * @static
  642.      */
  643.     function &vertical(&$part1, &$part2, $percentage = 50)
  644.     {
  645.         $obj =& Image_Graph::layoutFactory('Vertical', $part1, $part2, $percentage);
  646.         return $obj;
  647.     }
  648.  
  649.     /**
  650.      * The error handling routine set by set_error_handler().
  651.      *
  652.      * This method is used internaly by Image_Graph and PHP as a proxy for {@link
  653.      * Image_Graph::_error()}. 
  654.      *
  655.      * @param string $error_type The type of error being handled.
  656.      * @param string $error_msg The error message being handled.
  657.      * @param string $error_file The file in which the error occurred.
  658.      * @param integer $error_line The line in which the error occurred.
  659.      * @param string $error_context The context in which the error occurred.
  660.      * @access private
  661.      */
  662.     function _default_error_handler($error_type, $error_msg, $error_file, $error_line, $error_context)
  663.     {
  664.         switch( $error_type ) {
  665.         case E_ERROR:
  666.             $level = 'error';
  667.             break;
  668.  
  669.         case E_USER_ERROR:
  670.             $level = 'user error';
  671.             break;
  672.  
  673.         case E_WARNING:
  674.             $level = 'warning';
  675.             break;
  676.  
  677.         case E_USER_WARNING:
  678.             $level = 'user warning';
  679.             break;
  680.  
  681.         case E_NOTICE:
  682.             $level = 'notice';
  683.             break;
  684.  
  685.         case E_USER_NOTICE:
  686.             $level = 'user notice';
  687.             break;
  688.  
  689.         default:
  690.             $level = '(unknown)';
  691.             break;
  692.  
  693.         }
  694.  
  695.         $this->_error("PHP $level: $error_msg",
  696.             array(
  697.                 'type' => $error_type,
  698.                 'file' => $error_file,
  699.                 'line' => $error_line,
  700.                 'context' => $error_context
  701.             )
  702.         );
  703.     }
  704.  
  705.     /**
  706.      * Displays the errors on the error stack.
  707.      *
  708.      * Invoking this method cause all errors on the error stack to be displayed
  709.      * on the graph-output, by calling the {@link Image_Graph::_displayError()}
  710.      * method.
  711.      *
  712.      * @access private
  713.      */
  714.     function _displayErrors()
  715.     {
  716.         return true;
  717.     }
  718.  
  719.     /**
  720.      * Display an error from the error stack.
  721.      *
  722.      * This method writes error messages caught from the {@link Image_Graph::
  723.      * _default_error_handler()} if {@Image_Graph::displayErrors()} was invoked,
  724.      * and the error explicitly set by the system using {@link
  725.      * Image_Graph_Common::_error()}.
  726.      *
  727.      * @param int $x The horizontal position of the error message
  728.      * @param int $y The vertical position of the error message
  729.      * @param array $error The error context
  730.      *
  731.      * @access private
  732.      */
  733.     function _displayError($x, $y, $error)
  734.     {
  735.     }
  736.  
  737.     /**
  738.      * Outputs this graph using the canvas.
  739.      *
  740.      * This causes the graph to make all elements perform their output. Their
  741.      * result is 'written' to the output using the canvas, which also performs
  742.      * the actual output, fx. it being to a file or directly to the browser
  743.      * (in the latter case, the canvas will also make sure the correct HTTP
  744.      * headers are sent, making the browser handle the output correctly, if
  745.      * supported by it).
  746.      * 
  747.      * Parameters are the ones supported by the canvas, common ones are:
  748.      * 
  749.      * 'filename' To output to a file instead of browser
  750.      * 
  751.      * 'tohtml' Return a HTML string that encompasses the current graph/canvas - this
  752.      * implies an implicit save using the following parameters: 'filename' The "temporary"
  753.      * filename of the graph, 'filepath' A path in the file system where Image_Graph can
  754.      * store the output (this file must be in DOCUMENT_ROOT scope), 'urlpath' The URL that the
  755.      * 'filepath' corresponds to (i.e. filepath + filename must be reachable from a browser using
  756.      * urlpath + filename) 
  757.      *
  758.      * @param mixed $param The output parameters to pass to the canvas
  759.      * @return bool Was the output 'good' (true) or 'bad' (false).
  760.      */
  761.     function done($param = false)
  762.     {
  763.         $result = $this->_reset();
  764.         if (PEAR::isError($result)) {
  765.             return $result;
  766.         }
  767.         return $this->_done($param);
  768.     }
  769.  
  770.     /**
  771.      * Outputs this graph using the canvas.
  772.      *
  773.      * This causes the graph to make all elements perform their output. Their
  774.      * result is 'written' to the output using the canvas, which also performs
  775.      * the actual output, fx. it being to a file or directly to the browser
  776.      * (in the latter case, the canvas will also make sure the correct HTTP
  777.      * headers are sent, making the browser handle the output correctly, if
  778.      * supported by it).
  779.      *
  780.      * @param mixed $param The output parameters to pass to the canvas
  781.      * @return bool Was the output 'good' (true) or 'bad' (false).
  782.      * @access private
  783.      */
  784.     function _done($param = false)
  785.     {
  786.         $timeStart = $this->_getMicroTime();
  787.  
  788.         if ($this->_shadow) {
  789.             $this->setPadding(20);
  790.             $this->_setCoords(
  791.                 $this->_left,
  792.                 $this->_top,
  793.                 $this->_right - 10,
  794.                 $this->_bottom - 10);
  795.         }
  796.  
  797.         $result = $this->_updateCoords();        
  798.         if (PEAR::isError($result)) {
  799.             return $result;
  800.         }
  801.  
  802.         if ($this->_getBackground()) {
  803.             $this->_canvas->rectangle(
  804.                 array(
  805.                     'x0' => $this->_left,
  806.                     'y0' => $this->_top,
  807.                     'x1' => $this->_right,
  808.                     'y1' => $this->_bottom
  809.                 )
  810.             );
  811.         }
  812.  
  813.         $result = parent::_done();
  814.         if (PEAR::isError($result)) {
  815.             return $result;
  816.         }
  817.  
  818.         if ($this->_displayErrors) {
  819.             $this->_displayErrors();
  820.         }
  821.  
  822.         $timeEnd = $this->_getMicroTime();
  823.  
  824.         if (($this->_showTime) || 
  825.             ((isset($param['showtime'])) && ($param['showtime'] === true))
  826.         ) {
  827.             $text = 'Generated in ' .
  828.                 sprintf('%0.3f', $timeEnd - $timeStart) . ' sec';
  829.             $this->write(
  830.                 $this->_right,
  831.                 $this->_bottom,
  832.                 $text,
  833.                 IMAGE_GRAPH_ALIGN_RIGHT + IMAGE_GRAPH_ALIGN_BOTTOM,
  834.                 array('color' => 'red')
  835.             );
  836.         }
  837.                
  838.         if (isset($param['filename'])) {
  839.             if ((isset($param['tohtml'])) && ($param['tohtml'])) {
  840.                 return $this->_canvas->toHtml($param);
  841.             }
  842.             else {
  843.                 return $this->_canvas->save($param);
  844.             }
  845.         } else {
  846.             return $this->_canvas->show($param);
  847.         }
  848.     }
  849. }
  850.  
  851. ?>