From 97ffc75ed20f0d320d2e1caaa6f59f87596069e5 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Mon, 6 Mar 2017 22:51:29 +0100 Subject: [PATCH] #293 : PowerPoint2007 Writer : Support autoscale for Chart --- CHANGELOG.md | 1 + docs/shapes_chart.rst | 9 +++++++++ .../Writer/PowerPoint2007/PptCharts.php | 9 ++++----- .../Writer/PowerPoint2007/PptChartsTest.php | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f447c2e9a..f77bcbf03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - PowerPoint2007 Writer : Support text direction in Alignment for Table - @SeregPie GH-218 - PowerPoint2007 Writer : Support tick mark & unit in Axis for Chart - @Faab GH-218 - PowerPoint2007 Writer : Support separator in Series for Chart - @jphchaput GH-218 +- PowerPoint2007 Writer : Support autoscale for Chart - @Progi1984 GH-293 - Misc : Added two methods for setting Border & Fill in Legend - @Progi1984 GH-265 ## 0.7.0 - 2016-09-12 diff --git a/docs/shapes_chart.rst b/docs/shapes_chart.rst index e6ef4c9a0..d69d7f67d 100644 --- a/docs/shapes_chart.rst +++ b/docs/shapes_chart.rst @@ -145,6 +145,15 @@ You can define if some informations are displayed. $oSeries->setShowSeriesName(true); $oSeries->setShowValue(true); +View3D +^^^^^^ + +For enabling the autoscale for a shape, you must reset the height percent. + +.. code-block:: php + + $oShape->getView3D()->setHeightPercent(null); + Types ----- diff --git a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php index 2a2130df6..8828d6bab 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php @@ -97,16 +97,15 @@ public function writeChart(Chart $chart) $objWriter->writeAttribute('val', $chart->getView3D()->getRotationX()); $objWriter->endElement(); - // c:hPercent - $objWriter->startElement('c:hPercent'); - $objWriter->writeAttribute('val', $chart->getView3D()->getHeightPercent()); - $objWriter->endElement(); - // c:rotY $objWriter->startElement('c:rotY'); $objWriter->writeAttribute('val', $chart->getView3D()->getRotationY()); $objWriter->endElement(); + // c:hPercent + $hPercent = $chart->getView3D()->getHeightPercent(); + $objWriter->writeElementIf($hPercent != null, 'c:hPercent', 'val', $hPercent); + // c:depthPercent $objWriter->startElement('c:depthPercent'); $objWriter->writeAttribute('val', $chart->getView3D()->getDepthPercent()); diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php index 9bc4bc777..f2bb3296d 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php @@ -843,4 +843,22 @@ public function testTypeScatterSuperScript() $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'baseline', '30000'); } + + public function testView3D() + { + $oSlide = $this->oPresentation->getActiveSlide(); + $oLine = new Line(); + $oLine->addSeries(new Series('Downloads', $this->seriesData)); + $oShape = $oSlide->createChartShape(); + $oShape->getPlotArea()->setType($oLine); + + $element = '/c:chartSpace/c:chart/c:view3D/c:hPercent'; + $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); + $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 100); + + $oShape->getView3D()->setHeightPercent(null); + $this->resetPresentationFile(); + + $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); + } }