Skip to content

#356 : PowerPoint2007 Writer : Implement visibility for axis #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- PowerPoint2007 Writer : Write percentage values with a trailing percent sign instead of formatted as 1000th of a percent to comply with the standard - @k42b3 GH-307

### Features
- PowerPoint2007 Writer : Implemented XSD validation test case according to the ECMA/ISO standard - @k42b3 GH-307
- PowerPoint2007 Writer : Implement XSD validation test case according to the ECMA/ISO standard - @k42b3 GH-307
- PowerPoint2007 Writer : Implement visibility for axis - @kw-pr @Progi1984 GH-356

## 0.8.0 - 2017-04-03

Expand Down
10 changes: 10 additions & 0 deletions docs/shapes_chart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ For resetting them, you pass null as parameter to these methods.
$oShape->getPlotArea()->getAxisY()->setMinorUnit(null);
$oShape->getPlotArea()->getAxisY()->setMajorUnit(0.05);

You can define visibility for each axis (X & Y).

.. code-block:: php

$oLine = new Line();

$oShape = $oSlide->createChartShape();
$oShape->getPlotArea()->setType($oLine);
$oShape->getPlotArea()->getAxisX()->setIsVisible(false);

Title
^^^^^

Expand Down
24 changes: 12 additions & 12 deletions src/PhpPresentation/Shape/Chart/Axis.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ class Axis implements ComparableInterface
protected $outline;

/**
* @var int
* @var boolean
*/
protected $delete = 0;
protected $isVisible = true;

/**
* Create a new \PhpOffice\PhpPresentation\Shape\Chart\Axis instance
Expand Down Expand Up @@ -385,6 +385,7 @@ public function getHashIndex()
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
* @return $this
*/
public function setHashIndex($value)
{
Expand All @@ -393,24 +394,23 @@ public function setHashIndex($value)
}

/**
* Axis deleted and not visible?
*
* @return int Hash index
* Axis is hidden ?
* @return boolean
*/
public function getDelete()
public function isVisible()
{
return $this->delete;
return $this->isVisible;
}

/**
* Remove an axis.
* 0 not deleted, 1 = deleted and not visible
* Hide an axis
*
* @param int $value delete
* @param boolean $value delete
* @return $this
*/
public function setDelete($value)
public function setIsVisible($value)
{
$this->delete = $value;
$this->isVisible = (bool)$value;
return $this;
}
}
2 changes: 1 addition & 1 deletion src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, $typeAxis,

// $mainElement > c:delete
$objWriter->startElement('c:delete');
$objWriter->writeAttribute('val', $oAxis->getDelete());
$objWriter->writeAttribute('val', $oAxis->isVisible() ? '0' : '1');
$objWriter->endElement();

// $mainElement > c:axPos
Expand Down
10 changes: 10 additions & 0 deletions tests/PhpPresentation/Tests/Shape/Chart/AxisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ public function testHashIndex()
$this->assertEquals($value, $object->getHashIndex());
}

public function testIsVisible()
{
$object = new Axis();
$this->assertTrue($object->isVisible());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setIsVisible(false));
$this->assertFalse($object->isVisible());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setIsVisible(true));
$this->assertTrue($object->isVisible());
}

public function testTitle()
{
$object = new Axis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,38 @@ public function testAxisOutline()
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $expectedColorY);
}

public function testAxisVisibilityFalse()
{
$element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:delete';

$oSlide = $this->oPresentation->getActiveSlide();
$oShape = $oSlide->createChartShape();
$oLine = new Line();
$oShape->getPlotArea()->setType($oLine);

// Set Visible : FALSE
$this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\Chart\Axis', $oShape->getPlotArea()->getAxisX()->setIsVisible(false));
$this->assertFalse($oShape->getPlotArea()->getAxisX()->isVisible());
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '1');
}

public function testAxisVisibilityTrue()
{
$element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:delete';

$oSlide = $this->oPresentation->getActiveSlide();
$oShape = $oSlide->createChartShape();
$oLine = new Line();
$oShape->getPlotArea()->setType($oLine);

// Set Visible : TRUE
$this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\Chart\Axis', $oShape->getPlotArea()->getAxisX()->setIsVisible(true));
$this->assertTrue($oShape->getPlotArea()->getAxisX()->isVisible());
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '0');
}

public function testTypeArea()
{
$oSlide = $this->oPresentation->getActiveSlide();
Expand Down