Skip to content

Commit 6c46ff2

Browse files
authored
Merge pull request #658 from Progi1984/markerBorderFill
Added support for Border & Fill for Chart's Marker in PowerPoint2007 Writer
2 parents e15d411 + 921dbfd commit 6c46ff2

File tree

9 files changed

+281
-57
lines changed

9 files changed

+281
-57
lines changed

docs/changes/1.0.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- ODPresentation Writer
3636
- PowerPoint2007 Reader
3737
- PowerPoint2007 Writer
38+
- Support for Border & Fill for Chart's Marker in PowerPoint2007 Writer - @ksmeeks0001 GH-627 & @Progi1986 GH-658
3839

3940
## Project Management
4041
- Migrated from Travis CI to Github Actions - @Progi1984 GH-635

docs/usage/shapes/chart.md

Lines changed: 66 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ For each gridline, you can custom the width (in points), the fill type and the f
1818
``` php
1919
<?php
2020

21-
use \PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
21+
use PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
2222

2323
$line = new Line();
2424

@@ -37,7 +37,7 @@ For resetting them, you pass null as parameter to these methods.
3737
``` php
3838
<?php
3939

40-
use \PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
40+
use PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
4141

4242
$line = new Line();
4343

@@ -66,7 +66,7 @@ For resetting them, you pass Axis::TICK_MARK_NONE as parameter to these methods.
6666
``` php
6767
<?php
6868

69-
use \PhpOffice\PhpPresentation\Shape\Chart\Axis;
69+
use PhpOffice\PhpPresentation\Shape\Chart\Axis;
7070

7171
$line = new Line();
7272

@@ -82,7 +82,7 @@ For resetting them, you pass null as parameter to these methods.
8282
``` php
8383
<?php
8484

85-
use \PhpOffice\PhpPresentation\Shape\Chart\Axis;
85+
use PhpOffice\PhpPresentation\Shape\Chart\Axis;
8686

8787
$line = new Line();
8888

@@ -121,6 +121,23 @@ $shape->getTitle()->setVisible(false);
121121

122122
### Series
123123

124+
#### Display Informations
125+
You can define if some informations are displayed.
126+
127+
``` php
128+
<?php
129+
130+
$series = new Series('Downloads', $seriesData);
131+
$series->setSeparator(';');
132+
$series->setShowCategoryName(true);
133+
$series->setShowLeaderLines(true);
134+
$series->setShowLegendKey(true);
135+
$series->setShowPercentage(true);
136+
$series->setShowSeriesName(true);
137+
$series->setShowValue(true);
138+
```
139+
140+
#### Font
124141
You can custom the font of a serie.
125142

126143
``` php
@@ -131,59 +148,81 @@ $series = new Series('Downloads', $seriesData);
131148
$series->getFont()->setSize(25);
132149
```
133150

