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 / Axis.php

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

354 lines 8.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 /**
6 * Created by PhpStorm.
7 * User: Wiktor Trzonkowski
8 * Date: 6/17/14
9 * Time: 12:11 PM.
10 */
11 class Axis extends Properties
12 {
13 const AXIS_TYPE_CATEGORY = 'catAx';
14 const AXIS_TYPE_DATE = 'dateAx';
15 const AXIS_TYPE_VALUE = 'valAx';
16
17 const TIME_UNIT_DAYS = 'days';
18 const TIME_UNIT_MONTHS = 'months';
19 const TIME_UNIT_YEARS = 'years';
20
21 public function __construct()
22 {
23 parent::__construct();
24 $this->fillColor = new ChartColor();
25 }
26
27 /**
28 * Chart Major Gridlines as.
29 */
30 private ?GridLines $majorGridlines = null;
31
32 /**
33 * Chart Minor Gridlines as.
34 */
35 private ?GridLines $minorGridlines = null;
36
37 /**
38 * Axis Number.
39 *
40 * @var array{format: string, source_linked: int, numeric: ?bool}
41 */
42 private array $axisNumber = [
43 'format' => self::FORMAT_CODE_GENERAL,
44 'source_linked' => 1,
45 'numeric' => null,
46 ];
47
48 private string $axisType = '';
49
50 private ?AxisText $axisText = null;
51
52 private ?Title $dispUnitsTitle = null;
53
54 /**
55 * Axis Options.
56 *
57 * @var array<string, null|string>
58 */
59 private array $axisOptions = [
60 'minimum' => null,
61 'maximum' => null,
62 'major_unit' => null,
63 'minor_unit' => null,
64 'orientation' => self::ORIENTATION_NORMAL,
65 'minor_tick_mark' => self::TICK_MARK_NONE,
66 'major_tick_mark' => self::TICK_MARK_NONE,
67 'axis_labels' => self::AXIS_LABELS_NEXT_TO,
68 'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO,
69 'horizontal_crosses_value' => null,
70 'textRotation' => null,
71 'hidden' => null,
72 'majorTimeUnit' => self::TIME_UNIT_YEARS,
73 'minorTimeUnit' => self::TIME_UNIT_MONTHS,
74 'baseTimeUnit' => self::TIME_UNIT_DAYS,
75 'logBase' => null,
76 'dispUnitsBuiltIn' => null,
77 ];
78 public const DISP_UNITS_HUNDREDS = 'hundreds';
79 public const DISP_UNITS_THOUSANDS = 'thousands';
80 public const DISP_UNITS_TEN_THOUSANDS = 'tenThousands';
81 public const DISP_UNITS_HUNDRED_THOUSANDS = 'hundredThousands';
82 public const DISP_UNITS_MILLIONS = 'millions';
83 public const DISP_UNITS_TEN_MILLIONS = 'tenMillions';
84 public const DISP_UNITS_HUNDRED_MILLIONS = 'hundredMillions';
85 public const DISP_UNITS_BILLIONS = 'billions';
86 public const DISP_UNITS_TRILLIONS = 'trillions';
87 public const TRILLION_INDEX = (PHP_INT_SIZE > 4) ? 1000000000000 : '1000000000000';
88 public const DISP_UNITS_BUILTIN_INT = [
89 100 => self::DISP_UNITS_HUNDREDS,
90 1000 => self::DISP_UNITS_THOUSANDS,
91 10000 => self::DISP_UNITS_TEN_THOUSANDS,
92 100000 => self::DISP_UNITS_HUNDRED_THOUSANDS,
93 1000000 => self::DISP_UNITS_MILLIONS,
94 10000000 => self::DISP_UNITS_TEN_MILLIONS,
95 100000000 => self::DISP_UNITS_HUNDRED_MILLIONS,
96 1000000000 => self::DISP_UNITS_BILLIONS,
97 self::TRILLION_INDEX => self::DISP_UNITS_TRILLIONS, // overflow for 32-bit
98 ];
99
100 /**
101 * Fill Properties.
102 */
103 private ChartColor $fillColor;
104
105 private const NUMERIC_FORMAT = [
106 Properties::FORMAT_CODE_NUMBER,
107 Properties::FORMAT_CODE_DATE,
108 Properties::FORMAT_CODE_DATE_ISO8601,
109 ];
110
111 private bool $noFill = false;
112
113 /**
114 * Get Series Data Type.
115 */
116 public function setAxisNumberProperties(string $format_code, ?bool $numeric = null, int $sourceLinked = 0): void
117 {
118 $format = $format_code;
119 $this->axisNumber['format'] = $format;
120 $this->axisNumber['source_linked'] = $sourceLinked;
121 if (is_bool($numeric)) {
122 $this->axisNumber['numeric'] = $numeric;
123 } elseif (in_array($format, self::NUMERIC_FORMAT, true)) {
124 $this->axisNumber['numeric'] = true;
125 }
126 }
127
128 /**
129 * Get Axis Number Format Data Type.
130 */
131 public function getAxisNumberFormat(): string
132 {
133 return $this->axisNumber['format'];
134 }
135
136 /**
137 * Get Axis Number Source Linked.
138 */
139 public function getAxisNumberSourceLinked(): string
140 {
141 return (string) $this->axisNumber['source_linked'];
142 }
143
144 public function getAxisIsNumericFormat(): bool
145 {
146 return $this->axisType === self::AXIS_TYPE_DATE || (bool) $this->axisNumber['numeric'];
147 }
148
149 /**
150 * @param null|float|int|string $value
151 */
152 public function setAxisOption(string $key, $value): void
153 {
154 if ($value !== null && $value !== '') {
155 $this->axisOptions[$key] = (string) $value;
156 }
157 }
158
159 /**
160 * Set Axis Options Properties.
161 * @param null|float|int|string $minimum
162 * @param null|float|int|string $maximum
163 * @param null|float|int|string $majorUnit
164 * @param null|float|int|string $minorUnit
165 * @param null|float|int|string $textRotation
166 * @param null|float|int|string $logBase
167 */
168 public function setAxisOptionsProperties(
169 string $axisLabels,
170 ?string $horizontalCrossesValue = null,
171 ?string $horizontalCrosses = null,
172 ?string $axisOrientation = null,
173 ?string $majorTmt = null,
174 ?string $minorTmt = null,
175 $minimum = null,
176 $maximum = null,
177 $majorUnit = null,
178 $minorUnit = null,
179 $textRotation = null,
180 ?string $hidden = null,
181 ?string $baseTimeUnit = null,
182 ?string $majorTimeUnit = null,
183 ?string $minorTimeUnit = null,
184 $logBase = null,
185 ?string $dispUnitsBuiltIn = null
186 ): void {
187 $this->axisOptions['axis_labels'] = $axisLabels;
188 $this->setAxisOption('horizontal_crosses_value', $horizontalCrossesValue);
189 $this->setAxisOption('horizontal_crosses', $horizontalCrosses);
190 $this->setAxisOption('orientation', $axisOrientation);
191 $this->setAxisOption('major_tick_mark', $majorTmt);
192 $this->setAxisOption('minor_tick_mark', $minorTmt);
193 $this->setAxisOption('minimum', $minimum);
194 $this->setAxisOption('maximum', $maximum);
195 $this->setAxisOption('major_unit', $majorUnit);
196 $this->setAxisOption('minor_unit', $minorUnit);
197 $this->setAxisOption('textRotation', $textRotation);
198 $this->setAxisOption('hidden', $hidden);
199 $this->setAxisOption('baseTimeUnit', $baseTimeUnit);
200 $this->setAxisOption('majorTimeUnit', $majorTimeUnit);
201 $this->setAxisOption('minorTimeUnit', $minorTimeUnit);
202 $this->setAxisOption('logBase', $logBase);
203 $this->setAxisOption('dispUnitsBuiltIn', $dispUnitsBuiltIn);
204 }
205
206 /**
207 * Get Axis Options Property.
208 */
209 public function getAxisOptionsProperty(string $property): ?string
210 {
211 if ($property === 'textRotation') {
212 if ($this->axisText !== null) {
213 if ($this->axisText->getRotation() !== null) {
214 return (string) $this->axisText->getRotation();
215 }
216 }
217 }
218
219 return $this->axisOptions[$property];
220 }
221
222 /**
223 * Set Axis Orientation Property.
224 */
225 public function setAxisOrientation(string $orientation): void
226 {
227 $this->axisOptions['orientation'] = (string) $orientation;
228 }
229
230 public function getAxisType(): string
231 {
232 return $this->axisType;
233 }
234
235 public function setAxisType(string $type): self
236 {
237 if ($type === self::AXIS_TYPE_CATEGORY || $type === self::AXIS_TYPE_VALUE || $type === self::AXIS_TYPE_DATE) {
238 $this->axisType = $type;
239 } else {
240 $this->axisType = '';
241 }
242
243 return $this;
244 }
245
246 /**
247 * Set Fill Property.
248 */
249 public function setFillParameters(?string $color, ?int $alpha = null, ?string $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
250 {
251 $this->fillColor->setColorProperties($color, $alpha, $AlphaType);
252 }
253
254 /**
255 * Get Fill Property.
256 */
257 public function getFillProperty(string $property): string
258 {
259 return (string) $this->fillColor->getColorProperty($property);
260 }
261
262 public function getFillColorObject(): ChartColor
263 {
264 return $this->fillColor;
265 }
266
267 private string $crossBetween = ''; // 'between' or 'midCat' might be better
268
269 public function setCrossBetween(string $crossBetween): self
270 {
271 $this->crossBetween = $crossBetween;
272
273 return $this;
274 }
275
276 public function getCrossBetween(): string
277 {
278 return $this->crossBetween;
279 }
280
281 public function getMajorGridlines(): ?GridLines
282 {
283 return $this->majorGridlines;
284 }
285
286 public function getMinorGridlines(): ?GridLines
287 {
288 return $this->minorGridlines;
289 }
290
291 public function setMajorGridlines(?GridLines $gridlines): self
292 {
293 $this->majorGridlines = $gridlines;
294
295 return $this;
296 }
297
298 public function setMinorGridlines(?GridLines $gridlines): self
299 {
300 $this->minorGridlines = $gridlines;
301
302 return $this;
303 }
304
305 public function getAxisText(): ?AxisText
306 {
307 return $this->axisText;
308 }
309
310 public function setAxisText(?AxisText $axisText): self
311 {
312 $this->axisText = $axisText;
313
314 return $this;
315 }
316
317 public function setNoFill(bool $noFill): self
318 {
319 $this->noFill = $noFill;
320
321 return $this;
322 }
323
324 public function getNoFill(): bool
325 {
326 return $this->noFill;
327 }
328
329 public function setDispUnitsTitle(?Title $dispUnitsTitle): self
330 {
331 $this->dispUnitsTitle = $dispUnitsTitle;
332
333 return $this;
334 }
335
336 public function getDispUnitsTitle(): ?Title
337 {
338 return $this->dispUnitsTitle;
339 }
340
341 /**
342 * Implement PHP __clone to create a deep clone, not just a shallow copy.
343 */
344 public function __clone()
345 {
346 parent::__clone();
347 $this->majorGridlines = ($this->majorGridlines === null) ? null : clone $this->majorGridlines;
348 $this->minorGridlines = ($this->minorGridlines === null) ? null : clone $this->minorGridlines;
349 $this->axisText = ($this->axisText === null) ? null : clone $this->axisText;
350 $this->dispUnitsTitle = ($this->dispUnitsTitle === null) ? null : clone $this->dispUnitsTitle;
351 $this->fillColor = clone $this->fillColor;
352 }
353 }
354