Ejemplo n.º 1
0
 /**
  * Output an axis tick mark.
  *
  * @param int $value The value to output
  * @param int $level The label level to draw the tick for
  *
  * @return void
  * @access private
  */
 function _drawTick($value, $level = 1)
 {
     if (isset($this->_labelOptions[$level])) {
         $labelOptions = $this->_labelOptions[$level];
         $labelPosition = $this->_point($value);
         if (isset($labelOptions['offset'])) {
             $offset = $labelOptions['offset'];
         } else {
             $offset = 0;
         }
         if (isset($labelOptions['showtext']) && $labelOptions['showtext'] === true) {
             if (is_object($this->_dataPreProcessor)) {
                 $labelText = $this->_dataPreProcessor->_process($value);
             } elseif (isset($labelOptions['format'])) {
                 $labelText = sprintf($labelOptions['format'], $value);
             } elseif (isset($labelOptions['dateformat'])) {
                 $labelText = date($labelOptions['dateformat'], $value);
             } else {
                 $labelText = $value;
             }
             if (!in_array($labelText, $this->_labelText)) {
                 $this->_labelText[] = $labelText;
                 if (isset($labelOptions['font'])) {
                     $font = $this->_getFont($labelOptions['font']);
                 } else {
                     if ($this->_defaultFontOptions !== false) {
                         $font = $this->_defaultFontOptions;
                     } else {
                         $font = $this->_getFont();
                     }
                 }
                 $this->_canvas->setFont($font);
                 if (isset($labelOptions['position']) && $labelOptions['position'] == 'inside') {
                     $labelInside = true;
                 } else {
                     $labelInside = false;
                 }
                 if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
                     if ($this->_transpose) {
                         if ($labelInside) {
                             $this->write($labelPosition, $this->_top - 4 - $offset, $labelText, IMAGE_GRAPH_ALIGN_BOTTOM | IMAGE_GRAPH_ALIGN_CENTER_X, $font);
                         } else {
                             $this->write($labelPosition, $this->_top + 4 + $offset, $labelText, IMAGE_GRAPH_ALIGN_TOP | IMAGE_GRAPH_ALIGN_CENTER_X, $font);
                         }
                     } else {
                         if ($labelInside) {
                             $this->write($this->_right + 4 + $offset, $labelPosition, $labelText, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $font);
                         } else {
                             $this->write($this->_right - 4 - $offset, $labelPosition, $labelText, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT, $font);
                         }
                     }
                 } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {
                     if ($this->_transpose) {
                         if ($labelInside) {
                             $this->write($labelPosition, $this->_bottom + 4 + $offset, $labelText, IMAGE_GRAPH_ALIGN_TOP | IMAGE_GRAPH_ALIGN_CENTER_X, $font);
                         } else {
                             $this->write($labelPosition, $this->_bottom - 4 - $offset, $labelText, IMAGE_GRAPH_ALIGN_BOTTOM | IMAGE_GRAPH_ALIGN_CENTER_X, $font);
                         }
                     } else {
                         if ($labelInside) {
                             $this->write($this->_left - 4 - $offset, $labelPosition, $labelText, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT, $font);
                         } else {
                             $this->write($this->_left + 4 + $offset, $labelPosition, $labelText, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $font);
                         }
                     }
                 } else {
                     if ($this->_transpose) {
                         if ($labelInside) {
                             $this->write($this->_right + 4 + $offset, $labelPosition, $labelText, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT, $font);
                         } else {
                             $this->write($this->_right - 4 - $offset, $labelPosition, $labelText, IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT, $font);
                         }
                     } else {
                         if ($labelInside === true) {
                             $this->write($labelPosition, $this->_top - 4 - $offset, $labelText, IMAGE_GRAPH_ALIGN_CENTER_X | IMAGE_GRAPH_ALIGN_BOTTOM, $font);
                         } else {
                             $this->write($labelPosition, $this->_top + 4 + $offset, $labelText, IMAGE_GRAPH_ALIGN_CENTER_X | IMAGE_GRAPH_ALIGN_TOP, $font);
                         }
                     }
                 }
             }
         }
         $tickColor = false;
         if (isset($this->_labelOptions[$level]['tick'])) {
             if (isset($this->_labelOptions[$level]['tick']['start'])) {
                 $tickStart = $this->_labelOptions[$level]['tick']['start'];
             } else {
                 $tickStart = false;
             }
             if (isset($this->_labelOptions[$level]['tick']['end'])) {
                 $tickEnd = $this->_labelOptions[$level]['tick']['end'];
             } else {
                 $tickEnd = false;
             }
             if (isset($this->_labelOptions[$level]['tick']['color']) && $this->_labelOptions[$level]['tick']['color'] !== false) {
                 $tickColor = $this->_labelOptions[$level]['tick']['color'];
             }
         }
         if ($tickStart === false) {
             $tickStart = -2;
         }
         if ($tickEnd === false) {
             $tickEnd = 2;
         }
         if ($tickColor !== false) {
             $this->_canvas->setLineColor($tickColor);
         } else {
             $this->_getLineStyle();
         }
         if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
             if ($tickStart === 'auto') {
                 $tickStart = -$offset;
             }
             if ($this->_transpose) {
                 $this->_canvas->line(array('x0' => $labelPosition, 'y0' => $this->_top + $tickStart, 'x1' => $labelPosition, 'y1' => $this->_top + $tickEnd));
             } else {
                 $this->_canvas->line(array('x0' => $this->_right + $tickStart, 'y0' => $labelPosition, 'x1' => $this->_right + $tickEnd, 'y1' => $labelPosition));
             }
         } elseif ($this->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY) {
             if ($tickStart === 'auto') {
                 $tickStart = $offset;
             }
             if ($this->_transpose) {
                 $this->_canvas->line(array('x0' => $labelPosition, 'y0' => $this->_bottom - $tickStart, 'x1' => $labelPosition, 'y1' => $this->_bottom - $tickEnd));
             } else {
                 $this->_canvas->line(array('x0' => $this->_left - $tickStart, 'y0' => $labelPosition, 'x1' => $this->_left - $tickEnd, 'y1' => $labelPosition));
             }
         } else {
             if ($tickStart === 'auto') {
                 $tickStart = $offset;
             }
             if ($this->_transpose) {
                 $this->_canvas->line(array('x0' => $this->_right + $tickStart, 'y0' => $labelPosition, 'x1' => $this->_right + $tickEnd, 'y1' => $labelPosition));
             } else {
                 $this->_canvas->line(array('x0' => $labelPosition, 'y0' => $this->_top - $tickStart, 'x1' => $labelPosition, 'y1' => $this->_top - $tickEnd));
             }
         }
     }
 }
