Legend.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * PHPExcel_Chart_Legend
  4. *
  5. * Copyright (c) 2006 - 2015 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 - 2015 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. class PHPExcel_Chart_Legend
  28. {
  29. /** Legend positions */
  30. const xlLegendPositionBottom = -4107; // Below the chart.
  31. const xlLegendPositionCorner = 2; // In the upper right-hand corner of the chart border.
  32. const xlLegendPositionCustom = -4161; // A custom position.
  33. const xlLegendPositionLeft = -4131; // Left of the chart.
  34. const xlLegendPositionRight = -4152; // Right of the chart.
  35. const xlLegendPositionTop = -4160; // Above the chart.
  36. const POSITION_RIGHT = 'r';
  37. const POSITION_LEFT = 'l';
  38. const POSITION_BOTTOM = 'b';
  39. const POSITION_TOP = 't';
  40. const POSITION_TOPRIGHT = 'tr';
  41. private static $positionXLref = array(
  42. self::xlLegendPositionBottom => self::POSITION_BOTTOM,
  43. self::xlLegendPositionCorner => self::POSITION_TOPRIGHT,
  44. self::xlLegendPositionCustom => '??',
  45. self::xlLegendPositionLeft => self::POSITION_LEFT,
  46. self::xlLegendPositionRight => self::POSITION_RIGHT,
  47. self::xlLegendPositionTop => self::POSITION_TOP
  48. );
  49. /**
  50. * Legend position
  51. *
  52. * @var string
  53. */
  54. private $position = self::POSITION_RIGHT;
  55. /**
  56. * Allow overlay of other elements?
  57. *
  58. * @var boolean
  59. */
  60. private $overlay = true;
  61. /**
  62. * Legend Layout
  63. *
  64. * @var PHPExcel_Chart_Layout
  65. */
  66. private $layout = null;
  67. /**
  68. * Create a new PHPExcel_Chart_Legend
  69. */
  70. public function __construct($position = self::POSITION_RIGHT, PHPExcel_Chart_Layout $layout = null, $overlay = false)
  71. {
  72. $this->setPosition($position);
  73. $this->layout = $layout;
  74. $this->setOverlay($overlay);
  75. }
  76. /**
  77. * Get legend position as an excel string value
  78. *
  79. * @return string
  80. */
  81. public function getPosition()
  82. {
  83. return $this->position;
  84. }
  85. /**
  86. * Get legend position using an excel string value
  87. *
  88. * @param string $position
  89. */
  90. public function setPosition($position = self::POSITION_RIGHT)
  91. {
  92. if (!in_array($position, self::$positionXLref)) {
  93. return false;
  94. }
  95. $this->position = $position;
  96. return true;
  97. }
  98. /**
  99. * Get legend position as an Excel internal numeric value
  100. *
  101. * @return number
  102. */
  103. public function getPositionXL()
  104. {
  105. return array_search($this->position, self::$positionXLref);
  106. }
  107. /**
  108. * Set legend position using an Excel internal numeric value
  109. *
  110. * @param number $positionXL
  111. */
  112. public function setPositionXL($positionXL = self::xlLegendPositionRight)
  113. {
  114. if (!array_key_exists($positionXL, self::$positionXLref)) {
  115. return false;
  116. }
  117. $this->position = self::$positionXLref[$positionXL];
  118. return true;
  119. }
  120. /**
  121. * Get allow overlay of other elements?
  122. *
  123. * @return boolean
  124. */
  125. public function getOverlay()
  126. {
  127. return $this->overlay;
  128. }
  129. /**
  130. * Set allow overlay of other elements?
  131. *
  132. * @param boolean $overlay
  133. * @return boolean
  134. */
  135. public function setOverlay($overlay = false)
  136. {
  137. if (!is_bool($overlay)) {
  138. return false;
  139. }
  140. $this->overlay = $overlay;
  141. return true;
  142. }
  143. /**
  144. * Get Layout
  145. *
  146. * @return PHPExcel_Chart_Layout
  147. */
  148. public function getLayout()
  149. {
  150. return $this->layout;
  151. }
  152. }