← All changes
|
libraries/vendor/PhpSpreadsheet/Reader/Xlsx/Chart.php
+76
-21
3.3.2
→
3.4
View file →
| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | use TablePress\PhpOffice\PhpSpreadsheet\Chart\AxisText; |
| 8 | 8 | use TablePress\PhpOffice\PhpSpreadsheet\Chart\ChartColor; |
| 9 | 9 | use TablePress\PhpOffice\PhpSpreadsheet\Chart\DataSeries; |
| 10 | 10 | use TablePress\PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; |
| 11 | +use TablePress\PhpOffice\PhpSpreadsheet\Chart\DataTable; | |
| 11 | 12 | use TablePress\PhpOffice\PhpSpreadsheet\Chart\GridLines; |
| 12 | 13 | use TablePress\PhpOffice\PhpSpreadsheet\Chart\Layout; |
| 13 | 14 | use TablePress\PhpOffice\PhpSpreadsheet\Chart\Legend; |
| 14 | 15 | use TablePress\PhpOffice\PhpSpreadsheet\Chart\PlotArea; |
| @@ -90,15 +91,28 @@ | ||
| 90 | 91 | $chartBorderLines = null; |
| 91 | 92 | $chartFillColor = null; |
| 92 | 93 | $gradientArray = []; |
| 93 | 94 | $gradientLin = null; |
| 94 | - $roundedCorners = false; | |
| 95 | + $roundedCorners = null; | |
| 96 | + $date1904 = null; | |
| 97 | + $lang = null; | |
| 95 | 98 | $gapWidth = null; |
| 96 | 99 | $useUpBars = null; |
| 97 | 100 | $useDownBars = null; |
| 98 | 101 | $noBorder = false; |
| 102 | + $pageMargins = []; | |
| 103 | + $pageSetup = []; | |
| 99 | 104 | foreach ($chartElementsC as $chartElementKey => $chartElement) { |
| 100 | 105 | switch ($chartElementKey) { |
| 106 | + case 'printSettings': | |
| 107 | + if (isset($chartElement->pageMargins)) { | |
| 108 | + $pageMargins = current((array) $chartElement->pageMargins->attributes()); | |
| 109 | + } | |
| 110 | + if (isset($chartElement->pageSetup)) { | |
| 111 | + $pageSetup = current((array) $chartElement->pageSetup->attributes()); | |
| 112 | + } | |
| 113 | + | |
| 114 | + break; | |
| 101 | 115 | case 'spPr': |
| 102 | 116 | $children = $chartElementsC->spPr->children($this->aNamespace); |
| 103 | 117 | if (isset($children->noFill)) { |
| 104 | 118 | $chartNoFill = true; |
| @@ -115,18 +129,24 @@ | ||
| 115 | 129 | } |
| 116 | 130 | |
| 117 | 131 | break; |
| 118 | 132 | case 'roundedCorners': |
| 119 | - /** @var bool $roundedCorners */ | |
| 120 | 133 | $roundedCorners = self::getAttributeBoolean($chartElementsC->roundedCorners, 'val'); |
| 121 | 134 | |
| 122 | 135 | break; |
| 136 | + case 'date1904': | |
| 137 | + $date1904 = self::getAttributeBoolean($chartElementsC->date1904, 'val'); | |
| 138 | + | |
| 139 | + break; | |
| 140 | + case 'lang': | |
| 141 | + $lang = self::getAttributeString($chartElementsC->lang, 'val'); | |
| 142 | + | |
| 143 | + break; | |
| 123 | 144 | case 'chart': |
| 124 | 145 | foreach ($chartElement as $chartDetailsKey => $chartDetails) { |
| 125 | 146 | $chartDetails = Xlsx::testSimpleXml($chartDetails); |
| 126 | 147 | switch ($chartDetailsKey) { |
| 127 | 148 | case 'autoTitleDeleted': |
| 128 | - /** @var bool $autoTitleDeleted */ | |
| 129 | 149 | $autoTitleDeleted = self::getAttributeBoolean($chartElementsC->chart->autoTitleDeleted, 'val'); |
| 130 | 150 | |
| 131 | 151 | break; |
| 132 | 152 | case 'view3D': |
| @@ -136,9 +156,9 @@ | ||
| 136 | 156 | $perspective = self::getAttributeInteger($chartDetails->perspective, 'val'); |
| 137 | 157 | |
| 138 | 158 | break; |
| 139 | 159 | case 'plotArea': |
| 140 | - $plotAreaLayout = $XaxisLabel = $YaxisLabel = null; | |
| 160 | + $plotAreaLayout = $XaxisLabel = $YaxisLabel = $dataTable = null; | |
| 141 | 161 | $plotSeries = $plotAttributes = []; |
| 142 | 162 | $catAxRead = false; |
| 143 | 163 | $plotNoFill = false; |
| 144 | 164 | foreach ($chartDetails as $chartDetailKey => $chartDetail) { |
| @@ -358,8 +378,12 @@ | ||
| 358 | 378 | } |
| 359 | 379 | $plotAttributes = $this->readChartAttributes($chartDetail); |
| 360 | 380 | |
| 361 | 381 | break; |
| 382 | + case 'dTable': | |
| 383 | + $dataTable = $this->readDataTable($chartDetail); | |
| 384 | + | |
| 385 | + break; | |
| 362 | 386 | } |
| 363 | 387 | } |
| 364 | 388 | if ($plotAreaLayout == null) { |
| 365 | 389 | $plotAreaLayout = new Layout(); |
| @@ -364,8 +388,13 @@ | ||
| 364 | 388 | if ($plotAreaLayout == null) { |
| 365 | 389 | $plotAreaLayout = new Layout(); |
| 366 | 390 | } |
| 367 | 391 | $plotArea = new PlotArea($plotAreaLayout, $plotSeries); |
| 392 | + if ($dataTable !== null) { | |
| 393 | + $plotArea->setDataTable( | |
| 394 | + $dataTable | |
| 395 | + ); | |
| 396 | + } | |
| 368 | 397 | $this->setChartAttributes($plotAreaLayout, $plotAttributes); |
| 369 | 398 | if ($plotNoFill) { |
| 370 | 399 | $plotArea->setNoFill(true); |
| 371 | 400 | } |
| @@ -471,25 +500,20 @@ | ||
| 471 | 500 | } |
| 472 | 501 | if ($chartBorderLines !== null) { |
| 473 | 502 | $chart->setBorderLines($chartBorderLines); |
| 474 | 503 | } |
| 475 | - $chart->setNoBorder($noBorder); | |
| 476 | - $chart->setRoundedCorners($roundedCorners); | |
| 477 | - if (is_bool($autoTitleDeleted)) { | |
| 478 | - $chart->setAutoTitleDeleted($autoTitleDeleted); | |
| 479 | - } | |
| 480 | - if (is_int($rotX)) { | |
| 481 | - $chart->setRotX($rotX); | |
| 482 | - } | |
| 483 | - if (is_int($rotY)) { | |
| 484 | - $chart->setRotY($rotY); | |
| 485 | - } | |
| 486 | - if (is_int($rAngAx)) { | |
| 487 | - $chart->setRAngAx($rAngAx); | |
| 488 | - } | |
| 489 | - if (is_int($perspective)) { | |
| 490 | - $chart->setPerspective($perspective); | |
| 491 | - } | |
| 504 | + $chart | |
| 505 | + ->setNoBorder($noBorder) | |
| 506 | + ->setRoundedCorners($roundedCorners) | |
| 507 | + ->setDate1904($date1904) | |
| 508 | + ->setLang($lang) | |
| 509 | + ->setPageMargins($pageMargins) | |
| 510 | + ->setPageSetup($pageSetup) | |
| 511 | + ->setAutoTitleDeleted($autoTitleDeleted) | |
| 512 | + ->setRotX($rotX) | |
| 513 | + ->setRotY($rotY) | |
| 514 | + ->setRAngAx($rAngAx) | |
| 515 | + ->setPerspective($perspective); | |
| 492 | 516 | |
| 493 | 517 | return $chart; |
| 494 | 518 | } |
| 495 | 519 | |
| @@ -1288,8 +1312,11 @@ | ||
| 1288 | 1312 | $this->readEffects($txpr->p->pPr->defRPr, $labelEffects, false); |
| 1289 | 1313 | $plotAttributes['labelEffects'] = $labelEffects; |
| 1290 | 1314 | } |
| 1291 | 1315 | } |
| 1316 | + if (isset($txpr->bodyPr)) { | |
| 1317 | + $plotAttributes['bodyPr'] = current((array) $txpr->bodyPr->attributes()); | |
| 1318 | + } | |
| 1292 | 1319 | } |
| 1293 | 1320 | } |
| 1294 | 1321 | |
| 1295 | 1322 | return $plotAttributes; |
| @@ -1294,8 +1321,31 @@ | ||
| 1294 | 1321 | |
| 1295 | 1322 | return $plotAttributes; |
| 1296 | 1323 | } |
| 1297 | 1324 | |
| 1325 | + private function readDataTable(SimpleXMLElement $chartDetail): DataTable | |
| 1326 | + { | |
| 1327 | + $dataTable = new DataTable(); | |
| 1328 | + $temp = self::getAttributeBoolean($chartDetail->showHorzBorder, 'val'); | |
| 1329 | + if ($temp !== null) { | |
| 1330 | + $dataTable->setShowHorizontalBorder($temp); | |
| 1331 | + } | |
| 1332 | + $temp = self::getAttributeBoolean($chartDetail->showVertBorder, 'val'); | |
| 1333 | + if ($temp !== null) { | |
| 1334 | + $dataTable->setShowVerticalBorder($temp); | |
| 1335 | + } | |
| 1336 | + $temp = self::getAttributeBoolean($chartDetail->showOutline, 'val'); | |
| 1337 | + if ($temp !== null) { | |
| 1338 | + $dataTable->setShowOutline($temp); | |
| 1339 | + } | |
| 1340 | + $temp = self::getAttributeBoolean($chartDetail->showKeys, 'val'); | |
| 1341 | + if ($temp !== null) { | |
| 1342 | + $dataTable->setShowKeys($temp); | |
| 1343 | + } | |
| 1344 | + | |
| 1345 | + return $dataTable; | |
| 1346 | + } | |
| 1347 | + | |
| 1298 | 1348 | /** @param array<mixed> $plotAttributes */ |
| 1299 | 1349 | private function setChartAttributes(Layout $plotArea, array $plotAttributes): void |
| 1300 | 1350 | { |
| 1301 | 1351 | foreach ($plotAttributes as $plotAttributeKey => $plotAttributeValue) { |
| @@ -1331,8 +1381,13 @@ | ||
| 1331 | 1381 | break; |
| 1332 | 1382 | case 'labelFont': |
| 1333 | 1383 | /** @var ?Font $plotAttributeValue */ |
| 1334 | 1384 | $plotArea->setLabelFont($plotAttributeValue); |
| 1385 | + | |
| 1386 | + break; | |
| 1387 | + case 'bodyPr': | |
| 1388 | + /** @var mixed $plotAttributeValue */ | |
| 1389 | + $plotArea->setBodyPr($plotAttributeValue); | |
| 1335 | 1390 | |
| 1336 | 1391 | break; |
| 1337 | 1392 | } |
| 1338 | 1393 | } |