Ejemplo n.º 2
0
    /**
     * Output the axis
     * @access private
     */
    function _done()
    {
        parent::_done();

        if (!$this->_font) {
            $this->_font = $GLOBALS['_Image_Graph_font'];
        }

        $value = $this->_getNextLabel();
        
        $lastPosition = false;

        $this->_debug("Enumerating values from $value to ".$this->_getMaximum());
        while ($value <= $this->_getMaximum()) {
            if ((((abs($value) > 0.0001) or ($this->_showLabelZero)) and (($value > $this->_getMinimum()) or ($this->_showLabelMinimum)) and (($value < $this->_getMaximum()) or ($this->_showLabelMaximum))) and ($value>= $this->_getMinimum()) and ($value<= $this->_getMaximum())) {
                $labelPosition = $this->_point($value);

                if (is_object($this->_dataPreProcessor)) {
                    $labelText = $this->_dataPreProcessor->_process($value);
                } else {
                    $labelText = $value;
                }

                $doOutput = false;
                if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
                    $text = new Image_Graph_Text($this->_right - 3, $labelPosition, $labelText, $this->_font);
                    $text->setAlignment(IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT);
                    
                    if (($text->_fillBottom() < $lastPosition) or ($lastPosition === false)) {
                        $lastPosition = $text->_fillTop();
                        $doOutput = true;
                    }
                } else {
                    $text = new Image_Graph_Text($labelPosition, $this->_top + 3, $labelText, $this->_font);
                    $text->setAlignment(IMAGE_GRAPH_ALIGN_CENTER_X | IMAGE_GRAPH_ALIGN_TOP);

                    if (($text->_fillLeft() > $lastPosition) or ($lastPosition === false)) {
                        $lastPosition = $text->_fillRight();
                        $doOutput = true;
                    }
                }

                if ($doOutput) {
                    $this->add($text);
                    $text->_done();
                }

                if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
                    ImageLine($this->_canvas(), $this->_right, $labelPosition, $this->_right + 6, $labelPosition, $this->_getLineStyle());
                } else {
                    ImageLine($this->_canvas(), $labelPosition, $this->_top, $labelPosition, $this->_top - 6, $this->_getLineStyle());
                }
            }

            $nextValue = $this->_getNextLabel($value);
/*            if ($minorLabelInterval = $this->_minorLabelInterval()) {
                $minorValue = $value + $minorLabelInterval;
                while (($minorValue < $nextValue) and ($minorValue < $this->_getMaximum() - $minorLabelInterval)) {
                    if ($minorValue >= $this->_getMinimum()) {
                        $position = $this->_point($minorValue);
                        if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
                            ImageLine($this->_canvas(), $this->_right, $position, $this->_right + 3, $position, $this->_getLineStyle());
                        } else {
                            ImageLine($this->_canvas(), $position, $this->_top, $position, $this->_top - 3, $this->_getLineStyle());
                        }
                    }

                    $minorValue += $minorLabelInterval;
                }
            }*/

            $value = $nextValue;
        }

        if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
            ImageLine($this->_canvas(), $this->_right, $this->_top, $this->_right, $this->_bottom, $this->_getLineStyle());
            if ($this->_showArrow) {
                $arrow[] = $this->_right - 5;
                $arrow[] = $this->_top + 8;
                $arrow[] = $this->_right;
                $arrow[] = $this->_top;
                $arrow[] = $this->_right + 5;
                $arrow[] = $this->_top + 8;
                ImageFilledPolygon($this->_canvas(), $arrow, count($arrow) / 2, $this->_getFillStyle());
                ImagePolygon($this->_canvas(), $arrow, count($arrow) / 2, $this->_getLineStyle());
            }
        } else {
            ImageLine($this->_canvas(), $this->_left, $this->_top, $this->_right, $this->_top, $this->_getLineStyle());
            if ($this->_showArrow) {
                $arrow[] = $this->_right - 8;
                $arrow[] = $this->_top + 5;
                $arrow[] = $this->_right;
                $arrow[] = $this->_top;
                $arrow[] = $this->_right - 8;
                $arrow[] = $this->_top - 5;
                ImageFilledPolygon($this->_canvas(), $arrow, count($arrow) / 2, $this->_getFillStyle());
                ImagePolygon($this->_canvas(), $arrow, count($arrow) / 2, $this->_getLineStyle());
            }
        }
    }