Skip to content

Commit 0889665

Browse files
authored
Merge pull request #336 from Progi1984/issue319
#319 : PowerPoint2007 Writer : Implement Legend Key in Series for Chart
2 parents 89b566d + ccc441d commit 0889665

File tree

6 files changed

+84
-2
lines changed

6 files changed

+84
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- ODPresentation Writer : Axis Bounds in Chart - @Progi1984 GH-269
1717
- PowerPoint2007 Writer : Implement character spacing - @jvanoostrom GH-301
1818
- PowerPoint2007 Writer : Axis Bounds in Chart - @Progi1984 GH-269
19+
- PowerPoint2007 Writer : Implement Legend Key in Series for Chart - @Progi1984 GH-319
1920
- Misc : Added two methods for setting Border & Fill in Legend - @Progi1984 GH-265
2021

2122
## 0.7.0 - 2016-09-12

docs/shapes_chart.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ Each position is described in `MSDN <https://msdn.microsoft.com/en-us/library/mt
104104
$oSeries = new Series('Downloads', $seriesData);
105105
$oSeries->setLabelPosition(Series::LABEL_INSIDEEND);
106106
107+
You can define if some informations are displayed.
108+
109+
.. code-block:: php
110+
111+
$oSeries = new Series('Downloads', $seriesData);
112+
$oSeries->setShowCategoryName(true);
113+
$oSeries->setShowLeaderLines(true);
114+
$oSeries->setShowLegendKey(true);
115+
$oSeries->setShowPercentage(true);
116+
$oSeries->setShowSeriesName(true);
117+
$oSeries->setShowValue(true);
118+
107119
Types
108120
-----
109121

src/PhpPresentation/Shape/Chart/Series.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ class Series implements ComparableInterface
9797
*/
9898
private $showLeaderLines = true;
9999

100+
/**
101+
* Show Legend Key
102+
*
103+
* @var boolean
104+
*/
105+
private $showLegendKey = false;
106+
100107
/**
101108
* ShowPercentage
102109
*
@@ -341,6 +348,29 @@ public function setShowCategoryName($value)
341348
return $this;
342349
}
343350

351+
/**
352+
* Get ShowValue
353+
*
354+
* @return boolean
355+
*/
356+
public function hasShowLegendKey()
357+
{
358+
return $this->showLegendKey;
359+
}
360+
361+
/**
362+
* Set ShowValue
363+
*
364+
* @param boolean $value
365+
* @return \PhpOffice\PhpPresentation\Shape\Chart\Series
366+
*/
367+
public function setShowLegendKey($value)
368+
{
369+
$this->showLegendKey = (bool)$value;
370+
371+
return $this;
372+
}
373+
344374
/**
345375
* Get ShowValue
346376
*
@@ -354,7 +384,7 @@ public function hasShowValue()
354384
/**
355385
* Set ShowValue
356386
*
357-
* @param boolean $value
387+
* @param boolean $value
358388
* @return \PhpOffice\PhpPresentation\Shape\Chart\Series
359389
*/
360390
public function setShowValue($value)

src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,9 @@ protected function writeTypePie(XMLWriter $objWriter, Pie $subject, $includeShee
13211321
// c:dLblPos
13221322
$this->writeElementWithValAttribute($objWriter, 'c:dLblPos', $series->getLabelPosition());
13231323

1324+
// c:showLegendKey
1325+
$this->writeElementWithValAttribute($objWriter, 'c:showLegendKey', $series->hasShowLegendKey() ? '1' : '0');
1326+
13241327
// c:showVal
13251328
$this->writeElementWithValAttribute($objWriter, 'c:showVal', $series->hasShowValue() ? '1' : '0');
13261329

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

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

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

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function testConstruct()
4343
$this->assertEmpty($object->getValues());
4444
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Marker', $object->getMarker());
4545
$this->assertNull($object->getOutline());
46+
$this->assertFalse($object->hasShowLegendKey());
4647
}
4748

4849
public function testDataLabelNumFormat()
@@ -155,6 +156,21 @@ public function testShowLeaderLines()
155156
$this->assertFalse($object->hasShowLeaderLines());
156157
}
157158

159+
public function testShowLegendKey()
160+
{
161+
$object = new Series();
162+
163+
$this->assertFalse($object->hasShowLegendKey());
164+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(true));
165+
$this->assertTrue($object->hasShowLegendKey());
166+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(false));
167+
$this->assertFalse($object->hasShowLegendKey());
168+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(1));
169+
$this->assertTrue($object->hasShowLegendKey());
170+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setShowLegendKey(0));
171+
$this->assertFalse($object->hasShowLegendKey());
172+
}
173+
158174
public function testShowPercentage()
159175
{
160176
$object = new Series();

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,16 @@ public function testTypePie()
504504
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
505505
$element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:tx/c:v';
506506
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
507+
$element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:showLegendKey';
508+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
509+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 0);
510+
511+
$oSeries->setShowLegendKey(true);
512+
$this->resetPresentationFile();
513+
514+
$element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:showLegendKey';
515+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
516+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 1);
507517
}
508518

509519
public function testTypePie3D()
@@ -601,6 +611,16 @@ public function testTypeScatter()
601611
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
602612
$element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:tx/c:v';
603613
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
614+
$element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:dLbls/c:showLegendKey';
615+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
616+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 0);
617+
618+
$oSeries->setShowLegendKey(true);
619+
$this->resetPresentationFile();
620+
621+
$element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:dLbls/c:showLegendKey';
622+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
623+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 1);
604624
}
605625

606626
public function testTypeScatterMarker()

0 commit comments

Comments
 (0)