Skip to content

Commit ac58bac

Browse files
committed
#218 : PowerPoint2007 Writer : Support separator in Series for Chart
1 parent a58998b commit ac58bac

File tree

6 files changed

+110
-21
lines changed

6 files changed

+110
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- PowerPoint2007 Writer : Implement Legend Key in Series for Chart - @Progi1984 GH-319
2525
- PowerPoint2007 Writer : Support text direction in Alignment for Table - @SeregPie GH-218
2626
- PowerPoint2007 Writer : Support tick mark & unit in Axis for Chart - @Faab GH-218
27+
- PowerPoint2007 Writer : Support separator in Series for Chart - @jphchaput GH-218
2728
- Misc : Added two methods for setting Border & Fill in Legend - @Progi1984 GH-265
2829

2930
## 0.7.0 - 2016-09-12

docs/shapes_chart.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ You can define if some informations are displayed.
137137
.. code-block:: php
138138
139139
$oSeries = new Series('Downloads', $seriesData);
140+
$oSeries->setSeparator(';');
140141
$oSeries->setShowCategoryName(true);
141142
$oSeries->setShowLeaderLines(true);
142143
$oSeries->setShowLegendKey(true);

src/PhpPresentation/Shape/Chart/Series.php

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,39 @@ class Series implements ComparableInterface
4040

4141
/**
4242
* DataPointFills (key/value)
43-
*
4443
* @var array
4544
*/
46-
private $dataPointFills = array();
45+
protected $dataPointFills = array();
4746

4847
/**
4948
* Data Label Number Format
50-
*
5149
* @var string
5250
*/
53-
private $DlblNumFormat = '';
51+
protected $DlblNumFormat = '';
52+
53+
/**
54+
* Separator
55+
* @var string
56+
*/
57+
protected $separator = null;
5458

5559
/**
5660
* Fill
57-
*
5861
* @var \PhpOffice\PhpPresentation\Style\Fill
5962
*/
60-
private $fill;
63+
protected $fill;
6164

6265
/**
6366
* Font
64-
*
6567
* @var \PhpOffice\PhpPresentation\Style\Font
6668
*/
67-
private $font;
69+
protected $font;
6870

6971
/**
7072
* Label position
71-
*
7273
* @var string
7374
*/
74-
private $labelPosition = 'ctr';
75+
protected $labelPosition = 'ctr';
7576

7677
/**
7778
* @var Marker
@@ -84,64 +85,55 @@ class Series implements ComparableInterface
8485
protected $outline;
8586

8687
/**
87-
* ShowCategoryName
88-
*
88+
* Show Category Name
8989
* @var boolean
9090
*/
9191
private $showCategoryName = false;
9292

9393
/**
94-
* ShowLeaderLines
95-
*
94+
* Show Leader Lines
9695
* @var boolean
9796
*/
9897
private $showLeaderLines = true;
9998

10099
/**
101100
* Show Legend Key
102-
*
103101
* @var boolean
104102
*/
105103
private $showLegendKey = false;
106104

107105
/**
108106
* ShowPercentage
109-
*
110107
* @var boolean
111108
*/
112109
private $showPercentage = false;
113110

114111
/**
115112
* ShowSeriesName
116-
*
117113
* @var boolean
118114
*/
119115
private $showSeriesName = false;
120116

121117
/**
122118
* ShowValue
123-
*
124119
* @var boolean
125120
*/
126121
private $showValue = true;
127122

128123
/**
129124
* Title
130-
*
131125
* @var string
132126
*/
133127
private $title = 'Series Title';
134128

135129
/**
136130
* Values (key/value)
137-
*
138131
* @var array
139132
*/
140133
private $values = array();
141134

142135
/**
143136
* Hash index
144-
*
145137
* @var string
146138
*/
147139
private $hashIndex;
@@ -417,6 +409,36 @@ public function setShowPercentage($value)
417409
return $this;
418410
}
419411

