Skip to content

Commit 1887b70

Browse files
authored
Merge pull request #263 from Progi1984/issue255
#255 : PowerPoint2007 Writer : Add support for Outline in Axis
2 parents 429d548 + 3fb01f6 commit 1887b70

File tree

9 files changed

+272
-583
lines changed

9 files changed

+272
-583
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
- PowerPoint2007 Writer : Support of margins in cell in table - @carlosafonso @Progi1984 GH-273 GH-315
1313
- Fixed the corruption of file when an addExternalSlide is called - @Progi1984 GH-240
1414

15+
### Changes
16+
- Misc : Added two methods for setting Border & Fill in Legend - @Progi1984 GH-265
17+
1518
### Features
1619
- ODPresentation Writer : Show/Hide Value / Name / Series Name in Chart - @Progi1984 GH-272
1720
- ODPresentation Writer : Axis Bounds in Chart - @Progi1984 GH-269
@@ -25,8 +28,8 @@
2528
- PowerPoint2007 Writer : Support text direction in Alignment for Table - @SeregPie GH-218
2629
- PowerPoint2007 Writer : Support tick mark & unit in Axis for Chart - @Faab GH-218
2730
- PowerPoint2007 Writer : Support separator in Series for Chart - @jphchaput GH-218
31+
- PowerPoint2007 Writer : Add support for Outline in Axis - @Progi1984 GH-255
2832
- PowerPoint2007 Writer : Support autoscale for Chart - @Progi1984 GH-293
29-
- Misc : Added two methods for setting Border & Fill in Legend - @Progi1984 GH-265
3033

3134
## 0.7.0 - 2016-09-12
3235

docs/shapes_chart.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ For resetting them, you pass null as parameter to these methods.
4848
$oShape->getPlotArea()->getAxisX()->setMinBounds(0);
4949
$oShape->getPlotArea()->getAxisX()->setMaxBounds(200);
5050
51+
You can define outline for each axis (X & Y).
52+
53+
.. code-block:: php
54+
55+
$oLine = new Line();
56+
57+
$oShape = $oSlide->createChartShape();
58+
$oShape->getPlotArea()->setType($oLine);
59+
$oShape->getPlotArea()->getAxisX()->getOutline()->setWidth(10);
60+
$oShape->getPlotArea()->getAxisX()->getOutline()->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
61+
5162
For Axis Y, you can define tick mark with `setMinorTickMark` & `setMajorTickMark` methods.
5263
For resetting them, you pass Axis::TICK_MARK_NONE as parameter to these methods.
5364

samples/Sample_05_Chart_Line.php

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
$lineChart1->setSeries($series1);
8888

8989
// Create a shape (chart)
90-
echo date('H:i:s') . ' Create a shape (chart)' . EOL;
90+
echo date('H:i:s') . ' Create a shape (chart1)' . EOL;
9191
echo date('H:i:s') . ' Differences with previous : Values on right axis and Legend hidden' . EOL;
9292
$shape1 = clone $shape;
9393
$shape1->getLegend()->setVisible(false);
@@ -111,7 +111,7 @@
111111
$lineChart2->setSeries($series2);
112112

113113
// Create a shape (chart)
114-
echo date('H:i:s') . ' Create a shape (chart)' . EOL;
114+
echo date('H:i:s') . ' Create a shape (chart2)' . EOL;
115115
echo date('H:i:s') . ' Differences with previous : Values on right axis and Legend hidden' . EOL;
116116
$shape2 = clone $shape;
117117
$shape2->getLegend()->setVisible(false);
@@ -122,7 +122,7 @@
122122
$currentSlide->addShape($shape2);
123123

124124
// Create templated slide
125-
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
125+
echo EOL . date('H:i:s') . ' Create templated slide #3' . EOL;
126126
$currentSlide = createTemplatedSlide($objPHPPresentation);
127127

