diff --git a/docs/changes/1.1.0.md b/docs/changes/1.1.0.md index 1c4757927..eb19d3b37 100644 --- a/docs/changes/1.1.0.md +++ b/docs/changes/1.1.0.md @@ -17,6 +17,7 @@ - PowerPoint2077 Writer : Fixed broken PPT Presentations due to MS Office update 2309 - [@WFarmerEthisphere](https://github.com/WFarmerEthisphere) in [#770](https://github.com/PHPOffice/PHPPresentation/pull/770) - PowerPoint2077 Writer : Fixed error when defining min/max bounds to 0 - [@LilyEssence](https://github.com/LilyEssence) in [#771](https://github.com/PHPOffice/PHPPresentation/pull/771) - PowerPoint2007 Writer : Outline : Fixed the base unit - [@Pakku](https://github.com/Pakku) in [#772](https://github.com/PHPOffice/PHPPresentation/pull/772) +- PowerPoint2007 Writer : Fixed column indices for embedded spreadsheets - [@michael-roth](https://github.com/michael-roth) in [#773](https://github.com/PHPOffice/PHPPresentation/pull/773) ## BC Breaks - `PhpOffice\PhpPresentation\Style\Outline` : the width is now based on pixels (before in points) \ No newline at end of file diff --git a/src/PhpPresentation/Shape/Chart/Type/AbstractTypeBar.php b/src/PhpPresentation/Shape/Chart/Type/AbstractTypeBar.php index 612119598..751b23371 100644 --- a/src/PhpPresentation/Shape/Chart/Type/AbstractTypeBar.php +++ b/src/PhpPresentation/Shape/Chart/Type/AbstractTypeBar.php @@ -22,7 +22,7 @@ /** * \PhpOffice\PhpPresentation\Shape\Chart\Type\Bar. */ -class AbstractTypeBar extends AbstractType +abstract class AbstractTypeBar extends AbstractType { /** Orientation of bars */ public const DIRECTION_VERTICAL = 'col'; diff --git a/src/PhpPresentation/Shape/Chart/Type/AbstractTypeLine.php b/src/PhpPresentation/Shape/Chart/Type/AbstractTypeLine.php index 81b08bd05..159ca586a 100644 --- a/src/PhpPresentation/Shape/Chart/Type/AbstractTypeLine.php +++ b/src/PhpPresentation/Shape/Chart/Type/AbstractTypeLine.php @@ -19,7 +19,7 @@ namespace PhpOffice\PhpPresentation\Shape\Chart\Type; -class AbstractTypeLine extends AbstractType +abstract class AbstractTypeLine extends AbstractType { /** * Is Line Smooth? diff --git a/src/PhpPresentation/Shape/Chart/Type/AbstractTypePie.php b/src/PhpPresentation/Shape/Chart/Type/AbstractTypePie.php index 402d818ec..0583067bd 100644 --- a/src/PhpPresentation/Shape/Chart/Type/AbstractTypePie.php +++ b/src/PhpPresentation/Shape/Chart/Type/AbstractTypePie.php @@ -22,7 +22,7 @@ /** * \PhpOffice\PhpPresentation\Shape\Chart\Type\Bar. */ -class AbstractTypePie extends AbstractType +abstract class AbstractTypePie extends AbstractType { /** * Create a new self instance. diff --git a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php index ce0e5ff42..c65081ed7 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php @@ -253,20 +253,20 @@ protected function writeSpreadsheet(PhpPresentation $presentation, Chart $chart, $seriesIndex = 0; foreach ($chart->getPlotArea()->getType()->getSeries() as $series) { // Title - $sheet->setCellValueByColumnAndRow(1 + $seriesIndex, 1, $series->getTitle()); + $sheet->setCellValueByColumnAndRow(2 + $seriesIndex, 1, $series->getTitle()); // X-axis $axisXData = array_keys($series->getValues()); $numAxisXData = count($axisXData); for ($i = 0; $i < $numAxisXData; ++$i) { - $sheet->setCellValueByColumnAndRow(0, $i + 2, $axisXData[$i]); + $sheet->setCellValueByColumnAndRow(1, $i + 2, $axisXData[$i]); } // Y-axis $axisYData = array_values($series->getValues()); $numAxisYData = count($axisYData); for ($i = 0; $i < $numAxisYData; ++$i) { - $sheet->setCellValueByColumnAndRow(1 + $seriesIndex, $i + 2, $axisYData[$i]); + $sheet->setCellValueByColumnAndRow(2 + $seriesIndex, $i + 2, $axisYData[$i]); } ++$seriesIndex; @@ -723,7 +723,7 @@ protected function writeTypeArea(XMLWriter $objWriter, Area $subject, bool $incl // c:ser > c:tx $objWriter->startElement('c:tx'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : ''); $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords); $objWriter->endElement(); @@ -768,7 +768,7 @@ protected function writeTypeArea(XMLWriter $objWriter, Area $subject, bool $incl // c:val $objWriter->startElement('c:val'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : ''); $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords); $objWriter->endElement(); @@ -829,7 +829,7 @@ protected function writeTypeBar(XMLWriter $objWriter, Bar $subject, bool $includ // c:tx $objWriter->startElement('c:tx'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : ''); $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords); $objWriter->endElement(); @@ -965,7 +965,7 @@ protected function writeTypeBar(XMLWriter $objWriter, Bar $subject, bool $includ // c:val $objWriter->startElement('c:val'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : ''); $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords); $objWriter->endElement(); @@ -1040,7 +1040,7 @@ protected function writeTypeBar3D(XMLWriter $objWriter, Bar3D $subject, bool $in // c:tx $objWriter->startElement('c:tx'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : ''); $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords); $objWriter->endElement(); @@ -1161,7 +1161,7 @@ protected function writeTypeBar3D(XMLWriter $objWriter, Bar3D $subject, bool $in // c:val $objWriter->startElement('c:val'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : ''); $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords); $objWriter->endElement(); @@ -1226,7 +1226,7 @@ protected function writeTypeDoughnut(XMLWriter $objWriter, Doughnut $subject, bo // c:tx $objWriter->startElement('c:tx'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : ''); $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords); $objWriter->endElement(); @@ -1258,7 +1258,7 @@ protected function writeTypeDoughnut(XMLWriter $objWriter, Doughnut $subject, bo // c:val $objWriter->startElement('c:val'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : ''); $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords); $objWriter->endElement(); @@ -1271,14 +1271,6 @@ protected function writeTypeDoughnut(XMLWriter $objWriter, Doughnut $subject, bo // c:dLbls $objWriter->startElement('c:dLbls'); - $this->writeElementWithValAttribute($objWriter, 'c:showLegendKey', $series->hasShowLegendKey() ? '1' : '0'); - $this->writeElementWithValAttribute($objWriter, 'c:showVal', $series->hasShowValue() ? '1' : '0'); - $this->writeElementWithValAttribute($objWriter, 'c:showCatName', $series->hasShowCategoryName() ? '1' : '0'); - $this->writeElementWithValAttribute($objWriter, 'c:showSerName', $series->hasShowSeriesName() ? '1' : '0'); - $this->writeElementWithValAttribute($objWriter, 'c:showPercent', $series->hasShowPercentage() ? '1' : '0'); - $this->writeElementWithValAttribute($objWriter, 'c:showBubbleSize', '0'); - $this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0'); - if ($series->hasDlblNumFormat()) { //c:numFmt $objWriter->startElement('c:numFmt'); @@ -1334,6 +1326,14 @@ protected function writeTypeDoughnut(XMLWriter $objWriter, Doughnut $subject, bo // c:dLbls\c:txPr\ $objWriter->endElement(); + $this->writeElementWithValAttribute($objWriter, 'c:showLegendKey', $series->hasShowLegendKey() ? '1' : '0'); + $this->writeElementWithValAttribute($objWriter, 'c:showVal', $series->hasShowValue() ? '1' : '0'); + $this->writeElementWithValAttribute($objWriter, 'c:showCatName', $series->hasShowCategoryName() ? '1' : '0'); + $this->writeElementWithValAttribute($objWriter, 'c:showSerName', $series->hasShowSeriesName() ? '1' : '0'); + $this->writeElementWithValAttribute($objWriter, 'c:showPercent', $series->hasShowPercentage() ? '1' : '0'); + $this->writeElementWithValAttribute($objWriter, 'c:showBubbleSize', '0'); + $this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0'); + $separator = $series->getSeparator(); if (!empty($separator) && PHP_EOL != $separator) { // c:dLbls\c:separator @@ -1383,7 +1383,7 @@ protected function writeTypePie(XMLWriter $objWriter, Pie $subject, bool $includ // c:tx $objWriter->startElement('c:tx'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : ''); $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords); $objWriter->endElement(); @@ -1501,7 +1501,7 @@ protected function writeTypePie(XMLWriter $objWriter, Pie $subject, bool $includ // c:val $objWriter->startElement('c:val'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : ''); $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords); $objWriter->endElement(); @@ -1546,7 +1546,7 @@ protected function writeTypePie3D(XMLWriter $objWriter, Pie3D $subject, bool $in // c:tx $objWriter->startElement('c:tx'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : ''); $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords); $objWriter->endElement(); @@ -1658,7 +1658,7 @@ protected function writeTypePie3D(XMLWriter $objWriter, Pie3D $subject, bool $in // c:val $objWriter->startElement('c:val'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : ''); $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords); $objWriter->endElement(); @@ -1703,7 +1703,7 @@ protected function writeTypeLine(XMLWriter $objWriter, Line $subject, bool $incl // c:tx $objWriter->startElement('c:tx'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : ''); $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords); $objWriter->endElement(); @@ -1805,7 +1805,7 @@ protected function writeTypeLine(XMLWriter $objWriter, Line $subject, bool $incl // c:val $objWriter->startElement('c:val'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : ''); $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords); $objWriter->endElement(); @@ -1875,10 +1875,19 @@ protected function writeTypeRadar(XMLWriter $objWriter, Radar $subject, bool $in // c:tx $objWriter->startElement('c:tx'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : ''); $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords); $objWriter->endElement(); + // c:spPr + $objWriter->startElement('c:spPr'); + // Write fill + $this->writeFill($objWriter, $series->getFill()); + // Write outline + $this->writeOutline($objWriter, $series->getOutline()); + // ## c:spPr + $objWriter->endElement(); + // Marker $this->writeSeriesMarker($objWriter, $series->getMarker()); @@ -1957,15 +1966,6 @@ protected function writeTypeRadar(XMLWriter $objWriter, Radar $subject, bool $in $objWriter->endElement(); - // c:spPr - $objWriter->startElement('c:spPr'); - // Write fill - $this->writeFill($objWriter, $series->getFill()); - // Write outline - $this->writeOutline($objWriter, $series->getOutline()); - // ## c:spPr - $objWriter->endElement(); - // Write X axis data $axisXData = array_keys($series->getValues()); @@ -1979,15 +1979,10 @@ protected function writeTypeRadar(XMLWriter $objWriter, Radar $subject, bool $in // c:val $objWriter->startElement('c:val'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : ''); $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords); $objWriter->endElement(); - // c:smooth - $objWriter->startElement('c:smooth'); - $objWriter->writeAttribute('val', '0'); - $objWriter->endElement(); - $objWriter->endElement(); ++$seriesIndex; @@ -2042,7 +2037,7 @@ protected function writeTypeScatter(XMLWriter $objWriter, Scatter $subject, bool // c:tx $objWriter->startElement('c:tx'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(1 + $seriesIndex) . '$1' : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex(2 + $seriesIndex) . '$1' : ''); $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords); $objWriter->endElement(); @@ -2153,7 +2148,7 @@ protected function writeTypeScatter(XMLWriter $objWriter, Scatter $subject, bool // c:yVal $objWriter->startElement('c:yVal'); - $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : ''); + $coords = ($includeSheet ? 'Sheet1!$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$2:$' . Coordinate::stringFromColumnIndex($seriesIndex + 2) . '$' . (1 + count($axisYData)) : ''); $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords); $objWriter->endElement(); diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php index cfb193dcd..9ca8aadc1 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php @@ -99,15 +99,21 @@ public function testChartDisplayBlankAs(): void $this->assertIsSchemaECMA376Valid(); } - public function testChartIncludeSpreadsheet(): void + /** + * @dataProvider dataProviderIncludedSpreadsheet + */ + public function testChartIncludeSpreadsheet(string $chartType, string $chartElementName): void { $oSlide = $this->oPresentation->getActiveSlide(); $oShape = $oSlide->createChartShape(); $oShape->setIncludeSpreadsheet(true); - $oLine = new Line(); + /** @var AbstractType $oChart */ + $oChart = new $chartType(); $oSeries = new Series('Downloads', $this->seriesData); - $oLine->addSeries($oSeries); - $oShape->getPlotArea()->setType($oLine); + $oChart->addSeries($oSeries); + $oShape->getPlotArea()->setType($oChart); + + $chartBaseXmlPath = sprintf('/c:chartSpace/c:chart/c:plotArea/%s', $chartElementName); self::assertTrue($oShape->hasIncludedSpreadsheet()); @@ -120,24 +126,35 @@ public function testChartIncludeSpreadsheet(): void $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData'; $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart'; + $element = $chartBaseXmlPath; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser'; + $element = $chartBaseXmlPath . '/c:ser'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:v'; + $this->assertZipXmlElementCount('ppt/charts/' . $oShape->getIndexedFilename(), $element, 1); + $element = $chartBaseXmlPath . '/c:ser/c:tx/c:v'; $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:strRef'; + $element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:strRef/c:f'; + $element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:f'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'Sheet1!$A$1'); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:strRef/c:strCache'; + $this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'Sheet1!$B$1'); + $element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:strRef/c:strCache/c:pt'; + $element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache/c:pt'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:strRef/c:strCache/c:pt/c:v'; + $element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache/c:pt/c:v'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); $this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'Downloads'); + + $element = $chartBaseXmlPath . '/c:ser/c:val/c:numRef/c:numCache/c:pt/c:v'; + if ($oChart instanceof Scatter) { + $element = $chartBaseXmlPath . '/c:ser/c:yVal/c:numRef/c:numCache/c:pt/c:v'; + } + $this->assertZipXmlElementCount('ppt/charts/' . $oShape->getIndexedFilename(), $element, count($this->seriesData)); + foreach (array_values($this->seriesData) as $index => $value) { + $this->assertZipXmlElementAtIndexEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $index, $value); + } + $element = '/c:chartSpace/c:externalData'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); $this->assertZipXmlAttributeExists('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'r:id'); @@ -160,11 +177,11 @@ public function testChartIncludeSpreadsheet(): void $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData'; $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart'; + $element = $chartBaseXmlPath; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser'; + $element = $chartBaseXmlPath . '/c:ser'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); - $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:v'; + $element = $chartBaseXmlPath . '/c:ser/c:tx/c:v'; $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); $this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'Downloads'); $element = '/c:chartSpace/c:externalData'; @@ -1623,4 +1640,25 @@ public static function dataProviderMarkerSymbol(): iterable yield [$symbol]; } } + + /** + * @return array> + */ + public function dataProviderIncludedSpreadsheet(): iterable + { + $chartTypes = [ + [Area::class, 'c:areaChart'], + [Bar::class, 'c:barChart'], + [Bar3D::class, 'c:bar3DChart'], + [Doughnut::class, 'c:doughnutChart'], + [Pie::class, 'c:pieChart'], + [Pie3D::class, 'c:pie3DChart'], + [Line::class, 'c:lineChart'], + [Radar::class, 'c:radarChart'], + [Scatter::class, 'c:scatterChart'], + ]; + foreach ($chartTypes as $chartType) { + yield $chartType; + } + } } diff --git a/tests/PhpPresentation/Tests/_includes/PhpPresentationTestCase.php b/tests/PhpPresentation/Tests/_includes/PhpPresentationTestCase.php index 2d3ebbe47..76a16318a 100644 --- a/tests/PhpPresentation/Tests/_includes/PhpPresentationTestCase.php +++ b/tests/PhpPresentation/Tests/_includes/PhpPresentationTestCase.php @@ -268,6 +268,28 @@ public function assertZipXmlElementExists($filePath, $xPath): void ); } + /** + * @param string $filePath + * @param string $xPath + * @param int $index + */ + public function assertZipXmlElementAtIndexExists(string $filePath, string $xPath, int $index): void + { + $this->writePresentationFile($this->oPresentation, $this->writerName); + $nodeList = $this->getXmlNodeList($filePath, $xPath); + $element = $nodeList->item($index); + self::assertNotEquals( + null, + $element, + sprintf( + 'The element "%s" at index %d doesn\'t exist in the file "%s"', + $xPath, + $index, + $filePath + ) + ); + } + /** * @param string $filePath * @param string $xPath @@ -299,6 +321,19 @@ public function assertZipXmlElementEquals($filePath, $xPath, $value): void self::assertEquals($nodeList->item(0)->nodeValue, $value); } + /** + * @param string $filePath + * @param string $xPath + * @param int $index + * @param mixed $value + */ + public function assertZipXmlElementAtIndexEquals(string $filePath, string $xPath, int $index, $value): void + { + $this->writePresentationFile($this->oPresentation, $this->writerName); + $nodeList = $this->getXmlNodeList($filePath, $xPath); + self::assertEquals($nodeList->item($index)->nodeValue, $value); + } + /** * @param string $filePath * @param string $xPath @@ -308,7 +343,7 @@ public function assertZipXmlElementCount($filePath, $xPath, $num): void { $this->writePresentationFile($this->oPresentation, $this->writerName); $nodeList = $this->getXmlNodeList($filePath, $xPath); - self::assertEquals($nodeList->length, $num); + self::assertEquals($num, $nodeList->length); } /**