Skip to content

Commit f1e278f

Browse files
committed
#255 : PowerPoint2007 Writer : Add support for Outline in Axis
1 parent 637bf34 commit f1e278f

File tree

6 files changed

+123
-1
lines changed

6 files changed

+123
-1
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 0.8.0 - WIP
4+
5+
### Bugfix
6+
7+
### Changes
8+
9+
### Features
10+
- PowerPoint2007 Writer : Add support for Outline in Axis - @Progi1984 GH-255
11+
312
## 0.7.0 - 2016-09-12
413

514
### Bugfix

docs/shapes_chart.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ For each gridline, you can custom the width (in points), the fill type and the f
3434
$oShape->getPlotArea()->setType($oLine);
3535
$oShape->getPlotArea()->getAxisX()->setMajorGridlines($oGridLines);
3636
37+
You can define outline for each axis (X & Y).
38+
39+
.. code-block:: php
40+
41+
$oLine = new Line();
42+
43+
$oShape = $oSlide->createChartShape();
44+
$oShape->getPlotArea()->setType($oLine);
45+
$oShape->getPlotArea()->getAxisX()->getOutline()->setWidth(10);
46+
$oShape->getPlotArea()->getAxisX()->getOutline()->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
47+
3748
Title
3849
^^^^^
3950

samples/Sample_05_Chart_Line.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
$shape2->getPlotArea()->getAxisY()->setFormatCode('#,##0');
126126
$currentSlide->addShape($shape2);
127127

128-
129128
// Create templated slide
130129
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
131130
$currentSlide = createTemplatedSlide($objPHPPresentation);
@@ -152,6 +151,37 @@
152151
$shape3->getPlotArea()->getAxisX()->setMajorGridlines($oGridLines1);
153152
$shape3->getPlotArea()->getAxisY()->setMinorGridlines($oGridLines2);
154153
$currentSlide->addShape($shape3);
154+
155+
// Create templated slide
156+
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
157+
$currentSlide = createTemplatedSlide($objPHPPresentation);
158+
159+
// Create a line chart (that should be inserted in a shape)
160+
echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)' . EOL;
161+
$lineChart4 = clone $lineChart;
162+
163+
$oOutlineAxisX = new \PhpOffice\PhpPresentation\Style\Outline();
164+
$oOutlineAxisX->setWidth(2);
165+
$oOutlineAxisX->getFill()->setFillType(Fill::FILL_SOLID);
166+
$oOutlineAxisX->getFill()->getStartColor()->setRGB('012345');
167+
168+
$oOutlineAxisY = new \PhpOffice\PhpPresentation\Style\Outline();
169+
$oOutlineAxisY->setWidth(5);
170+
$oOutlineAxisY->getFill()->setFillType(Fill::FILL_SOLID);
171+
$oOutlineAxisY->getFill()->getStartColor()->setRGB('ABCDEF');
172+
173+
// Create a shape (chart)
174+
echo date('H:i:s') . ' Create a shape (chart4)' . EOL;
175+
echo date('H:i:s') . ' Feature : Axis Outline' . EOL;
176+
$shape4 = clone $shape;
177+
$shape4->setName('Shape 4');
178+
$shape4->getTitle()->setText('Chart with Outline on Axis');
179+
$shape4->getPlotArea()->setType($lineChart4);
180+
$shape4->getPlotArea()->getAxisX()->setOutline($oOutlineAxisX);
181+
$shape4->getPlotArea()->getAxisY()->setOutline($oOutlineAxisY);
182+
$currentSlide->addShape($shape4);
183+
184+
155185
// Save file
156186
echo EOL . write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
157187

src/PhpPresentation/Shape/Chart/Axis.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use PhpOffice\PhpPresentation\ComparableInterface;
2121
use PhpOffice\PhpPresentation\Style\Font;
22+
use PhpOffice\PhpPresentation\Style\Outline;
2223

2324
/**
2425
* \PhpOffice\PhpPresentation\Shape\Chart\Axis
@@ -59,6 +60,11 @@ class Axis implements ComparableInterface
5960
*/
6061
protected $minorGridlines;
6162

