Skip to content

Commit

Permalink
Merge pull request #336 from Progi1984/issue319
Browse files Browse the repository at this point in the history
#319 : PowerPoint2007 Writer : Implement Legend Key in Series for Chart
  • Loading branch information
Progi1984 authored Mar 5, 2017
2 parents 89b566d + ccc441d commit 0889665
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- ODPresentation Writer : Axis Bounds in Chart - @Progi1984 GH-269
- PowerPoint2007 Writer : Implement character spacing - @jvanoostrom GH-301
- PowerPoint2007 Writer : Axis Bounds in Chart - @Progi1984 GH-269
- PowerPoint2007 Writer : Implement Legend Key in Series for Chart - @Progi1984 GH-319
- Misc : Added two methods for setting Border & Fill in Legend - @Progi1984 GH-265

## 0.7.0 - 2016-09-12
Expand Down
12 changes: 12 additions & 0 deletions docs/shapes_chart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ Each position is described in `MSDN <https://msdn.microsoft.com/en-us/library/mt
$oSeries = new Series('Downloads', $seriesData);
$oSeries->setLabelPosition(Series::LABEL_INSIDEEND);
You can define if some informations are displayed.

.. code-block:: php
$oSeries = new Series('Downloads', $seriesData);
$oSeries->setShowCategoryName(true);
$oSeries->setShowLeaderLines(true);
$oSeries->setShowLegendKey(true);
$oSeries->setShowPercentage(true);
$oSeries->setShowSeriesName(true);
$oSeries->setShowValue(true);
Types
-----

Expand Down
32 changes: 31 additions & 1 deletion src/PhpPresentation/Shape/Chart/Series.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class Series implements ComparableInterface
*/
private $showLeaderLines = true;

/**
* Show Legend Key
*
* @var boolean
*/
private $showLegendKey = false;

/**
* ShowPercentage
*
Expand Down Expand Up @@ -341,6 +348,29 @@ public function setShowCategoryName($value)
return $this;
}

/**
* Get ShowValue
*
* @return boolean
*/
public function hasShowLegendKey()
{
return $this->showLegendKey;
}

/**
* Set ShowValue
*
* @param boolean $value
* @return \PhpOffice\PhpPresentation\Shape\Chart\Series
*/
public function setShowLegendKey($value)
{
$this->showLegendKey = (bool)$value;

return $this;
}

/**
* Get ShowValue
*
Expand All @@ -354,7 +384,7 @@ public function hasShowValue()
/**
* Set ShowValue
*
* @param boolean $value
* @param boolean $value
* @return \PhpOffice\PhpPresentation\Shape\Chart\Series
*/
public function setShowValue($value)
Expand Down
5 changes: 4 additions & 1 deletion src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,9 @@ protected function writeTypePie(XMLWriter $objWriter, Pie $subject, $includeShee
// c:dLblPos
$this->writeElementWithValAttribute($objWriter, 'c:dLblPos', $series->getLabelPosition());

// c:showLegendKey
$this->writeElementWithValAttribute($objWriter, 'c:showLegendKey', $series->hasShowLegendKey() ? '1' : '0');

// c:showVal
$this->writeElementWithValAttribute($objWriter, 'c:showVal', $series->hasShowValue() ? '1' : '0');

Expand Down Expand Up @@ -1802,7 +1805,7 @@ protected function writeTypeScatter(XMLWriter $objWriter, Scatter $subject, $inc
$objWriter->endElement();

// c:showLegendKey
$this->writeElementWithValAttribute($objWriter, 'c:showLegendKey', '0');
$this->writeElementWithValAttribute($objWriter, 'c:showLegendKey', $series->hasShowLegendKey() ? '1' : '0');

// c:showVal
$this->writeElementWithValAttribute($objWriter, 'c:showVal', $series->hasShowValue() ? '1' : '0');
Expand Down
16 changes: 16 additions & 0 deletions tests/PhpPresentation/Tests/Shape/Chart/SeriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function testConstruct()
$this->assertEmpty($object->getValues());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Marker', $object->getMarker());
$this->assertNull($object->getOutline());
$this->assertFalse($object->hasShowLegendKey());
}

public function testDataLabelNumFormat()
Expand Down Expand Up @@ -155,6 +156,21 @@ public function testShowLeaderLines()
$this->assertFalse($object->hasShowLeaderLines());
}

public function testShowLegendKey()
{
$object = new Series();

$this->assertFalse($object->hasShowLegendKey());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(true));
$this->assertTrue($object->hasShowLegendKey());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(false));
$this->assertFalse($object->hasShowLegendKey());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(1));
$this->assertTrue($object->hasShowLegendKey());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(0));
$this->assertFalse($object->hasShowLegendKey());
}

public function testShowPercentage()
{
$object = new Series();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,16 @@ public function testTypePie()
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:tx/c:v';
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
$element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:showLegendKey';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 0);

$oSeries->setShowLegendKey(true);
$this->resetPresentationFile();

$element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:showLegendKey';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 1);
}

public function testTypePie3D()
Expand Down Expand Up @@ -601,6 +611,16 @@ public function testTypeScatter()
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:tx/c:v';
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
$element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:dLbls/c:showLegendKey';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 0);

$oSeries->setShowLegendKey(true);
$this->resetPresentationFile();

$element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:dLbls/c:showLegendKey';
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 1);
}

public function testTypeScatterMarker()
Expand Down

0 comments on commit 0889665

Please sign in to comment.