412+
/**
413+
* Get ShowLeaderLines
414+
*
415+
* @return boolean
416+
*/
417+
public function hasShowSeparator()
418+
{
419+
return is_null($this->separator) ? false : true;
420+
}
421+
422+
/**
423+
* Set Separator
424+
* @param string $pValue
425+
* @return \PhpOffice\PhpPresentation\Shape\Chart\Series
426+
*/
427+
public function setSeparator($pValue)
428+
{
429+
$this->separator = $pValue;
430+
return $this;
431+
}
432+
433+
/**
434+
* Get Separator
435+
* @return string
436+
*/
437+
public function getSeparator()
438+
{
439+
return $this->separator;
440+
}
441+
420442
/**
421443
* Get ShowLeaderLines
422444
*

src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ protected function writeTypeBar(XMLWriter $objWriter, Bar $subject, $includeShee
925925
// c:showLeaderLines
926926
$this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0');
927927

928+
// c:separator
929+
if ($series->hasShowSeparator()) {
930+
$this->writeElementWithValAttribute($objWriter, 'c:separator', $series->getSeparator());
931+
}
932+
928933
$objWriter->endElement();
929934

930935
// c:spPr
@@ -1133,6 +1138,11 @@ protected function writeTypeBar3D(XMLWriter $objWriter, Bar3D $subject, $include
11331138
// c:showLeaderLines
11341139
$this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0');
11351140

1141+
// c:separator
1142+
if ($series->hasShowSeparator()) {
1143+
$this->writeElementWithValAttribute($objWriter, 'c:separator', $series->getSeparator());
1144+
}
1145+
11361146
$objWriter->endElement();
11371147

11381148
// c:spPr
@@ -1339,6 +1349,11 @@ protected function writeTypePie(XMLWriter $objWriter, Pie $subject, $includeShee
13391349
// c:showLeaderLines
13401350
$this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0');
13411351

1352+
// c:separator
1353+
if ($series->hasShowSeparator()) {
1354+
$this->writeElementWithValAttribute($objWriter, 'c:separator', $series->getSeparator());
1355+
}
1356+
13421357
$objWriter->endElement();
13431358

13441359
// Write X axis data
@@ -1504,6 +1519,11 @@ protected function writeTypePie3D(XMLWriter $objWriter, Pie3D $subject, $include
15041519
// c:showLeaderLines
15051520
$this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0');
15061521

1522+
// c:separator
1523+
if ($series->hasShowSeparator()) {
1524+
$this->writeElementWithValAttribute($objWriter, 'c:separator', $series->getSeparator());
1525+
}
1526+
15071527
$objWriter->endElement();
15081528

15091529
// Write X axis data
@@ -1644,6 +1664,11 @@ protected function writeTypeLine(XMLWriter $objWriter, Line $subject, $includeSh
16441664
// c:showLeaderLines
16451665
$this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0');
16461666

1667+
// c:separator
1668+
if ($series->hasShowSeparator()) {
1669+
$this->writeElementWithValAttribute($objWriter, 'c:separator', $series->getSeparator());
1670+
}
1671+
16471672
// > c:dLbls
16481673
$objWriter->endElement();
16491674

@@ -1822,6 +1847,11 @@ protected function writeTypeScatter(XMLWriter $objWriter, Scatter $subject, $inc
18221847
// c:showLeaderLines
18231848
$this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0');
18241849

1850+
// c:separator
1851+
if ($series->hasShowSeparator()) {
1852+
$this->writeElementWithValAttribute($objWriter, 'c:separator', $series->getSeparator());
1853+
}
1854+
18251855
$objWriter->endElement();
18261856

18271857
// c:spPr

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ public function testShowPercentage()
181181
$this->assertFalse($object->hasShowPercentage());
182182
}
183183

184+
public function testShowSeparator()
185+
{
186+
$value = ';';
187+
$object = new Series();
188+
189+
$this->assertFalse($object->hasShowSeparator());
190+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setSeparator($value));
191+
$this->assertEquals($value, $object->getSeparator());
192+
$this->assertTrue($object->hasShowSeparator());
193+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setSeparator(''));
194+
$this->assertFalse($object->hasShowPercentage());
195+
}
196+
184197
public function testShowSeriesName()
185198
{
186199
$object = new Series();

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,28 @@ public function testTypePie()
605605
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 1);
606606
}
607607

608+
public function testTypePieSeparator()
609+
{
610+
$value = ';';
611+
612+
$oSlide = $this->oPresentation->getActiveSlide();
613+
$oShape = $oSlide->createChartShape();
614+
$oPie = new Pie();
615+
$oSeries = new Series('Downloads', $this->seriesData);
616+
$oPie->addSeries($oSeries);
617+
$oShape->getPlotArea()->setType($oPie);
618+
619+
$element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:separator';
620+
$this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
621+
622+
$oSeries->setSeparator($value);
623+
$this->resetPresentationFile();
624+
625+
$element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:separator';
626+
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
627+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $value);
628+
}
629+
608630
public function testTypePie3D()
609631
{
610632
$oSlide = $this->oPresentation->getActiveSlide();

0 commit comments

Comments
 (0)