1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Chart; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet. |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU Lesser General Public |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16
|
|
|
* Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Lesser General Public |
19
|
|
|
* License along with this library; if not, write to the Free Software |
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21
|
|
|
* |
22
|
|
|
* @category PhpSpreadsheet |
23
|
|
|
* |
24
|
|
|
* @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) |
25
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
26
|
|
|
*/ |
27
|
|
|
class DataSeries |
28
|
|
|
{ |
29
|
|
|
const TYPE_BARCHART = 'barChart'; |
30
|
|
|
const TYPE_BARCHART_3D = 'bar3DChart'; |
31
|
|
|
const TYPE_LINECHART = 'lineChart'; |
32
|
|
|
const TYPE_LINECHART_3D = 'line3DChart'; |
33
|
|
|
const TYPE_AREACHART = 'areaChart'; |
34
|
|
|
const TYPE_AREACHART_3D = 'area3DChart'; |
35
|
|
|
const TYPE_PIECHART = 'pieChart'; |
36
|
|
|
const TYPE_PIECHART_3D = 'pie3DChart'; |
37
|
|
|
const TYPE_DOUGHTNUTCHART = 'doughnutChart'; |
38
|
|
|
const TYPE_DONUTCHART = self::TYPE_DOUGHTNUTCHART; // Synonym |
39
|
|
|
const TYPE_SCATTERCHART = 'scatterChart'; |
40
|
|
|
const TYPE_SURFACECHART = 'surfaceChart'; |
41
|
|
|
const TYPE_SURFACECHART_3D = 'surface3DChart'; |
42
|
|
|
const TYPE_RADARCHART = 'radarChart'; |
43
|
|
|
const TYPE_BUBBLECHART = 'bubbleChart'; |
44
|
|
|
const TYPE_STOCKCHART = 'stockChart'; |
45
|
|
|
const TYPE_CANDLECHART = self::TYPE_STOCKCHART; // Synonym |
46
|
|
|
|
47
|
|
|
const GROUPING_CLUSTERED = 'clustered'; |
48
|
|
|
const GROUPING_STACKED = 'stacked'; |
49
|
|
|
const GROUPING_PERCENT_STACKED = 'percentStacked'; |
50
|
|
|
const GROUPING_STANDARD = 'standard'; |
51
|
|
|
|
52
|
|
|
const DIRECTION_BAR = 'bar'; |
53
|
|
|
const DIRECTION_HORIZONTAL = self::DIRECTION_BAR; |
54
|
|
|
const DIRECTION_COL = 'col'; |
55
|
|
|
const DIRECTION_COLUMN = self::DIRECTION_COL; |
56
|
|
|
const DIRECTION_VERTICAL = self::DIRECTION_COL; |
57
|
|
|
|
58
|
|
|
const STYLE_LINEMARKER = 'lineMarker'; |
59
|
|
|
const STYLE_SMOOTHMARKER = 'smoothMarker'; |
60
|
|
|
const STYLE_MARKER = 'marker'; |
61
|
|
|
const STYLE_FILLED = 'filled'; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Series Plot Type. |
65
|
|
|
* |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
private $plotType; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Plot Grouping Type. |
72
|
|
|
* |
73
|
|
|
* @var string |
74
|
|
|
*/ |
75
|
|
|
private $plotGrouping; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Plot Direction. |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
private $plotDirection; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Plot Style. |
86
|
|
|
* |
87
|
|
|
* @var string |
88
|
|
|
*/ |
89
|
|
|
private $plotStyle; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Order of plots in Series. |
93
|
|
|
* |
94
|
|
|
* @var array of integer |
95
|
|
|
*/ |
96
|
|
|
private $plotOrder = []; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Plot Label. |
100
|
|
|
* |
101
|
|
|
* @var array of DataSeriesValues |
102
|
|
|
*/ |
103
|
|
|
private $plotLabel = []; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Plot Category. |
107
|
|
|
* |
108
|
|
|
* @var array of DataSeriesValues |
109
|
|
|
*/ |
110
|
|
|
private $plotCategory = []; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Smooth Line. |
114
|
|
|
* |
115
|
|
|
* @var bool |
116
|
|
|
*/ |
117
|
|
|
private $smoothLine; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Plot Values. |
121
|
|
|
* |
122
|
|
|
* @var array of DataSeriesValues |
123
|
|
|
*/ |
124
|
|
|
private $plotValues = []; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Create a new DataSeries. |
128
|
|
|
* |
129
|
|
|
* @param null|mixed $plotType |
130
|
|
|
* @param null|mixed $plotGrouping |
131
|
|
|
* @param mixed $plotOrder |
132
|
|
|
* @param mixed $plotLabel |
133
|
|
|
* @param mixed $plotCategory |
134
|
|
|
* @param mixed $plotValues |
135
|
|
|
* @param null|mixed $plotDirection |
136
|
|
|
* @param null|mixed $smoothLine |
137
|
|
|
* @param null|mixed $plotStyle |
138
|
|
|
*/ |
139
|
14 |
|
public function __construct($plotType = null, $plotGrouping = null, $plotOrder = [], $plotLabel = [], $plotCategory = [], $plotValues = [], $plotDirection = null, $smoothLine = null, $plotStyle = null) |
140
|
|
|
{ |
141
|
14 |
|
$this->plotType = $plotType; |
142
|
14 |
|
$this->plotGrouping = $plotGrouping; |
143
|
14 |
|
$this->plotOrder = $plotOrder; |
|
|
|
|
144
|
14 |
|
$keys = array_keys($plotValues); |
145
|
14 |
|
$this->plotValues = $plotValues; |
|
|
|
|
146
|
14 |
View Code Duplication |
if ((count($plotLabel) == 0) || (is_null($plotLabel[$keys[0]]))) { |
|
|
|
|
147
|
1 |
|
$plotLabel[$keys[0]] = new DataSeriesValues(); |
148
|
|
|
} |
149
|
|
|
|
150
|
14 |
|
$this->plotLabel = $plotLabel; |
|
|
|
|
151
|
14 |
View Code Duplication |
if ((count($plotCategory) == 0) || (is_null($plotCategory[$keys[0]]))) { |
|
|
|
|
152
|
2 |
|
$plotCategory[$keys[0]] = new DataSeriesValues(); |
153
|
|
|
} |
154
|
14 |
|
$this->plotCategory = $plotCategory; |
|
|
|
|
155
|
14 |
|
$this->smoothLine = $smoothLine; |
156
|
14 |
|
$this->plotStyle = $plotStyle; |
157
|
|
|
|
158
|
14 |
|
if (is_null($plotDirection)) { |
159
|
13 |
|
$plotDirection = self::DIRECTION_COL; |
160
|
|
|
} |
161
|
14 |
|
$this->plotDirection = $plotDirection; |
162
|
14 |
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Get Plot Type. |
166
|
|
|
* |
167
|
|
|
* @return string |
168
|
|
|
*/ |
169
|
13 |
|
public function getPlotType() |
170
|
|
|
{ |
171
|
13 |
|
return $this->plotType; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Set Plot Type. |
176
|
|
|
* |
177
|
|
|
* @param string $plotType |
178
|
|
|
* |
179
|
|
|
* @return DataSeries |
180
|
|
|
*/ |
181
|
|
|
public function setPlotType($plotType) |
182
|
|
|
{ |
183
|
|
|
$this->plotType = $plotType; |
184
|
|
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Get Plot Grouping Type. |
190
|
|
|
* |
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
13 |
|
public function getPlotGrouping() |
194
|
|
|
{ |
195
|
13 |
|
return $this->plotGrouping; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Set Plot Grouping Type. |
200
|
|
|
* |
201
|
|
|
* @param string $groupingType |
202
|
|
|
* |
203
|
|
|
* @return DataSeries |
204
|
|
|
*/ |
205
|
|
|
public function setPlotGrouping($groupingType) |
206
|
|
|
{ |
207
|
|
|
$this->plotGrouping = $groupingType; |
208
|
|
|
|
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Get Plot Direction. |
214
|
|
|
* |
215
|
|
|
* @return string |
216
|
|
|
*/ |
217
|
7 |
|
public function getPlotDirection() |
218
|
|
|
{ |
219
|
7 |
|
return $this->plotDirection; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Set Plot Direction. |
224
|
|
|
* |
225
|
|
|
* @param string $plotDirection |
226
|
|
|
* |
227
|
|
|
* @return DataSeries |
228
|
|
|
*/ |
229
|
8 |
|
public function setPlotDirection($plotDirection) |
230
|
|
|
{ |
231
|
8 |
|
$this->plotDirection = $plotDirection; |
232
|
|
|
|
233
|
8 |
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Get Plot Order. |
238
|
|
|
* |
239
|
|
|
* @return string |
240
|
|
|
*/ |
241
|
13 |
|
public function getPlotOrder() |
242
|
|
|
{ |
243
|
13 |
|
return $this->plotOrder; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Get Plot Labels. |
248
|
|
|
* |
249
|
|
|
* @return array of DataSeriesValues |
250
|
|
|
*/ |
251
|
|
|
public function getPlotLabels() |
252
|
|
|
{ |
253
|
|
|
return $this->plotLabel; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Get Plot Label by Index. |
258
|
|
|
* |
259
|
|
|
* @param mixed $index |
260
|
|
|
* |
261
|
|
|
* @return DataSeriesValues |
262
|
|
|
*/ |
263
|
13 |
View Code Duplication |
public function getPlotLabelByIndex($index) |
|
|
|
|
264
|
|
|
{ |
265
|
13 |
|
$keys = array_keys($this->plotLabel); |
266
|
13 |
|
if (in_array($index, $keys)) { |
267
|
13 |
|
return $this->plotLabel[$index]; |
268
|
1 |
|
} elseif (isset($keys[$index])) { |
269
|
1 |
|
return $this->plotLabel[$keys[$index]]; |
270
|
|
|
} |
271
|
|
|
|
272
|
1 |
|
return false; |
|
|
|
|
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Get Plot Categories. |
277
|
|
|
* |
278
|
|
|
* @return array of DataSeriesValues |
279
|
|
|
*/ |
280
|
|
|
public function getPlotCategories() |
281
|
|
|
{ |
282
|
|
|
return $this->plotCategory; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Get Plot Category by Index. |
287
|
|
|
* |
288
|
|
|
* @param mixed $index |
289
|
|
|
* |
290
|
|
|
* @return DataSeriesValues |
291
|
|
|
*/ |
292
|
13 |
View Code Duplication |
public function getPlotCategoryByIndex($index) |
|
|
|
|
293
|
|
|
{ |
294
|
13 |
|
$keys = array_keys($this->plotCategory); |
295
|
13 |
|
if (in_array($index, $keys)) { |
296
|
13 |
|
return $this->plotCategory[$index]; |
297
|
10 |
|
} elseif (isset($keys[$index])) { |
298
|
1 |
|
return $this->plotCategory[$keys[$index]]; |
299
|
|
|
} |
300
|
|
|
|
301
|
10 |
|
return false; |
|
|
|
|
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Get Plot Style. |
306
|
|
|
* |
307
|
|
|
* @return string |
308
|
|
|
*/ |
309
|
13 |
|
public function getPlotStyle() |
310
|
|
|
{ |
311
|
13 |
|
return $this->plotStyle; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Set Plot Style. |
316
|
|
|
* |
317
|
|
|
* @param string $plotStyle |
318
|
|
|
* |
319
|
|
|
* @return DataSeries |
320
|
|
|
*/ |
321
|
1 |
|
public function setPlotStyle($plotStyle) |
322
|
|
|
{ |
323
|
1 |
|
$this->plotStyle = $plotStyle; |
324
|
|
|
|
325
|
1 |
|
return $this; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Get Plot Values. |
330
|
|
|
* |
331
|
|
|
* @return array of DataSeriesValues |
332
|
|
|
*/ |
333
|
|
|
public function getPlotValues() |
334
|
|
|
{ |
335
|
|
|
return $this->plotValues; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Get Plot Values by Index. |
340
|
|
|
* |
341
|
|
|
* @param mixed $index |
342
|
|
|
* |
343
|
|
|
* @return DataSeriesValues |
344
|
|
|
*/ |
345
|
13 |
View Code Duplication |
public function getPlotValuesByIndex($index) |
|
|
|
|
346
|
|
|
{ |
347
|
13 |
|
$keys = array_keys($this->plotValues); |
348
|
13 |
|
if (in_array($index, $keys)) { |
349
|
13 |
|
return $this->plotValues[$index]; |
350
|
1 |
|
} elseif (isset($keys[$index])) { |
351
|
1 |
|
return $this->plotValues[$keys[$index]]; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
return false; |
|
|
|
|
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Get Number of Plot Series. |
359
|
|
|
* |
360
|
|
|
* @return int |
361
|
|
|
*/ |
362
|
|
|
public function getPlotSeriesCount() |
363
|
|
|
{ |
364
|
|
|
return count($this->plotValues); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Get Smooth Line. |
369
|
|
|
* |
370
|
|
|
* @return bool |
371
|
|
|
*/ |
372
|
3 |
|
public function getSmoothLine() |
373
|
|
|
{ |
374
|
3 |
|
return $this->smoothLine; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* Set Smooth Line. |
379
|
|
|
* |
380
|
|
|
* @param bool $smoothLine |
381
|
|
|
* |
382
|
|
|
* @return DataSeries |
383
|
|
|
*/ |
384
|
|
|
public function setSmoothLine($smoothLine) |
385
|
|
|
{ |
386
|
|
|
$this->smoothLine = $smoothLine; |
387
|
|
|
|
388
|
|
|
return $this; |
389
|
|
|
} |
390
|
|
|
|
391
|
13 |
|
public function refresh(\PhpOffice\PhpSpreadsheet\Worksheet $worksheet) |
392
|
|
|
{ |
393
|
13 |
|
foreach ($this->plotValues as $plotValues) { |
394
|
13 |
|
if ($plotValues !== null) { |
395
|
13 |
|
$plotValues->refresh($worksheet, true); |
396
|
|
|
} |
397
|
|
|
} |
398
|
13 |
|
foreach ($this->plotLabel as $plotValues) { |
399
|
13 |
|
if ($plotValues !== null) { |
400
|
13 |
|
$plotValues->refresh($worksheet, true); |
401
|
|
|
} |
402
|
|
|
} |
403
|
13 |
|
foreach ($this->plotCategory as $plotValues) { |
404
|
13 |
|
if ($plotValues !== null) { |
405
|
13 |
|
$plotValues->refresh($worksheet, false); |
406
|
|
|
} |
407
|
|
|
} |
408
|
13 |
|
} |
409
|
|
|
} |
410
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..