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 / Plotarea.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  39.5 KB  |  1,145 lines

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * Image_Graph - PEAR PHP OO Graph Rendering Utility.
  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.  * @subpackage Plotarea
  24.  * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  25.  * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  26.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  27.  * @version    CVS: $Id: Plotarea.php,v 1.23 2006/02/28 22:48:07 nosey Exp $
  28.  * @link       http://pear.php.net/package/Image_Graph
  29.  */
  30.  
  31. /**
  32.  * Include file Image/Graph/Layout.php
  33.  */
  34. require_once 'Image/Graph/Layout.php';
  35.  
  36. /**
  37.  * Plot area used for drawing plots.
  38.  *
  39.  * The plotarea consists of an x-axis and an y-axis, the plotarea can plot multiple
  40.  * charts within one plotares, by simply adding them (the axis' will scale to the
  41.  * plots automatically). A graph can consist of more plotareas
  42.  *
  43.  * @category   Images
  44.  * @package    Image_Graph
  45.  * @subpackage Plotarea
  46.  * @author     Jesper Veggerby <pear.nosey@veggerby.dk>
  47.  * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
  48.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  49.  * @version    Release: 0.7.2
  50.  * @link       http://pear.php.net/package/Image_Graph
  51.  */
  52. class Image_Graph_Plotarea extends Image_Graph_Layout
  53. {
  54.     
  55.     /**
  56.      * The left most pixel of the 'real' plot area on the canvas
  57.      * @var int
  58.      * @access private
  59.      */
  60.     var $_plotLeft = 0;
  61.  
  62.     /**
  63.      * The top most pixel of the 'real' plot area on the canvas
  64.      * @var int
  65.      * @access private
  66.      */
  67.     var $_plotTop = 0;
  68.  
  69.     /**
  70.      * The right most pixel of the 'real' plot area on the canvas
  71.      * @var int
  72.      * @access private
  73.      */
  74.     var $_plotRight = 0;
  75.  
  76.     /**
  77.      * The bottom most pixel of the 'real' plot area on the canvas
  78.      * @var int
  79.      * @access private
  80.      */
  81.     var $_plotBottom = 0;
  82.  
  83.     /**
  84.      * The X axis
  85.      * @var Axis
  86.      * @access private
  87.      */
  88.     var $_axisX = null;
  89.  
  90.     /**
  91.      * The Y axis
  92.      * @var Axis
  93.      * @access private
  94.      */
  95.     var $_axisY = null;
  96.  
  97.     /**
  98.      * The secondary Y axis
  99.      * @var Axis
  100.      * @access private
  101.      */
  102.     var $_axisYSecondary = null;
  103.  
  104.     /**
  105.      * The border style of the 'real' plot area
  106.      * @var LineStyle
  107.      * @access private
  108.      */
  109.     var $_plotBorderStyle = null;
  110.  
  111.     /**
  112.      * Does any plot have any data?
  113.      * @var bool
  114.      * @access private
  115.      */
  116.     var $_hasData = false;
  117.     
  118.     /**
  119.      * Is the plotarea horizontal?
  120.      * @var bool
  121.      * @access private
  122.      */
  123.     var $_horizontal = false;
  124.  
  125.     /**
  126.      * Image_Graph_Plotarea [Constructor]
  127.      *
  128.      * @param string $axisX The class of the X axis (if omitted a std. axis is created)
  129.      * @param string $axisY The class of the Y axis (if omitted a std. axis is created)
  130.      * @param string $direction The direction of the plotarea - 'horizontal' or 'vertical' (default)
  131.      */
  132.     function Image_Graph_Plotarea($axisX = 'Image_Graph_Axis_Category', $axisY = 'Image_Graph_Axis', $direction = 'vertical')
  133.     {
  134.         parent::Image_Graph_Layout();
  135.  
  136.         $this->_padding = array('left' => 5, 'top' => 5, 'right' => 5, 'bottom' => 5);;
  137.  
  138.         include_once 'Image/Graph.php';
  139.  
  140.         $this->_axisX =& Image_Graph::factory($axisX, IMAGE_GRAPH_AXIS_X);
  141.         $this->_axisX->_setParent($this);
  142.  
  143.         $this->_axisY =& Image_Graph::factory($axisY, IMAGE_GRAPH_AXIS_Y);
  144.         $this->_axisY->_setParent($this);
  145.         $this->_axisY->_setMinimum(0);
  146.  
  147.         $this->_fillStyle = false;
  148.         
  149.         if ($direction == 'horizontal') {
  150.             $this->_horizontal = true;
  151.             $this->_axisX->_transpose = true;
  152.             $this->_axisY->_transpose = true;
  153.         }
  154.     }
  155.  
  156.     /**
  157.      * Sets the parent. The parent chain should ultimately be a GraPHP object
  158.      *
  159.      * @see Image_Graph_Common
  160.      * @param Image_Graph_Common $parent The parent
  161.      * @access private
  162.      */
  163.     function _setParent(& $parent)
  164.     {
  165.         parent::_setParent($parent);
  166.         if ($this->_axisX !== null) {
  167.             $this->_axisX->_setParent($this);
  168.         }
  169.         if ($this->_axisY !== null) {
  170.             $this->_axisY->_setParent($this);
  171.         }
  172.         if ($this->_axisYSecondary !== null) {
  173.             $this->_axisYSecondary->_setParent($this);
  174.         }
  175.     }
  176.  
  177.     /**
  178.      * Sets the plot border line style of the element.
  179.      *
  180.      * @param Image_Graph_Line $lineStyle The line style of the border
  181.      * @deprecated 0.3.0dev2 - 2004-12-16
  182.      */
  183.     function setPlotBorderStyle(& $plotBorderStyle)
  184.     {        
  185.     }
  186.  
  187.     /**
  188.      * Adds an element to the plotarea
  189.      *
  190.      * @param Image_Graph_Element $element The element to add
  191.      * @param int $axis The axis to associate the element with, either
  192.      * IMAGE_GRAPH_AXIS_X, IMAGE_GRAPH_AXIS_Y, IMAGE_GRAPH_AXIS_Y_SECONDARY
  193.      * or the shorter string notations 'x', 'y' or 'ysec' (defaults to
  194.      * IMAGE_GRAPH_AXIS_Y)
  195.      * @return Image_Graph_Element The added element
  196.      * @see Image_Graph_Common::add()
  197.      */
  198.     function &add(& $element, $axis = IMAGE_GRAPH_AXIS_Y)    
  199.     {
  200.         if ($axis == 'x') {
  201.             $axis = IMAGE_GRAPH_AXIS_X;
  202.         }
  203.         if ($axis == 'y') {
  204.             $axis = IMAGE_GRAPH_AXIS_Y;
  205.         }
  206.         if ($axis == 'ysec') {
  207.             $axis = IMAGE_GRAPH_AXIS_Y_SECONDARY;
  208.         }
  209.         if (($axis == IMAGE_GRAPH_AXIS_Y_SECONDARY) &&
  210.             ($this->_axisYSecondary == null))
  211.         {
  212.             $this->_axisYSecondary =& Image_Graph::factory('axis', IMAGE_GRAPH_AXIS_Y_SECONDARY);
  213.             $this->_axisYSecondary->_setMinimum(0);
  214.             if ($this->_horizontal) {
  215.                 $this->_axisYSecondary->_transpose = true;
  216.             }
  217.         }
  218.  
  219.         parent::add($element);
  220.  
  221.         if (is_a($element, 'Image_Graph_Plot')) {
  222.             $element->_setAxisY($axis);
  223.             // postpone extrema calculation until we calculate coordinates
  224.             //$this->_setExtrema($element);
  225.         } elseif (is_a($element, 'Image_Graph_Grid')) {
  226.             switch ($axis) {
  227.             case IMAGE_GRAPH_AXIS_X:
  228.                 if ($this->_axisX != null) {
  229.                     $element->_setPrimaryAxis($this->_axisX);
  230.                     if ($this->_axisY != null) {
  231.                         $element->_setSecondaryAxis($this->_axisY);
  232.                     }
  233.                 }
  234.                 break;
  235.             case IMAGE_GRAPH_AXIS_Y:
  236.                 if ($this->_axisY != null) {
  237.                     $element->_setPrimaryAxis($this->_axisY);
  238.                     if ($this->_axisX != null) {
  239.                         $element->_setSecondaryAxis($this->_axisX);
  240.                     }
  241.                 }
  242.                 break;
  243.             case IMAGE_GRAPH_AXIS_Y_SECONDARY:
  244.                 if ($this->_axisYSecondary != null) {
  245.                     $element->_setPrimaryAxis($this->_axisYSecondary);
  246.                     if ($this->_axisX != null) {
  247.                         $element->_setSecondaryAxis($this->_axisX);
  248.                     }
  249.                 }
  250.                 break;
  251.             }
  252.         } elseif (is_a($element, 'Image_Graph_Axis')) {
  253.             switch ($element->_type) {
  254.             case IMAGE_GRAPH_AXIS_X:
  255.                 $this->_axisX =& $element;
  256.                 break;
  257.  
  258.             case IMAGE_GRAPH_AXIS_Y:
  259.                 $this->_axisY =& $element;
  260.                 break;
  261.  
  262.             case IMAGE_GRAPH_AXIS_Y_SECONDARY:
  263.                 $this->_axisYSecondary =& $element;
  264.                 break;
  265.  
  266.             }
  267.             if ($element->_getMinimum() == $element->_getMaximum()) {
  268.                 $element->_setMinimum(0);
  269.                 $element->_setMaximum(1);
  270.             }
  271.         }
  272.         return $element;
  273.     }    
  274.  
  275.     /**
  276.      * Get the width of the 'real' plotarea
  277.      *
  278.      * @return int The width of the 'real' plotarea, ie not including space occupied by padding and axis
  279.      * @access private
  280.      */
  281.     function _plotWidth()
  282.     {
  283.         return abs($this->_plotRight - $this->_plotLeft);
  284.     }
  285.  
  286.     /**
  287.      * Get the height of the 'real' plotarea
  288.      *
  289.      * @return int The height of the 'real' plotarea, ie not including space
  290.      *   occupied by padding and axis
  291.      * @access private
  292.      */
  293.     function _plotHeight()
  294.     {
  295.         return abs($this->_plotBottom - $this->_plotTop);
  296.     }
  297.  
  298.     /**
  299.      * Set the extrema of the axis
  300.      *
  301.      * @param Image_Graph_Plot $plot The plot that 'hold' the values
  302.      * @access private
  303.      */
  304.     function _setExtrema(& $plot)
  305.     {
  306.         if (($this->_axisX != null) && ($this->_axisX->_isNumeric())) {
  307.             $this->_axisX->_setMinimum($plot->_minimumX());
  308.             $this->_axisX->_setMaximum($plot->_maximumX());
  309.         }
  310.  
  311.         if (($plot->_axisY == IMAGE_GRAPH_AXIS_Y_SECONDARY) &&
  312.             ($this->_axisYSecondary !== null) &&
  313.             ($this->_axisYSecondary->_isNumeric()))
  314.         {
  315.             $this->_axisYSecondary->_setMinimum($plot->_minimumY());
  316.             $this->_axisYSecondary->_setMaximum($plot->_maximumY());
  317.         } elseif (($this->_axisY != null) && ($this->_axisY->_isNumeric())) {
  318.             $this->_axisY->_setMinimum($plot->_minimumY());
  319.             $this->_axisY->_setMaximum($plot->_maximumY());
  320.         }
  321.  
  322.         $datasets =& $plot->dataset();
  323.         if (!is_array($datasets)) {
  324.             $datasets = array($datasets);
  325.         }
  326.         
  327.         $keys = array_keys($datasets);
  328.         foreach ($keys as $key) {
  329.             $dataset =& $datasets[$key];
  330.             if ($dataset->count() > 0) {
  331.                 $this->_hasData = true;
  332.             }
  333.             
  334.             if (is_a($dataset, 'Image_Graph_Dataset')) {
  335.                 if (($this->_axisX != null) && (!$this->_axisX->_isNumeric())) {
  336.                     $this->_axisX->_applyDataset($dataset);
  337.                 }
  338.  
  339.                 if (($plot->_axisY == IMAGE_GRAPH_AXIS_Y_SECONDARY) &&
  340.                     ($this->_axisYSecondary !== null) &&
  341.                     (!$this->_axisYSecondary->_isNumeric()))
  342.                 {
  343.                     $this->_axisYSecondary->_applyDataset($dataset);
  344.                 } elseif (($this->_axisY != null) && (!$this->_axisY->_isNumeric())) {
  345.                     $this->_axisY->_applyDataset($dataset);
  346.                 }
  347.             }
  348.         }
  349.         unset($keys);
  350.     }
  351.  
  352.     /**
  353.      * Left boundary of the background fill area
  354.      *
  355.      * @return int Leftmost position on the canvas
  356.      * @access private
  357.      */
  358.     function _fillLeft()
  359.     {
  360.         return $this->_plotLeft;
  361.     }
  362.  
  363.     /**
  364.      * Top boundary of the background fill area
  365.      *
  366.      * @return int Topmost position on the canvas
  367.      * @access private
  368.      */
  369.     function _fillTop()
  370.     {
  371.         return $this->_plotTop;
  372.     }
  373.  
  374.     /**
  375.      * Right boundary of the background fill area
  376.      *
  377.      * @return int Rightmost position on the canvas
  378.      * @access private
  379.      */
  380.     function _fillRight()
  381.     {
  382.         return $this->_plotRight;
  383.     }
  384.  
  385.     /**
  386.      * Bottom boundary of the background fill area
  387.      *
  388.      * @return int Bottommost position on the canvas
  389.      * @access private
  390.      */
  391.     function _fillBottom()
  392.     {
  393.         return $this->_plotBottom;
  394.     }
  395.  
  396.     /**
  397.      * Get the point from the x-axis
  398.      * @param array $value The value array
  399.      * @param int $min The minimum pixel position possible
  400.      * @param int $max The maximum pixel position possible
  401.      * @return int The pixel position from the axis
  402.      * @access private
  403.      */
  404.     function _axisPointX($value, $min, $max)
  405.     {
  406.         if (($this->_axisX == null) || (!isset($value['X']))) {
  407.             return false;
  408.         }
  409.  
  410.         if ($value['X'] === '#min#') {
  411.             return $min;
  412.         }
  413.         if ($value['X'] === '#max#') {
  414.             return $max;
  415.         }
  416.  
  417.         return $this->_axisX->_point($value['X']);
  418.     }
  419.     
  420.     /**
  421.      * Get the point from the x-axis
  422.      * @param array $value The value array
  423.      * @param int $min The minimum pixel position possible
  424.      * @param int $max The maximum pixel position possible
  425.      * @return int The pixel position from the axis
  426.      * @access private
  427.      */
  428.     function _axisPointY($value, $min, $max)
  429.     {
  430.         if (!isset($value['Y'])) {
  431.             return false;
  432.         }
  433.     
  434.         if (($value['Y'] === '#min_pos#') || ($value['Y'] === '#max_nex#')) {
  435.             // return the minimum (bottom) position or if negative then zero
  436.             // or the maxmum (top) position or if positive then zero
  437.             if ((isset($value['AXIS_Y'])) &&
  438.                 ($value['AXIS_Y'] == IMAGE_GRAPH_AXIS_Y_SECONDARY) &&
  439.                 ($this->_axisYSecondary !== null)
  440.             ) {
  441.                 $axisY =& $this->_axisYSecondary;
  442.             } else {
  443.                 $axisY =& $this->_axisY;
  444.             }
  445.             if ($value['Y'] === '#min_pos#') {
  446.                 return $axisY->_point(max(0, $axisY->_getMinimum()));
  447.             } else {
  448.                 return $axisY->_point(min(0, $axisY->_getMaximum()));
  449.             }
  450.         }
  451.     
  452.         if ($value['Y'] === '#min#') {
  453.             return $min;
  454.         }
  455.         if ($value['Y'] === '#max#') {
  456.             return $max;
  457.         }
  458.     
  459.         if ((isset($value['AXIS_Y'])) &&
  460.             ($value['AXIS_Y'] == IMAGE_GRAPH_AXIS_Y_SECONDARY)
  461.         ) {
  462.             if ($this->_axisYSecondary !== null) {
  463.                 return $this->_axisYSecondary->_point($value['Y']);
  464.             }
  465.         } else {
  466.             if ($this->_axisY !== null) {
  467.                 return $this->_axisY->_point($value['Y']);
  468.             }
  469.         }
  470.         return false;      
  471.     }
  472.  
  473.     /**
  474.      * Get the X pixel position represented by a value
  475.      *
  476.      * @param double Value the value to get the pixel-point for
  477.      * @return double The pixel position along the axis
  478.      * @access private
  479.      */
  480.     function _pointX($value)
  481.     {
  482.         if ($this->_horizontal) {
  483.             return $this->_axisPointY($value, $this->_plotLeft, $this->_plotRight);
  484.         }
  485.         else {
  486.             return $this->_axisPointX($value, $this->_plotLeft, $this->_plotRight);
  487.         }
  488.     }
  489.  
  490.     /**
  491.      * Get the Y pixel position represented by a value
  492.      *
  493.      * @param double Value the value to get the pixel-point for
  494.      * @return double The pixel position along the axis
  495.      * @access private
  496.      */
  497.     function _pointY($value)
  498.     {
  499.         if ($this->_horizontal) {
  500.             return $this->_axisPointX($value, $this->_plotBottom, $this->_plotTop);
  501.         }
  502.         else {
  503.             return $this->_axisPointY($value, $this->_plotBottom, $this->_plotTop);
  504.         }
  505.     }
  506.  
  507.     /**
  508.      * Return the minimum value of the specified axis
  509.      *
  510.      * @param int $axis The axis to return the minimum value of (see {$link
  511.      * Image_Graph_Plotarea::getAxis()})
  512.      * @return double The minimum value of the axis
  513.      * @access private
  514.      */
  515.     function _getMinimum($axis = IMAGE_GRAPH_AXIS_Y)
  516.     {
  517.         $axis =& $this->getAxis($axis);
  518.         if ($axis !== null) {
  519.             return $axis->_getMinimum();
  520.         } else {
  521.             return 0;
  522.         }
  523.     }
  524.  
  525.     /**
  526.      * Return the maximum value of the specified axis
  527.      *
  528.      * @param int $axis The axis to return the maximum value of(see {$link
  529.      * Image_Graph_Plotarea::getAxis()})
  530.      * @return double The maximum value of the axis
  531.      * @access private
  532.      */
  533.     function _getMaximum($axis = IMAGE_GRAPH_AXIS_Y)
  534.     {
  535.         $axis =& $this->getAxis($axis);
  536.         if ($axis !== null) {
  537.             return $axis->_getMaximum();
  538.         } else {
  539.             return 0;
  540.         }
  541.     }
  542.  
  543.     /**
  544.      * Return the label distance for the specified axis.
  545.      *
  546.      * @param int $axis The axis to return the label distance for
  547.      * @return int The distance between 2 adjacent labels
  548.      * @access private
  549.      */
  550.     function _labelDistance($axis)
  551.     {
  552.         $axis =& $this->getAxis($axis);
  553.         if ($axis !== null) {
  554.             return $axis->_labelDistance();
  555.         }
  556.  
  557.         return false;
  558.     }
  559.  
  560.     /**
  561.      * Hides the axis
  562.      */
  563.     function hideAxis($axis = false)
  564.     {
  565.         if (((!$axis) || ($axis === $this->_axisX) || ($axis === 'x')) && ($this->_axisX != null)) {
  566.             $this->_axisX->hide();
  567.         }            
  568.         if (((!$axis) || ($axis === $this->_axisY) || ($axis === 'y')) && ($this->_axisY != null)) {
  569.             $this->_axisY->hide();
  570.         }            
  571.         if (((!$axis) || ($axis === $this->_axisYSecondary) || ($axis === 'y_sec')) && ($this->_axisYSecondary != null)) {
  572.             $this->_axisYSecondary->hide();
  573.         }            
  574.     }
  575.  
  576.     /**
  577.      * Clears/removes the axis
  578.      */
  579.     function clearAxis()
  580.     {
  581.         $this->_axisX = $this->_axisY = $this->_axisYSecondary = null;
  582.     }
  583.         
  584.     /**
  585.      * Get axis.
  586.      * 
  587.      * Possible values are IMAGE_GRAPH_AXIS_X, IMAGE_GRAPH_AXIS_Y,
  588.      * IMAGE_GRAPH_AXIS_Y_SECONDARY or a short hand notation using
  589.      * string identifiers: 'x', 'y', 'ysec'
  590.      * 
  591.      * @param int $axis The axis to return
  592.      * @return Image_Graph_Axis The axis
  593.      */
  594.     function &getAxis($axis = IMAGE_GRAPH_AXIS_X)
  595.     {
  596.         switch ($axis) {
  597.         case IMAGE_GRAPH_AXIS_X:
  598.         case 'x':
  599.             return $this->_axisX;
  600.  
  601.         case IMAGE_GRAPH_AXIS_Y:
  602.         case 'y':
  603.             return $this->_axisY;
  604.  
  605.         case IMAGE_GRAPH_AXIS_Y_SECONDARY:
  606.         case 'ysec':
  607.             return $this->_axisYSecondary;
  608.  
  609.         }
  610.         return null;
  611.     }
  612.  
  613.     /**
  614.      * Update coordinates
  615.      *
  616.      * @access private
  617.      */
  618.     function _updateCoords()
  619.     {               
  620.         if (is_array($this->_elements)) {
  621.             $keys = array_keys($this->_elements);
  622.             foreach ($keys as $key) {
  623.                 $element =& $this->_elements[$key];
  624.                 if (is_a($element, 'Image_Graph_Plot')) { 
  625.                     if (((is_a($element, 'Image_Graph_Plot_Bar')) ||
  626.                         (is_a($element, 'Image_Graph_Plot_Step')) ||
  627.                         (is_a($element, 'Image_Graph_Plot_Dot')) ||
  628.                         (is_a($element, 'Image_Graph_Plot_CandleStick')) ||
  629.                         (is_a($element, 'Image_Graph_Plot_BoxWhisker')) ||
  630.                         (is_a($element, 'Image_Graph_Plot_Impulse'))) &&
  631.                         ($this->_axisX != null) &&
  632.                         (strtolower(get_class($this->_axisX)) != 'image_graph_axis') // do not push plot if x-axis is linear
  633.                         )
  634.                     {
  635.                        $this->_axisX->_pushValues();
  636.                     }
  637.                     $this->_setExtrema($element);
  638.                 }
  639.             }
  640.             unset($keys);
  641.         }
  642.  
  643.         $this->_calcEdges();
  644.  
  645.         $pctWidth = (int) ($this->width() * 0.05);
  646.         $pctHeight = (int) ($this->height() * 0.05);
  647.  
  648.         $left = $this->_left + $this->_padding['left'];
  649.         $top = $this->_top + $this->_padding['top'];
  650.         $right = $this->_right - $this->_padding['right'];
  651.         $bottom = $this->_bottom - $this->_padding['bottom'];
  652.         
  653.         // temporary place holder for axis point calculations
  654.         $axisPoints['x'] = array($left, $top, $right, $bottom);
  655.         $axisPoints['y'] = $axisPoints['x'];
  656.         $axisPoints['y2'] = $axisPoints['x'];
  657.                 
  658.         if ($this->_axisX !== null) {
  659.             $intersectX = $this->_axisX->_getAxisIntersection();
  660.             $sizeX = $this->_axisX->_size();
  661.             $this->_axisX->_setCoords($left, $top, $right, $bottom);
  662.             $this->_axisX->_updateCoords();            
  663.         }
  664.         
  665.         if ($this->_axisY !== null) {
  666.             $intersectY = $this->_axisY->_getAxisIntersection();
  667.             $sizeY = $this->_axisY->_size();
  668.             $this->_axisY->_setCoords($left, $top, $right, $bottom);
  669.             $this->_axisY->_updateCoords();
  670.         }
  671.  
  672.         if ($this->_axisYSecondary !== null) {
  673.             $intersectYsec = $this->_axisYSecondary->_getAxisIntersection();
  674.             $sizeYsec = $this->_axisYSecondary->_size();
  675.             $this->_axisYSecondary->_setCoords($left, $top, $right, $bottom);
  676.             $this->_axisYSecondary->_updateCoords();
  677.         }   
  678.         
  679.         $axisCoordAdd = array('left' => 0, 'right' => 0, 'top' => 0, 'bottom' => 0);
  680.              
  681.         if ($this->_axisY != null) {
  682.             if ($this->_axisX != null) {                
  683.                 $pos = $this->_axisX->_intersectPoint($intersectY['value']);                
  684.             } else {
  685.                 $pos = ($this->_horizontal ? $bottom : $left);
  686.             }
  687.  
  688.             if ($this->_horizontal) {
  689.                 if (($pos + $sizeY) > $bottom) {
  690.                     $axisCoordAdd['bottom'] = ($pos + $sizeY) - $bottom;                    
  691.                     // the y-axis position needs to be recalculated!                
  692.                 } else {            
  693.                     // top & bottom may need to be adjusted when the x-axis has been
  694.                     // calculated!
  695.                     $this->_axisY->_setCoords(
  696.                         $left,
  697.                         $pos,
  698.                         $right,
  699.                         $pos + $sizeY
  700.                     );
  701.                     $this->_axisY->_updateCoords();
  702.                 }
  703.             }
  704.             else {
  705.                 if (($pos - $sizeY) < $left) {
  706.                     $axisCoordAdd['left'] = $left - ($pos - $sizeY);
  707.                     // the y-axis position needs to be recalculated!                
  708.                 } else {            
  709.                     // top & bottom may need to be adjusted when the x-axis has been
  710.                     // calculated!
  711.                     $this->_axisY->_setCoords(
  712.                         $pos - $sizeY,
  713.                         $top,
  714.                         $pos,
  715.                         $bottom
  716.                     );
  717.                     $this->_axisY->_updateCoords();
  718.                 }
  719.             }      
  720.         }      
  721.  
  722.         if ($this->_axisYSecondary != null) {
  723.             if ($this->_axisX != null) {
  724.                 $pos = $this->_axisX->_intersectPoint($intersectYsec['value']);
  725.             } else {
  726.                 $pos = ($this->_horizontal ? $top : $right);
  727.             }
  728.             
  729.             if ($this->_horizontal) {
  730.                 if (($pos - $sizeYsec) < $top) {
  731.                     $axisCoordAdd['top'] = $top - ($pos - $sizeYsec);
  732.                     // the secondary y-axis position need to be recalculated
  733.                 } else {
  734.                     // top & bottom may need to be adjusted when the x-axis has been
  735.                     // calculated!
  736.                     $this->_axisYSecondary->_setCoords(
  737.                         $left,
  738.                         $pos - $sizeY,
  739.                         $right,
  740.                         $pos
  741.                     );
  742.                     $this->_axisYSecondary->_updateCoords();
  743.                 }
  744.             }
  745.             else {
  746.                 if (($pos + $sizeYsec) > $right) {
  747.                     $axisCoordAdd['right'] = ($pos + $sizeYsec) - $right;
  748.                     // the secondary y-axis position need to be recalculated
  749.                 } else {
  750.                     // top & bottom may need to be adjusted when the x-axis has been
  751.                     // calculated!
  752.                     $this->_axisYSecondary->_setCoords(
  753.                         $pos,
  754.                         $top,
  755.                         $pos + $sizeY,
  756.                         $bottom
  757.                     );
  758.                     $this->_axisYSecondary->_updateCoords();
  759.                 }
  760.             }      
  761.         }      
  762.         
  763.         if ($this->_axisX != null) {
  764.             if (($intersectX['axis'] == IMAGE_GRAPH_AXIS_Y_SECONDARY) &&
  765.                 ($this->_axisYSecondary !== null)
  766.             ) {
  767.                 $axis =& $this->_axisYSecondary;
  768.             } elseif ($this->_axisY !== null) {
  769.                 $axis =& $this->_axisY;
  770.             } else {
  771.                 $axis = false;
  772.             }
  773.             
  774.             if ($axis !== false) {
  775.                 $pos = $axis->_intersectPoint($intersectX['value']);
  776.             } else {
  777.                 $pos = ($this->_horizontal ? $left : $bottom);
  778.             }
  779.              
  780.             if ($this->_horizontal) {
  781.                 if (($pos - $sizeX) < $left) {
  782.                     $axisCoordAdd['left'] = $left - ($pos - $sizeX);
  783.                     $pos = $left + $sizeX;
  784.                 }
  785.                           
  786.                 $this->_axisX->_setCoords(
  787.                     $pos - $sizeX,
  788.                     $top + $axisCoordAdd['top'],
  789.                     $pos,
  790.                     $bottom - $axisCoordAdd['bottom']
  791.                 );
  792.                 $this->_axisX->_updateCoords();
  793.             }
  794.             else {
  795.                 if (($pos + $sizeX) > $bottom) {
  796.                     $axisCoordAdd['bottom'] = ($pos + $sizeX) - $bottom;
  797.                     $pos = $bottom - $sizeX;
  798.                 }
  799.                           
  800.                 $this->_axisX->_setCoords(
  801.                     $left + $axisCoordAdd['left'],
  802.                     $pos,
  803.                     $right - $axisCoordAdd['right'],
  804.                     $pos + $sizeX
  805.                 );
  806.                 $this->_axisX->_updateCoords();
  807.             }
  808.         }
  809.         
  810.         if ($this->_horizontal) {
  811.             if (($this->_axisX !== null) && 
  812.                 (($axisCoordAdd['top'] != 0) ||
  813.                 ($axisCoordAdd['bottom'] != 0))
  814.             ) {
  815.                 // readjust y-axis for better estimate of position
  816.                 if ($this->_axisY !== null) {
  817.                     $pos = $this->_axisX->_intersectPoint($intersectY['value']);
  818.                     $this->_axisY->_setCoords(
  819.                         false,
  820.                         $pos,
  821.                         false,
  822.                         $pos + $sizeY
  823.                     );
  824.                     $this->_axisY->_updateCoords();
  825.                 }
  826.     
  827.                 if ($this->_axisYSecondary !== null) {
  828.                     $pos = $this->_axisX->_intersectPoint($intersectYsec['value']);
  829.                     $this->_axisYSecondary->_setCoords(
  830.                         false,
  831.                         $pos - $sizeYsec,
  832.                         false,
  833.                         $pos
  834.                     );
  835.                     $this->_axisYSecondary->_updateCoords();
  836.                 }
  837.             }        
  838.             
  839.             // adjust top and bottom of y-axis
  840.             if ($this->_axisY !== null) {
  841.                 $this->_axisY->_setCoords(
  842.                     $left + $axisCoordAdd['left'],
  843.                     false, 
  844.                     $right - $axisCoordAdd['right'],
  845.                     false                   
  846.                 );
  847.                 $this->_axisY->_updateCoords();
  848.             } 
  849.     
  850.             // adjust top and bottom of y-axis
  851.             if ($this->_axisYSecondary !== null) {
  852.                 $this->_axisYSecondary->_setCoords(
  853.                     $left + $axisCoordAdd['left'], 
  854.                     false, 
  855.                     $right - $axisCoordAdd['right'],
  856.                     false                    
  857.                 );
  858.                 $this->_axisYSecondary->_updateCoords();            
  859.             } 
  860.         
  861.             if ($this->_axisX !== null) {
  862.                 $this->_plotTop = $this->_axisX->_top;
  863.                 $this->_plotBottom = $this->_axisX->_bottom;
  864.             } else {
  865.                 $this->_plotTop = $top;
  866.                 $this->_plotBottom = $bottom;
  867.             }
  868.             
  869.             if ($this->_axisY !== null) {
  870.                 $this->_plotLeft = $this->_axisY->_left;
  871.                 $this->_plotRight = $this->_axisY->_right;
  872.             } elseif ($this->_axisYSecondary !== null) {
  873.                 $this->_plotLeft = $this->_axisYSecondary->_left;
  874.                 $this->_plotRight = $this->_axisYSecondary->_right;
  875.             } else {
  876.                 $this->_plotLeft = $this->_left;
  877.                 $this->_plotRight = $this->_right;
  878.             }
  879.         }
  880.         else {
  881.             if (($this->_axisX !== null) && 
  882.                 (($axisCoordAdd['left'] != 0) ||
  883.                 ($axisCoordAdd['right'] != 0))
  884.             ) {
  885.                 // readjust y-axis for better estimate of position
  886.                 if ($this->_axisY !== null) {
  887.                     $pos = $this->_axisX->_intersectPoint($intersectY['value']);
  888.                     $this->_axisY->_setCoords(
  889.                         $pos - $sizeY,
  890.                         false,
  891.                         $pos,
  892.                         false
  893.                     );
  894.                     $this->_axisY->_updateCoords();
  895.                 }
  896.     
  897.                 if ($this->_axisYSecondary !== null) {
  898.                     $pos = $this->_axisX->_intersectPoint($intersectYsec['value']);
  899.                     $this->_axisYSecondary->_setCoords(
  900.                         $pos,
  901.                         false,
  902.                         $pos + $sizeYsec,
  903.                         false
  904.                     );
  905.                     $this->_axisYSecondary->_updateCoords();
  906.                 }
  907.             }        
  908.             
  909.             // adjust top and bottom of y-axis
  910.             if ($this->_axisY !== null) {
  911.                 $this->_axisY->_setCoords(
  912.                     false, 
  913.                     $top + $axisCoordAdd['top'], 
  914.                     false, 
  915.                     $bottom - $axisCoordAdd['bottom']
  916.                 );
  917.                 $this->_axisY->_updateCoords();
  918.             } 
  919.     
  920.             // adjust top and bottom of y-axis
  921.             if ($this->_axisYSecondary !== null) {
  922.                 $this->_axisYSecondary->_setCoords(
  923.                     false, 
  924.                     $top + $axisCoordAdd['top'], 
  925.                     false, 
  926.                     $bottom - $axisCoordAdd['bottom']
  927.                 );
  928.                 $this->_axisYSecondary->_updateCoords();            
  929.             } 
  930.         
  931.             if ($this->_axisX !== null) {
  932.                 $this->_plotLeft = $this->_axisX->_left;
  933.                 $this->_plotRight = $this->_axisX->_right;
  934.             } else {
  935.                 $this->_plotLeft = $left;
  936.                 $this->_plotRight = $right;
  937.             }
  938.             
  939.             if ($this->_axisY !== null) {
  940.                 $this->_plotTop = $this->_axisY->_top;
  941.                 $this->_plotBottom = $this->_axisY->_bottom;
  942.             } elseif ($this->_axisYSecondary !== null) {
  943.                 $this->_plotTop = $this->_axisYSecondary->_top;
  944.                 $this->_plotBottom = $this->_axisYSecondary->_bottom;
  945.             } else {
  946.                 $this->_plotTop = $this->_top;
  947.                 $this->_plotBottom = $this->_bottom;
  948.             }
  949.         }
  950.         
  951.         Image_Graph_Element::_updateCoords();
  952. /*
  953.         if ($this->_axisX != null) {
  954.             $this->_axisX->_updateCoords();
  955.         }
  956.         if ($this->_axisY != null) {
  957.             $this->_axisY->_updateCoords();
  958.         }
  959.         if ($this->_axisYSecondary != null) {
  960.             $this->_axisYSecondary->_updateCoords();
  961.         }*/
  962.     }
  963.     
  964.     /**
  965.      * Set the axis padding for a specified position.
  966.      * 
  967.      * The axis padding is padding "inside" the plotarea (i.e. to put some space
  968.      * between the axis line and the actual plot).
  969.      * 
  970.      * This can be specified in a number of ways:
  971.      * 
  972.      * 1) Specify an associated array with 'left', 'top', 'right' and 'bottom'
  973.      * indices with values for the paddings. Leave out 2nd parameter.
  974.      * 
  975.      * 2) Specify an overall padding as the first parameter
  976.      * 
  977.      * 3) Specify the padding and position with position values as mentioned
  978.      * above
  979.      * 
  980.      * Normally you'd only consider applying axis padding to a category x-axis.
  981.      * 
  982.      * @param mixed $value The value/padding
  983.      * @param mixed $position The "position" of the padding
  984.      */
  985.     function setAxisPadding($value, $position = false)
  986.     {
  987.         if ($position === false) {
  988.             if (is_array($value)) {
  989.                 if ($this->_horizontal) {
  990.                     if ((isset($value['top'])) && ($this->_axisX !== null)) {
  991.                         $this->_axisX->_setAxisPadding('low', $value['top']);
  992.                     }
  993.                     if ((isset($value['bottom'])) && ($this->_axisX !== null)) {
  994.                         $this->_axisX->_setAxisPadding('high', $value['bottom']);
  995.                     }
  996.                     if ((isset($value['left'])) && ($this->_axisY !== null)) {
  997.                         $this->_axisY->_setAxisPadding('low', $value['left']);
  998.                     }
  999.                     if ((isset($value['right'])) && ($this->_axisY !== null)) {               
  1000.                         $this->_axisY->_setAxisPadding('high', $value['right']);
  1001.                     }
  1002.                     if ((isset($value['left'])) && ($this->_axisYSecondary !== null)) {
  1003.                         $this->_axisYSecondary->_setAxisPadding('low', $value['left']);
  1004.                     }
  1005.                     if ((isset($value['right'])) && ($this->_axisYSecondary !== null)) {               
  1006.                         $this->_axisYSecondary->_setAxisPadding('high', $value['right']);
  1007.                     }
  1008.                 }
  1009.                 else {
  1010.                     if ((isset($value['left'])) && ($this->_axisX !== null)) {
  1011.                         $this->_axisX->_setAxisPadding('low', $value['left']);
  1012.                     }
  1013.                     if ((isset($value['right'])) && ($this->_axisX !== null)) {
  1014.                         $this->_axisX->_setAxisPadding('high', $value['right']);
  1015.                     }
  1016.                     if ((isset($value['bottom'])) && ($this->_axisY !== null)) {
  1017.                         $this->_axisY->_setAxisPadding('low', $value['bottom']);
  1018.                     }
  1019.                     if ((isset($value['top'])) && ($this->_axisY !== null)) {               
  1020.                         $this->_axisY->_setAxisPadding('high', $value['top']);
  1021.                     }
  1022.                     if ((isset($value['bottom'])) && ($this->_axisYSecondary !== null)) {
  1023.                         $this->_axisYSecondary->_setAxisPadding('low', $value['bottom']);
  1024.                     }
  1025.                     if ((isset($value['top'])) && ($this->_axisYSecondary !== null)) {               
  1026.                         $this->_axisYSecondary->_setAxisPadding('high', $value['top']);
  1027.                     }
  1028.                 }
  1029.             } else {
  1030.                 if ($this->_axisX !== null) {
  1031.                     $this->_axisX->_setAxisPadding('low', $value);
  1032.                     $this->_axisX->_setAxisPadding('high', $value);
  1033.                 }
  1034.                 if ($this->_axisY !== null) {
  1035.                     $this->_axisY->_setAxisPadding('low', $value);
  1036.                     $this->_axisY->_setAxisPadding('high', $value);
  1037.                 }
  1038.                 if ($this->_axisYSecondary !== null) {
  1039.                     $this->_axisYSecondary->_setAxisPadding('low', $value);
  1040.                     $this->_axisYSecondary->_setAxisPadding('high', $value);
  1041.                 }
  1042.             }
  1043.         } else {
  1044.             switch ($position) {
  1045.             case 'left': 
  1046.                 if ($this->_horizontal) {
  1047.                     if ($this->_axisY !== null) {
  1048.                         $this->_axisY->_setAxisPadding('low', $value);
  1049.                     }
  1050.                     if ($this->_axisYSecondary !== null) {
  1051.                         $this->_axisYSecondary->_setAxisPadding('low', $value);
  1052.                     }
  1053.                 }
  1054.                 else if ($this->_axisX !== null) {
  1055.                    $this->_axisX->_setAxisPadding('low', $value);
  1056.                 }
  1057.                 break;
  1058.  
  1059.             case 'right': 
  1060.                 if ($this->_horizontal) {
  1061.                     if ($this->_axisY !== null) {
  1062.                         $this->_axisY->_setAxisPadding('high', $value);
  1063.                     }
  1064.                     if ($this->_axisYSecondary !== null) {
  1065.                         $this->_axisYSecondary->_setAxisPadding('high', $value);
  1066.                     }
  1067.                 }
  1068.                 else if ($this->_axisX !== null) {
  1069.                    $this->_axisX->_setAxisPadding('high', $value);
  1070.                 }
  1071.                 break;
  1072.  
  1073.             case 'top': 
  1074.                 if (!$this->_horizontal) {
  1075.                     if ($this->_axisY !== null) {
  1076.                         $this->_axisY->_setAxisPadding('high', $value);
  1077.                     }
  1078.                     if ($this->_axisYSecondary !== null) {
  1079.                         $this->_axisYSecondary->_setAxisPadding('high', $value);
  1080.                     }
  1081.                 }
  1082.                 else if ($this->_axisX !== null) {
  1083.                    $this->_axisX->_setAxisPadding('high', $value);
  1084.                 }               
  1085.                 break;
  1086.  
  1087.             case 'bottom': 
  1088.                 if (!$this->_horizontal) {
  1089.                     if ($this->_axisY !== null) {
  1090.                         $this->_axisY->_setAxisPadding('low', $value);
  1091.                     }
  1092.                     if ($this->_axisYSecondary !== null) {
  1093.                         $this->_axisYSecondary->_setAxisPadding('low', $value);
  1094.                     }
  1095.                 }
  1096.                 else if ($this->_axisX !== null) {
  1097.                    $this->_axisX->_setAxisPadding('low', $value);
  1098.                 }
  1099.                 break;
  1100.             }
  1101.         }
  1102.     }
  1103.     
  1104.     /**
  1105.      * Output the plotarea to the canvas
  1106.      *
  1107.      * @return bool Was the output 'good' (true) or 'bad' (false).
  1108.      * @access private
  1109.      */
  1110.     function _done()
  1111.     {
  1112.         if ($this->_hasData) {        
  1113.             $this->_canvas->startGroup(get_class($this));
  1114.         
  1115.             if ($this->_axisX != null) {
  1116.                 $this->add($this->_axisX);
  1117.             }
  1118.             if ($this->_axisY != null) {
  1119.                 $this->add($this->_axisY);
  1120.             }
  1121.             if ($this->_axisYSecondary != null) {
  1122.                 $this->add($this->_axisYSecondary);
  1123.             }
  1124.     
  1125.             $this->_getFillStyle();
  1126.             $this->_canvas->rectangle(
  1127.                 array(
  1128.                     'x0' => $this->_plotLeft,
  1129.                     'y0' => $this->_plotTop,
  1130.                     'x1' => $this->_plotRight,
  1131.                     'y1' => $this->_plotBottom
  1132.                 )
  1133.             );
  1134.             $result = parent::_done();
  1135.             $this->_canvas->endGroup();            
  1136.             return $result;
  1137.         } else {
  1138.             // no data -> do nothing at all!
  1139.             return true;
  1140.         }        
  1141.     }
  1142.  
  1143. }
  1144.  
  1145. ?>