Skip to content

Commit

Permalink
Merge pull request #778 from Progi1984/pr671
Browse files Browse the repository at this point in the history
PowerPoint2007 Writer : Fixed issue when first element in series is null
  • Loading branch information
Progi1984 authored Dec 7, 2023
2 parents ce54114 + d5c46c3 commit d9cc4dd
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changes/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- PowerPoint2007 Writer : Fixed column indices for embedded spreadsheets - [@michael-roth](https://github.com/michael-roth) in [#773](https://github.com/PHPOffice/PHPPresentation/pull/773)
- PowerPoint2007 Reader : Load images from file only if valid - [@aelliott1485](https://github.com/aelliott1485) in [#775](https://github.com/PHPOffice/PHPPresentation/pull/775)
- PowerPoint2007 Writer : Fixed broken video file relationship - [@potofcoffee](https://github.com/potofcoffee) in [#776](https://github.com/PHPOffice/PHPPresentation/pull/776)
- PowerPoint2007 Writer : Fixed issue when first element in series is null - [@ksmeeks0001](https://github.com/ksmeeks0001) in [#778](https://github.com/PHPOffice/PHPPresentation/pull/778)

## BC Breaks
- `PhpOffice\PhpPresentation\Style\Outline` : the width is now based on pixels (before in points)
11 changes: 10 additions & 1 deletion src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,16 @@ protected function writeMultipleValuesOrReference(XMLWriter $objWriter, bool $is
// c:strLit / c:numLit
// c:strRef / c:numRef
$referenceType = ($isReference ? 'Ref' : 'Lit');
$dataType = is_numeric($values[0]) ? 'num' : 'str';

// Get data type from first non-null value
$dataType = array_reduce($values, function ($carry, $item) {
if (!isset($item)) {
return $carry;
}

return is_numeric($item) ? 'num' : 'str';
}, 'num');

$objWriter->startElement('c:' . $dataType . $referenceType);

$numValues = count($values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,76 @@ public function testChartDisplayBlankAs(): void
$this->assertIsSchemaECMA376Valid();
}

/**
* @dataProvider dataProviderIncludedSpreadsheet
*/
public function testChartIncludeSpreadsheetNullValue(string $chartType, string $chartElementName): void
{
$seriesData = array_merge(['Z' => null], $this->seriesData);

$oSlide = $this->oPresentation->getActiveSlide();
$oShape = $oSlide->createChartShape();
$oShape->setIncludeSpreadsheet(true);
/** @var AbstractType $oChart */
$oChart = new $chartType();
$oSeries = new Series('Downloads', $seriesData);
$oChart->addSeries($oSeries);
$oShape->getPlotArea()->setType($oChart);

$chartBaseXmlPath = sprintf('/c:chartSpace/c:chart/c:plotArea/%s', $chartElementName);

self::assertTrue($oShape->hasIncludedSpreadsheet());

$this->assertZipFileExists('ppt/charts/' . $oShape->getIndexedFilename());
$this->assertZipFileExists('ppt/embeddings/' . $oShape->getIndexedFilename() . '.xlsx');

$this->assertZipFileExists('ppt/charts/_rels/' . $oShape->getIndexedFilename() . '.rels');
$element = '/Relationships/Relationship[@Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"]';
$this->assertZipXmlElementExists('ppt/charts/_rels/' . $oShape->getIndexedFilename() . '.rels', $element);

$element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
$this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
$element = $chartBaseXmlPath;
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = $chartBaseXmlPath . '/c:ser';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlElementCount('ppt/charts/' . $oShape->getIndexedFilename(), $element, 1);
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:v';
$this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$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!$B$1');
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = $chartBaseXmlPath . '/c:ser/c:tx/c:strRef/c:strCache/c:pt';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$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($seriesData));
foreach (array_values($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');
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'r:id', 'rId1');
$element = '/c:chartSpace/c:externalData/c:autoUpdate';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlAttributeExists('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val');
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '0');

$this->assertIsSchemaECMA376Valid();
}

/**
* @dataProvider dataProviderIncludedSpreadsheet
*/
Expand Down

0 comments on commit d9cc4dd

Please sign in to comment.