Skip to content

Commit 4a0adf8

Browse files
authored
Merge pull request #364 from Progi1984/issue358
#358 : PowerPoint2007 Writer : Implement gap width in Bar(3D) Charts
2 parents 44d670e + 2bd0670 commit 4a0adf8

File tree

8 files changed

+82
-3
lines changed

8 files changed

+82
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
- 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
77

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

1213
## 0.8.0 - 2017-04-03
1314

docs/shapes_chart.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,17 @@ TODO
186186
Bar & Bar3D
187187
^^^^^^^^^^^
188188

189+
Gap Width
190+
"""""""""
191+
192+
You can define the gap width between bar or columns clusters. It is defined in percent.
193+
The default value is 150%. The value must be defined between 0 and 500.
194+
195+
.. code-block:: php
196+
197+
$oBarChart = new Bar();
198+
$oBarChart->setGapWidthPercent(250);
199+
189200
Stacking
190201
""""""""
191202

samples/Sample_05_Chart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function fnSlide_Bar(PhpPresentation $objPHPPresentation) {
8282
// Create a bar chart (that should be inserted in a shape)
8383
echo date('H:i:s') . ' Create a bar chart (that should be inserted in a chart shape)'.EOL;
8484
$barChart = new Bar();
85+
$barChart->setGapWidthPercent(158);
8586
$series1 = new Series('2009', $series1Data);
8687
$series1->setShowSeriesName(true);
8788
$series1->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4F81BD'));

src/PhpPresentation/Shape/Chart/Type/AbstractTypeBar.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class AbstractTypeBar extends AbstractType
4848
protected $barGrouping = self::GROUPING_CLUSTERED;
4949

5050

51+
/**
52+
* Space between bar or columns clusters
53+
*
54+
* @var int
55+
*/
56+
protected $gapWidthPercent = 150;
57+
58+
5159
/**
5260
* Set bar orientation
5361
*
@@ -91,6 +99,30 @@ public function getBarGrouping()
9199
{
92100
return $this->barGrouping;
93101
}
102+
103+
/**
104+
* @return int
105+
*/
106+
public function getGapWidthPercent()
107+
{
108+
return $this->gapWidthPercent;
109+
}
110+
111+
/**
112+
* @param int $gapWidthPercent
113+
* @return $this
114+
*/
115+
public function setGapWidthPercent($gapWidthPercent)
116+
{
117+
if ($gapWidthPercent < 0) {
118+
$gapWidthPercent = 0;
119+
}
120+
if ($gapWidthPercent > 500) {
121+
$gapWidthPercent = 500;
122+
}
123+
$this->gapWidthPercent = $gapWidthPercent;
124+
return $this;
125+
}
94126

95127
/**
96128
* Get hash code

src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ protected function writeTypeBar(XMLWriter $objWriter, Bar $subject, $includeShee
972972

973973
// c:gapWidth
974974
$objWriter->startElement('c:gapWidth');
975-
$objWriter->writeAttribute('val', '75');
975+
$objWriter->writeAttribute('val', $subject->getGapWidthPercent());
976976
$objWriter->endElement();
977977

978978
// c:shape
@@ -1174,7 +1174,7 @@ protected function writeTypeBar3D(XMLWriter $objWriter, Bar3D $subject, $include
11741174

11751175
// c:gapWidth
11761176
$objWriter->startElement('c:gapWidth');
1177-
$objWriter->writeAttribute('val', '75');
1177+
$objWriter->writeAttribute('val', $subject->getGapWidthPercent());
11781178
$objWriter->endElement();
11791179

11801180
// c:shape

tests/PhpPresentation/Tests/Shape/Chart/Type/Bar3DTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ public function testBarGrouping()
7575
$this->assertEquals(Bar3D::GROUPING_PERCENTSTACKED, $object->getBarGrouping());
7676
}
7777

78+
public function testGapWidthPercent()
79+
{
80+
$value = rand(0, 500);
81+
$object = new Bar3D();
82+
$this->assertEquals(150, $object->getGapWidthPercent());
83+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar3D', $object->setGapWidthPercent($value));
84+
$this->assertEquals($value, $object->getGapWidthPercent());
85+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar3D', $object->setGapWidthPercent(-1));
86+
$this->assertEquals(0, $object->getGapWidthPercent());
87+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar3D', $object->setGapWidthPercent(501));
88+
$this->assertEquals(500, $object->getGapWidthPercent());
89+
}
90+
7891
public function testHashCode()
7992
{
8093
$oSeries = new Series();

tests/PhpPresentation/Tests/Shape/Chart/Type/BarTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ public function testBarGrouping()
7575
$this->assertEquals(Bar::GROUPING_PERCENTSTACKED, $object->getBarGrouping());
7676
}
7777

78+
public function testGapWidthPercent()
79+
{
80+
$value = rand(0, 500);
81+
$object = new Bar();
82+
$this->assertEquals(150, $object->getGapWidthPercent());
83+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar', $object->setGapWidthPercent($value));
84+
$this->assertEquals($value, $object->getGapWidthPercent());
85+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar', $object->setGapWidthPercent(-1));
86+
$this->assertEquals(0, $object->getGapWidthPercent());
87+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar', $object->setGapWidthPercent(501));
88+
$this->assertEquals(500, $object->getGapWidthPercent());
89+
}
90+
7891
public function testHashCode()
7992
{
8093
$oSeries = new Series();

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,12 @@ public function testTypeAxisUnit()
348348

349349
public function testTypeBar()
350350
{
351+
$valueGapWidthPercent = rand(0, 500);
351352
$oSlide = $this->oPresentation->getActiveSlide();
352353
$oShape = $oSlide->createChartShape();
353354
$oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
354355
$oBar = new Bar();
356+
$oBar->setGapWidthPercent($valueGapWidthPercent);
355357
$oSeries = new Series('Downloads', $this->seriesData);
356358
$oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
357359
$oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
@@ -371,14 +373,18 @@ public function testTypeBar()
371373
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
372374
$element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:tx/c:v';
373375
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
376+
$element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:gapWidth';
377+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $valueGapWidthPercent);
374378
}
375379

376380
public function testTypeBar3D()
377381
{
382+
$valueGapWidthPercent = rand(0, 500);
378383
$oSlide = $this->oPresentation->getActiveSlide();
379384
$oShape = $oSlide->createChartShape();
380385
$oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
381386
$oBar3D = new Bar3D();
387+
$oBar3D->setGapWidthPercent($valueGapWidthPercent);
382388
$oSeries = new Series('Downloads', $this->seriesData);
383389
$oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
384390
$oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
@@ -398,6 +404,8 @@ public function testTypeBar3D()
398404
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
399405
$element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:tx/c:v';
400406
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
407+
$element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:gapWidth';
408+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $valueGapWidthPercent);
401409
}
402410

403411
public function testTypeBar3DSubScript()

0 commit comments

Comments
 (0)