diff --git a/.gitignore b/.gitignore index d0a44e14a..bf0d32476 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ .Trashes Thumbs.db Desktop.ini +.idea/ ### Continuous Integration build/ diff --git a/docs/changes/1.2.0.md b/docs/changes/1.2.0.md index 0c03ba6bc..4247f38b8 100644 --- a/docs/changes/1.2.0.md +++ b/docs/changes/1.2.0.md @@ -16,6 +16,7 @@ - PowerPoint2007 Reader : Support for BarChart by [@Progi1984](https://github.com/Progi1984) fixing [#824](https://github.com/PHPOffice/PHPPresentation/pull/824) in [#856](https://github.com/PHPOffice/PHPPresentation/pull/856) - `phpoffice/phpspreadsheet`: Allow version 4.0 by [@nreynis](https://github.com/nreynis) in [#861](https://github.com/PHPOffice/PHPPresentation/pull/861) - Smaller package size by [@nreynis](https://github.com/nreynis) in [#862](https://github.com/PHPOffice/PHPPresentation/pull/862) +- Added setFirstSliceAngle to Doughnut Chart by [@seanlynchwv](http://github.com/seanlynchwv) in [#872](https://github.com/PHPOffice/PHPPresentation/pull/872) ## Bug fixes diff --git a/src/PhpPresentation/Shape/Chart/Type/Doughnut.php b/src/PhpPresentation/Shape/Chart/Type/Doughnut.php index 6f2437f67..77074e051 100644 --- a/src/PhpPresentation/Shape/Chart/Type/Doughnut.php +++ b/src/PhpPresentation/Shape/Chart/Type/Doughnut.php @@ -34,6 +34,13 @@ class Doughnut extends AbstractTypePie implements ComparableInterface */ protected $holeSize = 50; + /** + * Starting angle of the first slice. + * + * @var int + */ + private $firstSliceAngle = 0; + /** * @return int */ @@ -71,4 +78,16 @@ public function getHashCode(): string { return md5(parent::getHashCode() . __CLASS__); } + + public function setFirstSliceAngle(int $angle): self + { + $this->firstSliceAngle = (($angle % 360) + 360) % 360; + + return $this; + } + + public function getFirstSliceAngle(): int + { + return $this->firstSliceAngle; + } } diff --git a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php index a9a0ec758..e9f508b5c 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php @@ -115,38 +115,40 @@ protected function writeChart(Chart $chart): string $objWriter->endElement(); // c:view3D - $objWriter->startElement('c:view3D'); + if ($chart->getPlotArea()->getType() instanceof Bar3D || $chart->getPlotArea()->getType() instanceof Pie3D) { + $objWriter->startElement('c:view3D'); - // c:rotX - $objWriter->startElement('c:rotX'); - $objWriter->writeAttribute('val', $chart->getView3D()->getRotationX()); - $objWriter->endElement(); + // c:rotX + $objWriter->startElement('c:rotX'); + $objWriter->writeAttribute('val', $chart->getView3D()->getRotationX()); + $objWriter->endElement(); - // c:hPercent - $hPercent = $chart->getView3D()->getHeightPercent(); - $objWriter->writeElementIf(null != $hPercent, 'c:hPercent', 'val', $hPercent); + // c:hPercent + $hPercent = $chart->getView3D()->getHeightPercent(); + $objWriter->writeElementIf(null != $hPercent, 'c:hPercent', 'val', $hPercent); - // c:rotY - $objWriter->startElement('c:rotY'); - $objWriter->writeAttribute('val', $chart->getView3D()->getRotationY()); - $objWriter->endElement(); + // c:rotY + $objWriter->startElement('c:rotY'); + $objWriter->writeAttribute('val', $chart->getView3D()->getRotationY()); + $objWriter->endElement(); - // c:depthPercent - $objWriter->startElement('c:depthPercent'); - $objWriter->writeAttribute('val', $chart->getView3D()->getDepthPercent()); - $objWriter->endElement(); + // c:depthPercent + $objWriter->startElement('c:depthPercent'); + $objWriter->writeAttribute('val', $chart->getView3D()->getDepthPercent()); + $objWriter->endElement(); - // c:rAngAx - $objWriter->startElement('c:rAngAx'); - $objWriter->writeAttribute('val', $chart->getView3D()->hasRightAngleAxes() ? '1' : '0'); - $objWriter->endElement(); + // c:rAngAx + $objWriter->startElement('c:rAngAx'); + $objWriter->writeAttribute('val', $chart->getView3D()->hasRightAngleAxes() ? '1' : '0'); + $objWriter->endElement(); - // c:perspective - $objWriter->startElement('c:perspective'); - $objWriter->writeAttribute('val', $chart->getView3D()->getPerspective()); - $objWriter->endElement(); + // c:perspective + $objWriter->startElement('c:perspective'); + $objWriter->writeAttribute('val', $chart->getView3D()->getPerspective()); + $objWriter->endElement(); - $objWriter->endElement(); + $objWriter->endElement(); + } // Write plot area $this->writePlotArea($objWriter, $chart->getPlotArea(), $chart); @@ -1352,7 +1354,10 @@ protected function writeTypeDoughnut(XMLWriter $objWriter, Doughnut $subject, bo $objWriter->endElement(); } - $this->writeElementWithValAttribute($objWriter, 'c:firstSliceAng', '0'); + if (($angle = $subject->getFirstSliceAngle()) !== null) { + $this->writeElementWithValAttribute($objWriter, 'c:firstSliceAng', (string) $angle); + } + $this->writeElementWithValAttribute($objWriter, 'c:holeSize', (string) $subject->getHoleSize()); $objWriter->endElement(); diff --git a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php index 21ff6c5ac..7f6694375 100644 --- a/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php +++ b/tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php @@ -1809,20 +1809,38 @@ public function testTypeScatterSuperScript(): void public function testView3D(): void { $oSlide = $this->oPresentation->getActiveSlide(); - $oLine = new Line(); - $oLine->addSeries(new Series('Downloads', $this->seriesData)); - $oShape = $oSlide->createChartShape(); - $oShape->getPlotArea()->setType($oLine); + $shape3d = $oSlide->createChartShape(); + $shape3d->getPlotArea()->setType(new Bar3D()); $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'); + $this->assertZipXmlElementExists('ppt/charts/' . $shape3d->getIndexedFilename(), $element); + $this->assertZipXmlAttributeEquals('ppt/charts/' . $shape3d->getIndexedFilename(), $element, 'val', '100'); $this->assertIsSchemaECMA376Valid(); - $oShape->getView3D()->setHeightPercent(null); + $shape3d->getView3D()->setHeightPercent(null); $this->resetPresentationFile(); - $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $element); + $this->assertZipXmlElementNotExists('ppt/charts/' . $shape3d->getIndexedFilename(), $element); + $this->assertIsSchemaECMA376Valid(); + } + + public function testDoughnutFirstSliceAngle(): void + { + $slide = $this->oPresentation->getActiveSlide(); + $shape = $slide->createChartShape(); + + $doughnut = new Doughnut(); + $doughnut->setFirstSliceAngle(90); + $doughnut->addSeries(new Series('Downloads', $this->seriesData)); + + $shape->getPlotArea()->setType($doughnut); + + $path = 'ppt/charts/' . $shape->getIndexedFilename(); + $elt = '/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:firstSliceAng'; + + $this->assertZipXmlElementExists($path, $elt); + $this->assertZipXmlAttributeEquals($path, $elt, 'val', '90'); + $this->assertIsSchemaECMA376Valid(); }