128128
// Create a line chart (that should be inserted in a shape)
@@ -149,16 +149,45 @@
149149
$currentSlide->addShape($shape3);
150150

151151
// Create templated slide
152-
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
152+
echo EOL . date('H:i:s') . ' Create templated slide #4' . EOL;
153153
$currentSlide = createTemplatedSlide($objPHPPresentation);
154154

155+
// Create a line chart (that should be inserted in a shape)
156+
echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)' . EOL;
157+
$lineChart4 = clone $lineChart;
158+
159+
$oOutlineAxisX = new \PhpOffice\PhpPresentation\Style\Outline();
160+
$oOutlineAxisX->setWidth(2);
161+
$oOutlineAxisX->getFill()->setFillType(Fill::FILL_SOLID);
162+
$oOutlineAxisX->getFill()->getStartColor()->setRGB('012345');
163+
164+
$oOutlineAxisY = new \PhpOffice\PhpPresentation\Style\Outline();
165+
$oOutlineAxisY->setWidth(5);
166+
$oOutlineAxisY->getFill()->setFillType(Fill::FILL_SOLID);
167+
$oOutlineAxisY->getFill()->getStartColor()->setRGB('ABCDEF');
168+
155169
// Create a shape (chart)
156-
echo date('H:i:s') . ' Create a shape (chart3)' . EOL;
157-
echo date('H:i:s') . ' Feature : Gridlines' . EOL;
170+
echo date('H:i:s') . ' Create a shape (chart4)' . EOL;
171+
echo date('H:i:s') . ' Feature : Axis Outline' . EOL;
158172
$shape4 = clone $shape;
159-
$shape4->getPlotArea()->getAxisY()->setMinBounds(5);
160-
$shape4->getPlotArea()->getAxisY()->setMaxBounds(20);
173+
$shape4->setName('Shape 4');
174+
$shape4->getTitle()->setText('Chart with Outline on Axis');
175+
$shape4->getPlotArea()->setType($lineChart4);
176+
$shape4->getPlotArea()->getAxisX()->setOutline($oOutlineAxisX);
177+
$shape4->getPlotArea()->getAxisY()->setOutline($oOutlineAxisY);
161178
$currentSlide->addShape($shape4);
179+
180+
// Create templated slide
181+
echo EOL . date('H:i:s') . ' Create templated slide #5' . EOL;
182+
$currentSlide = createTemplatedSlide($objPHPPresentation);
183+
184+
// Create a shape (chart)
185+
echo date('H:i:s') . ' Create a shape (chart5)' . EOL;
186+
echo date('H:i:s') . ' Feature : Gridlines' . EOL;
187+
$shape5 = clone $shape;
188+
$shape5->getPlotArea()->getAxisY()->setMinBounds(5);
189+
$shape5->getPlotArea()->getAxisY()->setMaxBounds(20);
190+
$currentSlide->addShape($shape5);
162191
// Save file
163192
echo EOL . write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
164193

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
@@ -94,6 +95,11 @@ class Axis implements ComparableInterface
9495
*/
9596
protected $majorUnit;
9697

