From 487228be1d71a91428b856d4d3150526384e2993 Mon Sep 17 00:00:00 2001 From: Chris Wolcott Date: Fri, 17 Apr 2020 13:58:42 -0400 Subject: [PATCH 1/5] Hide Axis Allows developer to hide an axis fully (by default it is shown). --- CHANGELOG.md | 3 +++ src/PhpSpreadsheet/Chart/Axis.php | 24 ++++++++++++++++++++++++ src/PhpSpreadsheet/Writer/Xlsx/Chart.php | 4 ++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 593700a4b4..ff0da6aecd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org). ## [Unreleased] - Conditionals - Extend Support for (NOT)CONTAINSBLANKS [#1278](https://github.com/PHPOffice/PhpSpreadsheet/pull/1278) +### Added + +- Allow chart axis to be fully hidden [#1446](https://github.com/PHPOffice/PhpSpreadsheet/issues/1446) ### Fixed diff --git a/src/PhpSpreadsheet/Chart/Axis.php b/src/PhpSpreadsheet/Chart/Axis.php index 66242e3409..7f5a99ab73 100644 --- a/src/PhpSpreadsheet/Chart/Axis.php +++ b/src/PhpSpreadsheet/Chart/Axis.php @@ -26,6 +26,7 @@ class Axis extends Properties * @var array of mixed */ private $axisOptions = [ + 'hide' => 0, 'minimum' => null, 'maximum' => null, 'major_unit' => null, @@ -193,6 +194,29 @@ public function setAxisOptionsProperties($axis_labels, $horizontal_crosses_value ($minor_unit !== null) ? $this->axisOptions['minor_unit'] = (string) $minor_unit : null; } + /** + * Set Axis Visibility to TRUE + */ + public function showAxis () { + $this->axisOptions['hide'] = 0; + } + + /** + * Set Axis Visibility to FALSE + */ + public function hideAxis () { + $this->axisOptions['hide'] = 1; + } + + /** + * Get Axis Visibility. + * + * @return int + */ + public function getAxisVisibilty () { + return $this->axisOptions['hide']; + } + /** * Get Axis Options Property. * diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php index c9c3e055b2..acd1b755bb 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php @@ -415,7 +415,7 @@ private function writeCategoryAxis($objWriter, $xAxisLabel, $id1, $id2, $isMulti $objWriter->endElement(); $objWriter->startElement('c:delete'); - $objWriter->writeAttribute('val', 0); + $objWriter->writeAttribute('val', $yAxis ? $yAxis->getAxisVisibilty() : 0); $objWriter->endElement(); $objWriter->startElement('c:axPos'); @@ -552,7 +552,7 @@ private function writeValueAxis($objWriter, $yAxisLabel, $groupType, $id1, $id2, $objWriter->endElement(); $objWriter->startElement('c:delete'); - $objWriter->writeAttribute('val', 0); + $objWriter->writeAttribute('val', $xAxis ? $xAxis->getAxisVisibilty() : 0); $objWriter->endElement(); $objWriter->startElement('c:axPos'); From 47a183bcceb2919edceba9f46e4248c5572215eb Mon Sep 17 00:00:00 2001 From: Chris Wolcott Date: Fri, 17 Apr 2020 14:39:48 -0400 Subject: [PATCH 2/5] Hide Axis Correct code styling --- src/PhpSpreadsheet/Chart/Axis.php | 10 +++++----- src/PhpSpreadsheet/Writer/Xlsx/Chart.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PhpSpreadsheet/Chart/Axis.php b/src/PhpSpreadsheet/Chart/Axis.php index 7f5a99ab73..0643140b3b 100644 --- a/src/PhpSpreadsheet/Chart/Axis.php +++ b/src/PhpSpreadsheet/Chart/Axis.php @@ -195,16 +195,16 @@ public function setAxisOptionsProperties($axis_labels, $horizontal_crosses_value } /** - * Set Axis Visibility to TRUE + * Set Axis Visibility to TRUE. */ - public function showAxis () { + public function showAxis() { $this->axisOptions['hide'] = 0; } /** - * Set Axis Visibility to FALSE + * Set Axis Visibility to FALSE. */ - public function hideAxis () { + public function hideAxis() { $this->axisOptions['hide'] = 1; } @@ -213,7 +213,7 @@ public function hideAxis () { * * @return int */ - public function getAxisVisibilty () { + public function getAxisVisibilty() { return $this->axisOptions['hide']; } diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php index acd1b755bb..9c3e1be5f6 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php @@ -541,7 +541,7 @@ private function writeValueAxis($objWriter, $yAxisLabel, $groupType, $id1, $id2, if ($xAxis->getAxisOptionsProperty('minimum') !== null) { $objWriter->startElement('c:min'); - $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minimum')); + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minimum'));Chart.php $objWriter->endElement(); } From cc9f959e4611b5bb93b2039c001fa2e1dce176e3 Mon Sep 17 00:00:00 2001 From: Chris Wolcott Date: Fri, 17 Apr 2020 14:48:21 -0400 Subject: [PATCH 3/5] Hide Axis Typo --- src/PhpSpreadsheet/Writer/Xlsx/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php index 9c3e1be5f6..acd1b755bb 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php @@ -541,7 +541,7 @@ private function writeValueAxis($objWriter, $yAxisLabel, $groupType, $id1, $id2, if ($xAxis->getAxisOptionsProperty('minimum') !== null) { $objWriter->startElement('c:min'); - $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minimum'));Chart.php + $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minimum')); $objWriter->endElement(); } From 88dea3d85eb737ea088366c1613994c4c5f39dee Mon Sep 17 00:00:00 2001 From: Chris Wolcott Date: Fri, 17 Apr 2020 14:54:32 -0400 Subject: [PATCH 4/5] Hide Axis Code styling --- src/PhpSpreadsheet/Chart/Axis.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/PhpSpreadsheet/Chart/Axis.php b/src/PhpSpreadsheet/Chart/Axis.php index 0643140b3b..5a7ce3fc43 100644 --- a/src/PhpSpreadsheet/Chart/Axis.php +++ b/src/PhpSpreadsheet/Chart/Axis.php @@ -197,14 +197,16 @@ public function setAxisOptionsProperties($axis_labels, $horizontal_crosses_value /** * Set Axis Visibility to TRUE. */ - public function showAxis() { + public function showAxis() + { $this->axisOptions['hide'] = 0; } /** * Set Axis Visibility to FALSE. */ - public function hideAxis() { + public function hideAxis() + { $this->axisOptions['hide'] = 1; } @@ -213,7 +215,8 @@ public function hideAxis() { * * @return int */ - public function getAxisVisibilty() { + public function getAxisVisibilty() + { return $this->axisOptions['hide']; } From 5ebf8ab5c4575628320e175ad4a3781b4eacb667 Mon Sep 17 00:00:00 2001 From: Chris Wolcott Date: Fri, 17 Apr 2020 20:32:51 -0400 Subject: [PATCH 5/5] Hide Axis No need to test if property exists it is always an Axis type --- src/PhpSpreadsheet/Writer/Xlsx/Chart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php index acd1b755bb..a9ccb80753 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php @@ -415,7 +415,7 @@ private function writeCategoryAxis($objWriter, $xAxisLabel, $id1, $id2, $isMulti $objWriter->endElement(); $objWriter->startElement('c:delete'); - $objWriter->writeAttribute('val', $yAxis ? $yAxis->getAxisVisibilty() : 0); + $objWriter->writeAttribute('val', $yAxis->getAxisVisibilty()); $objWriter->endElement(); $objWriter->startElement('c:axPos'); @@ -552,7 +552,7 @@ private function writeValueAxis($objWriter, $yAxisLabel, $groupType, $id1, $id2, $objWriter->endElement(); $objWriter->startElement('c:delete'); - $objWriter->writeAttribute('val', $xAxis ? $xAxis->getAxisVisibilty() : 0); + $objWriter->writeAttribute('val', $xAxis->getAxisVisibilty()); $objWriter->endElement(); $objWriter->startElement('c:axPos');