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