1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Chart\DataSeries; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Chart\Layout; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Chart\Legend; |
10
|
|
|
use PhpOffice\PhpSpreadsheet\Chart\PlotArea; |
11
|
|
|
use PhpOffice\PhpSpreadsheet\Chart\Title; |
12
|
|
|
use PhpOffice\PhpSpreadsheet\RichText\RichText; |
13
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Color; |
14
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Font; |
15
|
|
|
use SimpleXMLElement; |
16
|
|
|
|
17
|
|
|
class Chart |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param string $name |
21
|
|
|
* @param string $format |
22
|
|
|
* |
23
|
|
|
* @return null|bool|float|int|string |
24
|
|
|
*/ |
25
|
5 |
|
private static function getAttribute(SimpleXMLElement $component, $name, $format) |
26
|
|
|
{ |
27
|
5 |
|
$attributes = $component->attributes(); |
28
|
5 |
|
if (isset($attributes[$name])) { |
29
|
5 |
|
if ($format == 'string') { |
30
|
5 |
|
return (string) $attributes[$name]; |
31
|
5 |
|
} elseif ($format == 'integer') { |
32
|
5 |
|
return (int) $attributes[$name]; |
33
|
5 |
|
} elseif ($format == 'boolean') { |
34
|
5 |
|
return (bool) ($attributes[$name] === '0' || $attributes[$name] !== 'true') ? false : true; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return (float) $attributes[$name]; |
38
|
|
|
} |
39
|
|
|
|
40
|
5 |
|
return null; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private static function readColor($color, $background = false) |
44
|
|
|
{ |
45
|
|
|
if (isset($color['rgb'])) { |
46
|
|
|
return (string) $color['rgb']; |
47
|
|
|
} elseif (isset($color['indexed'])) { |
48
|
|
|
return Color::indexedColor($color['indexed'] - 7, $background)->getARGB(); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $chartName |
54
|
|
|
* |
55
|
|
|
* @return \PhpOffice\PhpSpreadsheet\Chart\Chart |
56
|
|
|
*/ |
57
|
5 |
|
public static function readChart(SimpleXMLElement $chartElements, $chartName) |
58
|
|
|
{ |
59
|
5 |
|
$namespacesChartMeta = $chartElements->getNamespaces(true); |
60
|
5 |
|
$chartElementsC = $chartElements->children($namespacesChartMeta['c']); |
61
|
|
|
|
62
|
5 |
|
$XaxisLabel = $YaxisLabel = $legend = $title = null; |
63
|
5 |
|
$dispBlanksAs = $plotVisOnly = null; |
64
|
5 |
|
$plotArea = null; |
65
|
5 |
|
foreach ($chartElementsC as $chartElementKey => $chartElement) { |
66
|
|
|
switch ($chartElementKey) { |
67
|
5 |
|
case 'chart': |
68
|
5 |
|
foreach ($chartElement as $chartDetailsKey => $chartDetails) { |
69
|
5 |
|
$chartDetailsC = $chartDetails->children($namespacesChartMeta['c']); |
|
|
|
|
70
|
|
|
switch ($chartDetailsKey) { |
71
|
5 |
|
case 'plotArea': |
72
|
5 |
|
$plotAreaLayout = $XaxisLable = $YaxisLable = null; |
|
|
|
|
73
|
5 |
|
$plotSeries = $plotAttributes = []; |
74
|
5 |
|
foreach ($chartDetails as $chartDetailKey => $chartDetail) { |
75
|
|
|
switch ($chartDetailKey) { |
76
|
5 |
|
case 'layout': |
77
|
5 |
|
$plotAreaLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta); |
78
|
|
|
|
79
|
5 |
|
break; |
80
|
5 |
|
case 'catAx': |
81
|
5 |
|
if (isset($chartDetail->title)) { |
82
|
3 |
|
$XaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta); |
83
|
|
|
} |
84
|
|
|
|
85
|
5 |
|
break; |
86
|
5 |
|
case 'dateAx': |
87
|
|
|
if (isset($chartDetail->title)) { |
88
|
|
|
$XaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
break; |
92
|
5 |
|
case 'valAx': |
93
|
5 |
|
if (isset($chartDetail->title, $chartDetail->axPos)) { |
94
|
5 |
|
$axisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta); |
95
|
5 |
|
$axPos = self::getAttribute($chartDetail->axPos, 'val', 'string'); |
96
|
|
|
|
97
|
|
|
switch ($axPos) { |
98
|
5 |
|
case 't': |
99
|
5 |
|
case 'b': |
100
|
4 |
|
$XaxisLabel = $axisLabel; |
101
|
|
|
|
102
|
4 |
|
break; |
103
|
5 |
|
case 'r': |
104
|
5 |
|
case 'l': |
105
|
5 |
|
$YaxisLabel = $axisLabel; |
106
|
|
|
|
107
|
5 |
|
break; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
5 |
|
break; |
112
|
5 |
|
case 'barChart': |
113
|
4 |
|
case 'bar3DChart': |
114
|
4 |
|
$barDirection = self::getAttribute($chartDetail->barDir, 'val', 'string'); |
115
|
4 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
116
|
4 |
|
$plotSer->setPlotDirection($barDirection); |
117
|
4 |
|
$plotSeries[] = $plotSer; |
118
|
4 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
119
|
|
|
|
120
|
4 |
|
break; |
121
|
4 |
|
case 'lineChart': |
122
|
4 |
|
case 'line3DChart': |
123
|
4 |
|
$plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
124
|
4 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
125
|
|
|
|
126
|
4 |
|
break; |
127
|
4 |
|
case 'areaChart': |
128
|
4 |
|
case 'area3DChart': |
129
|
2 |
|
$plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
130
|
2 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
131
|
|
|
|
132
|
2 |
|
break; |
133
|
4 |
|
case 'doughnutChart': |
134
|
4 |
|
case 'pieChart': |
135
|
4 |
|
case 'pie3DChart': |
136
|
2 |
|
$explosion = isset($chartDetail->ser->explosion); |
137
|
2 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
138
|
2 |
|
$plotSer->setPlotStyle($explosion); |
139
|
2 |
|
$plotSeries[] = $plotSer; |
140
|
2 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
141
|
|
|
|
142
|
2 |
|
break; |
143
|
4 |
|
case 'scatterChart': |
144
|
4 |
|
$scatterStyle = self::getAttribute($chartDetail->scatterStyle, 'val', 'string'); |
145
|
4 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
146
|
4 |
|
$plotSer->setPlotStyle($scatterStyle); |
147
|
4 |
|
$plotSeries[] = $plotSer; |
148
|
4 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
149
|
|
|
|
150
|
4 |
|
break; |
151
|
3 |
|
case 'bubbleChart': |
152
|
2 |
|
$bubbleScale = self::getAttribute($chartDetail->bubbleScale, 'val', 'integer'); |
153
|
2 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
154
|
2 |
|
$plotSer->setPlotStyle($bubbleScale); |
155
|
2 |
|
$plotSeries[] = $plotSer; |
156
|
2 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
157
|
|
|
|
158
|
2 |
|
break; |
159
|
3 |
|
case 'radarChart': |
160
|
2 |
|
$radarStyle = self::getAttribute($chartDetail->radarStyle, 'val', 'string'); |
161
|
2 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
162
|
2 |
|
$plotSer->setPlotStyle($radarStyle); |
163
|
2 |
|
$plotSeries[] = $plotSer; |
164
|
2 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
165
|
|
|
|
166
|
2 |
|
break; |
167
|
3 |
|
case 'surfaceChart': |
168
|
3 |
|
case 'surface3DChart': |
169
|
2 |
|
$wireFrame = self::getAttribute($chartDetail->wireframe, 'val', 'boolean'); |
170
|
2 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
171
|
2 |
|
$plotSer->setPlotStyle($wireFrame); |
172
|
2 |
|
$plotSeries[] = $plotSer; |
173
|
2 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
174
|
|
|
|
175
|
2 |
|
break; |
176
|
3 |
|
case 'stockChart': |
177
|
2 |
|
$plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
178
|
2 |
|
$plotAttributes = self::readChartAttributes($plotAreaLayout); |
179
|
|
|
|
180
|
2 |
|
break; |
181
|
|
|
} |
182
|
|
|
} |
183
|
5 |
|
if ($plotAreaLayout == null) { |
184
|
5 |
|
$plotAreaLayout = new Layout(); |
185
|
|
|
} |
186
|
5 |
|
$plotArea = new PlotArea($plotAreaLayout, $plotSeries); |
187
|
5 |
|
self::setChartAttributes($plotAreaLayout, $plotAttributes); |
188
|
|
|
|
189
|
5 |
|
break; |
190
|
5 |
|
case 'plotVisOnly': |
191
|
5 |
|
$plotVisOnly = self::getAttribute($chartDetails, 'val', 'string'); |
|
|
|
|
192
|
|
|
|
193
|
5 |
|
break; |
194
|
5 |
|
case 'dispBlanksAs': |
195
|
4 |
|
$dispBlanksAs = self::getAttribute($chartDetails, 'val', 'string'); |
196
|
|
|
|
197
|
4 |
|
break; |
198
|
5 |
|
case 'title': |
199
|
5 |
|
$title = self::chartTitle($chartDetails, $namespacesChartMeta); |
|
|
|
|
200
|
|
|
|
201
|
5 |
|
break; |
202
|
5 |
|
case 'legend': |
203
|
5 |
|
$legendPos = 'r'; |
204
|
5 |
|
$legendLayout = null; |
205
|
5 |
|
$legendOverlay = false; |
206
|
5 |
|
foreach ($chartDetails as $chartDetailKey => $chartDetail) { |
207
|
|
|
switch ($chartDetailKey) { |
208
|
5 |
|
case 'legendPos': |
209
|
5 |
|
$legendPos = self::getAttribute($chartDetail, 'val', 'string'); |
210
|
|
|
|
211
|
5 |
|
break; |
212
|
5 |
|
case 'overlay': |
213
|
5 |
|
$legendOverlay = self::getAttribute($chartDetail, 'val', 'boolean'); |
214
|
|
|
|
215
|
5 |
|
break; |
216
|
5 |
|
case 'layout': |
217
|
3 |
|
$legendLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta); |
218
|
|
|
|
219
|
3 |
|
break; |
220
|
|
|
} |
221
|
|
|
} |
222
|
5 |
|
$legend = new Legend($legendPos, $legendLayout, $legendOverlay); |
223
|
|
|
|
224
|
5 |
|
break; |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
} |
229
|
5 |
|
$chart = new \PhpOffice\PhpSpreadsheet\Chart\Chart($chartName, $title, $legend, $plotArea, $plotVisOnly, $dispBlanksAs, $XaxisLabel, $YaxisLabel); |
230
|
|
|
|
231
|
5 |
|
return $chart; |
232
|
|
|
} |
233
|
|
|
|
234
|
5 |
|
private static function chartTitle(SimpleXMLElement $titleDetails, array $namespacesChartMeta) |
235
|
|
|
{ |
236
|
5 |
|
$caption = []; |
237
|
5 |
|
$titleLayout = null; |
238
|
5 |
|
foreach ($titleDetails as $titleDetailKey => $chartDetail) { |
239
|
|
|
switch ($titleDetailKey) { |
240
|
5 |
|
case 'tx': |
241
|
5 |
|
$titleDetails = $chartDetail->rich->children($namespacesChartMeta['a']); |
242
|
5 |
|
foreach ($titleDetails as $titleKey => $titleDetail) { |
243
|
|
|
switch ($titleKey) { |
244
|
5 |
|
case 'p': |
245
|
5 |
|
$titleDetailPart = $titleDetail->children($namespacesChartMeta['a']); |
|
|
|
|
246
|
5 |
|
$caption[] = self::parseRichText($titleDetailPart); |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
250
|
5 |
|
break; |
251
|
5 |
|
case 'layout': |
252
|
3 |
|
$titleLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta); |
253
|
|
|
|
254
|
3 |
|
break; |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
5 |
|
return new Title($caption, $titleLayout); |
259
|
|
|
} |
260
|
|
|
|
261
|
5 |
|
private static function chartLayoutDetails($chartDetail, $namespacesChartMeta) |
262
|
|
|
{ |
263
|
5 |
|
if (!isset($chartDetail->manualLayout)) { |
264
|
5 |
|
return null; |
265
|
|
|
} |
266
|
2 |
|
$details = $chartDetail->manualLayout->children($namespacesChartMeta['c']); |
267
|
2 |
|
if ($details === null) { |
268
|
|
|
return null; |
269
|
|
|
} |
270
|
2 |
|
$layout = []; |
271
|
2 |
|
foreach ($details as $detailKey => $detail) { |
272
|
2 |
|
$layout[$detailKey] = self::getAttribute($detail, 'val', 'string'); |
273
|
|
|
} |
274
|
|
|
|
275
|
2 |
|
return new Layout($layout); |
276
|
|
|
} |
277
|
|
|
|
278
|
5 |
|
private static function chartDataSeries($chartDetail, $namespacesChartMeta, $plotType) |
279
|
|
|
{ |
280
|
5 |
|
$multiSeriesType = null; |
281
|
5 |
|
$smoothLine = false; |
282
|
5 |
|
$seriesLabel = $seriesCategory = $seriesValues = $plotOrder = []; |
283
|
|
|
|
284
|
5 |
|
$seriesDetailSet = $chartDetail->children($namespacesChartMeta['c']); |
285
|
5 |
|
foreach ($seriesDetailSet as $seriesDetailKey => $seriesDetails) { |
286
|
|
|
switch ($seriesDetailKey) { |
287
|
5 |
|
case 'grouping': |
288
|
5 |
|
$multiSeriesType = self::getAttribute($chartDetail->grouping, 'val', 'string'); |
289
|
|
|
|
290
|
5 |
|
break; |
291
|
5 |
|
case 'ser': |
292
|
5 |
|
$marker = null; |
293
|
5 |
|
$seriesIndex = ''; |
294
|
5 |
|
foreach ($seriesDetails as $seriesKey => $seriesDetail) { |
295
|
|
|
switch ($seriesKey) { |
296
|
5 |
|
case 'idx': |
297
|
5 |
|
$seriesIndex = self::getAttribute($seriesDetail, 'val', 'integer'); |
298
|
|
|
|
299
|
5 |
|
break; |
300
|
5 |
|
case 'order': |
301
|
5 |
|
$seriesOrder = self::getAttribute($seriesDetail, 'val', 'integer'); |
302
|
5 |
|
$plotOrder[$seriesIndex] = $seriesOrder; |
303
|
|
|
|
304
|
5 |
|
break; |
305
|
5 |
|
case 'tx': |
306
|
5 |
|
$seriesLabel[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta); |
307
|
|
|
|
308
|
5 |
|
break; |
309
|
5 |
|
case 'marker': |
310
|
4 |
|
$marker = self::getAttribute($seriesDetail->symbol, 'val', 'string'); |
311
|
|
|
|
312
|
4 |
|
break; |
313
|
5 |
|
case 'smooth': |
314
|
4 |
|
$smoothLine = self::getAttribute($seriesDetail, 'val', 'boolean'); |
315
|
|
|
|
316
|
4 |
|
break; |
317
|
5 |
|
case 'cat': |
318
|
5 |
|
$seriesCategory[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta); |
319
|
|
|
|
320
|
5 |
|
break; |
321
|
5 |
|
case 'val': |
322
|
5 |
|
$seriesValues[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker); |
323
|
|
|
|
324
|
5 |
|
break; |
325
|
5 |
|
case 'xVal': |
326
|
4 |
|
$seriesCategory[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker); |
327
|
|
|
|
328
|
4 |
|
break; |
329
|
5 |
|
case 'yVal': |
330
|
4 |
|
$seriesValues[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker); |
331
|
|
|
|
332
|
4 |
|
break; |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
} |
337
|
|
|
|
338
|
5 |
|
return new DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine); |
339
|
|
|
} |
340
|
|
|
|
341
|
5 |
|
private static function chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker = null) |
342
|
|
|
{ |
343
|
5 |
|
if (isset($seriesDetail->strRef)) { |
344
|
5 |
|
$seriesSource = (string) $seriesDetail->strRef->f; |
345
|
5 |
|
$seriesValues = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, null, null, null, $marker); |
346
|
|
|
|
347
|
5 |
|
if (isset($seriesDetail->strRef->strCache)) { |
348
|
4 |
|
$seriesData = self::chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta['c']), 's'); |
349
|
|
|
$seriesValues |
350
|
4 |
|
->setFormatCode($seriesData['formatCode']) |
351
|
4 |
|
->setDataValues($seriesData['dataValues']); |
352
|
|
|
} |
353
|
|
|
|
354
|
5 |
|
return $seriesValues; |
355
|
5 |
|
} elseif (isset($seriesDetail->numRef)) { |
356
|
5 |
|
$seriesSource = (string) $seriesDetail->numRef->f; |
357
|
5 |
|
$seriesValues = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, $seriesSource, null, null, null, $marker); |
358
|
5 |
|
if (isset($seriesDetail->numRef->numCache)) { |
359
|
5 |
|
$seriesData = self::chartDataSeriesValues($seriesDetail->numRef->numCache->children($namespacesChartMeta['c'])); |
360
|
|
|
$seriesValues |
361
|
5 |
|
->setFormatCode($seriesData['formatCode']) |
362
|
5 |
|
->setDataValues($seriesData['dataValues']); |
363
|
|
|
} |
364
|
|
|
|
365
|
5 |
|
return $seriesValues; |
366
|
2 |
|
} elseif (isset($seriesDetail->multiLvlStrRef)) { |
367
|
2 |
|
$seriesSource = (string) $seriesDetail->multiLvlStrRef->f; |
368
|
2 |
|
$seriesValues = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, null, null, null, $marker); |
369
|
|
|
|
370
|
2 |
|
if (isset($seriesDetail->multiLvlStrRef->multiLvlStrCache)) { |
371
|
2 |
|
$seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlStrRef->multiLvlStrCache->children($namespacesChartMeta['c']), 's'); |
372
|
|
|
$seriesValues |
373
|
2 |
|
->setFormatCode($seriesData['formatCode']) |
374
|
2 |
|
->setDataValues($seriesData['dataValues']); |
375
|
|
|
} |
376
|
|
|
|
377
|
2 |
|
return $seriesValues; |
378
|
|
|
} elseif (isset($seriesDetail->multiLvlNumRef)) { |
379
|
|
|
$seriesSource = (string) $seriesDetail->multiLvlNumRef->f; |
380
|
|
|
$seriesValues = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, null, null, null, $marker); |
381
|
|
|
|
382
|
|
|
if (isset($seriesDetail->multiLvlNumRef->multiLvlNumCache)) { |
383
|
|
|
$seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlNumRef->multiLvlNumCache->children($namespacesChartMeta['c']), 's'); |
384
|
|
|
$seriesValues |
385
|
|
|
->setFormatCode($seriesData['formatCode']) |
386
|
|
|
->setDataValues($seriesData['dataValues']); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
return $seriesValues; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
return null; |
393
|
|
|
} |
394
|
|
|
|
395
|
5 |
|
private static function chartDataSeriesValues($seriesValueSet, $dataType = 'n') |
396
|
|
|
{ |
397
|
5 |
|
$seriesVal = []; |
398
|
5 |
|
$formatCode = ''; |
399
|
5 |
|
$pointCount = 0; |
400
|
|
|
|
401
|
5 |
|
foreach ($seriesValueSet as $seriesValueIdx => $seriesValue) { |
402
|
|
|
switch ($seriesValueIdx) { |
403
|
4 |
|
case 'ptCount': |
404
|
4 |
|
$pointCount = self::getAttribute($seriesValue, 'val', 'integer'); |
405
|
|
|
|
406
|
4 |
|
break; |
407
|
4 |
|
case 'formatCode': |
408
|
3 |
|
$formatCode = (string) $seriesValue; |
409
|
|
|
|
410
|
3 |
|
break; |
411
|
4 |
|
case 'pt': |
412
|
4 |
|
$pointVal = self::getAttribute($seriesValue, 'idx', 'integer'); |
413
|
4 |
|
if ($dataType == 's') { |
414
|
4 |
|
$seriesVal[$pointVal] = (string) $seriesValue->v; |
415
|
4 |
|
} elseif ($seriesValue->v === Functions::NA()) { |
416
|
|
|
$seriesVal[$pointVal] = null; |
417
|
|
|
} else { |
418
|
4 |
|
$seriesVal[$pointVal] = (float) $seriesValue->v; |
419
|
|
|
} |
420
|
|
|
|
421
|
4 |
|
break; |
422
|
|
|
} |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
return [ |
426
|
5 |
|
'formatCode' => $formatCode, |
427
|
5 |
|
'pointCount' => $pointCount, |
428
|
5 |
|
'dataValues' => $seriesVal, |
429
|
|
|
]; |
430
|
|
|
} |
431
|
|
|
|
432
|
2 |
|
private static function chartDataSeriesValuesMultiLevel($seriesValueSet, $dataType = 'n') |
433
|
|
|
{ |
434
|
2 |
|
$seriesVal = []; |
435
|
2 |
|
$formatCode = ''; |
436
|
2 |
|
$pointCount = 0; |
437
|
|
|
|
438
|
2 |
|
foreach ($seriesValueSet->lvl as $seriesLevelIdx => $seriesLevel) { |
439
|
2 |
|
foreach ($seriesLevel as $seriesValueIdx => $seriesValue) { |
440
|
|
|
switch ($seriesValueIdx) { |
441
|
2 |
|
case 'ptCount': |
442
|
|
|
$pointCount = self::getAttribute($seriesValue, 'val', 'integer'); |
443
|
|
|
|
444
|
|
|
break; |
445
|
2 |
|
case 'formatCode': |
446
|
|
|
$formatCode = (string) $seriesValue; |
447
|
|
|
|
448
|
|
|
break; |
449
|
2 |
|
case 'pt': |
450
|
2 |
|
$pointVal = self::getAttribute($seriesValue, 'idx', 'integer'); |
451
|
2 |
|
if ($dataType == 's') { |
452
|
2 |
|
$seriesVal[$pointVal][] = (string) $seriesValue->v; |
453
|
|
|
} elseif ($seriesValue->v === Functions::NA()) { |
454
|
|
|
$seriesVal[$pointVal] = null; |
455
|
|
|
} else { |
456
|
|
|
$seriesVal[$pointVal][] = (float) $seriesValue->v; |
457
|
|
|
} |
458
|
|
|
|
459
|
2 |
|
break; |
460
|
|
|
} |
461
|
|
|
} |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
return [ |
465
|
2 |
|
'formatCode' => $formatCode, |
466
|
2 |
|
'pointCount' => $pointCount, |
467
|
2 |
|
'dataValues' => $seriesVal, |
468
|
|
|
]; |
469
|
|
|
} |
470
|
|
|
|
471
|
5 |
|
private static function parseRichText(SimpleXMLElement $titleDetailPart) |
472
|
|
|
{ |
473
|
5 |
|
$value = new RichText(); |
474
|
5 |
|
$objText = null; |
475
|
5 |
|
foreach ($titleDetailPart as $titleDetailElementKey => $titleDetailElement) { |
476
|
5 |
|
if (isset($titleDetailElement->t)) { |
477
|
5 |
|
$objText = $value->createTextRun((string) $titleDetailElement->t); |
478
|
|
|
} |
479
|
5 |
|
if (isset($titleDetailElement->rPr)) { |
480
|
5 |
|
if (isset($titleDetailElement->rPr->rFont['val'])) { |
481
|
|
|
$objText->getFont()->setName((string) $titleDetailElement->rPr->rFont['val']); |
482
|
|
|
} |
483
|
|
|
|
484
|
5 |
|
$fontSize = (self::getAttribute($titleDetailElement->rPr, 'sz', 'integer')); |
485
|
5 |
|
if ($fontSize !== null) { |
486
|
2 |
|
$objText->getFont()->setSize(floor($fontSize / 100)); |
487
|
|
|
} |
488
|
|
|
|
489
|
5 |
|
$fontColor = (self::getAttribute($titleDetailElement->rPr, 'color', 'string')); |
490
|
5 |
|
if ($fontColor !== null) { |
491
|
|
|
$objText->getFont()->setColor(new Color(self::readColor($fontColor))); |
492
|
|
|
} |
493
|
|
|
|
494
|
5 |
|
$bold = self::getAttribute($titleDetailElement->rPr, 'b', 'boolean'); |
495
|
5 |
|
if ($bold !== null) { |
496
|
4 |
|
$objText->getFont()->setBold($bold); |
497
|
|
|
} |
498
|
|
|
|
499
|
5 |
|
$italic = self::getAttribute($titleDetailElement->rPr, 'i', 'boolean'); |
500
|
5 |
|
if ($italic !== null) { |
501
|
3 |
|
$objText->getFont()->setItalic($italic); |
502
|
|
|
} |
503
|
|
|
|
504
|
5 |
|
$baseline = self::getAttribute($titleDetailElement->rPr, 'baseline', 'integer'); |
505
|
5 |
|
if ($baseline !== null) { |
506
|
3 |
|
if ($baseline > 0) { |
507
|
2 |
|
$objText->getFont()->setSuperscript(true); |
508
|
3 |
|
} elseif ($baseline < 0) { |
509
|
2 |
|
$objText->getFont()->setSubscript(true); |
510
|
|
|
} |
511
|
|
|
} |
512
|
|
|
|
513
|
5 |
|
$underscore = (self::getAttribute($titleDetailElement->rPr, 'u', 'string')); |
514
|
5 |
|
if ($underscore !== null) { |
515
|
3 |
|
if ($underscore == 'sng') { |
516
|
2 |
|
$objText->getFont()->setUnderline(Font::UNDERLINE_SINGLE); |
517
|
3 |
|
} elseif ($underscore == 'dbl') { |
518
|
2 |
|
$objText->getFont()->setUnderline(Font::UNDERLINE_DOUBLE); |
519
|
|
|
} else { |
520
|
3 |
|
$objText->getFont()->setUnderline(Font::UNDERLINE_NONE); |
521
|
|
|
} |
522
|
|
|
} |
523
|
|
|
|
524
|
5 |
|
$strikethrough = (self::getAttribute($titleDetailElement->rPr, 's', 'string')); |
525
|
5 |
|
if ($strikethrough !== null) { |
526
|
|
|
if ($strikethrough == 'noStrike') { |
527
|
|
|
$objText->getFont()->setStrikethrough(false); |
528
|
|
|
} else { |
529
|
|
|
$objText->getFont()->setStrikethrough(true); |
530
|
|
|
} |
531
|
|
|
} |
532
|
|
|
} |
533
|
|
|
} |
534
|
|
|
|
535
|
5 |
|
return $value; |
536
|
|
|
} |
537
|
|
|
|
538
|
5 |
|
private static function readChartAttributes($chartDetail) |
539
|
|
|
{ |
540
|
5 |
|
$plotAttributes = []; |
541
|
5 |
|
if (isset($chartDetail->dLbls)) { |
542
|
5 |
|
if (isset($chartDetail->dLbls->showLegendKey)) { |
543
|
5 |
|
$plotAttributes['showLegendKey'] = self::getAttribute($chartDetail->dLbls->showLegendKey, 'val', 'string'); |
544
|
|
|
} |
545
|
5 |
|
if (isset($chartDetail->dLbls->showVal)) { |
546
|
5 |
|
$plotAttributes['showVal'] = self::getAttribute($chartDetail->dLbls->showVal, 'val', 'string'); |
547
|
|
|
} |
548
|
5 |
|
if (isset($chartDetail->dLbls->showCatName)) { |
549
|
5 |
|
$plotAttributes['showCatName'] = self::getAttribute($chartDetail->dLbls->showCatName, 'val', 'string'); |
550
|
|
|
} |
551
|
5 |
|
if (isset($chartDetail->dLbls->showSerName)) { |
552
|
5 |
|
$plotAttributes['showSerName'] = self::getAttribute($chartDetail->dLbls->showSerName, 'val', 'string'); |
553
|
|
|
} |
554
|
5 |
|
if (isset($chartDetail->dLbls->showPercent)) { |
555
|
5 |
|
$plotAttributes['showPercent'] = self::getAttribute($chartDetail->dLbls->showPercent, 'val', 'string'); |
556
|
|
|
} |
557
|
5 |
|
if (isset($chartDetail->dLbls->showBubbleSize)) { |
558
|
5 |
|
$plotAttributes['showBubbleSize'] = self::getAttribute($chartDetail->dLbls->showBubbleSize, 'val', 'string'); |
559
|
|
|
} |
560
|
5 |
|
if (isset($chartDetail->dLbls->showLeaderLines)) { |
561
|
3 |
|
$plotAttributes['showLeaderLines'] = self::getAttribute($chartDetail->dLbls->showLeaderLines, 'val', 'string'); |
562
|
|
|
} |
563
|
|
|
} |
564
|
|
|
|
565
|
5 |
|
return $plotAttributes; |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
/** |
569
|
|
|
* @param mixed $plotAttributes |
570
|
|
|
*/ |
571
|
5 |
|
private static function setChartAttributes(Layout $plotArea, $plotAttributes): void |
572
|
|
|
{ |
573
|
5 |
|
foreach ($plotAttributes as $plotAttributeKey => $plotAttributeValue) { |
574
|
|
|
switch ($plotAttributeKey) { |
575
|
5 |
|
case 'showLegendKey': |
576
|
5 |
|
$plotArea->setShowLegendKey($plotAttributeValue); |
577
|
|
|
|
578
|
5 |
|
break; |
579
|
5 |
|
case 'showVal': |
580
|
5 |
|
$plotArea->setShowVal($plotAttributeValue); |
581
|
|
|
|
582
|
5 |
|
break; |
583
|
5 |
|
case 'showCatName': |
584
|
5 |
|
$plotArea->setShowCatName($plotAttributeValue); |
585
|
|
|
|
586
|
5 |
|
break; |
587
|
5 |
|
case 'showSerName': |
588
|
5 |
|
$plotArea->setShowSerName($plotAttributeValue); |
589
|
|
|
|
590
|
5 |
|
break; |
591
|
5 |
|
case 'showPercent': |
592
|
5 |
|
$plotArea->setShowPercent($plotAttributeValue); |
593
|
|
|
|
594
|
5 |
|
break; |
595
|
5 |
|
case 'showBubbleSize': |
596
|
5 |
|
$plotArea->setShowBubbleSize($plotAttributeValue); |
597
|
|
|
|
598
|
5 |
|
break; |
599
|
3 |
|
case 'showLeaderLines': |
600
|
3 |
|
$plotArea->setShowLeaderLines($plotAttributeValue); |
601
|
|
|
|
602
|
3 |
|
break; |
603
|
|
|
} |
604
|
|
|
} |
605
|
5 |
|
} |
606
|
|
|
} |
607
|
|
|
|