Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402] [Versions 402 and 403]
1 <?php 2 3 namespace PhpOffice\PhpSpreadsheet\Chart; 4 5 class Legend 6 { 7 /** Legend positions */ 8 const XL_LEGEND_POSITION_BOTTOM = -4107; // Below the chart. 9 const XL_LEGEND_POSITION_CORNER = 2; // In the upper right-hand corner of the chart border. 10 const XL_LEGEND_POSITION_CUSTOM = -4161; // A custom position. 11 const XL_LEGEND_POSITION_LEFT = -4131; // Left of the chart. 12 const XL_LEGEND_POSITION_RIGHT = -4152; // Right of the chart. 13 const XL_LEGEND_POSITION_TOP = -4160; // Above the chart. 14 15 const POSITION_RIGHT = 'r'; 16 const POSITION_LEFT = 'l'; 17 const POSITION_BOTTOM = 'b'; 18 const POSITION_TOP = 't'; 19 const POSITION_TOPRIGHT = 'tr'; 20 21 const POSITION_XLREF = [ 22 self::XL_LEGEND_POSITION_BOTTOM => self::POSITION_BOTTOM, 23 self::XL_LEGEND_POSITION_CORNER => self::POSITION_TOPRIGHT, 24 self::XL_LEGEND_POSITION_CUSTOM => '??', 25 self::XL_LEGEND_POSITION_LEFT => self::POSITION_LEFT, 26 self::XL_LEGEND_POSITION_RIGHT => self::POSITION_RIGHT, 27 self::XL_LEGEND_POSITION_TOP => self::POSITION_TOP, 28 ]; 29 30 /** 31 * Legend position. 32 * 33 * @var string 34 */ 35 private $position = self::POSITION_RIGHT; 36 37 /** 38 * Allow overlay of other elements? 39 * 40 * @var bool 41 */ 42 private $overlay = true; 43 44 /** 45 * Legend Layout. 46 * 47 * @var ?Layout 48 */ 49 private $layout; 50 51 /** 52 * Create a new Legend. 53 * 54 * @param string $position 55 * @param ?Layout $layout 56 * @param bool $overlay 57 */ 58 public function __construct($position = self::POSITION_RIGHT, ?Layout $layout = null, $overlay = false) 59 { 60 $this->setPosition($position); 61 $this->layout = $layout; 62 $this->setOverlay($overlay); 63 } 64 65 /** 66 * Get legend position as an excel string value. 67 * 68 * @return string 69 */ 70 public function getPosition() 71 { 72 return $this->position; 73 } 74 75 /** 76 * Get legend position using an excel string value. 77 * 78 * @param string $position see self::POSITION_* 79 * 80 * @return bool 81 */ 82 public function setPosition($position) 83 { 84 if (!in_array($position, self::POSITION_XLREF)) { 85 return false; 86 } 87 88 $this->position = $position; 89 90 return true; 91 } 92 93 /** 94 * Get legend position as an Excel internal numeric value. 95 * 96 * @return false|int 97 */ 98 public function getPositionXL() 99 { 100 // Scrutinizer thinks the following could return string. It is wrong. 101 return array_search($this->position, self::POSITION_XLREF); 102 } 103 104 /** 105 * Set legend position using an Excel internal numeric value. 106 * 107 * @param int $positionXL see self::XL_LEGEND_POSITION_* 108 * 109 * @return bool 110 */ 111 public function setPositionXL($positionXL) 112 { 113 if (!isset(self::POSITION_XLREF[$positionXL])) { 114 return false; 115 } 116 117 $this->position = self::POSITION_XLREF[$positionXL]; 118 119 return true; 120 } 121 122 /** 123 * Get allow overlay of other elements? 124 * 125 * @return bool 126 */ 127 public function getOverlay() 128 { 129 return $this->overlay; 130 } 131 132 /** 133 * Set allow overlay of other elements? 134 * 135 * @param bool $overlay 136 */ 137 public function setOverlay($overlay): void 138 { 139 $this->overlay = $overlay; 140 } 141 142 /** 143 * Get Layout. 144 * 145 * @return ?Layout 146 */ 147 public function getLayout() 148 { 149 return $this->layout; 150 } 151 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body