/vendor/phpoffice/phpexcel/Classes/PHPExcel/Chart/Legend.php

https://gitlab.com/techniconline/kmc · PHP · 178 lines · 71 code · 20 blank · 87 comment · 3 complexity · 1a96ae2f40a5a69436af14196c83426d MD5 · raw file

  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Chart
  23. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /**
  28. * PHPExcel_Chart_Legend
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Chart
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Chart_Legend
  35. {
  36. /** Legend positions */
  37. const xlLegendPositionBottom = -4107; // Below the chart.
  38. const xlLegendPositionCorner = 2; // In the upper right-hand corner of the chart border.
  39. const xlLegendPositionCustom = -4161; // A custom position.
  40. const xlLegendPositionLeft = -4131; // Left of the chart.
  41. const xlLegendPositionRight = -4152; // Right of the chart.
  42. const xlLegendPositionTop = -4160; // Above the chart.
  43. const POSITION_RIGHT = 'r';
  44. const POSITION_LEFT = 'l';
  45. const POSITION_BOTTOM = 'b';
  46. const POSITION_TOP = 't';
  47. const POSITION_TOPRIGHT = 'tr';
  48. private static $_positionXLref = array(self::xlLegendPositionBottom => self::POSITION_BOTTOM,
  49. self::xlLegendPositionCorner => self::POSITION_TOPRIGHT,
  50. self::xlLegendPositionCustom => '??',
  51. self::xlLegendPositionLeft => self::POSITION_LEFT,
  52. self::xlLegendPositionRight => self::POSITION_RIGHT,
  53. self::xlLegendPositionTop => self::POSITION_TOP
  54. );
  55. /**
  56. * Legend position
  57. *
  58. * @var string
  59. */
  60. private $_position = self::POSITION_RIGHT;
  61. /**
  62. * Allow overlay of other elements?
  63. *
  64. * @var boolean
  65. */
  66. private $_overlay = TRUE;
  67. /**
  68. * Legend Layout
  69. *
  70. * @var PHPExcel_Chart_Layout
  71. */
  72. private $_layout = NULL;
  73. /**
  74. * Create a new PHPExcel_Chart_Legend
  75. */
  76. public function __construct($position = self::POSITION_RIGHT, PHPExcel_Chart_Layout $layout = NULL, $overlay = FALSE)
  77. {
  78. $this->setPosition($position);
  79. $this->_layout = $layout;
  80. $this->setOverlay($overlay);
  81. }
  82. /**
  83. * Get legend position as an excel string value
  84. *
  85. * @return string
  86. */
  87. public function getPosition()
  88. {
  89. return $this->_position;
  90. }
  91. /**
  92. * Get legend position using an excel string value
  93. *
  94. * @param string $position
  95. */
  96. public function setPosition($position = self::POSITION_RIGHT)
  97. {
  98. if (!in_array($position, self::$_positionXLref)) {
  99. return false;
  100. }
  101. $this->_position = $position;
  102. return true;
  103. }
  104. /**
  105. * Get legend position as an Excel internal numeric value
  106. *
  107. * @return number
  108. */
  109. public function getPositionXL()
  110. {
  111. return array_search($this->_position, self::$_positionXLref);
  112. }
  113. /**
  114. * Set legend position using an Excel internal numeric value
  115. *
  116. * @param number $positionXL
  117. */
  118. public function setPositionXL($positionXL = self::xlLegendPositionRight)
  119. {
  120. if (!array_key_exists($positionXL, self::$_positionXLref)) {
  121. return false;
  122. }
  123. $this->_position = self::$_positionXLref[$positionXL];
  124. return true;
  125. }
  126. /**
  127. * Get allow overlay of other elements?
  128. *
  129. * @return boolean
  130. */
  131. public function getOverlay()
  132. {
  133. return $this->_overlay;
  134. }
  135. /**
  136. * Set allow overlay of other elements?
  137. *
  138. * @param boolean $overlay
  139. * @return boolean
  140. */
  141. public function setOverlay($overlay = FALSE)
  142. {
  143. if (!is_bool($overlay)) {
  144. return false;
  145. }
  146. $this->_overlay = $overlay;
  147. return true;
  148. }
  149. /**
  150. * Get Layout
  151. *
  152. * @return PHPExcel_Chart_Layout
  153. */
  154. public function getLayout()
  155. {
  156. return $this->_layout;
  157. }
  158. }