Skip to content

Commit 536256d

Browse files
authored
Merge pull request #412 from PHPOffice/issue253pptx
#253 : Support for RadarChart
2 parents be74207 + 729db48 commit 536256d

File tree

15 files changed

+725
-275
lines changed

15 files changed

+725
-275
lines changed

docs/changes/1.0.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
- ODPresentation Writer
6666
- PowerPoint2007 Reader
6767
- PowerPoint2007 Writer
68+
- Support for RadarChart - @Progi1984 GH-253
69+
- ODPresentation Writer
70+
- PowerPoint2007 Writer
6871

6972
## Project Management
7073
- Migrated from Travis CI to Github Actions - @Progi1984 GH-635

docs/index.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Below are the supported features for each file formats.
4141
|---------------------------|----------------------|-------|-------|-------|-------|
4242
| **Document** | Mark as final | | | | :material-check: |
4343
| **Document Properties** | Standard | | :material-check: | | :material-check: |
44-
| | Custom | | | | |
44+
| | Custom | | :material-check: | | :material-check: |
4545
| **Slides** | | | :material-check: | | :material-check: |
4646
| | Name | | :material-check: | | |
4747
| **Element Shape** | Image | | :material-check: | | :material-check: |
@@ -51,9 +51,14 @@ Below are the supported features for each file formats.
5151
| | RichText | | :material-check: | | :material-check: |
5252
| | Table | | :material-check: | | :material-check: |
5353
| | Text | | :material-check: | | :material-check: |
54-
| **Charts** | Bar3D | | :material-check: | | :material-check: |
54+
| **Charts** | Area | | :material-check: | | :material-check: |
55+
| | Bar | | :material-check: | | :material-check: |
56+
| | Bar3D | | :material-check: | | :material-check: |
57+
| | Doughnut | | :material-check: | | :material-check: |
5558
| | Line | | :material-check: | | :material-check: |
59+
| | Pie | | :material-check: | | :material-check: |
5660
| | Pie3D | | :material-check: | | :material-check: |
61+
| | Radar | | :material-check: | | :material-check: |
5762
| | Scatter | | :material-check: | | :material-check: |
5863

5964

@@ -63,19 +68,25 @@ Below are the supported features for each file formats.
6368
|---------------------------|----------------------|--------|-------|-------|-------|-------|
6469
| **Document** | Mark as final | | | | | :material-check: |
6570
| **Document Properties** | Standard | | :material-check: | | | :material-check: |
66-
| | Custom | | | | | |
71+
| | Custom | | :material-check: | | | :material-check: |
6772
| **Slides** | | | :material-check: | | | :material-check: |
6873
| | Name | | | | | | :material-check: | |
6974
| **Element Shape** | Image | | :material-check: | | :material-check: | :material-check: |
7075
| | Hyperlink | | :material-check: | | :material-check: | :material-check: |
7176
| | RichText | | :material-check: | | :material-check: | :material-check: |
7277
| | Table | | | | | |
7378
| | Text | | :material-check: | | :material-check: | :material-check: |
74-
| **Charts** | Bar3D | | | | | |
79+
| **Charts** | Area | | | | | |
80+
| | Bar | | | | | |
81+
| | Bar3D | | | | | |
82+
| | Doughnut | | | | | |
7583
| | Line | | | | | |
84+
| | Pie | | | | | |
7685
| | Pie3D | | | | | |
86+
| | Radar | | | | | |
7787
| | Scatter | | | | | |
7888

89+
7990
## Contributing
8091

8192
We welcome everyone to contribute to PHPPresentation. Below are some of the things that you can do to contribute:

docs/usage/shapes/chart.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,21 @@ $chart->isSmooth();
385385

386386
TODO
387387

388+
### Radar
389+
390+
You can create a Radar Chart.
391+
392+
``` php
393+
<?php
394+
395+
use PhpOffice\PhpPresentation\Shape\Chart\Type\Radar;
396+
397+
$radarChart = new Radar();
398+
399+
$shape = $slide->createChartShape();
400+
$shape->getPlotArea()->setType($radarChart);
401+
```
402+
388403
### Scatter
389404

