示例#1
0
 /**
  * Adds an element to the plotarea
  *
  * @param Image_Graph_Element $element The element to add
  * @param int $axis The axis to associate the element with, either
  * IMAGE_GRAPH_AXIS_X, IMAGE_GRAPH_AXIS_Y, IMAGE_GRAPH_AXIS_Y_SECONDARY
  * or the shorter string notations 'x', 'y' or 'ysec' (defaults to
  * IMAGE_GRAPH_AXIS_Y)
  * @return Image_Graph_Element The added element
  * @see Image_Graph_Common::add()
  */
 function &add(&$element, $axis = IMAGE_GRAPH_AXIS_Y)
 {
     if ($axis == 'x') {
         $axis = IMAGE_GRAPH_AXIS_X;
     }
     if ($axis == 'y') {
         $axis = IMAGE_GRAPH_AXIS_Y;
     }
     if ($axis == 'ysec') {
         $axis = IMAGE_GRAPH_AXIS_Y_SECONDARY;
     }
     if ($axis == IMAGE_GRAPH_AXIS_Y_SECONDARY && $this->_axisYSecondary == null) {
         $this->_axisYSecondary =& Image_Graph::factory('axis', IMAGE_GRAPH_AXIS_Y_SECONDARY);
         $this->_axisYSecondary->_setMinimum(0);
         if ($this->_horizontal) {
             $this->_axisYSecondary->_transpose = true;
         }
     }
     parent::add($element);
     if (is_a($element, 'Image_Graph_Plot')) {
         $element->_setAxisY($axis);
         // postpone extrema calculation until we calculate coordinates
         //$this->_setExtrema($element);
     } elseif (is_a($element, 'Image_Graph_Grid')) {
         switch ($axis) {
             case IMAGE_GRAPH_AXIS_X:
                 if ($this->_axisX != null) {
                     $element->_setPrimaryAxis($this->_axisX);
                     if ($this->_axisY != null) {
                         $element->_setSecondaryAxis($this->_axisY);
                     }
                 }
                 break;
             case IMAGE_GRAPH_AXIS_Y:
                 if ($this->_axisY != null) {
                     $element->_setPrimaryAxis($this->_axisY);
                     if ($this->_axisX != null) {
                         $element->_setSecondaryAxis($this->_axisX);
                     }
                 }
                 break;
             case IMAGE_GRAPH_AXIS_Y_SECONDARY:
                 if ($this->_axisYSecondary != null) {
                     $element->_setPrimaryAxis($this->_axisYSecondary);
                     if ($this->_axisX != null) {
                         $element->_setSecondaryAxis($this->_axisX);
                     }
                 }
                 break;
         }
     } elseif (is_a($element, 'Image_Graph_Axis')) {
         switch ($element->_type) {
             case IMAGE_GRAPH_AXIS_X:
                 $this->_axisX =& $element;
                 break;
             case IMAGE_GRAPH_AXIS_Y:
                 $this->_axisY =& $element;
                 break;
             case IMAGE_GRAPH_AXIS_Y_SECONDARY:
                 $this->_axisYSecondary =& $element;
                 break;
         }
         if ($element->_getMinimum() == $element->_getMaximum()) {
             $element->_setMinimum(0);
             $element->_setMaximum(1);
         }
     }
     return $element;
 }