1<?php 2 3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 4 5/** 6 * Image_Graph - PEAR PHP OO Graph Rendering Utility. 7 * 8 * PHP version 5 9 * 10 * LICENSE: This library is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License as published by 12 * the Free Software Foundation; either version 2.1 of the License, or (at your 13 * option) any later version. This library is distributed in the hope that it 14 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 16 * General Public License for more details. You should have received a copy of 17 * the GNU Lesser General Public License along with this library; if not, write 18 * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 * 02111-1307 USA 20 * 21 * @category Images 22 * @package Image_Graph 23 * @subpackage Layout 24 * @author Jesper Veggerby <pear.nosey@veggerby.dk> 25 * @author Stefan Neufeind <pear.neufeind@speedpartner.de> 26 * @copyright 2003-2009 The PHP Group 27 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 28 * @version SVN: $Id: Horizontal.php 291170 2009-11-23 03:50:22Z neufeind $ 29 * @link http://pear.php.net/package/Image_Graph 30 */ 31 32/** 33 * Include file Image/Graph/Layout.php 34 */ 35require_once 'Image/Graph/Layout.php'; 36 37/** 38 * Layout for displaying two elements side by side. 39 * 40 * This splits the area contained by this element in two, side by side by 41 * a specified percentage (relative to the left side). A layout can be nested. 42 * Fx. a HorizontalLayout can layout two {@link Image_Graph_Layout_Vertical}s to 43 * make a 2 by 2 matrix of 'element-areas'. 44 * 45 * @category Images 46 * @package Image_Graph 47 * @subpackage Layout 48 * @author Jesper Veggerby <pear.nosey@veggerby.dk> 49 * @author Stefan Neufeind <pear.neufeind@speedpartner.de> 50 * @copyright 2003-2009 The PHP Group 51 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 52 * @version Release: 0.8.0 53 * @link http://pear.php.net/package/Image_Graph 54 */ 55class Image_Graph_Layout_Horizontal extends Image_Graph_Layout 56{ 57 58 /** 59 * Part1 of the layout 60 * @var GraPHPElemnt 61 * @access private 62 */ 63 var $_part1 = false; 64 65 /** 66 * Part2 of the layout 67 * @var GraPHPElemnt 68 * @access private 69 */ 70 var $_part2 = false; 71 72 /** 73 * The percentage of the graph where the split occurs 74 * @var int 75 * @access private 76 */ 77 var $_percentage; 78 79 /** 80 * An absolute position where the split occurs 81 * @var int 82 * @access private 83 */ 84 var $_absolute; 85 86 /** 87 * HorizontalLayout [Constructor] 88 * 89 * @param Image_Graph_Element &$part1 The 1st part of the layout 90 * @param Image_Graph_Element &$part2 The 2nd part of the layout 91 * @param int $percentage The percentage of the layout to split at 92 */ 93 function Image_Graph_Layout_Horizontal(& $part1, & $part2, $percentage = 50) 94 { 95 parent::__construct(); 96 if (!is_a($part1, 'Image_Graph_Layout')) { 97 $this->_error( 98 'Cannot create layout on non-layouable parts: ' . get_class($part1), 99 array('part1' => &$part1, 'part2' => &$part2) 100 ); 101 } elseif (!is_a($part2, 'Image_Graph_Layout')) { 102 $this->_error( 103 'Cannot create layout on non-layouable parts: ' . get_class($part2), 104 array('part1' => &$part1, 'part2' => &$part2) 105 ); 106 } else { 107 $this->_part1 =& $part1; 108 $this->_part2 =& $part2; 109 $this->add($this->_part1); 110 $this->add($this->_part2); 111 }; 112 if ($percentage === 'auto') { 113 $this->_percentage = false; 114 $this->_absolute = 'runtime'; 115 } else { 116 $this->_absolute = false; 117 $this->_percentage = max(0, min(100, $percentage)); 118 } 119 $this->_split(); 120 $this->_padding = array('left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0); 121 } 122 123 /** 124 * Gets the absolute size of one of the parts. 125 * 126 * @param string &$part The name of the part - auto_part(1|2) 127 * 128 * @return int The number of pixels the edge should be pushed 129 * @since 0.3.0dev2 130 * @access private 131 */ 132 function _getAbsolute(&$part) 133 { 134 $part1Size = $this->_part1->_getAutoSize(); 135 $part2Size = $this->_part2->_getAutoSize(); 136 $this->_percentage = false; 137 if (($part1Size !== false) and ($part2Size !== false)) { 138 $width = $this->_fillWidth() * $part1Size / ($part1Size + $part2Size); 139 } elseif ($part1Size !== false) { 140 $width = $part1Size; 141 } elseif ($part2Size !== false) { 142 $width = -$part2Size; 143 } else { 144 $width = $this->_fillWidth() / 2; 145 } 146 if ($part == 'auto_part2') { 147 $width = -$width; 148 } 149 150 return $width; 151 } 152 153 /** 154 * Splits the layout between the parts, by the specified percentage 155 * 156 * @return void 157 * @access private 158 */ 159 function _split() 160 { 161 if (($this->_part1) && ($this->_part2)) { 162 if ($this->_percentage !== false) { 163 $split1 = 100 - $this->_percentage; 164 $split2 = $this->_percentage; 165 $this->_part1->_push('right', "$split1%"); 166 $this->_part2->_push('left', "$split2%"); 167 } else { 168 $this->_part1->_push('right', 'auto_part1'); 169 $this->_part2->_push('left', 'auto_part2'); 170 } 171 } 172 } 173 174 /** 175 * Output the layout to the canvas 176 * 177 * @return bool Was the output 'good' (true) or 'bad' (false). 178 * @access private 179 */ 180 function _done() 181 { 182 if (($this->_part1) && ($this->_part2)) { 183 return (($this->_part1->_done()) && ($this->_part2->_done())); 184 } 185 return true; 186 } 187 188} 189 190?> 191