390405
#### Smooth line

samples/Sample_05_Chart.php

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
include_once 'Sample_Header.php';
44

55
use PhpOffice\PhpPresentation\PhpPresentation;
6+
use PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
7+
use PhpOffice\PhpPresentation\Shape\Chart\Legend;
8+
use PhpOffice\PhpPresentation\Shape\Chart\Marker;
69
use PhpOffice\PhpPresentation\Shape\Chart\Series;
710
use PhpOffice\PhpPresentation\Shape\Chart\Type\Area;
811
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar;
912
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar3D;
10-
use PhpOffice\PhpPresentation\Shape\Chart\Type\Line;
13+
use PhpOffice\PhpPresentation\Shape\Chart\Type\Doughnut;
1114
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie;
1215
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie3D;
16+
use PhpOffice\PhpPresentation\Shape\Chart\Type\Radar;
1317
use PhpOffice\PhpPresentation\Shape\Chart\Type\Scatter;
1418
use PhpOffice\PhpPresentation\Style\Alignment;
1519
use PhpOffice\PhpPresentation\Style\Border;
@@ -406,7 +410,7 @@ function fnSlide_Doughnut(PhpPresentation $objPHPPresentation)
406410

407411
// Create a doughnut chart (that should be inserted in a shape)
408412
echo date('H:i:s') . ' Create a non-3D Doughnut chart (that should be inserted in a chart shape)' . EOL;
409-
$doughnutChart = new \PhpOffice\PhpPresentation\Shape\Chart\Type\Doughnut();
413+
$doughnutChart = new Doughnut();
410414
$doughnutChart->setHoleSize(43);
411415
$series = new Series('Downloads', $seriesData);
412416
$series->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF7CB5EC'));
@@ -443,7 +447,7 @@ function fnSlide_Doughnut(PhpPresentation $objPHPPresentation)
443447
$shape->getPlotArea()->setType($doughnutChart);
444448
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
445449
$shape->getLegend()->getFont()->setItalic(true);
446-
$shape->getLegend()->setPosition(\PhpOffice\PhpPresentation\Shape\Chart\Legend::POSITION_LEFT);
450+
$shape->getLegend()->setPosition(Legend::POSITION_LEFT);
447451
}
448452

449453
function fnSlide_Pie3D(PhpPresentation $objPHPPresentation)
@@ -546,6 +550,63 @@ function fnSlide_Pie(PhpPresentation $objPHPPresentation)
546550
$shape->getLegend()->getFont()->setItalic(true);
547551
}
548552

