Skip to content

Commit

Permalink
#253 : PowerPoint2007 Writer : Support for RadarChart
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Aug 3, 2021
1 parent be74207 commit 8d52189
Show file tree
Hide file tree
Showing 12 changed files with 385 additions and 104 deletions.
3 changes: 3 additions & 0 deletions docs/changes/1.0.0.md
Expand Up @@ -65,6 +65,9 @@
- ODPresentation Writer
- PowerPoint2007 Reader
- PowerPoint2007 Writer
- Support for RadarChart - @Progi1984 GH-253
- ODPresentation Writer
- PowerPoint2007 Writer

## Project Management
- Migrated from Travis CI to Github Actions - @Progi1984 GH-635
Expand Down
71 changes: 67 additions & 4 deletions samples/Sample_05_Chart.php
Expand Up @@ -3,13 +3,17 @@
include_once 'Sample_Header.php';

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
use PhpOffice\PhpPresentation\Shape\Chart\Legend;
use PhpOffice\PhpPresentation\Shape\Chart\Marker;
use PhpOffice\PhpPresentation\Shape\Chart\Series;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Area;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar3D;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Line;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Doughnut;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie3D;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Radar;
use PhpOffice\PhpPresentation\Shape\Chart\Type\Scatter;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Style\Border;
Expand Down Expand Up @@ -406,7 +410,7 @@ function fnSlide_Doughnut(PhpPresentation $objPHPPresentation)

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

function fnSlide_Pie3D(PhpPresentation $objPHPPresentation)
Expand Down Expand Up @@ -546,6 +550,63 @@ function fnSlide_Pie(PhpPresentation $objPHPPresentation)
$shape->getLegend()->getFont()->setItalic(true);
}

function fnSlide_Radar(PhpPresentation $objPHPPresentation)
{
global $oFill;
global $oShadow;

// Create templated slide
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
$currentSlide = createTemplatedSlide($objPHPPresentation); // local function

// Generate sample data for fourth chart
echo date('H:i:s') . ' Generate sample data for chart' . EOL;
$seriesData = ['Monday' => 0.1, 'Tuesday' => 0.33333, 'Wednesday' => 0.4444, 'Thursday' => 0.5, 'Friday' => 0.4666, 'Saturday' => 0.3666, 'Sunday' => 0.1666];

// Create a scatter chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a radar chart (that should be inserted in a chart shape)' . EOL;
$oChart = new Radar();
$series = new Series('Downloads', $seriesData);
$series->setShowSeriesName(true);
$series->getMarker()->setSymbol(Marker::SYMBOL_DASH);
$series->getMarker()->setSize(10);
$oChart->addSeries($series);

// Create a shape (chart)
echo date('H:i:s') . ' Create a shape (chart)' . EOL;
$shape = $currentSlide->createChartShape();
$shape->setName('PHPPresentation Daily Download Distribution')
->setResizeProportional(false)
->setHeight(550)
->setWidth(700)
->setOffsetX(120)
->setOffsetY(80);
$shape->setShadow($oShadow);
$shape->setFill($oFill);
$shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getTitle()->setText('PHPPresentation Daily Downloads');
$shape->getTitle()->getFont()->setItalic(true);
$shape->getPlotArea()->setType($oChart);
$shape->getView3D()->setRotationX(30);
$shape->getView3D()->setPerspective(30);
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getLegend()->getFont()->setItalic(true);

$oGridlines = new Gridlines();
$oGridlines->getOutline()
->setWidth(1)
->getFill()
->setFillType(Fill::FILL_SOLID)
->setStartColor(new Color(Color::COLOR_RED)); // FF0000
$shape->getPlotArea()->getAxisY()
->setMajorGridlines($oGridlines)
->getOutline()
->setWidth(2)
->getFill()
->setFillType(Fill::FILL_SOLID)
->setStartColor(new Color(Color::COLOR_BLUE)); // 0000FF
}

function fnSlide_Scatter(PhpPresentation $objPHPPresentation)
{
global $oFill;
Expand All @@ -565,7 +626,7 @@ function fnSlide_Scatter(PhpPresentation $objPHPPresentation)
$lineChart->setIsSmooth(true);
$series = new Series('Downloads', $seriesData);
$series->setShowSeriesName(true);
$series->getMarker()->setSymbol(\PhpOffice\PhpPresentation\Shape\Chart\Marker::SYMBOL_CIRCLE);
$series->getMarker()->setSymbol(Marker::SYMBOL_CIRCLE);
$series->getMarker()->getFill()
->setFillType(Fill::FILL_SOLID)
->setStartColor(new Color('FF6F3510'))
Expand Down Expand Up @@ -640,6 +701,8 @@ function fnSlide_Scatter(PhpPresentation $objPHPPresentation)

fnSlide_Pie($objPHPPresentation);

fnSlide_Radar($objPHPPresentation);

fnSlide_Scatter($objPHPPresentation);

// Save file
Expand Down
39 changes: 39 additions & 0 deletions src/PhpPresentation/Shape/Chart/Type/Radar.php
@@ -0,0 +1,39 @@
<?php
/**
* This file is part of PHPPresentation - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPresentation is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
*
* @see https://github.com/PHPOffice/PHPPresentation
*
* @copyright 2009-2015 PHPPresentation contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpPresentation\Shape\Chart\Type;

use PhpOffice\PhpPresentation\ComparableInterface;

class Radar extends AbstractType implements ComparableInterface
{
/**
* Get hash code
*
* @return string Hash code
*/
public function getHashCode(): string
{
$hash = '';
foreach ($this->getSeries() as $series) {
$hash .= $series->getHashCode();
}

return md5($hash . __CLASS__);
}
}
55 changes: 25 additions & 30 deletions src/PhpPresentation/Style/Fill.php
Expand Up @@ -53,26 +53,26 @@ class Fill implements ComparableInterface
*
* @var string
*/
private $fillType;
private $fillType = self::FILL_NONE;

