Source for file AlphaGraphNode.inc
Documentation is available at AlphaGraphNode.inc
require_once $config->get('sysRoot'). 'alpha/exceptions/IllegalArguementException.inc';
* Maintains the geometry for a tree node
* @package alpha::util::graphs
* @author John Collins <dev@alphaframework.org>
* @version $Id: AlphaGraphNode.inc 1454 2011-12-04 15:14:05Z johnc $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
* * Neither the name of the Alpha Framework nor the names
* of its contributors may be used to endorse or promote
* products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* The x position of the node
* The y position of the node
* The node to the left of this one
* The node to the right of this one
* An array of child nodes of this node
private $children = array();
* The margin offset of the current node
* Optional positional modifier
* Parent node of this node (if any)
* The text message to display on the node
* A 2D array of the coordinates of the endpoints for connectots on this node
private $links = array();
* An array containing the R,G,B values for the colour of this node
* If the node is clickable in an image map, use this property to hold the target URL
* @param array $nodeColour
public function __construct($id, $width, $height, $message = '', $nodeColour = null, $URL = null) {
$this->message = $message;
$this->nodeColour = $nodeColour;
* Get the node colour array
return $this->nodeColour;
* Set the node colour array
* @param array $nodeColour
* @throws IllegalArguementException
$this->nodeColour = $nodeColour;
public function setURL($URL) {
* Get the node text message
* Set the node text message
$this->message = $message;
* @param integer $modifier
$this->modifier = $modifier;
* Get the number of child nodes attached to this node
return count($this->children);
* Get the parent node of this node (if any)
return $this->parentNode;
* @param AlphaGraphNode $node
* @throws IllegalArguementException
$this->parentNode = $node;
* Get the node to the left of this one (if any)
* Sets the node to the left of this node
* @param AlphaGraphNode $node
* @throws IllegalArguementException
* Get the node to the right of this one (if any)
* Sets the node to the right of this node
* @param AlphaGraphNode $node
* @throws IllegalArguementException
$this->rightNode = $node;
* Gets the child node at the index provided, or returns false if none is found
if(isset ($this->children[$i])) {
return $this->children[$i];
* Calculates and returns the midpoint X coordinate of the children of this node
return $node->getOffset() + (($node1->getOffset() - $node->getOffset()) + $node1->getWidth()) / 2;
* Returns the array of child AlphaGraphNode objects
* Add a new node to the children array of this node
* @param AlphaGraphNode $node
* @throws IllegalArguementException
* Returns the links array
* Sets up the array of connector endpoints
$xa = 0; $ya = 0; $xb = 0; $yb = 0; $xc = 0; $yc = 0; $xd = 0; $yd = 0;
$xa = $this->x + ($this->width / 2);
$ya = $this->y + $this->height;
foreach($this->children as $child) {
$xd = $xc = $child->getX() + ($child->getWidth() / 2);
$yb = $yc = $ya + ($yd - $ya) / 2;
$this->links[$child->id]['xa'] = $xa;
$this->links[$child->id]['ya'] = $ya;
$this->links[$child->id]['xb'] = $xb;
$this->links[$child->id]['yb'] = $yb;
$this->links[$child->id]['xc'] = $xc;
$this->links[$child->id]['yc'] = $yc;
$this->links[$child->id]['xd'] = $xd;
$this->links[$child->id]['yd'] = $yd;
* Returns the node height
* Returns the node X-coordinate
* Returns the node Y-coordinate
* Sets the node X-coordinate
public function setX($x) {
* Sets the node Y-coordinate
public function setY($y) {
|