Skip to content

Commit

Permalink
Merge pull request #364 from Progi1984/issue358
Browse files Browse the repository at this point in the history
#358 : PowerPoint2007 Writer : Implement gap width in Bar(3D) Charts
  • Loading branch information
Progi1984 authored May 21, 2017
2 parents 44d670e + 2bd0670 commit 4a0adf8
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
- 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

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

## 0.8.0 - 2017-04-03

Expand Down
11 changes: 11 additions & 0 deletions docs/shapes_chart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ TODO
Bar & Bar3D
^^^^^^^^^^^

Gap Width
"""""""""

You can define the gap width between bar or columns clusters. It is defined in percent.
The default value is 150%. The value must be defined between 0 and 500.

.. code-block:: php
$oBarChart = new Bar();
$oBarChart->setGapWidthPercent(250);
Stacking
""""""""

Expand Down
1 change: 1 addition & 0 deletions samples/Sample_05_Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function fnSlide_Bar(PhpPresentation $objPHPPresentation) {
// Create a bar chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a bar chart (that should be inserted in a chart shape)'.EOL;
$barChart = new Bar();
$barChart->setGapWidthPercent(158);
$series1 = new Series('2009', $series1Data);
$series1->setShowSeriesName(true);
$series1->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4F81BD'));
Expand Down
32 changes: 32 additions & 0 deletions src/PhpPresentation/Shape/Chart/Type/AbstractTypeBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class AbstractTypeBar extends AbstractType
protected $barGrouping = self::GROUPING_CLUSTERED;


/**
* Space between bar or columns clusters
*
* @var int
*/
protected $gapWidthPercent = 150;


/**
* Set bar orientation
*
Expand Down Expand Up @@ -91,6 +99,30 @@ public function getBarGrouping()
{
return $this->barGrouping;
}

/**
* @return int
*/
public function getGapWidthPercent()
{
return $this->gapWidthPercent;
}

/**
* @param int $gapWidthPercent
* @return $this
*/
public function setGapWidthPercent($gapWidthPercent)
{
if ($gapWidthPercent < 0) {
$gapWidthPercent = 0;
}
if ($gapWidthPercent > 500) {
$gapWidthPercent = 500;
}
$this->gapWidthPercent = $gapWidthPercent;
return $this;
}

/**
* Get hash code
Expand Down
4 changes: 2 additions & 2 deletions src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ protected function writeTypeBar(XMLWriter $objWriter, Bar $subject, $includeShee

// c:gapWidth
$objWriter->startElement('c:gapWidth');
$objWriter->writeAttribute('val', '75');
$objWriter->writeAttribute('val', $subject->getGapWidthPercent());
$objWriter->endElement();

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

// c:gapWidth
$objWriter->startElement('c:gapWidth');
$objWriter->writeAttribute('val', '75');
$objWriter->writeAttribute('val', $subject->getGapWidthPercent());
$objWriter->endElement();

// c:shape
Expand Down
13 changes: 13 additions & 0 deletions tests/PhpPresentation/Tests/Shape/Chart/Type/Bar3DTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ public function testBarGrouping()
$this->assertEquals(Bar3D::GROUPING_PERCENTSTACKED, $object->getBarGrouping());
}

public function testGapWidthPercent()
{
$value = rand(0, 500);
$object = new Bar3D();
$this->assertEquals(150, $object->getGapWidthPercent());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar3D', $object->setGapWidthPercent($value));
$this->assertEquals($value, $object->getGapWidthPercent());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar3D', $object->setGapWidthPercent(-1));
$this->assertEquals(0, $object->getGapWidthPercent());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar3D', $object->setGapWidthPercent(501));
$this->assertEquals(500, $object->getGapWidthPercent());
}

public function testHashCode()
{
$oSeries = new Series();
Expand Down
13 changes: 13 additions & 0 deletions tests/PhpPresentation/Tests/Shape/Chart/Type/BarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ public function testBarGrouping()
$this->assertEquals(Bar::GROUPING_PERCENTSTACKED, $object->getBarGrouping());
}

public function testGapWidthPercent()
{
$value = rand(0, 500);
$object = new Bar();
$this->assertEquals(150, $object->getGapWidthPercent());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar', $object->setGapWidthPercent($value));
$this->assertEquals($value, $object->getGapWidthPercent());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar', $object->setGapWidthPercent(-1));
$this->assertEquals(0, $object->getGapWidthPercent());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar', $object->setGapWidthPercent(501));
$this->assertEquals(500, $object->getGapWidthPercent());
}

public function testHashCode()
{
$oSeries = new Series();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,12 @@ public function testTypeAxisUnit()

public function testTypeBar()
{
$valueGapWidthPercent = rand(0, 500);
$oSlide = $this->oPresentation->getActiveSlide();
$oShape = $oSlide->createChartShape();
$oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
$oBar = new Bar();
$oBar->setGapWidthPercent($valueGapWidthPercent);
$oSeries = new Series('Downloads', $this->seriesData);
$oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
$oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
Expand All @@ -371,14 +373,18 @@ public function testTypeBar()
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:tx/c:v';
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
$element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:gapWidth';
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $valueGapWidthPercent);
}

public function testTypeBar3D()
{
$valueGapWidthPercent = rand(0, 500);
$oSlide = $this->oPresentation->getActiveSlide();
$oShape = $oSlide->createChartShape();
$oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
$oBar3D = new Bar3D();
$oBar3D->setGapWidthPercent($valueGapWidthPercent);
$oSeries = new Series('Downloads', $this->seriesData);
$oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
$oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
Expand All @@ -398,6 +404,8 @@ public function testTypeBar3D()
$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
$element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:tx/c:v';
$this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
$element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:gapWidth';
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $valueGapWidthPercent);
}

public function testTypeBar3DSubScript()
Expand Down

0 comments on commit 4a0adf8

Please sign in to comment.