553+
function fnSlide_Radar(PhpPresentation $objPHPPresentation)
554+
{
555+
global $oFill;
556+
global $oShadow;
557+
558+
// Create templated slide
559+
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
560+
$currentSlide = createTemplatedSlide($objPHPPresentation); // local function
561+
562+
// Generate sample data for fourth chart
563+
echo date('H:i:s') . ' Generate sample data for chart' . EOL;
564+
$seriesData = ['Monday' => 0.1, 'Tuesday' => 0.33333, 'Wednesday' => 0.4444, 'Thursday' => 0.5, 'Friday' => 0.4666, 'Saturday' => 0.3666, 'Sunday' => 0.1666];
565+
566+
// Create a scatter chart (that should be inserted in a shape)
567+
echo date('H:i:s') . ' Create a radar chart (that should be inserted in a chart shape)' . EOL;
568+
$oChart = new Radar();
569+
$series = new Series('Downloads', $seriesData);
570+
$series->setShowSeriesName(true);
571+
$series->getMarker()->setSymbol(Marker::SYMBOL_DASH);
572+
$series->getMarker()->setSize(10);
573+
$oChart->addSeries($series);
574+
575+
// Create a shape (chart)
576+
echo date('H:i:s') . ' Create a shape (chart)' . EOL;
577+
$shape = $currentSlide->createChartShape();
578+
$shape->setName('PHPPresentation Daily Download Distribution')
579+
->setResizeProportional(false)
580+
->setHeight(550)
581+
->setWidth(700)
582+
->setOffsetX(120)
583+
->setOffsetY(80);
584+
$shape->setShadow($oShadow);
585+
$shape->setFill($oFill);
586+
$shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
587+
$shape->getTitle()->setText('PHPPresentation Daily Downloads');
588+
$shape->getTitle()->getFont()->setItalic(true);
589+
$shape->getPlotArea()->setType($oChart);
590+
$shape->getView3D()->setRotationX(30);
591+
$shape->getView3D()->setPerspective(30);
592+
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
593+
$shape->getLegend()->getFont()->setItalic(true);
594+
595+
$oGridlines = new Gridlines();
596+
$oGridlines->getOutline()
597+
->setWidth(1)
598+
->getFill()
599+
->setFillType(Fill::FILL_SOLID)
600+
->setStartColor(new Color(Color::COLOR_RED)); // FF0000
601+
$shape->getPlotArea()->getAxisY()
602+
->setMajorGridlines($oGridlines)
603+
->getOutline()
604+
->setWidth(2)
605+
->getFill()
606+
->setFillType(Fill::FILL_SOLID)
607+
->setStartColor(new Color(Color::COLOR_BLUE)); // 0000FF
608+
}
609+
549610
function fnSlide_Scatter(PhpPresentation $objPHPPresentation)
550611
{
551612
global $oFill;
@@ -565,7 +626,7 @@ function fnSlide_Scatter(PhpPresentation $objPHPPresentation)
565626
$lineChart->setIsSmooth(true);
566627
$series = new Series('Downloads', $seriesData);
567628
$series->setShowSeriesName(true);
568-
$series->getMarker()->setSymbol(\PhpOffice\PhpPresentation\Shape\Chart\Marker::SYMBOL_CIRCLE);
629+
$series->getMarker()->setSymbol(Marker::SYMBOL_CIRCLE);
569630
$series->getMarker()->getFill()
570631
->setFillType(Fill::FILL_SOLID)
571632
->setStartColor(new Color('FF6F3510'))
@@ -640,6 +701,8 @@ function fnSlide_Scatter(PhpPresentation $objPHPPresentation)
640701

641702
fnSlide_Pie($objPHPPresentation);
642703

704+
fnSlide_Radar($objPHPPresentation);
705+
643706
fnSlide_Scatter($objPHPPresentation);
644707

645708
// Save file
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPPresentation
14+
*
15+
* @copyright 2009-2015 PHPPresentation contributors
16+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17+
*/
18+
19+
namespace PhpOffice\PhpPresentation\Shape\Chart\Type;
20+
21+
use PhpOffice\PhpPresentation\ComparableInterface;
22+
23+
class Radar extends AbstractType implements ComparableInterface
24+
{
25+
/**
26+
* Get hash code
27+
*
28+
* @return string Hash code
29+
*/
30+
public function getHashCode(): string
31+
{
32+
$hash = '';
33+
foreach ($this->getSeries() as $series) {
34+
$hash .= $series->getHashCode();
35+
}
36+
37+
return md5($hash . __CLASS__);
38+
}
39+
}

src/PhpPresentation/Style/Fill.php

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,26 @@ class Fill implements ComparableInterface
5353
*
5454
* @var string
5555
*/
56-
private $fillType;
56+
private $fillType = self::FILL_NONE;
5757

5858
/**
5959
* Rotation.
6060
*
6161
* @var float
6262
*/
63-
private $rotation;
63+
private $rotation = 0.0;
6464

6565
/**
6666
* Start color.
6767
*
68-
* @var \PhpOffice\PhpPresentation\Style\Color
68+
* @var Color
6969
*/
7070
private $startColor;
7171

7272
/**
7373
* End color.
7474
*
75-
* @var \PhpOffice\PhpPresentation\Style\Color
75+
* @var Color
7676
*/
7777
private $endColor;
7878

@@ -88,31 +88,28 @@ class Fill implements ComparableInterface
8888
*/
8989
public function __construct()
9090
{
91-
// Initialise values
92-
$this->fillType = self::FILL_NONE;
93-
$this->rotation = (float) 0;
94-
$this->startColor = new Color(Color::COLOR_WHITE);
95-
$this->endColor = new Color(Color::COLOR_BLACK);
91+
$this->startColor = new Color(Color::COLOR_BLACK);
92+
$this->endColor = new Color(Color::COLOR_WHITE);
9693
}
9794

9895
/**
9996
* Get Fill Type.
10097
*
10198
* @return string
10299
*/
103-
public function getFillType()
100+
public function getFillType(): string
104101
{
105102
return $this->fillType;
106103
}
107104

108105
/**
109106
* Set Fill Type.
110107
*
111-
* @param string $pValue \PhpOffice\PhpPresentation\Style\Fill fill type
108+
* @param string $pValue Fill type
112109
*
113-
* @return \PhpOffice\PhpPresentation\Style\Fill
110+
* @return self
114111
*/
115-
public function setFillType($pValue = self::FILL_NONE)
112+
public function setFillType(string $pValue = self::FILL_NONE): self
116113
{
117114
$this->fillType = $pValue;
118115

@@ -124,31 +121,31 @@ public function setFillType($pValue = self::FILL_NONE)
124121
*
125122
* @return float
126123
*/
127-
public function getRotation()
124+
public function getRotation(): float
128125
{
129126
return $this->rotation;
130127
}
131128

132129
/**
133130
* Set Rotation.
134131
*
135-
* @param float|int $pValue
132+
* @param float $pValue
136133
*
137-
* @return \PhpOffice\PhpPresentation\Style\Fill
134+
* @return self
138135
*/
139-
public function setRotation($pValue = 0)
136+
public function setRotation(float $pValue = 0): self
140137
{
141-
$this->rotation = (float) $pValue;
138+
$this->rotation = $pValue;
142139

143140
return $this;
144141
}
145142

146143
/**
147144
* Get Start Color.
148145
*
149-
* @return \PhpOffice\PhpPresentation\Style\Color
146+
* @return Color
150147
*/
151-
public function getStartColor()
148+
public function getStartColor(): Color
152149
{
153150
// It's a get but it may lead to a modified color which we won't detect but in which case we must bind.
154151
// So bind as an assurance.
@@ -158,13 +155,13 @@ public function getStartColor()
158155
/**
159156
* Set Start Color.
160157
*
161-
* @param \PhpOffice\PhpPresentation\Style\Color $pValue
158+
* @param Color $pValue
162159
*
163160
* @throws \Exception
164161
*
165-
* @return \PhpOffice\PhpPresentation\Style\Fill
162+
* @return self
166163
*/
167-
public function setStartColor(Color $pValue = null)
164+
public function setStartColor(Color $pValue): self
168165
{
169166
$this->startColor = $pValue;
170167

@@ -174,9 +171,9 @@ public function setStartColor(Color $pValue = null)
174171
/**
175172
* Get End Color.
176173
*
177-
* @return \PhpOffice\PhpPresentation\Style\Color
174+
* @return Color
178175
*/
179-
public function getEndColor()
176+
public function getEndColor(): Color
180177
{
181178
// It's a get but it may lead to a modified color which we won't detect but in which case we must bind.
182179
// So bind as an assurance.
@@ -186,13 +183,11 @@ public function getEndColor()
186183
/**
187184
* Set End Color.
188185
*
189-
* @param \PhpOffice\PhpPresentation\Style\Color $pValue
186+
* @param Color $pValue
190187
*
191-
* @throws \Exception
192-
*
193-
* @return \PhpOffice\PhpPresentation\Style\Fill
188+
* @return self
194189
*/
195-
public function setEndColor(Color $pValue = null)
190+
public function setEndColor(Color $pValue): self
196191
{
197192
$this->endColor = $pValue;
198193

0 commit comments

Comments
 (0)