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