151+
#### Label Position
152+
You can define the position of the data label.
153+
Each position is described in [MSDN](https://msdn.microsoft.com/en-us/library/mt459417(v=office.12).aspx).
154+
155+
``` php
156+
<?php
157+
158+
$series = new Series('Downloads', $seriesData);
159+
$series->setLabelPosition(Series::LABEL_INSIDEEND);
160+
```
161+
162+
#### Marker
134163
You can custom the marker of a serie, for Line & Scatter charts.
135164

165+
##### Customize the border
166+
167+
!!! warning
168+
Available only on the PowerPoint2007 Writer
169+
136170
``` php
137171
<?php
138172

139-
use \PhpOffice\PhpPresentation\Shape\Chart\Marker;
173+
use PhpOffice\PhpPresentation\Shape\Chart\Marker;
174+
use PhpOffice\PhpPresentation\Style\Border;
140175

141176
$series = new Series('Downloads', $seriesData);
142177
$marker = $series->getMarker();
143-
$marker->setSymbol(Marker::SYMBOL_DASH)->setSize(10);
178+
$marker->getBorder()->setLineStyle(Border::LINE_SINGLE);
144179
```
145180

146-
You can custom the line of a serie, for Line & Scatter charts.
181+
##### Customize the fill
182+
183+
!!! warning
184+
Available only on the PowerPoint2007 Writer
147185

148186
``` php
149187
<?php
150188

151-
use \PhpOffice\PhpPresentation\Style\Outline;
152-
153-
$outline = new Outline();
154-
// Define the color
155-
$outline->getFill()->setFillType(Fill::FILL_SOLID);
156-
$outline->getFill()->setStartColor(new Color(Color::COLOR_YELLOW));
157-
// Define the width (in points)
158-
$outline->setWidth(2);
189+
use PhpOffice\PhpPresentation\Shape\Chart\Marker;
190+
use PhpOffice\PhpPresentation\Style\Fill;
159191

160192
$series = new Series('Downloads', $seriesData);
161-
$series->setOutline($outline);
193+
$marker = $series->getMarker();
194+
$marker->getFill()->setFillType(Fill::FILL_SOLID);
162195
```
163196

164-
You can define the position of the data label.
165-
Each position is described in [MSDN](https://msdn.microsoft.com/en-us/library/mt459417(v=office.12).aspx).
197+
##### Customize the symbol
166198

167199
``` php
168200
<?php
169201

202+
use PhpOffice\PhpPresentation\Shape\Chart\Marker;
203+
170204
$series = new Series('Downloads', $seriesData);
171-
$series->setLabelPosition(Series::LABEL_INSIDEEND);
205+
$marker = $series->getMarker();
206+
$marker->setSymbol(Marker::SYMBOL_DASH)->setSize(10);
172207
```
173208

174-
You can define if some informations are displayed.
209+
#### Outline
210+
You can custom the line of a serie, for Line & Scatter charts.
175211

176212
``` php
177213
<?php
178214

215+
use PhpOffice\PhpPresentation\Style\Outline;
216+
217+
$outline = new Outline();
218+
// Define the color
219+
$outline->getFill()->setFillType(Fill::FILL_SOLID);
220+
$outline->getFill()->setStartColor(new Color(Color::COLOR_YELLOW));
221+
// Define the width (in points)
222+
$outline->setWidth(2);
223+
179224
$series = new Series('Downloads', $seriesData);
180-
$series->setSeparator(';');
181-
$series->setShowCategoryName(true);
182-
$series->setShowLeaderLines(true);
183-
$series->setShowLegendKey(true);
184-
$series->setShowPercentage(true);
185-
$series->setShowSeriesName(true);
186-
$series->setShowValue(true);
225+
$series->setOutline($outline);
187226
```
188227

189228
### View3D

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ markdown_extensions:
3434
- pymdownx.emoji:
3535
emoji_index: !!python/name:materialx.emoji.twemoji
3636
emoji_generator: !!python/name:materialx.emoji.to_svg
37+
## Support for call-outs
38+
- admonition
39+
- pymdownx.details
3740
use_directory_urls: false
3841

3942
## Navigation

samples/Sample_05_Chart.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,12 @@ function fnSlide_Scatter(PhpPresentation $objPHPPresentation)
564564
$lineChart = new Scatter();
565565
$series = new Series('Downloads', $seriesData);
566566
$series->setShowSeriesName(true);
567-
$series->getMarker()->setSymbol(\PhpOffice\PhpPresentation\Shape\Chart\Marker::SYMBOL_DASH);
567+
$series->getMarker()->setSymbol(\PhpOffice\PhpPresentation\Shape\Chart\Marker::SYMBOL_CIRCLE);
568+
$series->getMarker()->getFill()
569+
->setFillType(Fill::FILL_SOLID)
570+
->setStartColor(new Color('FF6F3510'))
571+
->setEndColor(new Color('FF6F3510'));
572+
$series->getMarker()->getBorder()->getColor()->setRGB('FF0000');
568573
$series->getMarker()->setSize(10);
569574
$lineChart->addSeries($series);
570575

src/PhpPresentation/Shape/Chart/Marker.php

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
namespace PhpOffice\PhpPresentation\Shape\Chart;
2020

21-
/**
22-
* \PhpOffice\PhpPresentation\Shape\Chart\Axis.
23-
*/
21+
use PhpOffice\PhpPresentation\Style\Border;
22+
use PhpOffice\PhpPresentation\Style\Fill;
23+
2424
class Marker
2525
{
2626
public const SYMBOL_CIRCLE = 'circle';
@@ -60,6 +60,22 @@ class Marker
6060
*/
6161
protected $size = 5;
6262

63+
/**
64+
* @var Fill
65+
*/
66+
protected $fill;
67+
68+
/**
69+
* @var Border
70+
*/
71+
protected $border;
72+
73+
public function __construct()
74+
{
75+
$this->fill = new Fill();
76+
$this->border = new Border();
77+
}
78+
6379
public function getSymbol(): string
6480
{
6581
return $this->symbol;
@@ -83,4 +99,44 @@ public function setSize(int $size = 5): self
8399

84100
return $this;
85101
}
102+
103+
/**
104+
* @return Fill
105+
*/
106+
public function getFill(): Fill
107+
{
108+
return $this->fill;
109+
}
110+
111+
/**
112+
* @param Fill $fill
113+
*
114+
* @return self
115+
*/
116+
public function setFill(Fill $fill): self
117+
{
118+
$this->fill = $fill;
119+
120+
return $this;
121+
}
122+
123+
/**
124+
* @return Border
125+
*/
126+
public function getBorder(): Border
127+
{
128+
return $this->border;
129+
}
130+
131+
/**
132+
* @param Border $border
133+
*
134+
* @return self
135+
*/
136+
public function setBorder(Border $border): self
137+
{
138+
$this->border = $border;
139+
140+
return $this;
141+
}
86142
}

src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ protected function writeRelationship(XMLWriter $objWriter, int $pId = 1, string
4747
* @param XMLWriter $objWriter XML Writer
4848
* @param Border $pBorder Border
4949
* @param string $pElementName Element name
50+
* @param bool $isMarker
5051
*
5152
* @throws \Exception
5253
*/
53-
protected function writeBorder(XMLWriter $objWriter, Border $pBorder, string $pElementName = 'L'): void
54+
protected function writeBorder(XMLWriter $objWriter, Border $pBorder, string $pElementName = 'L', bool $isMarker = false): void
5455
{
5556
if (!($pBorder instanceof Border)) {
5657
return;
5758
}
5859

59-
if (Border::LINE_NONE == $pBorder->getLineStyle() && '' == $pElementName) {
60+
if (Border::LINE_NONE == $pBorder->getLineStyle() && '' == $pElementName && !$isMarker) {
6061
return;
6162
}
6263

@@ -158,14 +159,15 @@ protected function writeFill(XMLWriter $objWriter, ?Fill $pFill): void
158159
return;
159160
}
160161

161-
// Check if this is a pattern type or gradient type
162+
// Is it a gradient fill?
162163
if (Fill::FILL_GRADIENT_LINEAR == $pFill->getFillType() || Fill::FILL_GRADIENT_PATH == $pFill->getFillType()) {
163-
// Gradient fill
164164
$this->writeGradientFill($objWriter, $pFill);
165-
} else {
166-
// Pattern fill
167-
$this->writePatternFill($objWriter, $pFill);
165+
166+
return;
168167
}
168+
169+
// Is it a pattern fill?
170+
$this->writePatternFill($objWriter, $pFill);
169171
}
170172

171173
/**

src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,18 +2058,18 @@ public function writeChartRelationships(Chart $pChart): string
20582058
return $objWriter->getData();
20592059
}
20602060

2061-
protected function writeSeriesMarker(XMLWriter $objWriter, Chart\Marker $oMarker): void
2061+
protected function writeSeriesMarker(XMLWriter $objWriter, Chart\Marker $marker): void
20622062
{
20632063
// c:marker
20642064
$objWriter->startElement('c:marker');
20652065
// c:marker > c:symbol
20662066
$objWriter->startElement('c:symbol');
2067-
$objWriter->writeAttribute('val', $oMarker->getSymbol());
2067+
$objWriter->writeAttribute('val', $marker->getSymbol());
20682068
$objWriter->endElement();
20692069

20702070
// Size if different of none
2071-
if (Chart\Marker::SYMBOL_NONE != $oMarker->getSymbol()) {
2072-
$markerSize = (int) $oMarker->getSize();
2071+
if (Chart\Marker::SYMBOL_NONE != $marker->getSymbol()) {
2072+
$markerSize = (int) $marker->getSize();
20732073
if ($markerSize < 2) {
20742074
$markerSize = 2;
20752075
}
@@ -2086,6 +2086,14 @@ protected function writeSeriesMarker(XMLWriter $objWriter, Chart\Marker $oMarker
20862086
$objWriter->writeAttribute('val', $markerSize);
20872087
$objWriter->endElement();
20882088
}
2089+
2090+
// // c:marker > c:spPr
2091+
$objWriter->startElement('c:spPr');
2092+
$this->writeFill($objWriter, $marker->getFill());
2093+
$this->writeBorder($objWriter, $marker->getBorder(), '', true);
2094+
$objWriter->endElement();
2095+
2096+
// > c:marker
20892097
$objWriter->endElement();
20902098
}
20912099

0 commit comments

Comments
 (0)