添加到 trunk

+YUCHENG HU+

git-svn-id: https://svn.code.sf.net/p/hawebs/svn@152 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
YuCheng Hu
2010-06-12 07:30:38 +00:00
parent ae9ac503a8
commit e9c87466cc
17 changed files with 5463 additions and 0 deletions
+225
View File
@@ -0,0 +1,225 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - Main class for the graph creation.
*
* 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
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Constants.php,v 1.7 2005/08/03 21:21:52 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Include file Image/Graph/Font.php
*/
require_once 'Image/Graph/Font.php';
// Constant declarations
/**
* Defines an X (horizontal) axis
*/
define('IMAGE_GRAPH_AXIS_X', 1);
/**
* Defines an Y (vertical) axis
*/
define('IMAGE_GRAPH_AXIS_Y', 2);
/**
* Defines an Y (vertical) axis
*/
define('IMAGE_GRAPH_AXIS_Y_SECONDARY', 3);
/**
* Defines an horizontal (X) axis
*/
define('IMAGE_GRAPH_AXIS_HORIZONTAL', 1);
/**
* Defines an vertical (Y) axis
*/
define('IMAGE_GRAPH_AXIS_VERTICAL', 2);
/**
* Define if label should be shown for axis minimum value
*/
define('IMAGE_GRAPH_LABEL_MINIMUM', 1);
/**
* Define if label should be shown for axis 0 (zero) value
*/
define('IMAGE_GRAPH_LABEL_ZERO', 2);
/**
* Define if label should be shown for axis maximum value
*/
define('IMAGE_GRAPH_LABEL_MAXIMUM', 4);
/**
* Defines a horizontal gradient fill
*/
define('IMAGE_GRAPH_GRAD_HORIZONTAL', 1);
/**
* Defines a vertical gradient fill
*/
define('IMAGE_GRAPH_GRAD_VERTICAL', 2);
/**
* Defines a horizontally mirrored gradient fill
*/
define('IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED', 3);
/**
* Defines a vertically mirrored gradient fill
*/
define('IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED', 4);
/**
* Defines a diagonal gradient fill from top-left to bottom-right
*/
define('IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR', 5);
/**
* Defines a diagonal gradient fill from bottom-left to top-right
*/
define('IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR', 6);
/**
* Defines a radial gradient fill
*/
define('IMAGE_GRAPH_GRAD_RADIAL', 7);
/**
* Defines the default builtin font
*/
define('IMAGE_GRAPH_FONT', 1);
/**
* Defines a X value should be used
*/
define('IMAGE_GRAPH_VALUE_X', 0);
/**
* Defines a Y value should be used
*/
define('IMAGE_GRAPH_VALUE_Y', 1);
/**
* Defines a min X% value should be used
*/
define('IMAGE_GRAPH_PCT_X_MIN', 2);
/**
* Defines a max X% value should be used
*/
define('IMAGE_GRAPH_PCT_X_MAX', 3);
/**
* Defines a min Y% value should be used
*/
define('IMAGE_GRAPH_PCT_Y_MIN', 4);
/**
* Defines a max Y% value should be used
*/
define('IMAGE_GRAPH_PCT_Y_MAX', 5);
/**
* Defines a total Y% value should be used
*/
define('IMAGE_GRAPH_PCT_Y_TOTAL', 6);
/**
* Defines a ID value should be used
*/
define('IMAGE_GRAPH_POINT_ID', 7);
/**
* Align text left
*/
define('IMAGE_GRAPH_ALIGN_LEFT', 0x1);
/**
* Align text right
*/
define('IMAGE_GRAPH_ALIGN_RIGHT', 0x2);
/**
* Align text center x (horizontal)
*/
define('IMAGE_GRAPH_ALIGN_CENTER_X', 0x4);
/**
* Align text top
*/
define('IMAGE_GRAPH_ALIGN_TOP', 0x8);
/**
* Align text bottom
*/
define('IMAGE_GRAPH_ALIGN_BOTTOM', 0x10);
/**
* Align text center y (vertical)
*/
define('IMAGE_GRAPH_ALIGN_CENTER_Y', 0x20);
/**
* Align text center (both x and y)
*/
define('IMAGE_GRAPH_ALIGN_CENTER', IMAGE_GRAPH_ALIGN_CENTER_X + IMAGE_GRAPH_ALIGN_CENTER_Y);
/**
* Align text top left
*/
define('IMAGE_GRAPH_ALIGN_TOP_LEFT', IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_LEFT);
/**
* Align text top right
*/
define('IMAGE_GRAPH_ALIGN_TOP_RIGHT', IMAGE_GRAPH_ALIGN_TOP + IMAGE_GRAPH_ALIGN_RIGHT);
/**
* Align text bottom left
*/
define('IMAGE_GRAPH_ALIGN_BOTTOM_LEFT', IMAGE_GRAPH_ALIGN_BOTTOM + IMAGE_GRAPH_ALIGN_LEFT);
/**
* Align text bottom right
*/
define('IMAGE_GRAPH_ALIGN_BOTTOM_RIGHT', IMAGE_GRAPH_ALIGN_BOTTOM + IMAGE_GRAPH_ALIGN_RIGHT);
/**
* Align vertical
*/
define('IMAGE_GRAPH_ALIGN_VERTICAL', IMAGE_GRAPH_ALIGN_TOP);
/**
* Align horizontal
*/
define('IMAGE_GRAPH_ALIGN_HORIZONTAL', IMAGE_GRAPH_ALIGN_LEFT);
// Error codes
define('IMAGE_GRAPH_ERROR_GENERIC', 0);
?>
@@ -0,0 +1,74 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - PEAR PHP OO Graph Rendering Utility.
*
* 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 DataPreprocessor
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: DataPreprocessor.php,v 1.7 2005/08/24 20:35:55 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Data preprocessor used for preformatting a data.
*
* A data preprocessor is used in cases where a value from a dataset or label must be
* displayed in another format or way than entered. This could for example be the need
* to display X-values as a date instead of 1, 2, 3, .. or even worse unix-timestamps.
* It could also be when a {@link Image_Graph_Marker_Value} needs to display values as percentages
* with 1 decimal digit instead of the default formatting (fx. 12.01271 -> 12.0%).
*
* @category Images
* @package Image_Graph
* @subpackage DataPreprocessor
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
* @abstract
*/
class Image_Graph_DataPreprocessor
{
/**
* Image_Graph_DataPreprocessor [Constructor].
*/
function Image_Graph_DataPreprocessor()
{
}
/**
* Process the value
*
* @param var $value The value to process/format
* @return string The processed value
* @access private
*/
function _process($value)
{
return $value;
}
}
?>
@@ -0,0 +1,67 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - PEAR PHP OO Graph Rendering Utility.
*
* 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 DataSelector
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: DataSelector.php,v 1.7 2005/08/24 20:35:56 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Filter used for selecting which data to show as markers
*
* @category Images
* @package Image_Graph
* @subpackage DataSelector
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
*/
class Image_Graph_DataSelector
{
/**
* Image_Graph_DataSelector [Constructor]
*/
function Image_Graph_DataSelector()
{
}
/**
* Check if a specified value should be 'selected', ie shown as a marker
*
* @param array $values The values to check
* @return bool True if the Values should cause a marker to be shown, false if not
* @access private
*/
function _select($values)
{
return true;
}
}
?>
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+63
View File
@@ -0,0 +1,63 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - PEAR PHP OO Graph Rendering Utility.
*
* 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 Fill
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Fill.php,v 1.6 2005/02/21 20:49:46 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Include file Image/Graph/Element.php
*/
require_once 'Image/Graph/Element.php';
/**
* Style used for filling elements.
*
* @category Images
* @package Image_Graph
* @subpackage Fill
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
* @abstract
*/
class Image_Graph_Fill extends Image_Graph_Common
{
/**
* Resets the fillstyle
*
* @access private
*/
function _reset()
{
}
}
?>
+158
View File
@@ -0,0 +1,158 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - PEAR PHP OO Graph Rendering Utility.
*
* 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 Text
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Font.php,v 1.8 2005/08/24 20:35:55 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Include file Image/Graph/Common.php
*/
require_once 'Image/Graph/Common.php';
/**
* A font.
*
* @category Images
* @package Image_Graph
* @subpackage Text
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
* @abstract
*/
class Image_Graph_Font extends Image_Graph_Common
{
/**
* The name of the font
* @var string
* @access private
*/
var $_name = false;
/**
* The angle of the output
* @var int
* @access private
*/
var $_angle = false;
/**
* The size of the font
* @var int
* @access private
*/
var $_size = 11;
/**
* The color of the font
* @var Color
* @access private
*/
var $_color = 'black';
/**
* Image_Graph_Font [Constructor]
*/
function Image_Graph_Font($name = false, $size = false)
{
parent::Image_Graph_Common();
if ($name !== false) {
$this->_name = $name;
}
if ($size !== false) {
$this->_size = $size;
}
}
/**
* Set the color of the font
*
* @param mixed $color The color object of the Font
*/
function setColor($color)
{
$this->_color = $color;
}
/**
* Set the angle slope of the output font.
*
* 0 = normal, 90 = bottom and up, 180 = upside down, 270 = top and down
*
* @param int $angle The angle in degrees to slope the text
*/
function setAngle($angle)
{
$this->_angle = $angle;
}
/**
* Set the size of the font
*
* @param int $size The size in pixels of the font
*/
function setSize($size)
{
$this->_size = $size;
}
/**
* Get the font 'array'
*
* @return array The font 'summary' to pass to the canvas
* @access private
*/
function _getFont($options = false)
{
if ($options === false) {
$options = array();
}
if ($this->_name !== false) {
$options['name'] = $this->_name;
}
if (!isset($options['color'])) {
$options['color'] = $this->_color;
}
if (!isset($options['size'])) {
$options['size'] = $this->_size;
}
if ((!isset($options['angle'])) && ($this->_angle !== false)) {
$options['angle'] = $this->_angle;
}
return $options;
}
}
?>
+175
View File
@@ -0,0 +1,175 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - PEAR PHP OO Graph Rendering Utility.
*
* 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 <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Grid.php,v 1.8 2005/02/21 20:49:47 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Include file Image/Graph/Element.php
*/
require_once 'Image/Graph/Element.php';
/**
* A grid displayed on the plotarea.
*
* A grid is associated with a primary and a secondary axis. The grid is
* displayed in context of the primary axis' label interval - meaning that a
* grid for an Y-axis displays a grid for every label on the y-axis (fx. a {@link
* Image_Graph_Grid_Lines}, which displays horizontal lines for every label on
* the y-axis from the x-axis minimum to the x-axis maximum). You should always
* add the grid as one of the first elements to the plotarea. This is due to the
* fact that elements are 'outputted' in the order they are added, i.e. if an
* grid is added *after* a chart, the grid will be displayed on top of the chart
* which is (probably) not desired.
*
* @category Images
* @package Image_Graph
* @subpackage Grid
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
* @abstract
*/
class Image_Graph_Grid extends Image_Graph_Plotarea_Element
{
/**
* The primary axis: the grid 'refers' to
* @var Axis
* @access private
*/
var $_primaryAxis = null;
/**
* The secondary axis
* @var Axis
* @access private
*/
var $_secondaryAxis = null;
/**
* Set the primary axis: the grid should 'refer' to
*
* @param Image_Graph_Axis $axis The axis
* @access private
*/
function _setPrimaryAxis(& $axis)
{
$this->_primaryAxis =& $axis;
}
/**
* Set the secondary axis
*
* @param Image_Graph_Axis $axis The axis
* @access private
*/
function _setSecondaryAxis(& $axis)
{
$this->_secondaryAxis =& $axis;
}
/**
* Get the points on the secondary axis that the grid should 'connect'
*
* @return array The secondary data values that should mark the grid 'end points'
* @access private
*/
function _getSecondaryAxisPoints()
{
if (is_a($this->_secondaryAxis, 'Image_Graph_Axis_Radar')) {
$secondaryValue = false;
$firstValue = $secondaryValue;
while (($secondaryValue = $this->_secondaryAxis->_getNextLabel($secondaryValue)) !== false) {
$secondaryAxisPoints[] = $secondaryValue;
}
$secondaryAxisPoints[] = $firstValue;
} else {
$secondaryAxisPoints = array ('#min#', '#max#');
}
return $secondaryAxisPoints;
}
/**
* Get the X pixel position represented by a value
*
* @param double $point the value to get the pixel-point for
* @return double The pixel position along the axis
* @access private
*/
function _pointX($point)
{
if (($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y) ||
($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY))
{
$point['AXIS_Y'] = $this->_primaryAxis->_type;
} else {
$point['AXIS_Y'] = $this->_secondaryAxis->_type;
}
return parent::_pointX($point);
}
/**
* Get the Y pixel position represented by a value
*
* @param double $point the value to get the pixel-point for
* @return double The pixel position along the axis
* @access private
*/
function _pointY($point)
{
if (($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y) ||
($this->_primaryAxis->_type == IMAGE_GRAPH_AXIS_Y_SECONDARY))
{
$point['AXIS_Y'] = $this->_primaryAxis->_type;
} else {
$point['AXIS_Y'] = $this->_secondaryAxis->_type;
}
return parent::_pointY($point);
}
/**
* Causes the object to update all sub elements coordinates.
*
* @access private
*/
function _updateCoords()
{
$this->_setCoords(
$this->_parent->_plotLeft,
$this->_parent->_plotTop,
$this->_parent->_plotRight,
$this->_parent->_plotBottom
);
parent::_updateCoords();
}
}
?>
+219
View File
@@ -0,0 +1,219 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - PEAR PHP OO Graph Rendering Utility.
*
* 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 Layout
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Layout.php,v 1.12 2006/02/28 22:48:07 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Include file Image/Graph/Plotarea/Element.php
*/
require_once 'Image/Graph/Plotarea/Element.php';
/**
* Defines an area of the graph that can be layout'ed.
*
* Any class that extends this abstract class can be used within a layout on the canvas.
*
* @category Images
* @package Image_Graph
* @subpackage Layout
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
* @abstract
*/
class Image_Graph_Layout extends Image_Graph_Plotarea_Element
{
/**
* Has the coordinates already been updated?
* @var bool
* @access private
*/
var $_updated = false;
/**
* Alignment of the area for each vertice (left, top, right, bottom)
* @var array
* @access private
*/
var $_alignSize = array ('left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0);
/**
* Image_Graph_Layout [Constructor]
*/
function Image_Graph_Layout()
{
parent::Image_Graph_Element();
$this->_padding = array('left' => 2, 'top' => 2, 'right' => 2, 'bottom' => 2);
}
/**
* Resets the elements
*
* @access private
*/
function _reset()
{
parent::_reset();
$this->_updated = false;
}
/**
* Calculate the edge offset for a specific edge
* @param array $alignSize The alignment of the edge
* @param int $offset The offset/posision of the at 0% edge
* @param int $total The total size (width or height) of the element
* @param int $multiplier +/- 1 if the edge should pushed either toward more
* negative or positive values
* @since 0.3.0dev2
* @access private
*/
function _calcEdgeOffset($alignSize, $offset, $total, $multiplier)
{
if ($alignSize['unit'] == 'percentage') {
return $offset + $multiplier * ($total * $alignSize['value'] / 100);
} elseif ($alignSize['unit'] == 'pixels') {
if (($alignSize['value'] == 'auto_part1') || ($alignSize['value'] == 'auto_part2')) {
$alignSize['value'] = $multiplier * $this->_parent->_getAbsolute($alignSize['value']);
}
if ($alignSize['value'] < 0) {
return $offset + $multiplier * ($total + $alignSize['value']);
} else {
return $offset + $multiplier * $alignSize['value'];
}
}
return $offset;
}
/**
* Calculate the edges
*
* @access private
*/
function _calcEdges()
{
if ((is_array($this->_alignSize)) && (!$this->_updated)) {
$left = $this->_calcEdgeOffset(
$this->_alignSize['left'],
$this->_parent->_fillLeft(),
$this->_parent->_fillWidth(),
+1
);
$top = $this->_calcEdgeOffset(
$this->_alignSize['top'],
$this->_parent->_fillTop(),
$this->_parent->_fillHeight(),
+1
);
$right = $this->_calcEdgeOffset(
$this->_alignSize['right'],
$this->_parent->_fillRight(),
$this->_parent->_fillWidth(),
-1
);
$bottom = $this->_calcEdgeOffset(
$this->_alignSize['bottom'],
$this->_parent->_fillBottom(),
$this->_parent->_fillHeight(),
-1
);
$this->_setCoords(
$left + $this->_padding['left'],
$top + $this->_padding['top'],
$right - $this->_padding['right'],
$bottom - $this->_padding['bottom']
);
}
}
/**
* Update coordinates
*
* @access private
*/
function _updateCoords()
{
$this->_calcEdges();
parent::_updateCoords();
}
/**
* Pushes an edge of area a specific distance 'into' the canvas
*
* @param int $edge The edge of the canvas to align relative to
* @param int $size The number of pixels or the percentage of the canvas total size to occupy relative to the selected alignment edge
* @access private
*/
function _push($edge, $size = '100%')
{
$result = array();
if (ereg("([0-9]*)\%", $size, $result)) {
$this->_alignSize[$edge] = array(
'value' => min(100, max(0, $result[1])),
'unit' => 'percentage'
);
} else {
$this->_alignSize[$edge] = array(
'value' => $size,
'unit' => 'pixels'
);
}
}
/**
* Sets the coordinates of the element
*
* @param int $left The leftmost pixel of the element on the canvas
* @param int $top The topmost pixel of the element on the canvas
* @param int $right The rightmost pixel of the element on the canvas
* @param int $bottom The bottommost pixel of the element on the canvas
* @access private
*/
function _setCoords($left, $top, $right, $bottom)
{
parent::_setCoords($left, $top, $right, $bottom);
$this->_updated = true;
}
/**
* Returns the calculated "auto" size
*
* @return int The calculated auto size
* @access private
*/
function _getAutoSize()
{
return false;
}
}
?>
File diff suppressed because it is too large Load Diff
+153
View File
@@ -0,0 +1,153 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - Main class for the graph creation.
*
* 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 Logo
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Logo.php,v 1.9 2005/08/24 20:35:56 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Include file Image/Graph/Element.php
*/
require_once 'Image/Graph/Element.php';
/**
* Displays a logo on the canvas.
*
* By default the logo is displayed in the top-right corner of the canvas.
*
* @category Images
* @package Image_Graph
* @subpackage Logo
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
*/
class Image_Graph_Logo extends Image_Graph_Element
{
/**
* The file name
* @var stirng
* @access private
*/
var $_filename;
/**
* The GD Image resource
* @var resource
* @access private
*/
var $_image;
/**
* Alignment of the logo
* @var int
* @access private
*/
var $_alignment;
/**
* Logo [Constructor]
*
* @param string $filename The filename and path of the image to use for logo
*/
function Image_Graph_Logo($filename, $alignment = IMAGE_GRAPH_ALIGN_TOP_RIGHT)
{
parent::Image_Graph_Element();
$this->_filename = $filename;
$this->_alignment = $alignment;
}
/**
* Sets the parent. The parent chain should ultimately be a GraPHP object
*
* @see Image_Graph
* @param Image_Graph_Common $parent The parent
* @access private
*/
function _setParent(& $parent)
{
parent::_setParent($parent);
$this->_setCoords(
$this->_parent->_left,
$this->_parent->_top,
$this->_parent->_right,
$this->_parent->_bottom
);
}
/**
* Output the logo
*
* @return bool Was the output 'good' (true) or 'bad' (false).
* @access private
*/
function _done()
{
if (parent::_done() === false) {
return false;
}
$align = array();
if ($this->_alignment & IMAGE_GRAPH_ALIGN_LEFT) {
$x = $this->_parent->_left + 2;
$align['horizontal'] = 'left';
} elseif ($this->_alignment & IMAGE_GRAPH_ALIGN_RIGHT) {
$x = $this->_parent->_right - 2;
$align['horizontal'] = 'right';
} else {
$x = ($this->_parent->_left + $this->_parent->_right) / 2;
$align['horizontal'] = 'center';
}
if ($this->_alignment & IMAGE_GRAPH_ALIGN_TOP) {
$y = $this->_parent->_top + 2;
$align['vertical'] = 'top';
} elseif ($this->_alignment & IMAGE_GRAPH_ALIGN_BOTTOM) {
$y = $this->_parent->_bottom - 2;
$align['vertical'] = 'bottom';
} else {
$y = ($this->_parent->_top + $this->_parent->_bottom) / 2;
$align['vertical'] = 'center';
}
$this->_canvas->image(
array(
'x' => $x,
'y' => $y,
'filename' => $this->_filename,
'alignment' => $align
)
);
return true;
}
}
?>
+123
View File
@@ -0,0 +1,123 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - PEAR PHP OO Graph Rendering Utility.
*
* 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 Marker
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Marker.php,v 1.8 2005/02/21 20:49:47 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Include file Image/Graph/Plotarea/Element.php
*/
require_once 'Image/Graph/Plotarea/Element.php';
/**
* Data point marker.
*
* The data point marker is used for marking the datapoints on a graph with some
* visual label, fx. a cross, a text box with the value or an icon.
*
* @category Images
* @package Image_Graph
* @subpackage Marker
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
* @abstract
*/
class Image_Graph_Marker extends Image_Graph_Plotarea_Element
{
/**
* Secondary marker
* @var Marker
* @access private
*/
var $_secondaryMarker = false;
/**
* The 'size' of the marker, the meaning depends on the specific Marker
* implementation
* @var int
* @access private
*/
var $_size = 6;
/**
* Set the 'size' of the marker
*
* @param int $size The 'size' of the marker, the meaning depends on the
* specific Marker implementation
*/
function setSize($size)
{
$this->_size = $size;
}
/**
* Set the secondary marker
*
* @param Marker $secondaryMarker The secondary marker
*/
function setSecondaryMarker(& $secondaryMarker)
{
$this->_secondaryMarker =& $secondaryMarker;
$this->_secondaryMarker->_setParent($this);
}
/**
* Draw the marker on the canvas
*
* @param int $x The X (horizontal) position (in pixels) of the marker on
* the canvas
* @param int $y The Y (vertical) position (in pixels) of the marker on the
* canvas
* @param array $values The values representing the data the marker 'points'
* to
* @access private
*/
function _drawMarker($x, $y, $values = false)
{
if (is_a($this->_secondaryMarker, 'Image_Graph_Marker')) {
$this->_secondaryMarker->_drawMarker($x, $y, $values);
}
}
/**
* Output to the canvas
*
* @return bool Was the output 'good' (true) or 'bad' (false).
* @access private
*/
function _done()
{
return true;
}
}
?>
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+121
View File
@@ -0,0 +1,121 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - Main class for the graph creation.
*
* 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
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Simple.php,v 1.8 2005/08/24 20:35:54 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Include file Image/Graph.php
*/
require_once 'Image/Graph.php';
/**
* Class for simple creation of graphs
*
* @category Images
* @package Image_Graph
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
*/
class Image_Graph_Simple extends Image_Graph
{
/**
* Image_Graph_Simple [Constructor]
*
* @param int $width The width of the graph in pixels
* @param int $height The height of the graph in pixels
*/
function Image_Graph_Simple($width, $height, $plotType, $data, $title, $lineColor = 'black', $fillColor = 'white', $font = false)
{
parent::Image_Graph($width, $height);
$plotarea =& Image_Graph::factory('plotarea');
$dataset =& Image_Graph::factory('dataset', array($data));
if ($font === false) {
$font =& Image_Graph::factory('Image_Graph_Font');
} elseif (is_string($font)) {
$font =& Image_Graph::factory('ttf_font', $font);
$font->setSize(8);
}
$this->setFont($font);
$this->add(
Image_Graph::vertical(
Image_Graph::factory('title',
array(
$title,
array('size_rel' => 2)
)
),
$plotarea,
10
)
);
$plotarea->addNew('line_grid', array(), IMAGE_GRAPH_AXIS_Y);
$plot =& $plotarea->addNew($plotType, array(&$dataset));
$plot->setLineColor($lineColor);
$plot->setFillColor($fillColor);
$axisX =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
$axisX->showLabel(
IMAGE_GRAPH_LABEL_MINIMUM +
IMAGE_GRAPH_LABEL_ZERO +
IMAGE_GRAPH_LABEL_MAXIMUM
);
}
/**
* Factory method to create the Image_Simple_Graph object.
*/
function &factory($width, $height, $plotType, $data, $title, $lineColor = 'black', $fillColor = 'white', $font = false)
{
$obj =& Image_Graph::factory('Image_Graph_Simple',
array(
$width,
$height,
$plotType,
$data,
$title,
$lineColor,
$fillColor,
$font
)
);
return $obj;
}
}
?>
+194
View File
@@ -0,0 +1,194 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - Main class for the graph creation.
*
* 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 Text
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Title.php,v 1.12 2005/08/24 20:35:56 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* Include file Image/Graph/Layout.php
*/
require_once 'Image/Graph/Layout.php';
/**
* Title
*
* @category Images
* @package Image_Graph
* @subpackage Text
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
*/
class Image_Graph_Title extends Image_Graph_Layout
{
/**
* The text to print
* @var string
* @access private
*/
var $_text;
/**
* The font to use
* @var Font
* @access private
*/
var $_font;
/**
* The alignment of the title
* @var int
* @access private
*/
var $_alignment = IMAGE_GRAPH_ALIGN_CENTER_X;
/**
* Create the title.
*
* Pass a Image_Graph_Font object - preferably by-ref (&amp;) as second
* parameter, the font size in pixels or an associated array with some or
* all of the followin keys:
*
* 'size' The size of the title
*
* 'angle' The angle at which to write the title (in degrees or 'vertical')
*
* 'color' The font-face color
*
* @param sting $text The text to represent the title
* @param mixed $fontOptions The font to use in the title
*/
function Image_Graph_Title($text, $fontOptions = false)
{
parent::Image_Graph_Layout();
if (is_object($fontOptions)) {
$this->_font =& $fontOptions;
} else {
if (is_array($fontOptions)) {
$this->_fontOptions = $fontOptions;
} else {
$this->_fontOptions['size'] = $fontOptions;
}
}
$this->setText($text);
}
/**
* Set the text
*
* @param string $text The text to display
*/
function setText($text)
{
$this->_text = $text;
}
/**
* Returns the calculated "auto" size
*
* @return int The calculated auto size
* @access private
*/
function _getAutoSize()
{
if ($this->_defaultFontOptions !== false) {
$this->_canvas->setFont($this->_defaultFontOptions);
} else {
$this->_canvas->setFont($this->_getFont());
}
return $this->_canvas->textHeight($this->_text);
}
/**
* Set the alignment of the legend
*
* @param int $alignment The alignment
*/
function setAlignment($alignment)
{
$this->_alignment = $alignment & 0x7;
}
/**
* Output the text
*
* @return bool Was the output 'good' (true) or 'bad' (false).
* @access private
*/
function _done()
{
if ($this->_defaultFontOptions !== false) {
$this->_canvas->setFont($this->_defaultFontOptions);
} else {
$this->_canvas->setFont($this->_getFont());
}
if (is_a($this->_parent, 'Image_Graph_Plotarea')) {
$this->_setCoords(
$this->_parent->_left,
$this->_parent->_top,
$this->_parent->_right,
$this->_parent->_top + $this->_canvas->textHeight($this->_text)
);
} elseif (!is_a($this->_parent, 'Image_Graph_Layout')) {
$this->_setCoords(
$this->_parent->_fillLeft(),
$this->_parent->_fillTop(),
$this->_parent->_fillRight(),
$this->_parent->_fillTop() + $this->_canvas->textHeight($this->_text)
);
}
if (parent::_done() === false) {
return false;
}
if ($this->_alignment == IMAGE_GRAPH_ALIGN_CENTER_X) {
$x = ($this->_left + $this->_right) / 2;
} elseif ($this->_alignment == IMAGE_GRAPH_ALIGN_LEFT) {
$x = $this->_left;
} else {
$x = $this->_right;
}
$y = ($this->_top + $this->_bottom) / 2;
$this->write(
$x,
$y,
$this->_text,
$this->_alignment + IMAGE_GRAPH_ALIGN_CENTER_Y
);
return true;
}
}
?>
+291
View File
@@ -0,0 +1,291 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Image_Graph - Main class for the graph creation.
*
* 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
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version CVS: $Id: Tool.php,v 1.4 2005/09/14 20:27:24 nosey Exp $
* @link http://pear.php.net/package/Image_Graph
*/
/**
* This class contains a set of tool-functions.
*
* These functions are all to be called statically
*
* @category Images
* @package Image_Graph
* @author Jesper Veggerby <[email protected]>
* @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: 0.7.2
* @link http://pear.php.net/package/Image_Graph
*/
class Image_Graph_Tool
{
/**
* Return the average of 2 points
*
* @param double P1 1st point
* @param double P2 2nd point
* @return double The average of P1 and P2
* @static
*/
function mid($p1, $p2)
{
return ($p1 + $p2) / 2;
}
/**
* Mirrors P1 in P2 by a amount of Factor
*
* @param double $p1 1st point, point to mirror
* @param double $o2 2nd point, mirror point
* @param double $factor Mirror factor, 0 returns $p2, 1 returns a pure
* mirror, ie $p1 on the exact other side of $p2
* @return double $p1 mirrored in $p2 by Factor
* @static
*/
function mirror($p1, $p2, $factor = 1)
{
return $p2 + $factor * ($p2 - $p1);
}
/**
* Calculates a Bezier control point, this function must be called for BOTH
* X and Y coordinates (will it work for 3D coordinates!?)
*
* @param double $p1 1st point
* @param double $p2 Point to
* @param double $factor Mirror factor, 0 returns P2, 1 returns a pure
* mirror, i.e. P1 on the exact other side of P2
* @return double P1 mirrored in P2 by Factor
* @static
*/
function controlPoint($p1, $p2, $factor, $smoothFactor = 0.75)
{
$sa = Image_Graph_Tool::mirror($p1, $p2, $smoothFactor);
$sb = Image_Graph_Tool::mid($p2, $sa);
$m = Image_Graph_Tool::mid($p2, $factor);
$pC = Image_Graph_Tool::mid($sb, $m);
return $pC;
}
/**
* Calculates a Bezier point, this function must be called for BOTH X and Y
* coordinates (will it work for 3D coordinates!?)
*
* @param double $t A position between $p2 and $p3, value between 0 and 1
* @param double $p1 Point to use for calculating control points
* @param double $p2 Point 1 to calculate bezier curve between
* @param double $p3 Point 2 to calculate bezier curve between
* @param double $p4 Point to use for calculating control points
* @return double The bezier value of the point t between $p2 and $p3 using
* $p1 and $p4 to calculate control points
* @static
*/
function bezier($t, $p1, $p2, $p3, $p4)
{
// (1-t)^3*p1 + 3*(1-t)^2*t*p2 + 3*(1-t)*t^2*p3 + t^3*p4
return pow(1 - $t, 3) * $p1 +
3 * pow(1 - $t, 2) * $t * $p2 +
3 * (1 - $t) * pow($t, 2) * $p3 +
pow($t, 3) * $p4;
}
/**
* For a given point (x,y) return a point rotated by a given angle aroung the center (xy,yc)
*
* @param int $x x coordinate of the point to rotate
* @param int $y y coordinate of the point to rotate
* @param int $xc x coordinate of the center of the rotation
* @param int $yc y coordinate of the center of the rotation
* @param int $angle angle of the rotation
* @return array the coordinate of the new point
* @static
*/
function rotate($x, $y, $xc, $yc, $angle)
{
$cos = cos(deg2rad($angle));
$sin = sin(deg2rad($angle));
$xr= $x - $xc;
$yr= $y - $yc;
$x1= $xc + $cos * $xr - $sin * $yr;
$y1= $yc + $sin * $xr + $cos * $yr;
return array((int) $x1,(int) $y1);
}
/**
* If a number is close 0 zero (i.e. 0 within $decimal decimals) it is rounded down to zero
*
* @param double $value The value to round
* @param int $decimal The number of decimals
* @return double The value or zero if "close enough" to zero
* @static
*/
function close2zero($value, $decimal)
{
if (abs($value) < pow(10, -$decimal)) {
return 0;
}
else {
return $value;
}
}
/**
* Calculate the dimensions and center point (of gravity) for an arc
*
* @param int $v1 The angle at which the arc starts
* @param int $v2 The angle at which the arc ends
* @return array An array with the dimensions in a fraction of a circle width radius 1 'rx', 'ry' and the
* center point of gravity ('cx', 'cy')
* @static
*/
function calculateArcDimensionAndCenter($v1, $v2)
{
// $v2 always larger than $v1
$r1x = Image_Graph_Tool::close2zero(cos(deg2rad($v1)), 3);
$r2x = Image_Graph_Tool::close2zero(cos(deg2rad($v2)), 3);
$r1y = Image_Graph_Tool::close2zero(sin(deg2rad($v1)), 3);
$r2y = Image_Graph_Tool::close2zero(sin(deg2rad($v2)), 3);
// $rx = how many percent of the x-diameter of the entire ellipse does the arc x-diameter occupy: 1 entire width, 0 no width
// $cx = at what percentage of the diameter does the center lie
// if the arc passes through 0/360 degrees the "highest" of r1x and r2x is replaced by 1!
if ((($v1 <= 0) && ($v2 >= 0)) || (($v1 <= 360) && ($v2 >= 360))) {
$r1x = min($r1x, $r2x);
$r2x = 1;
}
// if the arc passes through 180 degrees the "lowest" of r1x and r2x is replaced by -1!
if ((($v1 <= 180) && ($v2 >= 180)) || (($v1 <= 540) && ($v2 >= 540))) {
$r1x = max($r1x, $r2x);
$r2x = -1;
}
if ($r1x >= 0) { // start between [270; 360] or [0; 90]
if ($r2x >= 0) {
$rx = max($r1x, $r2x) / 2;
$cx = 0; // center lies 0 percent along this "vector"
}
else {
$rx = abs($r1x - $r2x) / 2;
$cx = abs($r2x / 2) / $rx;
}
}
else { // start between ]90; 270[
if ($r2x < 0) {
$rx = max(abs($r1x), abs($r2x)) / 2;
$cx = $rx;
}
else {
$rx = abs($r1x - $r2x) / 2;
$cx = abs($r1x / 2) / $rx;
}
}
// $ry = how many percent of the y-diameter of the entire ellipse does the arc y-diameter occupy: 1 entire, 0 none
// $cy = at what percentage of the y-diameter does the center lie
// if the arc passes through 90 degrees the "lowest" of r1x and r2x is replaced by -1!
if ((($v1 <= 90) && ($v2 >= 90)) || (($v1 <= 450) && ($v2 >= 450))) {
$r1y = min($r1y, $r2y);
$r2y = 1;
}
// if the arc passes through 270 degrees the "highest" of r1y and r2y is replaced by -1!
if ((($v1 <= 270) && ($v2 >= 270)) || (($v1 <= 630) && ($v2 >= 630))) {
$r1y = max($r1y, $r2y);
$r2y = -1;
}
if ($r1y >= 0) { // start between [0; 180]
if ($r2y >= 0) {
$ry = max($r1y, $r2y) / 2;
$cy = 0; // center lies 0 percent along this "vector"
}
else {
$ry = abs($r1y - $r2y) / 2;
$cy = abs($r2y / 2) / $ry;
}
}
else { // start between ]180; 360[
if ($r2y < 0) {
$ry = max(abs($r1y), abs($r2y)) / 2;
$cy = $ry;
}
else {
$ry = abs($r1y - $r2y) / 2;
$cy = abs($r1y / 2) / $ry;
}
}
return array(
'rx' => $rx,
'cx' => $cx,
'ry' => $ry,
'cy' => $cy
);
}
/**
* Calculate linear regression on a dataset
* @param array $data The data to calculate regression upon
* @return array The slope and intersection of the "best-fit" line
* @static
*/
function calculateLinearRegression(&$data)
{
$sumX = 0;
$sumY = 0;
foreach ($data as $point) {
$sumX += $point['X'];
$sumY += $point['Y'];
}
$meanX = $sumX / count($data);
$meanY = $sumY / count($data);
$sumXX = 0;
$sumYY = 0;
$sumXY = 0;
foreach ($data as $point) {
$sumXX += ($point['X'] - $meanX) * ($point['X'] - $meanX);
$sumYY += ($point['Y'] - $meanY) * ($point['Y'] - $meanY);
$sumXY += ($point['X'] - $meanX) * ($point['Y'] - $meanY);
}
$result = array();
$result['slope'] = ($sumXY / $sumXX);
$result['intersection'] = $meanY - ($result['slope'] * $meanX);
return $result;
}
}
?>