1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet. |
9
|
|
|
* |
10
|
|
|
* This library is free software; you can redistribute it and/or |
11
|
|
|
* modify it under the terms of the GNU Lesser General Public |
12
|
|
|
* License as published by the Free Software Foundation; either |
13
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This library is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18
|
|
|
* Lesser General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Lesser General Public |
21
|
|
|
* License along with this library; if not, write to the Free Software |
22
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23
|
|
|
* |
24
|
|
|
* @category PhpSpreadsheet |
25
|
|
|
* |
26
|
|
|
* @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) |
27
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
28
|
|
|
*/ |
29
|
|
|
class Chart |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @param \SimpleXMLElement $component |
33
|
|
|
* @param string $name |
34
|
|
|
* @param string $format |
35
|
|
|
*/ |
36
|
1 |
|
private static function getAttribute(\SimpleXMLElement $component, $name, $format) |
37
|
|
|
{ |
38
|
1 |
|
$attributes = $component->attributes(); |
39
|
1 |
|
if (isset($attributes[$name])) { |
40
|
1 |
|
if ($format == 'string') { |
41
|
1 |
|
return (string) $attributes[$name]; |
42
|
1 |
|
} elseif ($format == 'integer') { |
43
|
1 |
|
return (int) $attributes[$name]; |
44
|
1 |
|
} elseif ($format == 'boolean') { |
45
|
1 |
|
return (bool) ($attributes[$name] === '0' || $attributes[$name] !== 'true') ? false : true; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return (float) $attributes[$name]; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
return null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private static function readColor($color, $background = false) |
55
|
|
|
{ |
56
|
|
|
if (isset($color['rgb'])) { |
57
|
|
|
return (string) $color['rgb']; |
58
|
|
|
} elseif (isset($color['indexed'])) { |
59
|
|
|
return \PhpOffice\PhpSpreadsheet\Style\Color::indexedColor($color['indexed'] - 7, $background)->getARGB(); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param \SimpleXMLElement $chartElements |
65
|
|
|
* @param string $chartName |
66
|
|
|
*/ |
67
|
1 |
|
public static function readChart(\SimpleXMLElement $chartElements, $chartName) |
68
|
|
|
{ |
69
|
1 |
|
$namespacesChartMeta = $chartElements->getNamespaces(true); |
70
|
1 |
|
$chartElementsC = $chartElements->children($namespacesChartMeta['c']); |
71
|
|
|
|
72
|
1 |
|
$XaxisLabel = $YaxisLabel = $legend = $title = null; |
73
|
1 |
|
$dispBlanksAs = $plotVisOnly = null; |
74
|
|
|
|
75
|
1 |
|
foreach ($chartElementsC as $chartElementKey => $chartElement) { |
76
|
|
|
switch ($chartElementKey) { |
77
|
1 |
|
case 'chart': |
78
|
1 |
|
foreach ($chartElement as $chartDetailsKey => $chartDetails) { |
79
|
1 |
|
$chartDetailsC = $chartDetails->children($namespacesChartMeta['c']); |
|
|
|
|
80
|
|
|
switch ($chartDetailsKey) { |
81
|
1 |
|
case 'plotArea': |
82
|
1 |
|
$plotAreaLayout = $XaxisLable = $YaxisLable = null; |
|
|
|
|
83
|
1 |
|
$plotSeries = $plotAttributes = []; |
84
|
1 |
|
foreach ($chartDetails as $chartDetailKey => $chartDetail) { |
85
|
|
|
switch ($chartDetailKey) { |
86
|
1 |
|
case 'layout': |
87
|
1 |
|
$plotAreaLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta); |
88
|
1 |
|
break; |
89
|
1 |
View Code Duplication |
case 'catAx': |
|
|
|
|
90
|
1 |
|
if (isset($chartDetail->title)) { |
91
|
1 |
|
$XaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta); |
92
|
|
|
} |
93
|
1 |
|
break; |
94
|
1 |
View Code Duplication |
case 'dateAx': |
|
|
|
|
95
|
|
|
if (isset($chartDetail->title)) { |
96
|
|
|
$XaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta); |
97
|
|
|
} |
98
|
|
|
break; |
99
|
1 |
View Code Duplication |
case 'valAx': |
|
|
|
|
100
|
1 |
|
if (isset($chartDetail->title)) { |
101
|
1 |
|
$YaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta); |
102
|
|
|
} |
103
|
1 |
|
break; |
104
|
1 |
|
case 'barChart': |
105
|
1 |
|
case 'bar3DChart': |
106
|
1 |
|
$barDirection = self::getAttribute($chartDetail->barDir, 'val', 'string'); |
107
|
1 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
108
|
1 |
|
$plotSer->setPlotDirection($barDirection); |
109
|
1 |
|
$plotSeries[] = $plotSer; |
110
|
1 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
111
|
1 |
|
break; |
112
|
1 |
|
case 'lineChart': |
113
|
1 |
View Code Duplication |
case 'line3DChart': |
|
|
|
|
114
|
1 |
|
$plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
115
|
1 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
116
|
1 |
|
break; |
117
|
1 |
|
case 'areaChart': |
118
|
1 |
View Code Duplication |
case 'area3DChart': |
|
|
|
|
119
|
1 |
|
$plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
120
|
1 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
121
|
1 |
|
break; |
122
|
1 |
|
case 'doughnutChart': |
123
|
1 |
|
case 'pieChart': |
124
|
1 |
|
case 'pie3DChart': |
125
|
1 |
|
$explosion = isset($chartDetail->ser->explosion); |
126
|
1 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
127
|
1 |
|
$plotSer->setPlotStyle($explosion); |
|
|
|
|
128
|
1 |
|
$plotSeries[] = $plotSer; |
129
|
1 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
130
|
1 |
|
break; |
131
|
1 |
View Code Duplication |
case 'scatterChart': |
|
|
|
|
132
|
1 |
|
$scatterStyle = self::getAttribute($chartDetail->scatterStyle, 'val', 'string'); |
133
|
1 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
134
|
1 |
|
$plotSer->setPlotStyle($scatterStyle); |
135
|
1 |
|
$plotSeries[] = $plotSer; |
136
|
1 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
137
|
1 |
|
break; |
138
|
1 |
|
case 'bubbleChart': |
139
|
1 |
|
$bubbleScale = self::getAttribute($chartDetail->bubbleScale, 'val', 'integer'); |
140
|
1 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
141
|
1 |
|
$plotSer->setPlotStyle($bubbleScale); |
142
|
1 |
|
$plotSeries[] = $plotSer; |
143
|
1 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
144
|
1 |
|
break; |
145
|
1 |
View Code Duplication |
case 'radarChart': |
|
|
|
|
146
|
1 |
|
$radarStyle = self::getAttribute($chartDetail->radarStyle, 'val', 'string'); |
147
|
1 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
148
|
1 |
|
$plotSer->setPlotStyle($radarStyle); |
149
|
1 |
|
$plotSeries[] = $plotSer; |
150
|
1 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
151
|
1 |
|
break; |
152
|
1 |
|
case 'surfaceChart': |
153
|
1 |
|
case 'surface3DChart': |
154
|
1 |
|
$wireFrame = self::getAttribute($chartDetail->wireframe, 'val', 'boolean'); |
155
|
1 |
|
$plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
156
|
1 |
|
$plotSer->setPlotStyle($wireFrame); |
157
|
1 |
|
$plotSeries[] = $plotSer; |
158
|
1 |
|
$plotAttributes = self::readChartAttributes($chartDetail); |
159
|
1 |
|
break; |
160
|
1 |
View Code Duplication |
case 'stockChart': |
|
|
|
|
161
|
1 |
|
$plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey); |
162
|
1 |
|
$plotAttributes = self::readChartAttributes($plotAreaLayout); |
163
|
1 |
|
break; |
164
|
|
|
} |
165
|
|
|
} |
166
|
1 |
|
if ($plotAreaLayout == null) { |
167
|
1 |
|
$plotAreaLayout = new \PhpOffice\PhpSpreadsheet\Chart\Layout(); |
168
|
|
|
} |
169
|
1 |
|
$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea($plotAreaLayout, $plotSeries); |
170
|
1 |
|
self::setChartAttributes($plotAreaLayout, $plotAttributes); |
171
|
1 |
|
break; |
172
|
1 |
|
case 'plotVisOnly': |
173
|
1 |
|
$plotVisOnly = self::getAttribute($chartDetails, 'val', 'string'); |
174
|
1 |
|
break; |
175
|
1 |
|
case 'dispBlanksAs': |
176
|
1 |
|
$dispBlanksAs = self::getAttribute($chartDetails, 'val', 'string'); |
177
|
1 |
|
break; |
178
|
1 |
|
case 'title': |
179
|
1 |
|
$title = self::chartTitle($chartDetails, $namespacesChartMeta); |
180
|
1 |
|
break; |
181
|
1 |
|
case 'legend': |
182
|
1 |
|
$legendPos = 'r'; |
183
|
1 |
|
$legendLayout = null; |
184
|
1 |
|
$legendOverlay = false; |
185
|
1 |
|
foreach ($chartDetails as $chartDetailKey => $chartDetail) { |
186
|
|
|
switch ($chartDetailKey) { |
187
|
1 |
|
case 'legendPos': |
188
|
1 |
|
$legendPos = self::getAttribute($chartDetail, 'val', 'string'); |
189
|
1 |
|
break; |
190
|
1 |
|
case 'overlay': |
191
|
1 |
|
$legendOverlay = self::getAttribute($chartDetail, 'val', 'boolean'); |
192
|
1 |
|
break; |
193
|
1 |
|
case 'layout': |
194
|
1 |
|
$legendLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta); |
195
|
1 |
|
break; |
196
|
|
|
} |
197
|
|
|
} |
198
|
1 |
|
$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend($legendPos, $legendLayout, $legendOverlay); |
199
|
1 |
|
break; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
} |
204
|
1 |
|
$chart = new \PhpOffice\PhpSpreadsheet\Chart($chartName, $title, $legend, $plotArea, $plotVisOnly, $dispBlanksAs, $XaxisLabel, $YaxisLabel); |
|
|
|
|
205
|
|
|
|
206
|
1 |
|
return $chart; |
207
|
|
|
} |
208
|
|
|
|
209
|
1 |
|
private static function chartTitle(\SimpleXMLElement $titleDetails, array $namespacesChartMeta) |
210
|
|
|
{ |
211
|
1 |
|
$caption = []; |
212
|
1 |
|
$titleLayout = null; |
213
|
1 |
|
foreach ($titleDetails as $titleDetailKey => $chartDetail) { |
214
|
|
|
switch ($titleDetailKey) { |
215
|
1 |
|
case 'tx': |
216
|
1 |
|
$titleDetails = $chartDetail->rich->children($namespacesChartMeta['a']); |
217
|
1 |
|
foreach ($titleDetails as $titleKey => $titleDetail) { |
218
|
|
|
switch ($titleKey) { |
219
|
1 |
|
case 'p': |
220
|
1 |
|
$titleDetailPart = $titleDetail->children($namespacesChartMeta['a']); |
221
|
1 |
|
$caption[] = self::parseRichText($titleDetailPart); |
222
|
|
|
} |
223
|
|
|
} |
224
|
1 |
|
break; |
225
|
1 |
|
case 'layout': |
226
|
1 |
|
$titleLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta); |
227
|
1 |
|
break; |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
231
|
1 |
|
return new \PhpOffice\PhpSpreadsheet\Chart\Title($caption, $titleLayout); |
232
|
|
|
} |
233
|
|
|
|
234
|
1 |
|
private static function chartLayoutDetails($chartDetail, $namespacesChartMeta) |
235
|
|
|
{ |
236
|
1 |
|
if (!isset($chartDetail->manualLayout)) { |
237
|
1 |
|
return null; |
238
|
|
|
} |
239
|
1 |
|
$details = $chartDetail->manualLayout->children($namespacesChartMeta['c']); |
240
|
1 |
|
if (is_null($details)) { |
241
|
|
|
return null; |
242
|
|
|
} |
243
|
1 |
|
$layout = []; |
244
|
1 |
|
foreach ($details as $detailKey => $detail) { |
245
|
1 |
|
$layout[$detailKey] = self::getAttribute($detail, 'val', 'string'); |
246
|
|
|
} |
247
|
|
|
|
248
|
1 |
|
return new \PhpOffice\PhpSpreadsheet\Chart\Layout($layout); |
249
|
|
|
} |
250
|
|
|
|
251
|
1 |
|
private static function chartDataSeries($chartDetail, $namespacesChartMeta, $plotType) |
252
|
|
|
{ |
253
|
1 |
|
$multiSeriesType = null; |
254
|
1 |
|
$smoothLine = false; |
255
|
1 |
|
$seriesLabel = $seriesCategory = $seriesValues = $plotOrder = []; |
256
|
|
|
|
257
|
1 |
|
$seriesDetailSet = $chartDetail->children($namespacesChartMeta['c']); |
258
|
1 |
|
foreach ($seriesDetailSet as $seriesDetailKey => $seriesDetails) { |
259
|
|
|
switch ($seriesDetailKey) { |
260
|
1 |
|
case 'grouping': |
261
|
1 |
|
$multiSeriesType = self::getAttribute($chartDetail->grouping, 'val', 'string'); |
262
|
1 |
|
break; |
263
|
1 |
|
case 'ser': |
264
|
1 |
|
$marker = null; |
265
|
1 |
|
foreach ($seriesDetails as $seriesKey => $seriesDetail) { |
266
|
|
|
switch ($seriesKey) { |
267
|
1 |
|
case 'idx': |
268
|
1 |
|
$seriesIndex = self::getAttribute($seriesDetail, 'val', 'integer'); |
269
|
1 |
|
break; |
270
|
1 |
|
case 'order': |
271
|
1 |
|
$seriesOrder = self::getAttribute($seriesDetail, 'val', 'integer'); |
272
|
1 |
|
$plotOrder[$seriesIndex] = $seriesOrder; |
|
|
|
|
273
|
1 |
|
break; |
274
|
1 |
|
case 'tx': |
275
|
1 |
|
$seriesLabel[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta); |
276
|
1 |
|
break; |
277
|
1 |
|
case 'marker': |
278
|
1 |
|
$marker = self::getAttribute($seriesDetail->symbol, 'val', 'string'); |
279
|
1 |
|
break; |
280
|
1 |
|
case 'smooth': |
281
|
1 |
|
$smoothLine = self::getAttribute($seriesDetail, 'val', 'boolean'); |
282
|
1 |
|
break; |
283
|
1 |
|
case 'cat': |
284
|
1 |
|
$seriesCategory[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta); |
285
|
1 |
|
break; |
286
|
1 |
|
case 'val': |
287
|
1 |
|
$seriesValues[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker); |
288
|
1 |
|
break; |
289
|
1 |
|
case 'xVal': |
290
|
1 |
|
$seriesCategory[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker); |
291
|
1 |
|
break; |
292
|
1 |
|
case 'yVal': |
293
|
1 |
|
$seriesValues[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker); |
294
|
1 |
|
break; |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|
300
|
1 |
|
return new \PhpOffice\PhpSpreadsheet\Chart\DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine); |
301
|
|
|
} |
302
|
|
|
|
303
|
1 |
|
private static function chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker = null, $smoothLine = false) |
304
|
|
|
{ |
305
|
1 |
|
if (isset($seriesDetail->strRef)) { |
306
|
1 |
|
$seriesSource = (string) $seriesDetail->strRef->f; |
307
|
1 |
|
$seriesData = self::chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta['c']), 's'); |
308
|
|
|
|
309
|
1 |
|
return new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); |
|
|
|
|
310
|
|
|
} elseif (isset($seriesDetail->numRef)) { |
311
|
1 |
|
$seriesSource = (string) $seriesDetail->numRef->f; |
312
|
1 |
|
$seriesData = self::chartDataSeriesValues($seriesDetail->numRef->numCache->children($namespacesChartMeta['c'])); |
313
|
|
|
|
314
|
1 |
|
return new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); |
|
|
|
|
315
|
|
|
} elseif (isset($seriesDetail->multiLvlStrRef)) { |
316
|
1 |
|
$seriesSource = (string) $seriesDetail->multiLvlStrRef->f; |
317
|
1 |
|
$seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlStrRef->multiLvlStrCache->children($namespacesChartMeta['c']), 's'); |
318
|
1 |
|
$seriesData['pointCount'] = count($seriesData['dataValues']); |
319
|
|
|
|
320
|
1 |
|
return new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); |
|
|
|
|
321
|
|
|
} elseif (isset($seriesDetail->multiLvlNumRef)) { |
322
|
|
|
$seriesSource = (string) $seriesDetail->multiLvlNumRef->f; |
323
|
|
|
$seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlNumRef->multiLvlNumCache->children($namespacesChartMeta['c']), 's'); |
324
|
|
|
$seriesData['pointCount'] = count($seriesData['dataValues']); |
325
|
|
|
|
326
|
|
|
return new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker, $smoothLine); |
|
|
|
|
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
return null; |
330
|
|
|
} |
331
|
|
|
|
332
|
1 |
|
private static function chartDataSeriesValues($seriesValueSet, $dataType = 'n') |
333
|
|
|
{ |
334
|
1 |
|
$seriesVal = []; |
335
|
1 |
|
$formatCode = ''; |
336
|
1 |
|
$pointCount = 0; |
337
|
|
|
|
338
|
1 |
View Code Duplication |
foreach ($seriesValueSet as $seriesValueIdx => $seriesValue) { |
|
|
|
|
339
|
|
|
switch ($seriesValueIdx) { |
340
|
1 |
|
case 'ptCount': |
341
|
1 |
|
$pointCount = self::getAttribute($seriesValue, 'val', 'integer'); |
342
|
1 |
|
break; |
343
|
1 |
|
case 'formatCode': |
344
|
1 |
|
$formatCode = (string) $seriesValue; |
345
|
1 |
|
break; |
346
|
1 |
|
case 'pt': |
347
|
1 |
|
$pointVal = self::getAttribute($seriesValue, 'idx', 'integer'); |
348
|
1 |
|
if ($dataType == 's') { |
349
|
1 |
|
$seriesVal[$pointVal] = (string) $seriesValue->v; |
350
|
1 |
|
} elseif ($seriesValue->v === Functions::NA()) { |
351
|
|
|
$seriesVal[$pointVal] = null; |
352
|
|
|
} else { |
353
|
1 |
|
$seriesVal[$pointVal] = (float) $seriesValue->v; |
354
|
|
|
} |
355
|
1 |
|
break; |
356
|
|
|
} |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
return [ |
360
|
1 |
|
'formatCode' => $formatCode, |
361
|
1 |
|
'pointCount' => $pointCount, |
362
|
1 |
|
'dataValues' => $seriesVal, |
363
|
|
|
]; |
364
|
|
|
} |
365
|
|
|
|
366
|
1 |
|
private static function chartDataSeriesValuesMultiLevel($seriesValueSet, $dataType = 'n') |
367
|
|
|
{ |
368
|
1 |
|
$seriesVal = []; |
369
|
1 |
|
$formatCode = ''; |
370
|
1 |
|
$pointCount = 0; |
371
|
|
|
|
372
|
1 |
|
foreach ($seriesValueSet->lvl as $seriesLevelIdx => $seriesLevel) { |
373
|
1 |
View Code Duplication |
foreach ($seriesLevel as $seriesValueIdx => $seriesValue) { |
|
|
|
|
374
|
|
|
switch ($seriesValueIdx) { |
375
|
1 |
|
case 'ptCount': |
376
|
|
|
$pointCount = self::getAttribute($seriesValue, 'val', 'integer'); |
377
|
|
|
break; |
378
|
1 |
|
case 'formatCode': |
379
|
|
|
$formatCode = (string) $seriesValue; |
380
|
|
|
break; |
381
|
1 |
|
case 'pt': |
382
|
1 |
|
$pointVal = self::getAttribute($seriesValue, 'idx', 'integer'); |
383
|
1 |
|
if ($dataType == 's') { |
384
|
1 |
|
$seriesVal[$pointVal][] = (string) $seriesValue->v; |
385
|
|
|
} elseif ($seriesValue->v === Functions::NA()) { |
386
|
|
|
$seriesVal[$pointVal] = null; |
387
|
|
|
} else { |
388
|
|
|
$seriesVal[$pointVal][] = (float) $seriesValue->v; |
389
|
|
|
} |
390
|
1 |
|
break; |
391
|
|
|
} |
392
|
|
|
} |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
return [ |
396
|
1 |
|
'formatCode' => $formatCode, |
397
|
1 |
|
'pointCount' => $pointCount, |
398
|
1 |
|
'dataValues' => $seriesVal, |
399
|
|
|
]; |
400
|
|
|
} |
401
|
|
|
|
402
|
1 |
|
private static function parseRichText(\SimpleXMLElement $titleDetailPart) |
403
|
|
|
{ |
404
|
1 |
|
$value = new \PhpOffice\PhpSpreadsheet\RichText(); |
405
|
|
|
|
406
|
1 |
|
foreach ($titleDetailPart as $titleDetailElementKey => $titleDetailElement) { |
407
|
1 |
|
if (isset($titleDetailElement->t)) { |
408
|
1 |
|
$objText = $value->createTextRun((string) $titleDetailElement->t); |
409
|
|
|
} |
410
|
1 |
|
if (isset($titleDetailElement->rPr)) { |
411
|
1 |
View Code Duplication |
if (isset($titleDetailElement->rPr->rFont['val'])) { |
|
|
|
|
412
|
|
|
$objText->getFont()->setName((string) $titleDetailElement->rPr->rFont['val']); |
|
|
|
|
413
|
|
|
} |
414
|
|
|
|
415
|
1 |
|
$fontSize = (self::getAttribute($titleDetailElement->rPr, 'sz', 'integer')); |
416
|
1 |
|
if (!is_null($fontSize)) { |
417
|
1 |
|
$objText->getFont()->setSize(floor($fontSize / 100)); |
418
|
|
|
} |
419
|
|
|
|
420
|
1 |
|
$fontColor = (self::getAttribute($titleDetailElement->rPr, 'color', 'string')); |
421
|
1 |
|
if (!is_null($fontColor)) { |
422
|
|
|
$objText->getFont()->setColor(new \PhpOffice\PhpSpreadsheet\Style\Color(self::readColor($fontColor))); |
423
|
|
|
} |
424
|
|
|
|
425
|
1 |
|
$bold = self::getAttribute($titleDetailElement->rPr, 'b', 'boolean'); |
426
|
1 |
|
if (!is_null($bold)) { |
427
|
1 |
|
$objText->getFont()->setBold($bold); |
428
|
|
|
} |
429
|
|
|
|
430
|
1 |
|
$italic = self::getAttribute($titleDetailElement->rPr, 'i', 'boolean'); |
431
|
1 |
|
if (!is_null($italic)) { |
432
|
1 |
|
$objText->getFont()->setItalic($italic); |
433
|
|
|
} |
434
|
|
|
|
435
|
1 |
|
$baseline = self::getAttribute($titleDetailElement->rPr, 'baseline', 'integer'); |
436
|
1 |
|
if (!is_null($baseline)) { |
437
|
1 |
|
if ($baseline > 0) { |
438
|
1 |
|
$objText->getFont()->setSuperScript(true); |
439
|
1 |
|
} elseif ($baseline < 0) { |
440
|
1 |
|
$objText->getFont()->setSubScript(true); |
441
|
|
|
} |
442
|
|
|
} |
443
|
|
|
|
444
|
1 |
|
$underscore = (self::getAttribute($titleDetailElement->rPr, 'u', 'string')); |
445
|
1 |
|
if (!is_null($underscore)) { |
446
|
1 |
|
if ($underscore == 'sng') { |
447
|
1 |
|
$objText->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE); |
448
|
1 |
|
} elseif ($underscore == 'dbl') { |
449
|
1 |
|
$objText->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_DOUBLE); |
450
|
|
|
} else { |
451
|
1 |
|
$objText->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_NONE); |
452
|
|
|
} |
453
|
|
|
} |
454
|
|
|
|
455
|
1 |
|
$strikethrough = (self::getAttribute($titleDetailElement->rPr, 's', 'string')); |
456
|
1 |
|
if (!is_null($strikethrough)) { |
457
|
|
|
if ($strikethrough == 'noStrike') { |
458
|
|
|
$objText->getFont()->setStrikethrough(false); |
459
|
|
|
} else { |
460
|
|
|
$objText->getFont()->setStrikethrough(true); |
461
|
|
|
} |
462
|
|
|
} |
463
|
|
|
} |
464
|
|
|
} |
465
|
|
|
|
466
|
1 |
|
return $value; |
467
|
|
|
} |
468
|
|
|
|
469
|
1 |
|
private static function readChartAttributes($chartDetail) |
470
|
|
|
{ |
471
|
1 |
|
$plotAttributes = []; |
472
|
1 |
|
if (isset($chartDetail->dLbls)) { |
473
|
1 |
|
if (isset($chartDetail->dLbls->howLegendKey)) { |
474
|
|
|
$plotAttributes['showLegendKey'] = self::getAttribute($chartDetail->dLbls->showLegendKey, 'val', 'string'); |
475
|
|
|
} |
476
|
1 |
View Code Duplication |
if (isset($chartDetail->dLbls->showVal)) { |
|
|
|
|
477
|
1 |
|
$plotAttributes['showVal'] = self::getAttribute($chartDetail->dLbls->showVal, 'val', 'string'); |
478
|
|
|
} |
479
|
1 |
View Code Duplication |
if (isset($chartDetail->dLbls->showCatName)) { |
|
|
|
|
480
|
1 |
|
$plotAttributes['showCatName'] = self::getAttribute($chartDetail->dLbls->showCatName, 'val', 'string'); |
481
|
|
|
} |
482
|
1 |
View Code Duplication |
if (isset($chartDetail->dLbls->showSerName)) { |
|
|
|
|
483
|
1 |
|
$plotAttributes['showSerName'] = self::getAttribute($chartDetail->dLbls->showSerName, 'val', 'string'); |
484
|
|
|
} |
485
|
1 |
View Code Duplication |
if (isset($chartDetail->dLbls->showPercent)) { |
|
|
|
|
486
|
1 |
|
$plotAttributes['showPercent'] = self::getAttribute($chartDetail->dLbls->showPercent, 'val', 'string'); |
487
|
|
|
} |
488
|
1 |
View Code Duplication |
if (isset($chartDetail->dLbls->showBubbleSize)) { |
|
|
|
|
489
|
1 |
|
$plotAttributes['showBubbleSize'] = self::getAttribute($chartDetail->dLbls->showBubbleSize, 'val', 'string'); |
490
|
|
|
} |
491
|
1 |
View Code Duplication |
if (isset($chartDetail->dLbls->showLeaderLines)) { |
|
|
|
|
492
|
1 |
|
$plotAttributes['showLeaderLines'] = self::getAttribute($chartDetail->dLbls->showLeaderLines, 'val', 'string'); |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
|
496
|
1 |
|
return $plotAttributes; |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
/** |
500
|
|
|
* @param \PhpOffice\PhpSpreadsheet\Chart\Layout $plotArea |
501
|
|
|
* @param mixed $plotAttributes |
502
|
|
|
*/ |
503
|
1 |
|
private static function setChartAttributes(\PhpOffice\PhpSpreadsheet\Chart\Layout $plotArea, $plotAttributes) |
504
|
|
|
{ |
505
|
1 |
|
foreach ($plotAttributes as $plotAttributeKey => $plotAttributeValue) { |
506
|
|
|
switch ($plotAttributeKey) { |
507
|
1 |
|
case 'showLegendKey': |
508
|
|
|
$plotArea->setShowLegendKey($plotAttributeValue); |
509
|
|
|
break; |
510
|
1 |
|
case 'showVal': |
511
|
1 |
|
$plotArea->setShowVal($plotAttributeValue); |
512
|
1 |
|
break; |
513
|
1 |
|
case 'showCatName': |
514
|
1 |
|
$plotArea->setShowCatName($plotAttributeValue); |
515
|
1 |
|
break; |
516
|
1 |
|
case 'showSerName': |
517
|
1 |
|
$plotArea->setShowSerName($plotAttributeValue); |
518
|
1 |
|
break; |
519
|
1 |
|
case 'showPercent': |
520
|
1 |
|
$plotArea->setShowPercent($plotAttributeValue); |
521
|
1 |
|
break; |
522
|
1 |
|
case 'showBubbleSize': |
523
|
1 |
|
$plotArea->setShowBubbleSize($plotAttributeValue); |
524
|
1 |
|
break; |
525
|
1 |
|
case 'showLeaderLines': |
526
|
1 |
|
$plotArea->setShowLeaderLines($plotAttributeValue); |
527
|
1 |
|
break; |
528
|
|
|
} |
529
|
|
|
} |
530
|
1 |
|
} |
531
|
|
|
} |
532
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.