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
|
|
|
switch ($chartDetailsKey) { |
73
|
2 |
|
case 'plotArea': |
74
|
2 |
|
$plotAreaLayout = $XaxisLable = $YaxisLable = null; |
|
|
|
|
75
|
2 |
|
$plotSeries = $plotAttributes = []; |
76
|
2 |
|
foreach ($chartDetails as $chartDetailKey => $chartDetail) { |
77
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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 |
|
$seriesIndex = ''; |
282
|
2 |
|
foreach ($seriesDetails as $seriesKey => $seriesDetail) { |
283
|
|
|
switch ($seriesKey) { |
284
|
2 |
|
case 'idx': |
285
|
2 |
|
$seriesIndex = self::getAttribute($seriesDetail, 'val', 'integer'); |
286
|
|
|
|
287
|
2 |
|
break; |
288
|
2 |
|
case 'order': |
289
|
2 |
|
$seriesOrder = self::getAttribute($seriesDetail, 'val', 'integer'); |
290
|
2 |
|
$plotOrder[$seriesIndex] = $seriesOrder; |
291
|
|
|
|
292
|
2 |
|
break; |
293
|
2 |
|
case 'tx': |
294
|
2 |
|
$seriesLabel[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta); |
295
|
|
|
|
296
|
2 |
|
break; |
297
|
2 |
|
case 'marker': |
298
|
2 |
|
$marker = self::getAttribute($seriesDetail->symbol, 'val', 'string'); |
299
|
|
|
|
300
|
2 |
|
break; |
301
|
2 |
|
case 'smooth': |
302
|
2 |
|
$smoothLine = self::getAttribute($seriesDetail, 'val', 'boolean'); |
303
|
|
|
|
304
|
2 |
|
break; |
305
|
2 |
|
case 'cat': |
306
|
2 |
|
$seriesCategory[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta); |
307
|
|
|
|
308
|
2 |
|
break; |
309
|
2 |
|
case 'val': |
310
|
2 |
|
$seriesValues[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker); |
311
|
|
|
|
312
|
2 |
|
break; |
313
|
2 |
|
case 'xVal': |
314
|
2 |
|
$seriesCategory[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker); |
315
|
|
|
|
316
|
2 |
|
break; |
317
|
2 |
|
case 'yVal': |
318
|
2 |
|
$seriesValues[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker); |
319
|
|
|
|
320
|
2 |
|
break; |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
} |
325
|
|
|
|
326
|
2 |
|
return new DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine); |
327
|
|
|
} |
328
|
|
|
|
329
|
2 |
|
private static function chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker = null) |
330
|
|
|
{ |
331
|
2 |
|
if (isset($seriesDetail->strRef)) { |
332
|
2 |
|
$seriesSource = (string) $seriesDetail->strRef->f; |
333
|
2 |
|
$seriesData = self::chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta['c']), 's'); |
334
|
|
|
|
335
|
2 |
|
return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker); |
336
|
2 |
|
} elseif (isset($seriesDetail->numRef)) { |
337
|
2 |
|
$seriesSource = (string) $seriesDetail->numRef->f; |
338
|
2 |
|
$seriesData = self::chartDataSeriesValues($seriesDetail->numRef->numCache->children($namespacesChartMeta['c'])); |
339
|
|
|
|
340
|
2 |
|
return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker); |
341
|
2 |
|
} elseif (isset($seriesDetail->multiLvlStrRef)) { |
342
|
2 |
|
$seriesSource = (string) $seriesDetail->multiLvlStrRef->f; |
343
|
2 |
|
$seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlStrRef->multiLvlStrCache->children($namespacesChartMeta['c']), 's'); |
344
|
2 |
|
$seriesData['pointCount'] = count($seriesData['dataValues']); |
345
|
|
|
|
346
|
2 |
|
return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker); |
347
|
|
|
} elseif (isset($seriesDetail->multiLvlNumRef)) { |
348
|
|
|
$seriesSource = (string) $seriesDetail->multiLvlNumRef->f; |
349
|
|
|
$seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlNumRef->multiLvlNumCache->children($namespacesChartMeta['c']), 's'); |
350
|
|
|
$seriesData['pointCount'] = count($seriesData['dataValues']); |
351
|
|
|
|
352
|
|
|
return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
return null; |
356
|
|
|
} |
357
|
|
|
|
358
|
2 |
|
private static function chartDataSeriesValues($seriesValueSet, $dataType = 'n') |
359
|
|
|
{ |
360
|
2 |
|
$seriesVal = []; |
361
|
2 |
|
$formatCode = ''; |
362
|
2 |
|
$pointCount = 0; |
363
|
|
|
|
364
|
2 |
|
foreach ($seriesValueSet as $seriesValueIdx => $seriesValue) { |
365
|
|
|
switch ($seriesValueIdx) { |
366
|
2 |
|
case 'ptCount': |
367
|
2 |
|
$pointCount = self::getAttribute($seriesValue, 'val', 'integer'); |
368
|
|
|
|
369
|
2 |
|
break; |
370
|
2 |
|
case 'formatCode': |
371
|
2 |
|
$formatCode = (string) $seriesValue; |
372
|
|
|
|
373
|
2 |
|
break; |
374
|
2 |
|
case 'pt': |
375
|
2 |
|
$pointVal = self::getAttribute($seriesValue, 'idx', 'integer'); |
376
|
2 |
|
if ($dataType == 's') { |
377
|
2 |
|
$seriesVal[$pointVal] = (string) $seriesValue->v; |
378
|
2 |
|
} elseif ($seriesValue->v === Functions::NA()) { |
379
|
|
|
$seriesVal[$pointVal] = null; |
380
|
|
|
} else { |
381
|
2 |
|
$seriesVal[$pointVal] = (float) $seriesValue->v; |
382
|
|
|
} |
383
|
|
|
|
384
|
2 |
|
break; |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
return [ |
389
|
2 |
|
'formatCode' => $formatCode, |
390
|
2 |
|
'pointCount' => $pointCount, |
391
|
2 |
|
'dataValues' => $seriesVal, |
392
|
|
|
]; |
393
|
|
|
} |
394
|
|
|
|
395
|
2 |
|
private static function chartDataSeriesValuesMultiLevel($seriesValueSet, $dataType = 'n') |
396
|
|
|
{ |
397
|
2 |
|
$seriesVal = []; |
398
|
2 |
|
$formatCode = ''; |
399
|
2 |
|
$pointCount = 0; |
400
|
|
|
|
401
|
2 |
|
foreach ($seriesValueSet->lvl as $seriesLevelIdx => $seriesLevel) { |
402
|
2 |
|
foreach ($seriesLevel as $seriesValueIdx => $seriesValue) { |
403
|
|
|
switch ($seriesValueIdx) { |
404
|
2 |
|
case 'ptCount': |
405
|
|
|
$pointCount = self::getAttribute($seriesValue, 'val', 'integer'); |
406
|
|
|
|
407
|
|
|
break; |
408
|
2 |
|
case 'formatCode': |
409
|
|
|
$formatCode = (string) $seriesValue; |
410
|
|
|
|
411
|
|
|
break; |
412
|
2 |
|
case 'pt': |
413
|
2 |
|
$pointVal = self::getAttribute($seriesValue, 'idx', 'integer'); |
414
|
2 |
|
if ($dataType == 's') { |
415
|
2 |
|
$seriesVal[$pointVal][] = (string) $seriesValue->v; |
416
|
|
|
} elseif ($seriesValue->v === Functions::NA()) { |
417
|
|
|
$seriesVal[$pointVal] = null; |
418
|
|
|
} else { |
419
|
|
|
$seriesVal[$pointVal][] = (float) $seriesValue->v; |
420
|
|
|
} |
421
|
|
|
|
422
|
2 |
|
break; |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
return [ |
428
|
2 |
|
'formatCode' => $formatCode, |
429
|
2 |
|
'pointCount' => $pointCount, |
430
|
2 |
|
'dataValues' => $seriesVal, |
431
|
|
|
]; |
432
|
|
|
} |
433
|
|
|
|
434
|
2 |
|
private static function parseRichText(SimpleXMLElement $titleDetailPart) |
435
|
|
|
{ |
436
|
2 |
|
$value = new RichText(); |
437
|
2 |
|
$objText = null; |
438
|
2 |
|
foreach ($titleDetailPart as $titleDetailElementKey => $titleDetailElement) { |
439
|
2 |
|
if (isset($titleDetailElement->t)) { |
440
|
2 |
|
$objText = $value->createTextRun((string) $titleDetailElement->t); |
441
|
|
|
} |
442
|
2 |
|
if (isset($titleDetailElement->rPr)) { |
443
|
2 |
|
if (isset($titleDetailElement->rPr->rFont['val'])) { |
444
|
|
|
$objText->getFont()->setName((string) $titleDetailElement->rPr->rFont['val']); |
445
|
|
|
} |
446
|
|
|
|
447
|
2 |
|
$fontSize = (self::getAttribute($titleDetailElement->rPr, 'sz', 'integer')); |
448
|
2 |
|
if ($fontSize !== null) { |
449
|
2 |
|
$objText->getFont()->setSize(floor($fontSize / 100)); |
450
|
|
|
} |
451
|
|
|
|
452
|
2 |
|
$fontColor = (self::getAttribute($titleDetailElement->rPr, 'color', 'string')); |
453
|
2 |
|
if ($fontColor !== null) { |
454
|
|
|
$objText->getFont()->setColor(new Color(self::readColor($fontColor))); |
455
|
|
|
} |
456
|
|
|
|
457
|
2 |
|
$bold = self::getAttribute($titleDetailElement->rPr, 'b', 'boolean'); |
458
|
2 |
|
if ($bold !== null) { |
459
|
2 |
|
$objText->getFont()->setBold($bold); |
460
|
|
|
} |
461
|
|
|
|
462
|
2 |
|
$italic = self::getAttribute($titleDetailElement->rPr, 'i', 'boolean'); |
463
|
2 |
|
if ($italic !== null) { |
464
|
2 |
|
$objText->getFont()->setItalic($italic); |
465
|
|
|
} |
466
|
|
|
|
467
|
2 |
|
$baseline = self::getAttribute($titleDetailElement->rPr, 'baseline', 'integer'); |
468
|
2 |
|
if ($baseline !== null) { |
469
|
2 |
|
if ($baseline > 0) { |
470
|
2 |
|
$objText->getFont()->setSuperscript(true); |
471
|
2 |
|
} elseif ($baseline < 0) { |
472
|
2 |
|
$objText->getFont()->setSubscript(true); |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
|
476
|
2 |
|
$underscore = (self::getAttribute($titleDetailElement->rPr, 'u', 'string')); |
477
|
2 |
|
if ($underscore !== null) { |
478
|
2 |
|
if ($underscore == 'sng') { |
479
|
2 |
|
$objText->getFont()->setUnderline(Font::UNDERLINE_SINGLE); |
480
|
2 |
|
} elseif ($underscore == 'dbl') { |
481
|
2 |
|
$objText->getFont()->setUnderline(Font::UNDERLINE_DOUBLE); |
482
|
|
|
} else { |
483
|
2 |
|
$objText->getFont()->setUnderline(Font::UNDERLINE_NONE); |
484
|
|
|
} |
485
|
|
|
} |
486
|
|
|
|
487
|
2 |
|
$strikethrough = (self::getAttribute($titleDetailElement->rPr, 's', 'string')); |
488
|
2 |
|
if ($strikethrough !== null) { |
489
|
|
|
if ($strikethrough == 'noStrike') { |
490
|
|
|
$objText->getFont()->setStrikethrough(false); |
491
|
|
|
} else { |
492
|
|
|
$objText->getFont()->setStrikethrough(true); |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
} |
496
|
|
|
} |
497
|
|
|
|
498
|
2 |
|
return $value; |
499
|
|
|
} |
500
|
|
|
|
501
|
2 |
|
private static function readChartAttributes($chartDetail) |
502
|
|
|
{ |
503
|
2 |
|
$plotAttributes = []; |
504
|
2 |
|
if (isset($chartDetail->dLbls)) { |
505
|
2 |
|
if (isset($chartDetail->dLbls->howLegendKey)) { |
506
|
|
|
$plotAttributes['showLegendKey'] = self::getAttribute($chartDetail->dLbls->showLegendKey, 'val', 'string'); |
507
|
|
|
} |
508
|
2 |
|
if (isset($chartDetail->dLbls->showVal)) { |
509
|
2 |
|
$plotAttributes['showVal'] = self::getAttribute($chartDetail->dLbls->showVal, 'val', 'string'); |
510
|
|
|
} |
511
|
2 |
|
if (isset($chartDetail->dLbls->showCatName)) { |
512
|
2 |
|
$plotAttributes['showCatName'] = self::getAttribute($chartDetail->dLbls->showCatName, 'val', 'string'); |
513
|
|
|
} |
514
|
2 |
|
if (isset($chartDetail->dLbls->showSerName)) { |
515
|
2 |
|
$plotAttributes['showSerName'] = self::getAttribute($chartDetail->dLbls->showSerName, 'val', 'string'); |
516
|
|
|
} |
517
|
2 |
|
if (isset($chartDetail->dLbls->showPercent)) { |
518
|
2 |
|
$plotAttributes['showPercent'] = self::getAttribute($chartDetail->dLbls->showPercent, 'val', 'string'); |
519
|
|
|
} |
520
|
2 |
|
if (isset($chartDetail->dLbls->showBubbleSize)) { |
521
|
2 |
|
$plotAttributes['showBubbleSize'] = self::getAttribute($chartDetail->dLbls->showBubbleSize, 'val', 'string'); |
522
|
|
|
} |
523
|
2 |
|
if (isset($chartDetail->dLbls->showLeaderLines)) { |
524
|
2 |
|
$plotAttributes['showLeaderLines'] = self::getAttribute($chartDetail->dLbls->showLeaderLines, 'val', 'string'); |
525
|
|
|
} |
526
|
|
|
} |
527
|
|
|
|
528
|
2 |
|
return $plotAttributes; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* @param Layout $plotArea |
533
|
|
|
* @param mixed $plotAttributes |
534
|
|
|
*/ |
535
|
2 |
|
private static function setChartAttributes(Layout $plotArea, $plotAttributes) |
536
|
|
|
{ |
537
|
2 |
|
foreach ($plotAttributes as $plotAttributeKey => $plotAttributeValue) { |
538
|
|
|
switch ($plotAttributeKey) { |
539
|
2 |
|
case 'showLegendKey': |
540
|
|
|
$plotArea->setShowLegendKey($plotAttributeValue); |
541
|
|
|
|
542
|
|
|
break; |
543
|
2 |
|
case 'showVal': |
544
|
2 |
|
$plotArea->setShowVal($plotAttributeValue); |
545
|
|
|
|
546
|
2 |
|
break; |
547
|
2 |
|
case 'showCatName': |
548
|
2 |
|
$plotArea->setShowCatName($plotAttributeValue); |
549
|
|
|
|
550
|
2 |
|
break; |
551
|
2 |
|
case 'showSerName': |
552
|
2 |
|
$plotArea->setShowSerName($plotAttributeValue); |
553
|
|
|
|
554
|
2 |
|
break; |
555
|
2 |
|
case 'showPercent': |
556
|
2 |
|
$plotArea->setShowPercent($plotAttributeValue); |
557
|
|
|
|
558
|
2 |
|
break; |
559
|
2 |
|
case 'showBubbleSize': |
560
|
2 |
|
$plotArea->setShowBubbleSize($plotAttributeValue); |
561
|
|
|
|
562
|
2 |
|
break; |
563
|
2 |
|
case 'showLeaderLines': |
564
|
2 |
|
$plotArea->setShowLeaderLines($plotAttributeValue); |
565
|
|
|
|
566
|
2 |
|
break; |
567
|
|
|
} |
568
|
|
|
} |
569
|
2 |
|
} |
570
|
|
|
} |
571
|
|
|
|