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

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

409 lines 7.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 use TablePress\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
6
7 class DataSeries
8 {
9 const TYPE_BARCHART = 'barChart';
10 const TYPE_BARCHART_3D = 'bar3DChart';
11 const TYPE_LINECHART = 'lineChart';
12 const TYPE_LINECHART_3D = 'line3DChart';
13 const TYPE_AREACHART = 'areaChart';
14 const TYPE_AREACHART_3D = 'area3DChart';
15 const TYPE_PIECHART = 'pieChart';
16 const TYPE_PIECHART_3D = 'pie3DChart';
17 const TYPE_DOUGHNUTCHART = 'doughnutChart';
18 const TYPE_DONUTCHART = self::TYPE_DOUGHNUTCHART; // Synonym
19 const TYPE_SCATTERCHART = 'scatterChart';
20 const TYPE_SURFACECHART = 'surfaceChart';
21 const TYPE_SURFACECHART_3D = 'surface3DChart';
22 const TYPE_RADARCHART = 'radarChart';
23 const TYPE_BUBBLECHART = 'bubbleChart';
24 const TYPE_STOCKCHART = 'stockChart';
25 const TYPE_CANDLECHART = self::TYPE_STOCKCHART; // Synonym
26
27 const GROUPING_CLUSTERED = 'clustered';
28 const GROUPING_STACKED = 'stacked';
29 const GROUPING_PERCENT_STACKED = 'percentStacked';
30 const GROUPING_STANDARD = 'standard';
31
32 const DIRECTION_BAR = 'bar';
33 const DIRECTION_HORIZONTAL = self::DIRECTION_BAR;
34 const DIRECTION_COL = 'col';
35 const DIRECTION_COLUMN = self::DIRECTION_COL;
36 const DIRECTION_VERTICAL = self::DIRECTION_COL;
37
38 const STYLE_LINEMARKER = 'lineMarker';
39 const STYLE_SMOOTHMARKER = 'smoothMarker';
40 const STYLE_MARKER = 'marker';
41 const STYLE_FILLED = 'filled';
42
43 const EMPTY_AS_GAP = 'gap';
44 const EMPTY_AS_ZERO = 'zero';
45 const EMPTY_AS_SPAN = 'span';
46 const DEFAULT_EMPTY_AS = self::EMPTY_AS_GAP;
47 const VALID_EMPTY_AS = [self::EMPTY_AS_GAP, self::EMPTY_AS_ZERO, self::EMPTY_AS_SPAN];
48
49 /**
50 * Series Plot Type.
51 */
52 private ?string $plotType;
53
54 /**
55 * Plot Grouping Type.
56 */
57 private ?string $plotGrouping;
58
59 /**
60 * Plot Direction.
61 */
62 private string $plotDirection;
63
64 /**
65 * Plot Style.
66 */
67 private ?string $plotStyle;
68
69 /**
70 * Order of plots in Series.
71 *
72 * @var int[]
73 */
74 private array $plotOrder;
75
76 /**
77 * Plot Label.
78 *
79 * @var DataSeriesValues[]
80 */
81 private array $plotLabel;
82
83 /**
84 * Plot Category.
85 *
86 * @var DataSeriesValues[]
87 */
88 private array $plotCategory;
89
90 /**
91 * Smooth Line. Must be specified for both DataSeries and DataSeriesValues.
92 */
93 private bool $smoothLine;
94
95 /**
96 * Plot Values.
97 *
98 * @var DataSeriesValues[]
99 */
100 private array $plotValues;
101
102 /**
103 * Plot Bubble Sizes.
104 *
105 * @var DataSeriesValues[]
106 */
107 private array $plotBubbleSizes = [];
108
109 /**
110 * Create a new DataSeries.
111 *
112 * @param int[] $plotOrder
113 * @param DataSeriesValues[] $plotLabel
114 * @param DataSeriesValues[] $plotCategory
115 * @param DataSeriesValues[] $plotValues
116 */
117 public function __construct(
118 ?string $plotType = null,
119 ?string $plotGrouping = null,
120 array $plotOrder = [],
121 array $plotLabel = [],
122 array $plotCategory = [],
123 array $plotValues = [],
124 ?string $plotDirection = null,
125 bool $smoothLine = false,
126 ?string $plotStyle = null
127 ) {
128 $this->plotType = $plotType;
129 $this->plotGrouping = $plotGrouping;
130 $this->plotOrder = $plotOrder;
131 $keys = array_keys($plotValues);
132 $this->plotValues = $plotValues;
133 if (!isset($plotLabel[$keys[0]])) {
134 $plotLabel[$keys[0]] = new DataSeriesValues();
135 }
136 $this->plotLabel = $plotLabel;
137
138 if (!isset($plotCategory[$keys[0]])) {
139 $plotCategory[$keys[0]] = new DataSeriesValues();
140 }
141 $this->plotCategory = $plotCategory;
142
143 $this->smoothLine = (bool) $smoothLine;
144 $this->plotStyle = $plotStyle;
145
146 if ($plotDirection === null) {
147 $plotDirection = self::DIRECTION_COL;
148 }
149 $this->plotDirection = $plotDirection;
150 }
151
152 /**
153 * Get Plot Type.
154 */
155 public function getPlotType(): ?string
156 {
157 return $this->plotType;
158 }
159
160 /**
161 * Set Plot Type.
162 *
163 * @return $this
164 */
165 public function setPlotType(string $plotType)
166 {
167 $this->plotType = $plotType;
168
169 return $this;
170 }
171
172 /**
173 * Get Plot Grouping Type.
174 */
175 public function getPlotGrouping(): ?string
176 {
177 return $this->plotGrouping;
178 }
179
180 /**
181 * Set Plot Grouping Type.
182 *
183 * @return $this
184 */
185 public function setPlotGrouping(string $groupingType)
186 {
187 $this->plotGrouping = $groupingType;
188
189 return $this;
190 }
191
192 /**
193 * Get Plot Direction.
194 */
195 public function getPlotDirection(): string
196 {
197 return $this->plotDirection;
198 }
199
200 /**
201 * Set Plot Direction.
202 *
203 * @return $this
204 */
205 public function setPlotDirection(string $plotDirection)
206 {
207 $this->plotDirection = $plotDirection;
208
209 return $this;
210 }
211
212 /**
213 * Get Plot Order.
214 *
215 * @return int[]
216 */
217 public function getPlotOrder(): array
218 {
219 return $this->plotOrder;
220 }
221
222 /**
223 * Get Plot Labels.
224 *
225 * @return DataSeriesValues[]
226 */
227 public function getPlotLabels(): array
228 {
229 return $this->plotLabel;
230 }
231
232 /**
233 * Get Plot Label by Index.
234 *
235 * @return DataSeriesValues|false
236 */
237 public function getPlotLabelByIndex(int $index)
238 {
239 $keys = array_keys($this->plotLabel);
240 if (in_array($index, $keys)) {
241 return $this->plotLabel[$index];
242 }
243
244 return false;
245 }
246
247 /**
248 * Get Plot Categories.
249 *
250 * @return DataSeriesValues[]
251 */
252 public function getPlotCategories(): array
253 {
254 return $this->plotCategory;
255 }
256
257 /**
258 * Get Plot Category by Index.
259 *
260 * @return DataSeriesValues|false
261 */
262 public function getPlotCategoryByIndex(int $index)
263 {
264 $keys = array_keys($this->plotCategory);
265 if (in_array($index, $keys)) {
266 return $this->plotCategory[$index];
267 } elseif (isset($keys[$index])) {
268 return $this->plotCategory[$keys[$index]];
269 }
270
271 return false;
272 }
273
274 /**
275 * Get Plot Style.
276 */
277 public function getPlotStyle(): ?string
278 {
279 return $this->plotStyle;
280 }
281
282 /**
283 * Set Plot Style.
284 *
285 * @return $this
286 */
287 public function setPlotStyle(?string $plotStyle)
288 {
289 $this->plotStyle = $plotStyle;
290
291 return $this;
292 }
293
294 /**
295 * Get Plot Values.
296 *
297 * @return DataSeriesValues[]
298 */
299 public function getPlotValues(): array
300 {
301 return $this->plotValues;
302 }
303
304 /**
305 * Get Plot Values by Index.
306 *
307 * @return DataSeriesValues|false
308 */
309 public function getPlotValuesByIndex(int $index)
310 {
311 $keys = array_keys($this->plotValues);
312 if (in_array($index, $keys)) {
313 return $this->plotValues[$index];
314 }
315
316 return false;
317 }
318
319 /**
320 * Get Plot Bubble Sizes.
321 *
322 * @return DataSeriesValues[]
323 */
324 public function getPlotBubbleSizes(): array
325 {
326 return $this->plotBubbleSizes;
327 }
328
329 /**
330 * Set Plot Bubble Sizes.
331 *
332 * @param DataSeriesValues[] $plotBubbleSizes
333 */
334 public function setPlotBubbleSizes(array $plotBubbleSizes): self
335 {
336 $this->plotBubbleSizes = $plotBubbleSizes;
337
338 return $this;
339 }
340
341 /**
342 * Get Number of Plot Series.
343 */
344 public function getPlotSeriesCount(): int
345 {
346 return count($this->plotValues);
347 }
348
349 /**
350 * Get Smooth Line.
351 */
352 public function getSmoothLine(): bool
353 {
354 return $this->smoothLine;
355 }
356
357 /**
358 * Set Smooth Line.
359 *
360 * @return $this
361 */
362 public function setSmoothLine(bool $smoothLine)
363 {
364 $this->smoothLine = $smoothLine;
365
366 return $this;
367 }
368
369 public function refresh(Worksheet $worksheet): void
370 {
371 foreach ($this->plotValues as $plotValues) {
372 $plotValues->refresh($worksheet, true);
373 }
374 foreach ($this->plotLabel as $plotValues) {
375 $plotValues->refresh($worksheet, true);
376 }
377 foreach ($this->plotCategory as $plotValues) {
378 $plotValues->refresh($worksheet, false);
379 }
380 }
381
382 /**
383 * Implement PHP __clone to create a deep clone, not just a shallow copy.
384 */
385 public function __clone()
386 {
387 $plotLabels = $this->plotLabel;
388 $this->plotLabel = [];
389 foreach ($plotLabels as $plotLabel) {
390 $this->plotLabel[] = clone $plotLabel;
391 }
392 $plotCategories = $this->plotCategory;
393 $this->plotCategory = [];
394 foreach ($plotCategories as $plotCategory) {
395 $this->plotCategory[] = clone $plotCategory;
396 }
397 $plotValues = $this->plotValues;
398 $this->plotValues = [];
399 foreach ($plotValues as $plotValue) {
400 $this->plotValues[] = clone $plotValue;
401 }
402 $plotBubbleSizes = $this->plotBubbleSizes;
403 $this->plotBubbleSizes = [];
404 foreach ($plotBubbleSizes as $plotBubbleSize) {
405 $this->plotBubbleSizes[] = clone $plotBubbleSize;
406 }
407 }
408 }
409