Skip to content

Commit

Permalink
Fix xml schema and unit test
Browse files Browse the repository at this point in the history
- Move xml elements in chart writer to fix schema
- Change xml path for Scatter chart test
  • Loading branch information
michael-roth committed Aug 14, 2021
1 parent 64ef59b commit d7d3099
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
39 changes: 17 additions & 22 deletions src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -1280,14 +1280,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');
Expand Down Expand Up @@ -1343,6 +1335,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
Expand Down Expand Up @@ -1898,6 +1898,15 @@ protected function writeTypeRadar(XMLWriter $objWriter, Radar $subject, bool $in
$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());

Expand Down Expand Up @@ -1976,15 +1985,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());

Expand All @@ -2002,11 +2002,6 @@ protected function writeTypeRadar(XMLWriter $objWriter, Radar $subject, bool $in
$this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
$objWriter->endElement();

// c:smooth
$objWriter->startElement('c:smooth');
$objWriter->writeAttribute('val', '0');
$objWriter->endElement();

$objWriter->endElement();

++$seriesIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,16 @@ public function testChartIncludeSpreadsheet(string $chartType): void
$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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,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);
}

/**
Expand Down

0 comments on commit d7d3099

Please sign in to comment.