98+
/**
99+
* @var Outline
100+
*/
101+
protected $outline;
102+
97103
/**
98104
* Create a new \PhpOffice\PhpPresentation\Shape\Chart\Axis instance
99105
*
@@ -102,6 +108,7 @@ class Axis implements ComparableInterface
102108
public function __construct($title = 'Axis Title')
103109
{
104110
$this->title = $title;
111+
$this->outline = new Outline();
105112
$this->font = new Font();
106113
}
107114

@@ -318,6 +325,24 @@ public function setMajorUnit($pUnit = null)
318325
return $this;
319326
}
320327

328+
/**
329+
* @return Outline
330+
*/
331+
public function getOutline()
332+
{
333+
return $this->outline;
334+
}
335+
336+
/**
337+
* @param Outline $outline
338+
* @return Axis
339+
*/
340+
public function setOutline($outline)
341+
{
342+
$this->outline = $outline;
343+
return $this;
344+
}
345+
321346
/**
322347
* Get hash code
323348
*

src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ protected function writeFill(XMLWriter $objWriter, $pFill)
151151

152152
// Is it a fill?
153153
if ($pFill->getFillType() == Fill::FILL_NONE) {
154+
$objWriter->writeElement('a:noFill');
154155
return;
155156
}
156157

src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php

Lines changed: 82 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -193,82 +193,84 @@ protected function writeShapeText(XMLWriter $objWriter, RichText $shape, $shapeI
193193
$objWriter->endElement();
194194
// p:sp\p:spPr
195195
$objWriter->startElement('p:spPr');
196-
// p:sp\p:spPr\a:xfrm
197-
$objWriter->startElement('a:xfrm');
198-
$objWriter->writeAttributeIf($shape->getRotation() != 0, 'rot', CommonDrawing::degreesToAngle($shape->getRotation()));
199-
// p:sp\p:spPr\a:xfrm\a:off
200-
$objWriter->startElement('a:off');
201-
$objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX()));
202-
$objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY()));
203-
$objWriter->endElement();
204-
// p:sp\p:spPr\a:xfrm\a:ext
205-
$objWriter->startElement('a:ext');
206-
$objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth()));
207-
$objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight()));
208-
$objWriter->endElement();
209-
// > p:sp\p:spPr\a:xfrm
210-
$objWriter->endElement();
211-
// p:sp\p:spPr\a:prstGeom
212-
$objWriter->startElement('a:prstGeom');
213-
$objWriter->writeAttribute('prst', 'rect');
214196

215-
// p:sp\p:spPr\a:prstGeom\a:avLst
216-
$objWriter->writeElement('a:avLst');
197+
if (!$shape->isPlaceholder()) {
198+
// p:sp\p:spPr\a:xfrm
199+
$objWriter->startElement('a:xfrm');
200+
$objWriter->writeAttributeIf($shape->getRotation() != 0, 'rot', CommonDrawing::degreesToAngle($shape->getRotation()));
201+
// p:sp\p:spPr\a:xfrm\a:off
202+
$objWriter->startElement('a:off');
203+
$objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX()));
204+
$objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY()));
205+
$objWriter->endElement();
206+
// p:sp\p:spPr\a:xfrm\a:ext
207+
$objWriter->startElement('a:ext');
208+
$objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth()));
209+
$objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight()));
210+
$objWriter->endElement();
211+
// > p:sp\p:spPr\a:xfrm
212+
$objWriter->endElement();
213+
// p:sp\p:spPr\a:prstGeom
214+
$objWriter->startElement('a:prstGeom');
215+
$objWriter->writeAttribute('prst', 'rect');
217216

218-
$objWriter->endElement();
219-
$this->writeFill($objWriter, $shape->getFill());
220-
if ($shape->getBorder()->getLineStyle() != Border::LINE_NONE) {
221-
$this->writeBorder($objWriter, $shape->getBorder(), '');
222-
}
223-
if ($shape->getShadow()->isVisible()) {
224-
$this->writeShadow($objWriter, $shape->getShadow());
217+
// p:sp\p:spPr\a:prstGeom\a:avLst
218+
$objWriter->writeElement('a:avLst');
219+
220+
$objWriter->endElement();
225221
}
222+
$this->writeFill($objWriter, $shape->getFill());
223+
$this->writeBorder($objWriter, $shape->getBorder(), '');
224+
$this->writeShadow($objWriter, $shape->getShadow());
225+
226226
// > p:sp\p:spPr
227227
$objWriter->endElement();
228228
// p:txBody
229229
$objWriter->startElement('p:txBody');
230230
// a:bodyPr
231231
//@link :http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.bodyproperties%28v=office.14%29.aspx
232232
$objWriter->startElement('a:bodyPr');
233-
$verticalAlign = $shape->getActiveParagraph()->getAlignment()->getVertical();
234-
if ($verticalAlign != Alignment::VERTICAL_BASE && $verticalAlign != Alignment::VERTICAL_AUTO) {
235-
$objWriter->writeAttribute('anchor', $verticalAlign);
236-
}
237-
if ($shape->getWrap() != RichText::WRAP_SQUARE) {
238-
$objWriter->writeAttribute('wrap', $shape->getWrap());
239-
}
240-
$objWriter->writeAttribute('rtlCol', '0');
241-
if ($shape->getHorizontalOverflow() != RichText::OVERFLOW_OVERFLOW) {
242-
$objWriter->writeAttribute('horzOverflow', $shape->getHorizontalOverflow());
243-
}
244-
if ($shape->getVerticalOverflow() != RichText::OVERFLOW_OVERFLOW) {
245-
$objWriter->writeAttribute('vertOverflow', $shape->getVerticalOverflow());
246-
}
247-
if ($shape->isUpright()) {
248-
$objWriter->writeAttribute('upright', '1');
249-
}
250-
if ($shape->isVertical()) {
251-
$objWriter->writeAttribute('vert', 'vert');
252-
}
253-
$objWriter->writeAttribute('bIns', CommonDrawing::pixelsToEmu($shape->getInsetBottom()));
254-
$objWriter->writeAttribute('lIns', CommonDrawing::pixelsToEmu($shape->getInsetLeft()));
255-
$objWriter->writeAttribute('rIns', CommonDrawing::pixelsToEmu($shape->getInsetRight()));
256-
$objWriter->writeAttribute('tIns', CommonDrawing::pixelsToEmu($shape->getInsetTop()));
257-
if ($shape->getColumns() <> 1) {
258-
$objWriter->writeAttribute('numCol', $shape->getColumns());
259-
}
260-
// a:spAutoFit
261-
$objWriter->startElement('a:' . $shape->getAutoFit());
262-
if ($shape->getAutoFit() == RichText::AUTOFIT_NORMAL) {
263-
if (!is_null($shape->getFontScale())) {
264-
$objWriter->writeAttribute('fontScale', (int)($shape->getFontScale() * 1000));
233+
if (!$shape->isPlaceholder()) {
234+
$verticalAlign = $shape->getActiveParagraph()->getAlignment()->getVertical();
235+
if ($verticalAlign != Alignment::VERTICAL_BASE && $verticalAlign != Alignment::VERTICAL_AUTO) {
236+
$objWriter->writeAttribute('anchor', $verticalAlign);
237+
}
238+
if ($shape->getWrap() != RichText::WRAP_SQUARE) {
239+
$objWriter->writeAttribute('wrap', $shape->getWrap());
240+
}
241+
$objWriter->writeAttribute('rtlCol', '0');
242+
if ($shape->getHorizontalOverflow() != RichText::OVERFLOW_OVERFLOW) {
243+
$objWriter->writeAttribute('horzOverflow', $shape->getHorizontalOverflow());
244+
}
245+
if ($shape->getVerticalOverflow() != RichText::OVERFLOW_OVERFLOW) {
246+
$objWriter->writeAttribute('vertOverflow', $shape->getVerticalOverflow());
247+
}
248+
if ($shape->isUpright()) {
249+
$objWriter->writeAttribute('upright', '1');
265250
}
266-
if (!is_null($shape->getLineSpaceReduction())) {
267-
$objWriter->writeAttribute('lnSpcReduction', (int)($shape->getLineSpaceReduction() * 1000));
251+
if ($shape->isVertical()) {
252+
$objWriter->writeAttribute('vert', 'vert');
268253
}
254+
$objWriter->writeAttribute('bIns', CommonDrawing::pixelsToEmu($shape->getInsetBottom()));
255+
$objWriter->writeAttribute('lIns', CommonDrawing::pixelsToEmu($shape->getInsetLeft()));
256+
$objWriter->writeAttribute('rIns', CommonDrawing::pixelsToEmu($shape->getInsetRight()));
257+
$objWriter->writeAttribute('tIns', CommonDrawing::pixelsToEmu($shape->getInsetTop()));
258+
if ($shape->getColumns() <> 1) {
259+
$objWriter->writeAttribute('numCol', $shape->getColumns());
260+
}
261+
// a:spAutoFit
262+
$objWriter->startElement('a:' . $shape->getAutoFit());
263+
if ($shape->getAutoFit() == RichText::AUTOFIT_NORMAL) {
264+
if (!is_null($shape->getFontScale())) {
265+
$objWriter->writeAttribute('fontScale', (int)($shape->getFontScale() * 1000));
266+
}
267+
if (!is_null($shape->getLineSpaceReduction())) {
268+
$objWriter->writeAttribute('lnSpcReduction', (int)($shape->getLineSpaceReduction() * 1000));
269+
}
270+
}
271+
$objWriter->endElement();
269272
}
270273
$objWriter->endElement();
271-
$objWriter->endElement();
272274
// a:lstStyle
273275
$objWriter->writeElement('a:lstStyle', null);
274276
if ($shape->isPlaceholder() &&
@@ -642,7 +644,13 @@ protected function writeShapeLine(XMLWriter $objWriter, Line $shape, $shapeId)
642644
// p:cNvCxnSpPr
643645
$objWriter->writeElement('p:cNvCxnSpPr', null);
644646
// p:nvPr
645-
$objWriter->writeElement('p:nvPr', null);
647+
$objWriter->startElement('p:nvPr');
648+
if ($shape->isPlaceholder()) {
649+
$objWriter->startElement('p:ph');
650+
$objWriter->writeAttribute('type', $shape->getPlaceholder()->getType());
651+
$objWriter->endElement();
652+
}
653+
$objWriter->endElement();
646654
$objWriter->endElement();
647655
// p:spPr
648656
$objWriter->startElement('p:spPr');
@@ -704,9 +712,7 @@ protected function writeShapeLine(XMLWriter $objWriter, Line $shape, $shapeId)
704712
$objWriter->writeElement('a:avLst');
705713

706714
$objWriter->endElement();
707-
if ($shape->getBorder()->getLineStyle() != Border::LINE_NONE) {
708-
$this->writeBorder($objWriter, $shape->getBorder(), '');
709-
}
715+
$this->writeBorder($objWriter, $shape->getBorder(), '');
710716
$objWriter->endElement();
711717
$objWriter->endElement();
712718
}
@@ -752,6 +758,9 @@ protected function writeShadow(XMLWriter $objWriter, $oShadow)
752758
*/
753759
protected function writeHyperlink(XMLWriter $objWriter, $shape)
754760
{
761+
if (!$shape->hasHyperlink()) {
762+
return;
763+
}
755764
// a:hlinkClick
756765
$objWriter->startElement('a:hlinkClick');
757766
$objWriter->writeAttribute('r:id', $shape->getHyperlink()->relationId);
@@ -1071,7 +1080,13 @@ protected function writeShapeChart(XMLWriter $objWriter, ShapeChart $shape, $sha
10711080
// p:cNvGraphicFramePr
10721081
$objWriter->writeElement('p:cNvGraphicFramePr', null);
10731082
// p:nvPr
1074-
$objWriter->writeElement('p:nvPr', null);
1083+
$objWriter->startElement('p:nvPr');
1084+
if ($shape->isPlaceholder()) {
1085+
$objWriter->startElement('p:ph');
1086+
$objWriter->writeAttribute('type', $shape->getPlaceholder()->getType());
1087+
$objWriter->endElement();
1088+
}
1089+
$objWriter->endElement();
10751090
$objWriter->endElement();
10761091
// p:xfrm
10771092
$objWriter->startElement('p:xfrm');

0 commit comments

Comments
 (0)