63+
/**
64+
* @var Outline
65+
*/
66+
protected $outline;
67+
6268
/**
6369
* Create a new \PhpOffice\PhpPresentation\Shape\Chart\Axis instance
6470
*
@@ -68,6 +74,7 @@ public function __construct($title = 'Axis Title')
6874
{
6975
$this->title = $title;
7076
$this->font = new Font();
77+
$this->outline = new Outline();
7178
}
7279

7380
/**
@@ -175,6 +182,24 @@ public function setMinorGridlines(Gridlines $minorGridlines)
175182
return $this;
176183
}
177184

185+
/**
186+
* @return Outline
187+
*/
188+
public function getOutline()
189+
{
190+
return $this->outline;
191+
}
192+
193+
/**
194+
* @param Outline $outline
195+
* @return Axis
196+
*/
197+
public function setOutline($outline)
198+
{
199+
$this->outline = $outline;
200+
return $this;
201+
}
202+
178203
/**
179204
* Get hash code
180205
*

src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,13 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, $typeAxis)
20762076
$objWriter->writeAttribute('val', 'nextTo');
20772077
$objWriter->endElement();
20782078

2079+
// c:spPr
2080+
$objWriter->startElement('c:spPr');
2081+
// Outline
2082+
$this->writeOutline($objWriter, $oAxis->getOutline());
2083+
// ##c:spPr
2084+
$objWriter->endElement();
2085+
20792086
// c:txPr
20802087
$objWriter->startElement('c:txPr');
20812088

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,46 @@ public function testAxisFont()
132132
$this->assertEquals(Font::UNDERLINE_DASH, $oXMLDoc->getElementAttribute($element, 'u', 'ppt/charts/'.$oShape->getIndexedFilename())); //Underline YAxis
133133
}
134134

135+
public function testAxisOutline()
136+
{
137+
$expectedWidthX = 2;
138+
$expectedColorX = 'ABCDEF';
139+
$expectedWidthY = 4;
140+
$expectedColorY = '012345';
141+
142+
$oSlide = $this->oPresentation->getActiveSlide();
143+
$oShape = $oSlide->createChartShape();
144+
$oBar = new Bar();
145+
$oSeries = new Series('Downloads', $this->seriesData);
146+
$oBar->addSeries($oSeries);
147+
$oShape->getPlotArea()->setType($oBar);
148+
$oShape->getPlotArea()->getAxisX()->getOutline()->setWidth($expectedWidthX);
149+
$oShape->getPlotArea()->getAxisX()->getOutline()->getFill()->setFillType(Fill::FILL_SOLID);
150+
$oShape->getPlotArea()->getAxisX()->getOutline()->getFill()->getStartColor()->setRGB($expectedColorX);
151+
$oShape->getPlotArea()->getAxisY()->getOutline()->setWidth($expectedWidthY);
152+
$oShape->getPlotArea()->getAxisY()->getOutline()->getFill()->setFillType(Fill::FILL_SOLID);
153+
$oShape->getPlotArea()->getAxisY()->getOutline()->getFill()->getStartColor()->setRGB($expectedColorY);
154+
155+
156+
$oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007');
157+
$element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:spPr';
158+
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
159+
$element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:spPr/a:ln';
160+
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
161+
$this->assertEquals(Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidthX)), $oXMLDoc->getElementAttribute($element, 'w', 'ppt/charts/'.$oShape->getIndexedFilename()));
162+
$element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:spPr/a:ln/a:solidFill/a:srgbClr';
163+
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
164+
$this->assertEquals($expectedColorX, $oXMLDoc->getElementAttribute($element, 'val', 'ppt/charts/'.$oShape->getIndexedFilename()));
165+
$element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:spPr';
166+
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
167+
$element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:spPr/a:ln';
168+
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
169+
$this->assertEquals(Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidthY)), $oXMLDoc->getElementAttribute($element, 'w', 'ppt/charts/'.$oShape->getIndexedFilename()));
170+
$element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:spPr/a:ln/a:solidFill/a:srgbClr';
171+
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/'.$oShape->getIndexedFilename()));
172+
$this->assertEquals($expectedColorY, $oXMLDoc->getElementAttribute($element, 'val', 'ppt/charts/'.$oShape->getIndexedFilename()));
173+
}
174+
135175
public function testTypeArea()
136176
{
137177
$oSlide = $this->oPresentation->getActiveSlide();

0 commit comments

Comments
 (0)