PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/Image/Graph/Layout/Horizontal.php

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