731a11c42e1d7f2859a78f24f472f0d900de8c7b.svn-base 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. return $this->_position;
  89. }
  90. /**
  91. * Get legend position using an excel string value
  92. *
  93. * @param string $position
  94. */
  95. public function setPosition($position = self::POSITION_RIGHT) {
  96. if (!in_array($position,self::$_positionXLref)) {
  97. return false;
  98. }
  99. $this->_position = $position;
  100. return true;
  101. }
  102. /**
  103. * Get legend position as an Excel internal numeric value
  104. *
  105. * @return number
  106. */
  107. public function getPositionXL() {
  108. return array_search($this->_position,self::$_positionXLref);
  109. }
  110. /**
  111. * Set legend position using an Excel internal numeric value
  112. *
  113. * @param number $positionXL
  114. */
  115. public function setPositionXL($positionXL = self::xlLegendPositionRight) {
  116. if (!array_key_exists($positionXL,self::$_positionXLref)) {
  117. return false;
  118. }
  119. $this->_position = self::$_positionXLref[$positionXL];
  120. return true;
  121. }
  122. /**
  123. * Get allow overlay of other elements?
  124. *
  125. * @return boolean
  126. */
  127. public function getOverlay() {
  128. return $this->_overlay;
  129. }
  130. /**
  131. * Set allow overlay of other elements?
  132. *
  133. * @param boolean $overlay
  134. * @return boolean
  135. */
  136. public function setOverlay($overlay = FALSE) {
  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. return $this->_layout;
  150. }
  151. }