Skip to content

Commit 2bd0670

Browse files
committed
#356 : PowerPoint2007 Writer : Implement visibility for axis (Docs)
2 parents 28bd7e8 + 44d670e commit 2bd0670

File tree

6 files changed

+66
-13
lines changed

6 files changed

+66
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
### Features
99
- PowerPoint2007 Writer : Implemented XSD validation test case according to the ECMA/ISO standard - @k42b3 GH-307
10+
- PowerPoint2007 Writer : Implement visibility for axis - @kw-pr @Progi1984 GH-356
1011
- PowerPoint2007 Writer : Implement gap width in Bar(3D) Charts - @Progi1984 GH-358
1112

1213
## 0.8.0 - 2017-04-03

docs/shapes_chart.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ For resetting them, you pass null as parameter to these methods.
8787
$oShape->getPlotArea()->getAxisY()->setMinorUnit(null);
8888
$oShape->getPlotArea()->getAxisY()->setMajorUnit(0.05);
8989
90+
You can define visibility for each axis (X & Y).
91+
92+
.. code-block:: php
93+
94+
$oLine = new Line();
95+
96+
$oShape = $oSlide->createChartShape();
97+
$oShape->getPlotArea()->setType($oLine);
98+
$oShape->getPlotArea()->getAxisX()->setIsVisible(false);
99+
90100
Title
91101
^^^^^
92102

src/PhpPresentation/Shape/Chart/Axis.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ class Axis implements ComparableInterface
101101
protected $outline;
102102

103103
/**
104-
* @var int
104+
* @var boolean
105105
*/
106-
protected $delete = 0;
106+
protected $isVisible = true;
107107

108108
/**
109109
* Create a new \PhpOffice\PhpPresentation\Shape\Chart\Axis instance
@@ -385,6 +385,7 @@ public function getHashIndex()
385385
* while doing a write of a workbook and when changes are not allowed.
386386
*
387387
* @param string $value Hash index
388+
* @return $this
388389
*/
389390
public function setHashIndex($value)
390391
{
@@ -393,24 +394,23 @@ public function setHashIndex($value)
393394
}
394395

395396
/**
396-
* Axis deleted and not visible?
397-
*
398-
* @return int Hash index
397+
* Axis is hidden ?
398+
* @return boolean
399399
*/
400-
public function getDelete()
400+
public function isVisible()
401401
{
402-
return $this->delete;
402+
return $this->isVisible;
403403
}
404404

405405
/**
406-
* Remove an axis.
407-
* 0 not deleted, 1 = deleted and not visible
406+
* Hide an axis
408407
*
409-
* @param int $value delete
408+
* @param boolean $value delete
409+
* @return $this
410410
*/
411-
public function setDelete($value)
411+
public function setIsVisible($value)
412412
{
413-
$this->delete = $value;
413+
$this->isVisible = (bool)$value;
414414
return $this;
415415
}
416416
}

src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, $typeAxis,
20122012

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

20182018
// $mainElement > c:axPos

tests/PhpPresentation/Tests/Shape/Chart/AxisTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ public function testHashIndex()
9696
$this->assertEquals($value, $object->getHashIndex());
9797
}
9898

99+
public function testIsVisible()
100+
{
101+
$object = new Axis();
102+
$this->assertTrue($object->isVisible());
103+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setIsVisible(false));
104+
$this->assertFalse($object->isVisible());
105+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setIsVisible(true));
106+
$this->assertTrue($object->isVisible());
107+
}
108+
99109
public function testTitle()
100110
{
101111
$object = new Axis();

tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptChartsTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,38 @@ public function testAxisOutline()
165165
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $expectedColorY);
166166
}
167167

168+
public function testAxisVisibilityFalse()
169+
{
170+
$element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:delete';
171+
172+
$oSlide = $this->oPresentation->getActiveSlide();
173+
$oShape = $oSlide->createChartShape();
174+
$oLine = new Line();
175+
$oShape->getPlotArea()->setType($oLine);
176+
177+
// Set Visible : FALSE
178+
$this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\Chart\Axis', $oShape->getPlotArea()->getAxisX()->setIsVisible(false));
179+
$this->assertFalse($oShape->getPlotArea()->getAxisX()->isVisible());
180+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
181+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '1');
182+
}
183+
184+
public function testAxisVisibilityTrue()
185+
{
186+
$element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:delete';
187+
188+
$oSlide = $this->oPresentation->getActiveSlide();
189+
$oShape = $oSlide->createChartShape();
190+
$oLine = new Line();
191+
$oShape->getPlotArea()->setType($oLine);
192+
193+
// Set Visible : TRUE
194+
$this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\Chart\Axis', $oShape->getPlotArea()->getAxisX()->setIsVisible(true));
195+
$this->assertTrue($oShape->getPlotArea()->getAxisX()->isVisible());
196+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
197+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '0');
198+
}
199+
168200
public function testTypeArea()
169201
{
170202
$oSlide = $this->oPresentation->getActiveSlide();

0 commit comments

Comments
 (0)