From 9e572ecd9b44dd5dc1bcd0f1497fdaa72bdeb00b Mon Sep 17 00:00:00 2001 From: Stephan212 <48237559+Stephan212@users.noreply.github.com> Date: Wed, 21 Aug 2019 10:18:33 +0100 Subject: [PATCH] chart - Add dynamic Legend positions (#1) * Writer/Part/chart.php - Add dynamic Legend positions The position of the legend of charts was always fixed to the right. Adding in the option to set it dynamically via a new option under styles/chart * Update Styles/Chart.php Add in the public functions to getStyle() to get and set the legend position --- src/PhpWord/Style/Chart.php | 35 ++++++++++++++++++++++ src/PhpWord/Writer/Word2007/Part/Chart.php | 3 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 06b4829c..7b271586 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -66,6 +66,13 @@ class Chart extends AbstractStyle */ private $showLegend = false; + /** + * Chart legend Position. + * + * @var string + */ + private $legendPosition = 'r'; + /** * A list of display options for data labels * @@ -285,6 +292,34 @@ class Chart extends AbstractStyle return $this; } + /** + * Get chart legend position + * + * @return string + */ + public function getLegendPosition() + { + return $this->legendPosition; + } + + /** + * Set chart legend position. choices: + * "r" - right of chart + * "b" - bottom of chart + * "t" - top of chart + * "l" - left of chart + * + * default: right + * + * @param bool $value + */ + public function setLegendPosition($value = 'r') + { + $this->legendPosition = $value; + + return $this; + } + /* * Show labels for axis * diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 812d3bf1..dd738d1e 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -131,6 +131,7 @@ class Chart extends AbstractPart $title = $style->getTitle(); $showLegend = $style->isShowLegend(); + $legendPosition = $style->getLegendPosition(); //Chart title if ($title) { @@ -154,7 +155,7 @@ class Chart extends AbstractPart //Chart legend if ($showLegend) { - $xmlWriter->writeRaw(''); + $xmlWriter->writeRaw(''); } $xmlWriter->startElement('c:plotArea');