/**
* Rotation.
*
* @var float
*/
private $rotation;
private $rotation = 0.0;

/**
* Start color.
*
* @var \PhpOffice\PhpPresentation\Style\Color
* @var Color
*/
private $startColor;

/**
* End color.
*
* @var \PhpOffice\PhpPresentation\Style\Color
* @var Color
*/
private $endColor;

Expand All @@ -88,31 +88,28 @@ class Fill implements ComparableInterface
*/
public function __construct()
{
// Initialise values
$this->fillType = self::FILL_NONE;
$this->rotation = (float) 0;
$this->startColor = new Color(Color::COLOR_WHITE);
$this->endColor = new Color(Color::COLOR_BLACK);
$this->startColor = new Color(Color::COLOR_BLACK);
$this->endColor = new Color(Color::COLOR_WHITE);
}

/**
* Get Fill Type.
*
* @return string
*/
public function getFillType()
public function getFillType(): string
{
return $this->fillType;
}

/**
* Set Fill Type.
*
* @param string $pValue \PhpOffice\PhpPresentation\Style\Fill fill type
* @param string $pValue Fill type
*
* @return \PhpOffice\PhpPresentation\Style\Fill
* @return self
*/
public function setFillType($pValue = self::FILL_NONE)
public function setFillType(string $pValue = self::FILL_NONE): self
{
$this->fillType = $pValue;

Expand All @@ -124,31 +121,31 @@ public function setFillType($pValue = self::FILL_NONE)
*
* @return float
*/
public function getRotation()
public function getRotation(): float
{
return $this->rotation;
}

/**
* Set Rotation.
*
* @param float|int $pValue
* @param float $pValue
*
* @return \PhpOffice\PhpPresentation\Style\Fill
* @return self
*/
public function setRotation($pValue = 0)
public function setRotation(float $pValue = 0): self
{
$this->rotation = (float) $pValue;
$this->rotation = $pValue;

return $this;
}

/**
* Get Start Color.
*
* @return \PhpOffice\PhpPresentation\Style\Color
* @return Color
*/
public function getStartColor()
public function getStartColor(): Color
{
// It's a get but it may lead to a modified color which we won't detect but in which case we must bind.
// So bind as an assurance.
Expand All @@ -158,13 +155,13 @@ public function getStartColor()
/**
* Set Start Color.
*
* @param \PhpOffice\PhpPresentation\Style\Color $pValue
* @param Color $pValue
*
* @throws \Exception
*
* @return \PhpOffice\PhpPresentation\Style\Fill
* @return self
*/
public function setStartColor(Color $pValue = null)
public function setStartColor(Color $pValue): self
{
$this->startColor = $pValue;

Expand All @@ -174,9 +171,9 @@ public function setStartColor(Color $pValue = null)
/**
* Get End Color.
*
* @return \PhpOffice\PhpPresentation\Style\Color
* @return Color
*/
public function getEndColor()
public function getEndColor(): Color
{
// It's a get but it may lead to a modified color which we won't detect but in which case we must bind.
// So bind as an assurance.
Expand All @@ -186,13 +183,11 @@ public function getEndColor()
/**
* Set End Color.
*
* @param \PhpOffice\PhpPresentation\Style\Color $pValue
* @param Color $pValue
*
* @throws \Exception
*
* @return \PhpOffice\PhpPresentation\Style\Fill
* @return self
*/
public function setEndColor(Color $pValue = null)
public function setEndColor(Color $pValue): self
{
$this->endColor = $pValue;

Expand Down
9 changes: 5 additions & 4 deletions src/PhpPresentation/Style/Outline.php
Expand Up @@ -27,10 +27,11 @@ class Outline
* @var Fill
*/
protected $fill;

/**
* @var int|null
* @var float
*/
protected $width;
protected $width = 1;

public function __construct()
{
Expand All @@ -49,15 +50,15 @@ public function setFill(Fill $fill): self
return $this;
}

public function getWidth(): ?int
public function getWidth(): float
{
return $this->width;
}

/**
* Value in points.
*/
public function setWidth(int $pValue = 0): self
public function setWidth(float $pValue = 1): self
{
$this->width = $pValue;

Expand Down

0 comments on commit 8d52189

Please sign in to comment.