From d42854ddb6c0083622c7905cb607f453b01aa0c3 Mon Sep 17 00:00:00 2001 From: csk83 Date: Sat, 29 Aug 2020 20:41:25 +0800 Subject: [PATCH] chart doc/sample/code comments --- docs/styles.rst | 1 + samples/Sample_32_Chart.php | 5 +++++ src/PhpWord/Style/Chart.php | 19 ++++++++++++++----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/docs/styles.rst b/docs/styles.rst index 18a9c2ec..06d983e5 100644 --- a/docs/styles.rst +++ b/docs/styles.rst @@ -201,6 +201,7 @@ Available Chart style options: - ``colors``. A list of colors to use in the chart. - ``title``. The title for the chart. - ``showLegend``. Show legend, *true* or *false*. +- ``LegendPosition``. Legend position, *r* (default), *b*, *t*, *l* or *tr*. - ``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. diff --git a/samples/Sample_32_Chart.php b/samples/Sample_32_Chart.php index c24a6f8e..bfb9ffe8 100644 --- a/samples/Sample_32_Chart.php +++ b/samples/Sample_32_Chart.php @@ -25,6 +25,9 @@ $series2 = array(3, 1, 7, 2, 6); $series3 = array(8, 3, 2, 5, 4); $showGridLines = false; $showAxisLabels = false; +$showLegend = true; +$legendPosition = 't'; +// r = right, l = left, t = top, b = bottom, tr = top right foreach ($chartTypes as $chartType) { $section->addTitle(ucfirst($chartType), 2); @@ -33,6 +36,8 @@ foreach ($chartTypes as $chartType) { $chart->getStyle()->setShowGridX($showGridLines); $chart->getStyle()->setShowGridY($showGridLines); $chart->getStyle()->setShowAxisLabels($showAxisLabels); + $chart->getStyle()->setShowLegend($showLegend); + $chart->getStyle()->setLegendPosition($legendPosition); if (in_array($chartType, $twoSeries)) { $chart->addSeries($categories, $series2); } diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index f6de7c22..c02c0af4 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -67,7 +67,8 @@ class Chart extends AbstractStyle private $showLegend = false; /** - * Chart legend Position. + * Chart legend Position. + * Possible values are 'r', 't', 'b', 'l', 'tr' * * @var string */ @@ -240,6 +241,7 @@ class Chart extends AbstractStyle * Set the colors to use in a chart. * * @param array $value a list of colors to use in the chart + * @return self */ public function setColors($value = array()) { @@ -262,6 +264,7 @@ class Chart extends AbstractStyle * Set the chart title * * @param string $value + * @return self */ public function setTitle($value = null) { @@ -284,6 +287,7 @@ class Chart extends AbstractStyle * Set chart legend visibility * * @param bool $value + * @return self */ public function setShowLegend($value = false) { @@ -312,11 +316,13 @@ class Chart extends AbstractStyle * * default: right * - * @param bool $value + * @param string $legendPosition + * @return self */ - public function setLegendPosition($value = 'r') + public function setLegendPosition($legendPosition = 'r') { - $this->legendPosition = $value; + $enum = array('r', 'b', 't', 'l', 'tr'); + $this->legendPosition = $this->setEnumVal($legendPosition, $enum, $this->legendPosition); return $this; } @@ -364,7 +370,10 @@ class Chart extends AbstractStyle { foreach (array_keys($this->dataLabelOptions) as $option) { if (isset($values[$option])) { - $this->dataLabelOptions[$option] = $this->setBoolVal($values[$option], $this->dataLabelOptions[$option]); + $this->dataLabelOptions[$option] = $this->setBoolVal( + $values[$option], + $this->dataLabelOptions[$option] + ); } } }