Skip to content

Commit 28bd7e8

Browse files
committed
#358 : PowerPoint2007 Writer : Implement gap width in Bar(3D) Charts
1 parent 898663f commit 28bd7e8

File tree

8 files changed

+81
-2
lines changed

8 files changed

+81
-2
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 gap width in Bar(3D) Charts - @Progi1984 GH-358
1011

1112
## 0.8.0 - 2017-04-03
1213

docs/shapes_chart.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ TODO
176176
Bar & Bar3D
177177
^^^^^^^^^^^
178178

179+
Gap Width
180+
"""""""""
181+
182+
You can define the gap width between bar or columns clusters. It is defined in percent.
183+
The default value is 150%. The value must be defined between 0 and 500.
184+
185+
.. code-block:: php
186+
187+
$oBarChart = new Bar();
188+
$oBarChart->setGapWidthPercent(250);
189+
179190
Stacking
180191
""""""""
181192

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
@@ -316,10 +316,12 @@ public function testTypeAxisUnit()
316316

317317
public function testTypeBar()
318318
{
319+
$valueGapWidthPercent = rand(0, 500);
319320
$oSlide = $this->oPresentation->getActiveSlide();
320321
$oShape = $oSlide->createChartShape();
321322
$oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
322323
$oBar = new Bar();
324+
$oBar->setGapWidthPercent($valueGapWidthPercent);
323325
$oSeries = new Series('Downloads', $this->seriesData);
324326
$oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
325327
$oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
@@ -339,14 +341,18 @@ public function testTypeBar()
339341
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
340342
$element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:tx/c:v';
341343
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
344+
$element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:gapWidth';
345+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $valueGapWidthPercent);
342346
}
343347

344348
public function testTypeBar3D()
345349
{
350+
$valueGapWidthPercent = rand(0, 500);
346351
$oSlide = $this->oPresentation->getActiveSlide();
347352
$oShape = $oSlide->createChartShape();
348353
$oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
349354
$oBar3D = new Bar3D();
355+
$oBar3D->setGapWidthPercent($valueGapWidthPercent);
350356
$oSeries = new Series('Downloads', $this->seriesData);
351357
$oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
352358
$oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
@@ -366,6 +372,8 @@ public function testTypeBar3D()
366372
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
367373
$element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:tx/c:v';
368374
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
375+
$element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:gapWidth';
376+
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $valueGapWidthPercent);
369377
}
370378

371379
public function testTypeBar3DSubScript()

0 commit comments

Comments
 (0)