From 0c3eb4bafc9b28313fb31c48c6bfc958a362b47f Mon Sep 17 00:00:00 2001
From: Tom-Magill <41332981+Tom-Magill@users.noreply.github.com>
Date: Tue, 17 Jul 2018 14:10:02 +0100
Subject: [PATCH 1/5] Update Chart.php
---
src/PhpWord/Style/Chart.php | 58 +++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php
index 5b02e636..5c96afd2 100644
--- a/src/PhpWord/Style/Chart.php
+++ b/src/PhpWord/Style/Chart.php
@@ -51,6 +51,20 @@ class Chart extends AbstractStyle
* @var array
*/
private $colors = array();
+
+ /**
+ * Chart title
+ *
+ * @var string
+ */
+ private $title = null;
+
+ /**
+ * Chart legend visibility
+ *
+ * @var bool
+ */
+ private $showLegend = false;
/**
* A list of display options for data labels
@@ -220,6 +234,50 @@ class Chart extends AbstractStyle
return $this;
}
+
+ /**
+ * Get the chart title
+ *
+ * @return string
+ */
+ public function getTitle()
+ {
+ return $this->title;
+ }
+
+ /**
+ * Set the chart title
+ *
+ * @param string $value
+ */
+ public function setTitle($value = null)
+ {
+ $this->title = $value;
+
+ return $this;
+ }
+
+ /**
+ * Get chart legend visibility
+ *
+ * @return bool
+ */
+ public function getShowLegend()
+ {
+ return $this->showLegend;
+ }
+
+ /**
+ * Set chart legend visibility
+ *
+ * @param bool $value
+ */
+ public function setShowLegend($value = false)
+ {
+ $this->showLegend = $value;
+
+ return $this;
+ }
/*
* Show labels for axis
From 139242612d750f0258472cf0bbc1f7044610785d Mon Sep 17 00:00:00 2001
From: Tom-Magill <41332981+Tom-Magill@users.noreply.github.com>
Date: Tue, 17 Jul 2018 14:11:55 +0100
Subject: [PATCH 2/5] Update Chart.php
---
src/PhpWord/Writer/Word2007/Part/Chart.php | 32 ++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php
index 5a3ef276..e14a708b 100644
--- a/src/PhpWord/Writer/Word2007/Part/Chart.php
+++ b/src/PhpWord/Writer/Word2007/Part/Chart.php
@@ -105,8 +105,6 @@ class Chart extends AbstractPart
{
$xmlWriter->startElement('c:chart');
- $xmlWriter->writeElementBlock('c:autoTitleDeleted', 'val', 1);
-
$this->writePlotArea($xmlWriter);
$xmlWriter->endElement(); // c:chart
@@ -130,6 +128,36 @@ class Chart extends AbstractPart
$type = $this->element->getType();
$style = $this->element->getStyle();
$this->options = $this->types[$type];
+
+ $title = $style->getTitle();
+ $showLegend = $style->getShowLegend();
+
+ //Chart title
+ if($title){
+ $xmlWriter->startElement('c:title');
+ $xmlWriter->startElement('c:tx');
+ $xmlWriter->startElement('c:rich');
+ $xmlWriter->writeRaw('
+
+
+
+
+ '.$title.'
+
+ ');
+
+ $xmlWriter->endElement(); // c:rich
+ $xmlWriter->endElement(); // c:tx
+ $xmlWriter->endElement(); // c:title
+
+ }else{
+ $xmlWriter->writeElementBlock('c:autoTitleDeleted', 'val', 1);
+ }
+
+ //Chart legend
+ if($showLegend){
+ $xmlWriter->writeRaw('');
+ }
$xmlWriter->startElement('c:plotArea');
$xmlWriter->writeElement('c:layout');
From 5b688d50d82cf491b6114e94bc84de59dc96941d Mon Sep 17 00:00:00 2001
From: troosan
Date: Sun, 2 Dec 2018 23:54:25 +0100
Subject: [PATCH 3/5] fix formatting
---
src/PhpWord/Style/Chart.php | 26 +++++++++++++---------
src/PhpWord/Writer/Word2007/Part/Chart.php | 16 ++++++-------
2 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php
index 5c96afd2..06b4829c 100644
--- a/src/PhpWord/Style/Chart.php
+++ b/src/PhpWord/Style/Chart.php
@@ -51,8 +51,8 @@ class Chart extends AbstractStyle
* @var array
*/
private $colors = array();
-
- /**
+
+ /**
* Chart title
*
* @var string
@@ -111,9 +111,15 @@ class Chart extends AbstractStyle
*/
private $valueAxisTitle;
+ /**
+ * The position for major tick marks
+ * Possible values are 'in', 'out', 'cross', 'none'
+ *
+ * @var string
+ */
private $majorTickMarkPos = 'none';
- /*
+ /**
* Show labels for axis
*
* @var bool
@@ -234,7 +240,7 @@ class Chart extends AbstractStyle
return $this;
}
-
+
/**
* Get the chart title
*
@@ -248,7 +254,7 @@ class Chart extends AbstractStyle
/**
* Set the chart title
*
- * @param string $value
+ * @param string $value
*/
public function setTitle($value = null)
{
@@ -262,7 +268,7 @@ class Chart extends AbstractStyle
*
* @return bool
*/
- public function getShowLegend()
+ public function isShowLegend()
{
return $this->showLegend;
}
@@ -270,7 +276,7 @@ class Chart extends AbstractStyle
/**
* Set chart legend visibility
*
- * @param bool $value
+ * @param bool $value
*/
public function setShowLegend($value = false)
{
@@ -452,8 +458,8 @@ class Chart extends AbstractStyle
}
/**
- * set the position for major tick marks
- * @param string $position [description]
+ * Set the position for major tick marks
+ * @param string $position
*/
public function setMajorTickPosition($position)
{
@@ -461,7 +467,7 @@ class Chart extends AbstractStyle
$this->majorTickMarkPos = $this->setEnumVal($position, $enum, $this->majorTickMarkPos);
}
- /*
+ /**
* Show Gridlines for X-Axis
*
* @return bool
diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php
index e14a708b..812d3bf1 100644
--- a/src/PhpWord/Writer/Word2007/Part/Chart.php
+++ b/src/PhpWord/Writer/Word2007/Part/Chart.php
@@ -128,12 +128,12 @@ class Chart extends AbstractPart
$type = $this->element->getType();
$style = $this->element->getStyle();
$this->options = $this->types[$type];
-
- $title = $style->getTitle();
- $showLegend = $style->getShowLegend();
+
+ $title = $style->getTitle();
+ $showLegend = $style->isShowLegend();
//Chart title
- if($title){
+ if ($title) {
$xmlWriter->startElement('c:title');
$xmlWriter->startElement('c:tx');
$xmlWriter->startElement('c:rich');
@@ -142,20 +142,18 @@ class Chart extends AbstractPart
- '.$title.'
+ ' . $title . '
');
-
$xmlWriter->endElement(); // c:rich
$xmlWriter->endElement(); // c:tx
$xmlWriter->endElement(); // c:title
-
- }else{
+ } else {
$xmlWriter->writeElementBlock('c:autoTitleDeleted', 'val', 1);
}
//Chart legend
- if($showLegend){
+ if ($showLegend) {
$xmlWriter->writeRaw('');
}
From 0c4bd1d02f3b175d3944d6577c377a800e27aace Mon Sep 17 00:00:00 2001
From: troosan
Date: Sun, 2 Dec 2018 23:54:32 +0100
Subject: [PATCH 4/5] update documentation
---
docs/styles.rst | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/docs/styles.rst b/docs/styles.rst
index 8c5de7cb..f8d26a9b 100644
--- a/docs/styles.rst
+++ b/docs/styles.rst
@@ -192,6 +192,14 @@ Available Chart style options:
- ``width``. Width (in EMU).
- ``height``. Height (in EMU).
- ``3d``. Is 3D; applies to pie, bar, line, area, *true* or *false*.
+- ``colors``. A list of colors to use in the chart.
+- ``title``. The title for the chart.
+- ``showLegend``. Show legend, *true* or *false*.
+- ``categoryLabelPosition``. Label position for categories, *nextTo* (default), *low* or *high*.
+- ``valueLabelPosition``. Label position for values, *nextTo* (default), *low* or *high*.
+- ``categoryAxisTitle``. The title for the category axis.
+- ``valueAxisTitle``. The title for the values axis.
+- ``majorTickMarkPos``. The position for major tick marks, *in*, *out*, *cross*, *none* (default).
- ``showAxisLabels``. Show labels for axis, *true* or *false*.
- ``gridX``. Show Gridlines for X-Axis, *true* or *false*.
- ``gridY``. Show Gridlines for Y-Axis, *true* or *false*.
From 9f684c745e3b7f41c304659a77c74967e662f3f1 Mon Sep 17 00:00:00 2001
From: troosan
Date: Sun, 2 Dec 2018 23:54:40 +0100
Subject: [PATCH 5/5] update changelog
---
CHANGELOG.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d1db7a5e..79ae2511 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
v0.16.0 (xx xxx 2018)
----------------------
### Added
+- Add setting Chart Title and Legend visibility @Tom-Magill #1433
### Fixed
- Fix regex in `cloneBlock` function @nicoder #1269