PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Chart / Legend.php

Legend.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Chart/Legend.php

176 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\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 private string $position = self::POSITION_RIGHT;
34
35 /**
36 * Allow overlay of other elements?
37 */
38 private bool $overlay = true;
39
40 /**
41 * Legend Layout.
42 */
43 private ?Layout $layout;
44
45 private GridLines $borderLines;
46
47 private ChartColor $fillColor;
48
49 private ?AxisText $legendText = null;
50
51 /**
52 * Create a new Legend.
53 */
54 public function __construct(string $position = self::POSITION_RIGHT, ?Layout $layout = null, bool $overlay = false)
55 {
56 $this->setPosition($position);
57 $this->layout = $layout;
58 $this->setOverlay($overlay);
59 $this->borderLines = new GridLines();
60 $this->fillColor = new ChartColor();
61 }
62
63 public function getFillColor(): ChartColor
64 {
65 return $this->fillColor;
66 }
67
68 /**
69 * Get legend position as an Excel string value.
70 */
71 public function getPosition(): string
72 {
73 return $this->position;
74 }
75
76 /**
77 * Get legend position using an Excel string value.
78 *
79 * @param string $position see self::POSITION_*
80 */
81 public function setPosition(string $position): bool
82 {
83 if (!in_array($position, self::POSITION_XLREF)) {
84 return false;
85 }
86
87 $this->position = $position;
88
89 return true;
90 }
91
92 /**
93 * Get legend position as an Excel internal numeric value.
94 * @return false|int
95 */
96 public function getPositionXL()
97 {
98 return array_search($this->position, self::POSITION_XLREF);
99 }
100
101 /**
102 * Set legend position using an Excel internal numeric value.
103 *
104 * @param int $positionXL see self::XL_LEGEND_POSITION_*
105 */
106 public function setPositionXL(int $positionXL): bool
107 {
108 if (!isset(self::POSITION_XLREF[$positionXL])) {
109 return false;
110 }
111
112 $this->position = self::POSITION_XLREF[$positionXL];
113
114 return true;
115 }
116
117 /**
118 * Get allow overlay of other elements?
119 */
120 public function getOverlay(): bool
121 {
122 return $this->overlay;
123 }
124
125 /**
126 * Set allow overlay of other elements?
127 */
128 public function setOverlay(bool $overlay): void
129 {
130 $this->overlay = $overlay;
131 }
132
133 /**
134 * Get Layout.
135 */
136 public function getLayout(): ?Layout
137 {
138 return $this->layout;
139 }
140
141 public function getLegendText(): ?AxisText
142 {
143 return $this->legendText;
144 }
145
146 public function setLegendText(?AxisText $legendText): self
147 {
148 $this->legendText = $legendText;
149
150 return $this;
151 }
152
153 public function getBorderLines(): GridLines
154 {
155 return $this->borderLines;
156 }
157
158 public function setBorderLines(GridLines $borderLines): self
159 {
160 $this->borderLines = $borderLines;
161
162 return $this;
163 }
164
165 /**
166 * Implement PHP __clone to create a deep clone, not just a shallow copy.
167 */
168 public function __clone()
169 {
170 $this->layout = ($this->layout === null) ? null : clone $this->layout;
171 $this->legendText = ($this->legendText === null) ? null : clone $this->legendText;
172 $this->borderLines = clone $this->borderLines;
173 $this->fillColor = clone $this->fillColor;
174 }
175 }
176