Skip to content

Commit

Permalink
fix problem where axis cannot be set to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyEssence committed Aug 31, 2023
1 parent 1d5b988 commit ab20a4a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2319,13 +2319,13 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, string $ty
$objWriter->writeAttribute('val', $orientation);
$objWriter->endElement();

if (null != $oAxis->getMaxBounds()) {
if (null !== $oAxis->getMaxBounds()) {
$objWriter->startElement('c:max');
$objWriter->writeAttribute('val', $oAxis->getMaxBounds());
$objWriter->endElement();
}

if (null != $oAxis->getMinBounds()) {
if (null !== $oAxis->getMinBounds()) {
$objWriter->startElement('c:min');
$objWriter->writeAttribute('val', $oAxis->getMinBounds());
$objWriter->endElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,57 @@ public function testTitleVisibilityFalse(): void
public function testAxisBounds(): void
{
$value = mt_rand(0, 100);
$value = 0;

$oSeries = new Series('Downloads', $this->seriesData);
$oSeries->getFill()->setStartColor(new Color('FFAABBCC'));
$oLine = new Line();
$oLine->addSeries($oSeries);
$oShape = $this->oPresentation->getActiveSlide()->createChartShape();
$oShape->getPlotArea()->setType($oLine);

$elementMax = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:scaling/c:max';
$elementMin = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:scaling/c:min';

$this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
$this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);

$this->assertIsSchemaECMA376Valid();

$oShape->getPlotArea()->getAxisX()->setMinBounds($value);
$this->resetPresentationFile();

$this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', $value);

$this->assertIsSchemaECMA376Valid();

$oShape->getPlotArea()->getAxisX()->setMinBounds(null);
$oShape->getPlotArea()->getAxisX()->setMaxBounds($value);
$this->resetPresentationFile();

$this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value);

$this->assertIsSchemaECMA376Valid();

$oShape->getPlotArea()->getAxisX()->setMinBounds($value);
$oShape->getPlotArea()->getAxisX()->setMaxBounds($value);
$this->resetPresentationFile();

$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', $value);
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value);

$this->assertIsSchemaECMA376Valid();
}

public function testAxisBoundsIfZero(): void
{
$value = 0;

$oSeries = new Series('Downloads', $this->seriesData);
$oSeries->getFill()->setStartColor(new Color('FFAABBCC'));
Expand Down

0 comments on commit ab20a4a

Please sign in to comment.