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