Legend.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. class PHPExcel_Chart_Legend
  8. {
  9. /** Legend positions */
  10. const xlLegendPositionBottom = -4107; // Below the chart.
  11. const xlLegendPositionCorner = 2; // In the upper right-hand corner of the chart border.
  12. const xlLegendPositionCustom = -4161; // A custom position.
  13. const xlLegendPositionLeft = -4131; // Left of the chart.
  14. const xlLegendPositionRight = -4152; // Right of the chart.
  15. const xlLegendPositionTop = -4160; // Above the chart.
  16. const POSITION_RIGHT = 'r';
  17. const POSITION_LEFT = 'l';
  18. const POSITION_BOTTOM = 'b';
  19. const POSITION_TOP = 't';
  20. const POSITION_TOPRIGHT = 'tr';
  21. private static $positionXLref = array(
  22. self::xlLegendPositionBottom => self::POSITION_BOTTOM,
  23. self::xlLegendPositionCorner => self::POSITION_TOPRIGHT,
  24. self::xlLegendPositionCustom => '??',
  25. self::xlLegendPositionLeft => self::POSITION_LEFT,
  26. self::xlLegendPositionRight => self::POSITION_RIGHT,
  27. self::xlLegendPositionTop => self::POSITION_TOP
  28. );
  29. /**
  30. * Legend position
  31. *
  32. * @var string
  33. */
  34. private $position = self::POSITION_RIGHT;
  35. /**
  36. * Allow overlay of other elements?
  37. *
  38. * @var boolean
  39. */
  40. private $overlay = true;
  41. /**
  42. * Legend Layout
  43. *
  44. * @var PHPExcel_Chart_Layout
  45. */
  46. private $layout = null;
  47. /**
  48. * Create a new PHPExcel_Chart_Legend
  49. */
  50. public function __construct($position = self::POSITION_RIGHT, PHPExcel_Chart_Layout $layout = null, $overlay = false)
  51. {
  52. $this->setPosition($position);
  53. $this->layout = $layout;
  54. $this->setOverlay($overlay);
  55. }
  56. /**
  57. * Get legend position as an excel string value
  58. *
  59. * @return string
  60. */
  61. public function getPosition()
  62. {
  63. return $this->position;
  64. }
  65. /**
  66. * Get legend position using an excel string value
  67. *
  68. * @param string $position
  69. */
  70. public function setPosition($position = self::POSITION_RIGHT)
  71. {
  72. if (!in_array($position, self::$positionXLref)) {
  73. return false;
  74. }
  75. $this->position = $position;
  76. return true;
  77. }
  78. /**
  79. * Get legend position as an Excel internal numeric value
  80. *
  81. * @return number
  82. */
  83. public function getPositionXL()
  84. {
  85. return array_search($this->position, self::$positionXLref);
  86. }
  87. /**
  88. * Set legend position using an Excel internal numeric value
  89. *
  90. * @param number $positionXL
  91. */
  92. public function setPositionXL($positionXL = self::xlLegendPositionRight)
  93. {
  94. if (!array_key_exists($positionXL, self::$positionXLref)) {
  95. return false;
  96. }
  97. $this->position = self::$positionXLref[$positionXL];
  98. return true;
  99. }
  100. /**
  101. * Get allow overlay of other elements?
  102. *
  103. * @return boolean
  104. */
  105. public function getOverlay()
  106. {
  107. return $this->overlay;
  108. }
  109. /**
  110. * Set allow overlay of other elements?
  111. *
  112. * @param boolean $overlay
  113. * @return boolean
  114. */
  115. public function setOverlay($overlay = false)
  116. {
  117. if (!is_bool($overlay)) {
  118. return false;
  119. }
  120. $this->overlay = $overlay;
  121. return true;
  122. }
  123. /**
  124. * Get Layout
  125. *
  126. * @return PHPExcel_Chart_Layout
  127. */
  128. public function getLayout()
  129. {
  130. return $this->layout;
  131. }
  132. }