Skip to content

Commit

Permalink
#76 : Added option for explosion in Pie3D Chart (ODPresentation & Pow…
Browse files Browse the repository at this point in the history
…erPoint2007)
  • Loading branch information
Progi1984 committed Dec 30, 2014
1 parent 53bdc90 commit 85d60c3
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- Added support for calculating the offset and extent on a Slide. - @Pr0phet GH-68
- Added support for Horizontal bar chart - @rdoepke @Progi1984 GH-58
- Added support for hyperlink on picture (ODPresentation & PowerPoint2007) - @Progi1984 GH-49
- Added support for notes slide (ODPresentation & PowerPoint2007) - @Progi1984 GH-63
- Added option for explosion in Pie3D Chart (ODPresentation & PowerPoint2007) - @Progi1984 GH-76

### Bugfix
- PSR-0 via composer broken - @Progi1984 GH-51
Expand Down
2 changes: 2 additions & 0 deletions samples/Sample_07_Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
// Create a pie chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a pie chart (that should be inserted in a chart shape)'.EOL;
$pie3DChart = new Pie3D();
$pie3DChart->setExplosion(20);
$series = new Series('Downloads', $seriesData);
$series->setShowSeriesName(true);
$series->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4672A8'));
Expand Down Expand Up @@ -176,6 +177,7 @@
$lineChart = new Line();
$series = new Series('Downloads', $seriesData);
$series->setShowSeriesName(true);
$series->setShowValue(false);
$lineChart->addSeries($series);

// Create a shape (chart)
Expand Down
29 changes: 29 additions & 0 deletions src/PhpPowerpoint/Shape/Chart/Type/Pie3D.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
*/
class Pie3D extends AbstractType implements ComparableInterface
{
/**
* Explosion of the Pie3D
*
* @var integer
*/
protected $explosion = 0;

/**
* Create a new self instance
*/
Expand All @@ -32,6 +39,28 @@ public function __construct()
$this->hasAxisX = false;
$this->hasAxisY = false;
}

/**
* Set explosion
*
* @param integer $value
* @return \PhpOffice\PhpPowerpoint\Shape\Chart\Type\Bar3D
*/
public function setExplosion($value = 0)
{
$this->explosion = $value;
return $this;
}

/**
* Get orientation
*
* @return string
*/
public function getExplosion()
{
return $this->explosion;
}

/**
* Get hash code
Expand Down
3 changes: 1 addition & 2 deletions src/PhpPowerpoint/Writer/ODPresentation/ObjectsChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,7 @@ private function writeSeriesStyle(Chart $chart, Chart\Series $series)
$this->xmlContent->writeAttribute('chart:data-label-number', 'value');
$this->xmlContent->writeAttribute('chart:label-position', 'right');
if ($chartType instanceof Pie3D) {
//@todo : Permit edit the offset of a pie
$this->xmlContent->writeAttribute('chart:pie-offset', '20');
$this->xmlContent->writeAttribute('chart:pie-offset', $chartType->getExplosion());
}
if ($chartType instanceof Line) {
//@todo : Permit edit the symbol of a line
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPowerpoint/Writer/PowerPoint2007/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ protected function writeTypePie3D(XMLWriter $objWriter, Pie3D $subject, $include

// c:explosion
$objWriter->startElement('c:explosion');
$objWriter->writeAttribute('val', '20');
$objWriter->writeAttribute('val', $subject->getExplosion());
$objWriter->endElement();

// Fills for points?
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPowerpoint/Writer/PowerPoint2007/Slide.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function writeSlide(SlideElement $pSlide = null)
$objWriter->startElement('p:clrMapOvr');

// a:masterClrMapping
$objWriter->writeElement('a:masterClrMapping', '');
$objWriter->writeElement('a:masterClrMapping', null);

$objWriter->endElement();

Expand Down
13 changes: 12 additions & 1 deletion tests/PhpPowerpoint/Tests/Shape/Chart/Type/Pie3DTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,25 @@ public function testData()
$this->assertCount(count($array), $object->getData());
}

public function testSerties()
public function testSeries()
{
$object = new Pie3D();

$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Chart\\Type\\Pie3D', $object->addSeries(new Series()));
$this->assertCount(1, $object->getData());
}

public function testExplosion()
{
$value = rand(0, 100);

$object = new Pie3D();

$this->assertEquals(0, $object->getExplosion());
$this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\Chart\\Type\\Pie3D', $object->setExplosion($value));
$this->assertEquals($value, $object->getExplosion());
}

public function testHashCode()
{
$oSeries = new Series();
Expand Down
23 changes: 23 additions & 0 deletions tests/PhpPowerpoint/Tests/Writer/ODPresentation/ChartsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,29 @@ public function testChartPie3D()
$this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
}

public function testChartPie3DExplosion()
{
$value = rand(0, 100);

$oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));
$oSeries->setShowSeriesName(true);

$oPie3D = new Pie3D();
$oPie3D->setExplosion($value);
$oPie3D->addSeries($oSeries);

$phpPowerPoint = new PhpPowerpoint();
$oSlide = $phpPowerPoint->getActiveSlide();
$oChart = $oSlide->createChartShape();
$oChart->getPlotArea()->setType($oPie3D);

$pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');

$element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleSeries0\'][@style:family=\'chart\']/style:chart-properties';
$this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
$this->assertEquals($value, $pres->getElementAttribute($element, 'chart:pie-offset', 'Object 1/content.xml'));
}

public function testChartScatter()
{
$oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));
Expand Down
28 changes: 28 additions & 0 deletions tests/PhpPowerpoint/Tests/Writer/PowerPoint2007/ChartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,34 @@ public function testTypePie3D()
$this->assertEquals($oSeries->getTitle(), $oXMLDoc->getElement($element, 'ppt/charts/'.$oShape->getIndexedFilename())->nodeValue);
}

public function testTypePie3DExplosion()
{
$value = rand(1, 100);
$seriesData = array(
'A' => 1,
'B' => 2,
'C' => 4,
'D' => 3,
'E' => 2,
);

$oPHPPowerPoint = new PhpPowerpoint();
$oSlide = $oPHPPowerPoint->getActiveSlide();
$oShape = $oSlide->createChartShape();
$oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
$oPie3D = new Pie3D();
$oPie3D->setExplosion($value);
$oSeries = new Series('Downloads', $seriesData);
$oPie3D->addSeries($oSeries);
$oShape->getPlotArea()->setType($oPie3D);

$oXMLDoc = TestHelperDOCX::getDocument($oPHPPowerPoint, 'PowerPoint2007');

$element = '/c:chartSpace/c:chart/c:plotArea/c:pie3DChart/c:ser/c:explosion';
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
$this->assertEquals($value, $oXMLDoc->getElementAttribute($element, 'val', 'ppt/charts/'.$oShape->getIndexedFilename()));
}

public function testTypePie3DSubScript()
{
$seriesData = array(
Expand Down

0 comments on commit 85d60c3

Please sign in to comment.