Initial Commit of AgileBill Open Source
This commit is contained in:
426
includes/pear/Image/Graph/Axis/Category.php
Normal file
426
includes/pear/Image/Graph/Axis/Category.php
Normal file
@@ -0,0 +1,426 @@
|
||||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class for axis handling.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version. This library is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
||||
* General Public License for more details. You should have received a copy of
|
||||
* the GNU Lesser General Public License along with this library; if not, write
|
||||
* to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*
|
||||
* @category Images
|
||||
* @package Image_Graph
|
||||
* @subpackage Axis
|
||||
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
|
||||
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Category.php,v 1.17 2005/10/05 20:51:23 nosey Exp $
|
||||
* @link http://pear.php.net/package/Image_Graph
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include file Image/Graph/Axis.php
|
||||
*/
|
||||
require_once 'Image/Graph/Axis.php';
|
||||
|
||||
/**
|
||||
* A normal axis thats displays labels with a 'interval' of 1.
|
||||
* This is basically a normal axis where the range is
|
||||
* the number of labels defined, that is the range is explicitly defined
|
||||
* when constructing the axis.
|
||||
*
|
||||
* @category Images
|
||||
* @package Image_Graph
|
||||
* @subpackage Axis
|
||||
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
|
||||
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/Image_Graph
|
||||
*/
|
||||
class Image_Graph_Axis_Category extends Image_Graph_Axis
|
||||
{
|
||||
|
||||
/**
|
||||
* The labels shown on the axis
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_labels = false;
|
||||
|
||||
/**
|
||||
* Image_Graph_Axis_Category [Constructor].
|
||||
*
|
||||
* @param int $type The type (direction) of the Axis
|
||||
*/
|
||||
function Image_Graph_Axis_Category($type = IMAGE_GRAPH_AXIS_X)
|
||||
{
|
||||
parent::Image_Graph_Axis($type);
|
||||
$this->_labels = array();
|
||||
$this->setlabelInterval(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the minimum value the axis will show.
|
||||
*
|
||||
* This is always 0
|
||||
*
|
||||
* @return double The minumum value
|
||||
* @access private
|
||||
*/
|
||||
function _getMinimum()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum value the axis will show.
|
||||
*
|
||||
* This is always the number of labels passed to the constructor.
|
||||
*
|
||||
* @return double The maximum value
|
||||
* @access private
|
||||
*/
|
||||
function _getMaximum()
|
||||
{
|
||||
return count($this->_labels) - ($this->_pushValues ? 0 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum value the axis will show.
|
||||
*
|
||||
* A minimum cannot be set on a SequentialAxis, it is always 0.
|
||||
*
|
||||
* @param double Minimum The minumum value to use on the axis
|
||||
* @access private
|
||||
*/
|
||||
function _setMinimum($minimum)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum value the axis will show
|
||||
*
|
||||
* A maximum cannot be set on a SequentialAxis, it is always the number
|
||||
* of labels passed to the constructor.
|
||||
*
|
||||
* @param double Maximum The maximum value to use on the axis
|
||||
* @access private
|
||||
*/
|
||||
function _setMaximum($maximum)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the minimum value of the axis
|
||||
*
|
||||
* A minimum cannot be set on a SequentialAxis, it is always 0.
|
||||
*
|
||||
* @param double $minimum The minumum value to use on the axis
|
||||
*/
|
||||
function forceMinimum($minimum, $userEnforce = true)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the maximum value of the axis
|
||||
*
|
||||
* A maximum cannot be set on a SequentialAxis, it is always the number
|
||||
* of labels passed to the constructor.
|
||||
*
|
||||
* @param double $maximum The maximum value to use on the axis
|
||||
*/
|
||||
function forceMaximum($maximum, $userEnforce = true)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an interval for where labels are shown on the axis.
|
||||
*
|
||||
* The label interval is rounded to nearest integer value
|
||||
*
|
||||
* @param double $labelInterval The interval with which labels are shown
|
||||
*/
|
||||
function setLabelInterval($labelInterval = 'auto', $level = 1)
|
||||
{
|
||||
if ($labelInterval == 'auto') {
|
||||
parent::setLabelInterval(1);
|
||||
} else {
|
||||
parent::setLabelInterval(round($labelInterval));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocessor for values, ie for using logarithmic axis
|
||||
*
|
||||
* @param double $value The value to preprocess
|
||||
* @return double The preprocessed value
|
||||
* @access private
|
||||
*/
|
||||
function _value($value)
|
||||
{
|
||||
// $the_value = array_search($value, $this->_labels);
|
||||
if (isset($this->_labels[$value])) {
|
||||
$the_value = $this->_labels[$value];
|
||||
if ($the_value !== false) {
|
||||
return $the_value + ($this->_pushValues ? 0.5 : 0);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the minor label interval with which axis label ticks are drawn.
|
||||
*
|
||||
* For a sequential axis this is always disabled (i.e false)
|
||||
*
|
||||
* @return double The minor label interval, always false
|
||||
* @access private
|
||||
*/
|
||||
function _minorLabelInterval()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size in pixels of the axis.
|
||||
*
|
||||
* For an x-axis this is the width of the axis including labels, and for an
|
||||
* y-axis it is the corrresponding height
|
||||
*
|
||||
* @return int The size of the axis
|
||||
* @access private
|
||||
*/
|
||||
function _size()
|
||||
{
|
||||
if (!$this->_visible) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->_canvas->setFont($this->_getFont());
|
||||
|
||||
$maxSize = 0;
|
||||
foreach($this->_labels as $label => $id) {
|
||||
$labelPosition = $this->_point($label);
|
||||
|
||||
if (is_object($this->_dataPreProcessor)) {
|
||||
$labelText = $this->_dataPreProcessor->_process($label);
|
||||
} else {
|
||||
$labelText = $label;
|
||||
}
|
||||
|
||||
if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose)) ||
|
||||
(($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose)))
|
||||
{
|
||||
$maxSize = max($maxSize, $this->_canvas->textHeight($labelText));
|
||||
} else {
|
||||
$maxSize = max($maxSize, $this->_canvas->textWidth($labelText));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_title) {
|
||||
$this->_canvas->setFont($this->_getTitleFont());
|
||||
|
||||
if ((($this->_type == IMAGE_GRAPH_AXIS_X) && (!$this->_transpose)) ||
|
||||
(($this->_type != IMAGE_GRAPH_AXIS_X) && ($this->_transpose)))
|
||||
{
|
||||
$maxSize += $this->_canvas->textHeight($this->_title);
|
||||
} else {
|
||||
$maxSize += $this->_canvas->textWidth($this->_title);
|
||||
}
|
||||
$maxSize += 10;
|
||||
}
|
||||
return $maxSize +3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the dataset to the axis.
|
||||
*
|
||||
* This calculates the order of the categories, which is very important
|
||||
* for fx. line plots, so that the line does not "go backwards", consider
|
||||
* these X-sets:<p>
|
||||
* 1: (1, 2, 3, 4, 5, 6)<br>
|
||||
* 2: (0, 1, 2, 3, 4, 5, 6, 7)<p>
|
||||
* If they are not ordered, but simply appended, the categories on the axis
|
||||
* would be:<p>
|
||||
* X: (1, 2, 3, 4, 5, 6, 0, 7)<p>
|
||||
* Which would render the a line for the second plot to show incorrectly.
|
||||
* Instead this algorithm, uses and 'value- is- before' method to see that
|
||||
* the 0 is before a 1 in the second set, and that it should also be before
|
||||
* a 1 in the X set. Hence:<p>
|
||||
* X: (0, 1, 2, 3, 4, 5, 6, 7)
|
||||
*
|
||||
* @param Image_Graph_Dataset $dataset The dataset
|
||||
* @access private
|
||||
*/
|
||||
function _applyDataset(&$dataset)
|
||||
{
|
||||
$newLabels = array();
|
||||
$allLabels = array();
|
||||
|
||||
$dataset->_reset();
|
||||
$count = 0;
|
||||
$count_new = 0;
|
||||
while ($point = $dataset->_next()) {
|
||||
if ($this->_type == IMAGE_GRAPH_AXIS_X) {
|
||||
$data = $point['X'];
|
||||
} else {
|
||||
$data = $point['Y'];
|
||||
}
|
||||
if (!isset($this->_labels[$data])) {
|
||||
$newLabels[$data] = $count_new++;
|
||||
//$this->_labels[] = $data;
|
||||
}
|
||||
$allLabels[$data] = $count++;
|
||||
}
|
||||
|
||||
if (count($this->_labels) == 0) {
|
||||
$this->_labels = $newLabels;
|
||||
} elseif ((is_array($newLabels)) && (count($newLabels) > 0)) {
|
||||
// get all intersecting labels
|
||||
$intersect = array_intersect(array_keys($allLabels), array_keys($this->_labels));
|
||||
// traverse all new and find their relative position withing the
|
||||
// intersec, fx value X0 is before X1 in the intersection, which
|
||||
// means that X0 should be placed before X1 in the label array
|
||||
foreach($newLabels as $newLabel => $id) {
|
||||
$key = $allLabels[$newLabel];
|
||||
reset($intersect);
|
||||
$this_value = false;
|
||||
// intersect indexes are the same as in allLabels!
|
||||
$first = true;
|
||||
while ((list($id, $value) = each($intersect)) &&
|
||||
($this_value === false))
|
||||
{
|
||||
if (($first) && ($id > $key)) {
|
||||
$this_value = $value;
|
||||
} elseif ($id >= $key) {
|
||||
$this_value = $value;
|
||||
}
|
||||
$first = false;
|
||||
}
|
||||
|
||||
if ($this_value === false) {
|
||||
// the new label was not found before anything in the
|
||||
// intersection -> append it
|
||||
$this->_labels[$newLabel] = count($this->_labels);
|
||||
} else {
|
||||
// the new label was found before $this_value in the
|
||||
// intersection, insert the label before this position in
|
||||
// the label array
|
||||
// $key = $this->_labels[$this_value];
|
||||
$keys = array_keys($this->_labels);
|
||||
$key = array_search($this_value, $keys);
|
||||
$pre = array_slice($keys, 0, $key);
|
||||
$pre[] = $newLabel;
|
||||
$post = array_slice($keys, $key);
|
||||
$this->_labels = array_flip(array_merge($pre, $post));
|
||||
}
|
||||
}
|
||||
unset($keys);
|
||||
}
|
||||
|
||||
$labels = array_keys($this->_labels);
|
||||
$i = 0;
|
||||
foreach ($labels as $label) {
|
||||
$this->_labels[$label] = $i++;
|
||||
}
|
||||
|
||||
// $this->_labels = array_values(array_unique($this->_labels));
|
||||
$this->_calcLabelInterval();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the label distance.
|
||||
*
|
||||
* @return int The distance between 2 adjacent labels
|
||||
* @access private
|
||||
*/
|
||||
function _labelDistance($level = 1)
|
||||
{
|
||||
reset($this->_labels);
|
||||
list($l1) = each($this->_labels);
|
||||
list($l2) = each($this->_labels);
|
||||
return abs($this->_point($l2) - $this->_point($l1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next label point
|
||||
*
|
||||
* @param doubt $point The current point, if omitted or false, the first is
|
||||
* returned
|
||||
* @return double The next label point
|
||||
* @access private
|
||||
*/
|
||||
function _getNextLabel($currentLabel = false, $level = 1)
|
||||
{
|
||||
if ($currentLabel === false) {
|
||||
reset($this->_labels);
|
||||
}
|
||||
$result = false;
|
||||
$count = ($currentLabel === false ? $this->_labelInterval() - 1 : 0);
|
||||
while ($count < $this->_labelInterval()) {
|
||||
$result = (list($label) = each($this->_labels));
|
||||
$count++;
|
||||
}
|
||||
if ($result) {
|
||||
return $label;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the axis numeric or not?
|
||||
*
|
||||
* @return bool True if numeric, false if not
|
||||
* @access private
|
||||
*/
|
||||
function _isNumeric()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the axis
|
||||
*
|
||||
* @return bool Was the output 'good' (true) or 'bad' (false).
|
||||
* @access private
|
||||
*/
|
||||
function _done()
|
||||
{
|
||||
$result = true;
|
||||
if (Image_Graph_Element::_done() === false) {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
$this->_canvas->startGroup(get_class($this));
|
||||
|
||||
$this->_drawAxisLines();
|
||||
|
||||
$this->_canvas->startGroup(get_class($this) . '_ticks');
|
||||
$label = false;
|
||||
while (($label = $this->_getNextLabel($label)) !== false) {
|
||||
$this->_drawTick($label);
|
||||
}
|
||||
$this->_canvas->endGroup();
|
||||
|
||||
$this->_canvas->endGroup();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
175
includes/pear/Image/Graph/Axis/Logarithmic.php
Normal file
175
includes/pear/Image/Graph/Axis/Logarithmic.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class for axis handling.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version. This library is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
||||
* General Public License for more details. You should have received a copy of
|
||||
* the GNU Lesser General Public License along with this library; if not, write
|
||||
* to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*
|
||||
* @category Images
|
||||
* @package Image_Graph
|
||||
* @subpackage Axis
|
||||
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
|
||||
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Logarithmic.php,v 1.13 2005/09/25 17:52:17 nosey Exp $
|
||||
* @link http://pear.php.net/package/Image_Graph
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include file Image/Graph/Axis.php
|
||||
*/
|
||||
require_once 'Image/Graph/Axis.php';
|
||||
|
||||
/**
|
||||
* Diplays a logarithmic axis (either X- or Y-axis).
|
||||
*
|
||||
* @category Images
|
||||
* @package Image_Graph
|
||||
* @subpackage Axis
|
||||
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
|
||||
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/Image_Graph
|
||||
*/
|
||||
class Image_Graph_Axis_Logarithmic extends Image_Graph_Axis
|
||||
{
|
||||
|
||||
/**
|
||||
* Image_Graph_AxisLogarithmic [Constructor].
|
||||
*
|
||||
* Normally a manual creation should not be necessary, axis are
|
||||
* created automatically by the {@link Image_Graph_Plotarea} constructor
|
||||
* unless explicitly defined otherwise
|
||||
*
|
||||
* @param int $type The type (direction) of the Axis, use IMAGE_GRAPH_AXIS_X
|
||||
* for an X-axis (default, may be omitted) and IMAGE_GRAPH_AXIS_Y for Y-
|
||||
* axis)
|
||||
*/
|
||||
function Image_Graph_Axis_Logarithmic($type = IMAGE_GRAPH_AXIS_X)
|
||||
{
|
||||
parent::Image_Graph_Axis($type);
|
||||
$this->showLabel(IMAGE_GRAPH_LABEL_MINIMUM + IMAGE_GRAPH_LABEL_MAXIMUM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the label interval
|
||||
*
|
||||
* If explicitly defined this will be calucated to an approximate best.
|
||||
*
|
||||
* @return double The label interval
|
||||
* @access private
|
||||
*/
|
||||
function _calcLabelInterval()
|
||||
{
|
||||
$result = parent::_calcLabelInterval();
|
||||
$this->_axisValueSpan = $this->_value($this->_axisSpan);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the minimum value of the axis.
|
||||
*
|
||||
* For an logarithimc axis this is always 0
|
||||
*
|
||||
* @param double $minimum The minumum value to use on the axis
|
||||
*/
|
||||
function forceMinimum($minimum)
|
||||
{
|
||||
parent::forceMinimum(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the minimum value the axis will show.
|
||||
*
|
||||
* For an logarithimc axis this is always 0
|
||||
*
|
||||
* @return double The minumum value
|
||||
* @access private
|
||||
*/
|
||||
function _getMinimum()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocessor for values, ie for using logarithmic axis
|
||||
*
|
||||
* @param double $value The value to preprocess
|
||||
* @return double The preprocessed value
|
||||
* @access private
|
||||
*/
|
||||
function _value($value)
|
||||
{
|
||||
return log10($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next label point
|
||||
*
|
||||
* @param doubt $point The current point, if omitted or false, the first is
|
||||
* returned
|
||||
* @return double The next label point
|
||||
* @access private
|
||||
*/
|
||||
function _getNextLabel($currentLabel = false, $level = 1)
|
||||
{
|
||||
if (is_array($this->_labelOptions[$level]['interval'])) {
|
||||
return parent::_getNextLabel($currentLabel, $level);
|
||||
}
|
||||
|
||||
if ($currentLabel !== false) {
|
||||
$value = log10($currentLabel);
|
||||
$base = floor($value);
|
||||
$frac = $value - $base;
|
||||
for ($i = 2; $i < 10; $i++) {
|
||||
if ($frac <= (log10($i)-0.01)) {
|
||||
$label = pow(10, $base)*$i;
|
||||
if ($label > $this->_getMaximum()) {
|
||||
return false;
|
||||
} else {
|
||||
return $label;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pow(10, $base+1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the axis intersection pixel position
|
||||
*
|
||||
* This is only to be called prior to output! I.e. between the user
|
||||
* invokation of Image_Graph::done() and any actual output is performed.
|
||||
* This is because it can change the axis range.
|
||||
*
|
||||
* @param double $value the intersection value to get the pixel-point for
|
||||
* @return double The pixel position along the axis
|
||||
* @access private
|
||||
*/
|
||||
function _intersectPoint($value)
|
||||
{
|
||||
if (($value <= 0) && ($value !== 'max') && ($value !== 'min')) {
|
||||
$value = 1;
|
||||
}
|
||||
return parent::_intersectPoint($value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
156
includes/pear/Image/Graph/Axis/Marker/Area.php
Normal file
156
includes/pear/Image/Graph/Axis/Marker/Area.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class file containing a axis marker used for explicitly highlighting a area
|
||||
* on the graph, based on an interval specified on an axis.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version. This library is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
||||
* General Public License for more details. You should have received a copy of
|
||||
* the GNU Lesser General Public License along with this library; if not, write
|
||||
* to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*
|
||||
* @category Images
|
||||
* @package Image_Graph
|
||||
* @subpackage Grid
|
||||
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
|
||||
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Area.php,v 1.11 2005/08/24 20:36:04 nosey Exp $
|
||||
* @link http://pear.php.net/package/Image_Graph
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include file Image/Graph/Grid.php
|
||||
*/
|
||||
require_once 'Image/Graph/Grid.php';
|
||||
|
||||
/**
|
||||
* Display a grid
|
||||
*
|
||||
* {@link Image_Graph_Grid}
|
||||
*
|
||||
* @category Images
|
||||
* @package Image_Graph
|
||||
* @subpackage Grid
|
||||
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
|
||||
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/Image_Graph
|
||||
*/
|
||||
class Image_Graph_Axis_Marker_Area extends Image_Graph_Grid
|
||||
{
|
||||
|
||||
/**
|
||||
* The lower bound
|
||||
* @var double
|
||||
* @access private
|
||||
*/
|
||||
var $_lower = false;
|
||||
|
||||
/**
|
||||
* The upper bound
|
||||
* @var double
|
||||
* @access private
|
||||
*/
|
||||
var $_upper = false;
|
||||
|
||||
/**
|
||||
* [Constructor]
|
||||
*/
|
||||
function Image_Graph_Axis_Marker_Area()
|
||||
{
|
||||
parent::Image_Graph_Grid();
|
||||
$this->_lineStyle = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lower bound of the area (value on the axis)
|
||||
*
|
||||
* @param double $lower the lower bound
|
||||
*/
|
||||
function setLowerBound($lower)
|
||||
{
|
||||
$this->_lower = $lower;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the upper bound of the area (value on the axis)
|
||||
*
|
||||
* @param double $upper the upper bound
|
||||
*/
|
||||
function setUpperBound($upper)
|
||||
{
|
||||
$this->_upper = $upper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the grid
|
||||
*
|
||||
* @return bool Was the output 'good' (true) or 'bad' (false).
|
||||
* @access private
|
||||
*/
|
||||
function _done()
|
||||
{
|
||||
if (parent::_done() === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->_primaryAxis) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_canvas->startGroup(get_class($this));
|
||||
|
||||
$i = 0;
|
||||
|
||||
$this->_lower = max($this->_primaryAxis->_getMinimum(), $this->_lower);
|
||||
$this->_upper = min($this->_primaryAxis->_getMaximum(), $this->_upper);
|
||||
|
||||
$secondaryPoints = $this->_getSecondaryAxisPoints();
|
||||
|
||||
reset($secondaryPoints);
|
||||
list ($id, $previousSecondaryValue) = each($secondaryPoints);
|
||||
while (list ($id, $secondaryValue) = each($secondaryPoints)) {
|
||||
if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_X) {
|
||||
$p1 = array ('Y' => $secondaryValue, 'X' => $this->_lower);
|
||||
$p2 = array ('Y' => $previousSecondaryValue, 'X' => $this->_lower);
|
||||
$p3 = array ('Y' => $previousSecondaryValue, 'X' => $this->_upper);
|
||||
$p4 = array ('Y' => $secondaryValue, 'X' => $this->_upper);
|
||||
} else {
|
||||
$p1 = array ('X' => $secondaryValue, 'Y' => $this->_lower);
|
||||
$p2 = array ('X' => $previousSecondaryValue, 'Y' => $this->_lower);
|
||||
$p3 = array ('X' => $previousSecondaryValue, 'Y' => $this->_upper);
|
||||
$p4 = array ('X' => $secondaryValue, 'Y' => $this->_upper);
|
||||
}
|
||||
|
||||
$this->_canvas->addVertex(array('x' => $this->_pointX($p1), 'y' => $this->_pointY($p1)));
|
||||
$this->_canvas->addVertex(array('x' => $this->_pointX($p2), 'y' => $this->_pointY($p2)));
|
||||
$this->_canvas->addVertex(array('x' => $this->_pointX($p3), 'y' => $this->_pointY($p3)));
|
||||
$this->_canvas->addVertex(array('x' => $this->_pointX($p4), 'y' => $this->_pointY($p4)));
|
||||
|
||||
$previousSecondaryValue = $secondaryValue;
|
||||
|
||||
$this->_getLineStyle();
|
||||
$this->_getFillStyle();
|
||||
$this->_canvas->polygon(array('connect' => true));
|
||||
}
|
||||
|
||||
$this->_canvas->endGroup();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
124
includes/pear/Image/Graph/Axis/Marker/Line.php
Normal file
124
includes/pear/Image/Graph/Axis/Marker/Line.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class file containing a axis marker used for explicitly highlighting a point
|
||||
* (line) on the graph, based on an value specified on an axis.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version. This library is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
||||
* General Public License for more details. You should have received a copy of
|
||||
* the GNU Lesser General Public License along with this library; if not, write
|
||||
* to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*
|
||||
* @category Images
|
||||
* @package Image_Graph
|
||||
* @subpackage Grid
|
||||
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
|
||||
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Line.php,v 1.11 2005/08/03 21:21:58 nosey Exp $
|
||||
* @link http://pear.php.net/package/Image_Graph
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include file Image/Graph/Grid.php
|
||||
*/
|
||||
require_once 'Image/Graph/Grid.php';
|
||||
|
||||
/**
|
||||
* Display a grid
|
||||
*
|
||||
* {@link Image_Graph_Grid}
|
||||
*
|
||||
* @category Images
|
||||
* @package Image_Graph
|
||||
* @subpackage Grid
|
||||
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
|
||||
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/Image_Graph
|
||||
*/
|
||||
class Image_Graph_Axis_Marker_Line extends Image_Graph_Grid
|
||||
{
|
||||
|
||||
/**
|
||||
* The value
|
||||
* @var double
|
||||
* @access private
|
||||
*/
|
||||
var $_value = false;
|
||||
|
||||
/**
|
||||
* Sets the value of the line marker (value on the axis)
|
||||
*
|
||||
* @param double $value the value
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->_value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the grid
|
||||
*
|
||||
* @return bool Was the output 'good' (true) or 'bad' (false).
|
||||
* @access private
|
||||
*/
|
||||
function _done()
|
||||
{
|
||||
if (parent::_done() === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->_primaryAxis) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_canvas->startGroup(get_class($this));
|
||||
|
||||
$i = 0;
|
||||
|
||||
$this->_value = min($this->_primaryAxis->_getMaximum(), max($this->_primaryAxis->_getMinimum(), $this->_value));
|
||||
|
||||
$secondaryPoints = $this->_getSecondaryAxisPoints();
|
||||
|
||||
reset($secondaryPoints);
|
||||
list ($id, $previousSecondaryValue) = each($secondaryPoints);
|
||||
while (list ($id, $secondaryValue) = each($secondaryPoints)) {
|
||||
if ($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_X) {
|
||||
$p1 = array ('X' => $this->_value, 'Y' => $secondaryValue);
|
||||
$p2 = array ('X' => $this->_value, 'Y' => $previousSecondaryValue);
|
||||
} else {
|
||||
$p1 = array ('X' => $secondaryValue, 'Y' => $this->_value);
|
||||
$p2 = array ('X' => $previousSecondaryValue, 'Y' => $this->_value);
|
||||
}
|
||||
|
||||
$x1 = $this->_pointX($p1);
|
||||
$y1 = $this->_pointY($p1);
|
||||
$x2 = $this->_pointX($p2);
|
||||
$y2 = $this->_pointY($p2);
|
||||
|
||||
$previousSecondaryValue = $secondaryValue;
|
||||
|
||||
$this->_getLineStyle();
|
||||
$this->_canvas->line(array('x0' => $x1, 'y0' => $y1, 'x1' => $x2, 'y1' => $y2));
|
||||
}
|
||||
|
||||
$this->_canvas->endGroup();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
204
includes/pear/Image/Graph/Axis/Radar.php
Normal file
204
includes/pear/Image/Graph/Axis/Radar.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Class for axis handling.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE: This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version. This library is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
||||
* General Public License for more details. You should have received a copy of
|
||||
* the GNU Lesser General Public License along with this library; if not, write
|
||||
* to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*
|
||||
* @category Images
|
||||
* @package Image_Graph
|
||||
* @subpackage Axis
|
||||
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
|
||||
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Radar.php,v 1.6 2005/08/03 21:22:11 nosey Exp $
|
||||
* @link http://pear.php.net/package/Image_Graph
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include file Image/Graph/Axis/Category.php
|
||||
*/
|
||||
require_once 'Image/Graph/Axis/Category.php';
|
||||
|
||||
/**
|
||||
* Displays an 'X'-axis in a radar plot chart.
|
||||
*
|
||||
* This axis maps the number of elements in the dataset to a angle (from 0-
|
||||
* 360 degrees). Displaying the axis consist of drawing a number of lines from
|
||||
* center to the edge of the 'circle' than encloses the radar plot. The labels
|
||||
* are drawn on the 'ends' of these radial lines.
|
||||
*
|
||||
* @category Images
|
||||
* @package Image_Graph
|
||||
* @subpackage Axis
|
||||
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
|
||||
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version Release: @package_version@
|
||||
* @link http://pear.php.net/package/Image_Graph
|
||||
*/
|
||||
class Image_Graph_Axis_Radar extends Image_Graph_Axis_Category
|
||||
{
|
||||
|
||||
/**
|
||||
* Specifies the number of pixels, the labels is offsetted from the end of
|
||||
* the axis
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $_distanceFromEnd = 5;
|
||||
|
||||
/**
|
||||
* Gets the minimum value the axis will show.
|
||||
*
|
||||
* This is always 0
|
||||
*
|
||||
* @return double The minumum value
|
||||
* @access private
|
||||
*/
|
||||
function _getMinimum()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum value the axis will show.
|
||||
*
|
||||
* This is always the number of labels passed to the constructor.
|
||||
*
|
||||
* @return double The maximum value
|
||||
* @access private
|
||||
*/
|
||||
function _getMaximum()
|
||||
{
|
||||
return count($this->_labels);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the delta value (the number of pixels representing one unit
|
||||
* on the axis)
|
||||
*
|
||||
* @return double The label interval
|
||||
* @access private
|
||||
*/
|
||||
function _calcDelta()
|
||||
{
|
||||
if (abs($this->_getMaximum() - $this->_getMinimum()) == 0) {
|
||||
$this->_delta = false;
|
||||
} else {
|
||||
$this->_delta = 360 / ($this->_getMaximum() - $this->_getMinimum());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pixel position represented by a value on the canvas
|
||||
*
|
||||
* @param double $value the value to get the pixel-point for
|
||||
* @return double The pixel position along the axis
|
||||
* @access private
|
||||
*/
|
||||
function _point($value)
|
||||
{
|
||||
return (90 + (int) ($this->_value($value) * $this->_delta)) % 360;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size in pixels of the axis.
|
||||
*
|
||||
* For a radar plot this is always 0
|
||||
*
|
||||
* @return int The size of the axis
|
||||
* @access private
|
||||
*/
|
||||
function _size()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the distance from the end of the category lines to the label.
|
||||
*
|
||||
* @param int $distance The distance in pixels
|
||||
*/
|
||||
function setDistanceFromEnd($distance = 5)
|
||||
{
|
||||
$this->_distanceFromEnd = $distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws axis lines.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _drawAxisLines()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Output an axis tick mark.
|
||||
*
|
||||
* @param int $value The value to output
|
||||
* @access private
|
||||
*/
|
||||
function _drawTick($value, $level = 1)
|
||||
{
|
||||
$centerX = (int) (($this->_left + $this->_right) / 2);
|
||||
$centerY = (int) (($this->_top + $this->_bottom) / 2);
|
||||
|
||||
$radius = min($this->height(), $this->width()) / 2;
|
||||
|
||||
$endPoint = array ('X' => $value, 'Y' => '#max#');
|
||||
$dX = $this->_pointX($endPoint);
|
||||
$dY = $this->_pointY($endPoint);
|
||||
|
||||
$offX = ($dX - $centerX);
|
||||
$offY = ($dY - $centerY);
|
||||
|
||||
$hyp = sqrt($offX*$offX + $offY*$offY);
|
||||
if ($hyp != 0) {
|
||||
$scale = $this->_distanceFromEnd / $hyp;
|
||||
} else {
|
||||
$scale = 1;
|
||||
}
|
||||
|
||||
$adX = $dX + $offX * $scale;
|
||||
$adY = $dY + $offY * $scale;
|
||||
|
||||
if (is_object($this->_dataPreProcessor)) {
|
||||
$labelText = $this->_dataPreProcessor->_process($value);
|
||||
} else {
|
||||
$labelText = $value;
|
||||
}
|
||||
|
||||
if ((abs($dX - $centerX) < 1.5) && ($dY < $centerY)) {
|
||||
$align = IMAGE_GRAPH_ALIGN_BOTTOM + IMAGE_GRAPH_ALIGN_CENTER_X;
|
||||
} elseif ((abs($dX - $centerX) < 1.5) && ($dY > $centerY)) {
|
||||
$align = IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_CENTER_X;
|
||||
} elseif ($dX < $centerX) {
|
||||
$align = IMAGE_GRAPH_ALIGN_RIGHT + IMAGE_GRAPH_ALIGN_CENTER_Y;
|
||||
} else {
|
||||
$align = IMAGE_GRAPH_ALIGN_LEFT + IMAGE_GRAPH_ALIGN_CENTER_Y;
|
||||
}
|
||||
$this->write($adX, $adY, $labelText, $align);
|
||||
|
||||
$this->_getLineStyle();
|
||||
$this->_canvas->line(array('x0' => $centerX, 'y0' => $centerY, 'x1' => $dX, 'y1' => $dY));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user