From fc1fec5a53667e61363b1eb6d0b98899b71ec8ac Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Fri, 12 Jan 2018 10:45:26 -0700 Subject: [PATCH 01/68] debug code --- src/PhpWord/Writer/Word2007/Part/Chart.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index c3703f9f6d..f5d2fe3257 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -184,6 +184,8 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) { $series = $this->element->getSeries(); + print_r($series); + $index = 0; foreach ($series as $seriesItem) { $categories = $seriesItem['categories']; From ca459f261fb08a8f6d46c7b30b563f24a82da922 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Fri, 12 Jan 2018 11:33:22 -0700 Subject: [PATCH 02/68] bring back old way of writing text in chart series items --- src/PhpWord/Writer/Word2007/Part/Chart.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index f5d2fe3257..e1947e25c9 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -184,8 +184,6 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) { $series = $this->element->getSeries(); - print_r($series); - $index = 0; foreach ($series as $seriesItem) { $categories = $seriesItem['categories']; @@ -238,7 +236,13 @@ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values) $xmlWriter->startElement('c:pt'); $xmlWriter->writeAttribute('idx', $index); $xmlWriter->startElement('c:v'); - $this->writeText($value); + if (\PhpOffice\PhpWord\Settings::isOutputEscapingEnabled()) { + $xmlWriter->writeElement('c:v', $value); + } else { + $xmlWriter->startElement('c:v'); + $xmlWriter->writeRaw($value); + $xmlWriter->endElement(); + } $xmlWriter->endElement(); // c:v $xmlWriter->endElement(); // c:pt $index++; From 02191611a94ef9e52ed744dbeac4cffa6f64e5f0 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Fri, 12 Jan 2018 11:36:39 -0700 Subject: [PATCH 03/68] add stacked bar and column charts --- src/PhpWord/Writer/Word2007/Part/Chart.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index e1947e25c9..6bd8786da7 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -41,14 +41,16 @@ class Chart extends AbstractPart * @var array */ private $types = array( - 'pie' => array('type' => 'pie', 'colors' => 1), - 'doughnut' => array('type' => 'doughnut', 'colors' => 1, 'hole' => 75, 'no3d' => true), - 'bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar'), - 'column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col'), - 'line' => array('type' => 'line', 'colors' => 0, 'axes' => true), - 'area' => array('type' => 'area', 'colors' => 0, 'axes' => true), - 'radar' => array('type' => 'radar', 'colors' => 0, 'axes' => true, 'radar' => 'standard', 'no3d' => true), - 'scatter' => array('type' => 'scatter', 'colors' => 0, 'axes' => true, 'scatter' => 'marker', 'no3d' => true), + 'pie' => array('type' => 'pie', 'colors' => 1), + 'doughnut' => array('type' => 'doughnut', 'colors' => 1, 'hole' => 75, 'no3d' => true), + 'bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'clustered'), + 'stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'stacked'), + 'column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'clustered'), + 'stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'stacked'), + 'line' => array('type' => 'line', 'colors' => 0, 'axes' => true), + 'area' => array('type' => 'area', 'colors' => 0, 'axes' => true), + 'radar' => array('type' => 'radar', 'colors' => 0, 'axes' => true, 'radar' => 'standard', 'no3d' => true), + 'scatter' => array('type' => 'scatter', 'colors' => 0, 'axes' => true, 'scatter' => 'marker', 'no3d' => true), ); /** @@ -145,7 +147,7 @@ private function writePlotArea(XMLWriter $xmlWriter) } if (isset($this->options['bar'])) { $xmlWriter->writeElementBlock('c:barDir', 'val', $this->options['bar']); // bar|col - $xmlWriter->writeElementBlock('c:grouping', 'val', 'clustered'); // 3d; standard = percentStacked + $xmlWriter->writeElementBlock('c:grouping', 'val', $this->options['grouping']); // 3d; standard = percentStacked } if (isset($this->options['radar'])) { $xmlWriter->writeElementBlock('c:radarStyle', 'val', $this->options['radar']); From 11975d6b01e86125551e02ecd9f7c06be2a86396 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Fri, 12 Jan 2018 11:43:40 -0700 Subject: [PATCH 04/68] allow stacked bar and column charts to be added to documents --- src/PhpWord/Element/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Element/Chart.php b/src/PhpWord/Element/Chart.php index c340da4058..898d50fbef 100644 --- a/src/PhpWord/Element/Chart.php +++ b/src/PhpWord/Element/Chart.php @@ -86,7 +86,7 @@ public function getType() */ public function setType($value) { - $enum = array('pie', 'doughnut', 'line', 'bar', 'column', 'area', 'radar', 'scatter'); + $enum = array('pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'column', 'stacked_column' 'area', 'radar', 'scatter'); $this->type = $this->setEnumVal($value, $enum, 'pie'); } From 4b50d9a0b3c2ec55598f1e55628eec10ce8df3a1 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Fri, 12 Jan 2018 11:52:50 -0700 Subject: [PATCH 05/68] forgot a comma --- src/PhpWord/Element/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Element/Chart.php b/src/PhpWord/Element/Chart.php index 898d50fbef..86eefdabc8 100644 --- a/src/PhpWord/Element/Chart.php +++ b/src/PhpWord/Element/Chart.php @@ -86,7 +86,7 @@ public function getType() */ public function setType($value) { - $enum = array('pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'column', 'stacked_column' 'area', 'radar', 'scatter'); + $enum = array('pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'column', 'stacked_column', 'area', 'radar', 'scatter'); $this->type = $this->setEnumVal($value, $enum, 'pie'); } From 8d7e6e0bd1cb4ec78fd0a40e60598826032a0406 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Fri, 12 Jan 2018 12:32:10 -0700 Subject: [PATCH 06/68] remove extra 's on series element values --- src/PhpWord/Writer/Word2007/Part/Chart.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 6bd8786da7..2ff9164fb1 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -237,15 +237,13 @@ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values) foreach ($values as $value) { $xmlWriter->startElement('c:pt'); $xmlWriter->writeAttribute('idx', $index); - $xmlWriter->startElement('c:v'); if (\PhpOffice\PhpWord\Settings::isOutputEscapingEnabled()) { $xmlWriter->writeElement('c:v', $value); } else { $xmlWriter->startElement('c:v'); $xmlWriter->writeRaw($value); - $xmlWriter->endElement(); + $xmlWriter->endElement(); // c:v } - $xmlWriter->endElement(); // c:v $xmlWriter->endElement(); // c:pt $index++; } From 3743a9a2e1e419c04146b2d3f2609851bc40c6f3 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Fri, 12 Jan 2018 14:13:46 -0700 Subject: [PATCH 07/68] possible fix for stack charts behaving strangely --- src/PhpWord/Writer/Word2007/Part/Chart.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 2ff9164fb1..7c25894012 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -234,6 +234,10 @@ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values) $xmlWriter->startElement($itemLit); $index = 0; + $xmlWriter->startElement("c:ptCount"); + $xmlWriter->writeAttribute('val', count($values)); + $xmlWriter->endElement(); // c:ptCount + foreach ($values as $value) { $xmlWriter->startElement('c:pt'); $xmlWriter->writeAttribute('idx', $index); From 8b10157d23f23311096200e01a6221549007feaa Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Fri, 12 Jan 2018 14:39:10 -0700 Subject: [PATCH 08/68] potential stack chart layout fix --- src/PhpWord/Writer/Word2007/Part/Chart.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 7c25894012..e00ccc1fc5 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -173,6 +173,8 @@ private function writePlotArea(XMLWriter $xmlWriter) $this->writeAxis($xmlWriter, 'val'); } + $xmlWriter->writeElementBlock('c:plotVisOnly', 'val', 1); + $xmlWriter->endElement(); // c:plotArea } @@ -232,12 +234,9 @@ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values) $xmlWriter->startElement($itemType); $xmlWriter->startElement($itemLit); + $xmlWriter->writeElementBlock('c:ptCount', 'val', count($values)); $index = 0; - $xmlWriter->startElement("c:ptCount"); - $xmlWriter->writeAttribute('val', count($values)); - $xmlWriter->endElement(); // c:ptCount - foreach ($values as $value) { $xmlWriter->startElement('c:pt'); $xmlWriter->writeAttribute('idx', $index); From 3e5b8bc580f2074a5ba19fef4a1b382700e6c96a Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Fri, 12 Jan 2018 14:43:39 -0700 Subject: [PATCH 09/68] move this attribute to its proper place --- src/PhpWord/Writer/Word2007/Part/Chart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index e00ccc1fc5..25a20a9b84 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -107,6 +107,8 @@ private function writeChart(XMLWriter $xmlWriter) $this->writePlotArea($xmlWriter); + $xmlWriter->writeElementBlock('c:plotVisOnly', 'val', 1); + $xmlWriter->endElement(); // c:chart } @@ -173,8 +175,6 @@ private function writePlotArea(XMLWriter $xmlWriter) $this->writeAxis($xmlWriter, 'val'); } - $xmlWriter->writeElementBlock('c:plotVisOnly', 'val', 1); - $xmlWriter->endElement(); // c:plotArea } From bf6fa59a45324038618a4597f6745dcc57a83af4 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Fri, 12 Jan 2018 14:50:11 -0700 Subject: [PATCH 10/68] another possible fix for stack chart layouts --- src/PhpWord/Writer/Word2007/Part/Chart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 25a20a9b84..f6b627db37 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -107,8 +107,6 @@ private function writeChart(XMLWriter $xmlWriter) $this->writePlotArea($xmlWriter); - $xmlWriter->writeElementBlock('c:plotVisOnly', 'val', 1); - $xmlWriter->endElement(); // c:chart } @@ -161,6 +159,8 @@ private function writePlotArea(XMLWriter $xmlWriter) // Series $this->writeSeries($xmlWriter, isset($this->options['scatter'])); + $xmlWriter->writeElementBlock('c:overlap', 'val', '100'); + // Axes if (isset($this->options['axes'])) { $xmlWriter->writeElementBlock('c:axId', 'val', 1); From 9fc07d5fc8a4a60cfc953b3e12c4fdf7290f0b45 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Tue, 16 Jan 2018 12:06:25 -0700 Subject: [PATCH 11/68] add chart colors feature --- src/PhpWord/Style/Chart.php | 22 ++++++++++++++++++++++ src/PhpWord/Writer/Word2007/Part/Chart.php | 20 ++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 694fcddccc..a5280db379 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -45,6 +45,14 @@ class Chart extends AbstractStyle */ private $is3d = false; + + /** + * A list of colors to use in the chart + * + * @var array + */ + private $colors = []; + /** * Create a new instance * @@ -123,4 +131,18 @@ public function set3d($value = true) return $this; } + + /** + * get a list of colors to use in the chart. + * @return array + */ + public function getColors() + { + return $this->colors; + } + + public function setColors($value = []) + { + $this->colors = $value; + } } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index f6b627db37..77c6b2cf5e 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -157,7 +157,7 @@ private function writePlotArea(XMLWriter $xmlWriter) } // Series - $this->writeSeries($xmlWriter, isset($this->options['scatter'])); + $this->writeSeries($xmlWriter, isset($this->options['scatter']), $style->getColors()); $xmlWriter->writeElementBlock('c:overlap', 'val', '100'); @@ -184,7 +184,7 @@ private function writePlotArea(XMLWriter $xmlWriter) * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param bool $scatter */ - private function writeSeries(XMLWriter $xmlWriter, $scatter = false) + private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = null) { $series = $this->element->getSeries(); @@ -208,6 +208,22 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) } else { $this->writeSeriesItem($xmlWriter, 'cat', $categories); $this->writeSeriesItem($xmlWriter, 'val', $values); + + $chartColors = $style = $this->element->getStyle()->getColors(); + if(is_array($chartColors) && count($chartColors)) { + $colorIndex = 0; + foreach ($elementColors as $color) { + $xmlWriter->startElement('c:dPt'); + $xmlWriter->writeElementBlock('c:idx', 'val', $colorIndex); + $xmlWriter->startElement('c:spPr'); + $xmlWriter->startElement('a:solidFill'); + $xmlWriter->writeElementBlock('a:srgbClr', 'val', $color); + $xmlWriter->endElement(); // a:solidFill + $xmlWriter->endElement(); // c:spPr + $xmlWriter->endElement(); // c:dPt + $colorIndex++; + } + } } $xmlWriter->endElement(); // c:ser From 8202ce19f211abb48482a44086d90d5e5916ca58 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Tue, 16 Jan 2018 13:17:24 -0700 Subject: [PATCH 12/68] use the correct variable when getting chart colors --- src/PhpWord/Writer/Word2007/Part/Chart.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 77c6b2cf5e..cbab3a7473 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -209,10 +209,9 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n $this->writeSeriesItem($xmlWriter, 'cat', $categories); $this->writeSeriesItem($xmlWriter, 'val', $values); - $chartColors = $style = $this->element->getStyle()->getColors(); - if(is_array($chartColors) && count($chartColors)) { + if(is_array($colors) && count($colors)) { $colorIndex = 0; - foreach ($elementColors as $color) { + foreach ($colors as $color) { $xmlWriter->startElement('c:dPt'); $xmlWriter->writeElementBlock('c:idx', 'val', $colorIndex); $xmlWriter->startElement('c:spPr'); From 200d625de85b9515673f7fccb67a850da1724eae Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Tue, 16 Jan 2018 13:24:30 -0700 Subject: [PATCH 13/68] add SurveyGizmo specific options to the Word chart writer --- src/PhpWord/Writer/Word2007/Part/Chart.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index cbab3a7473..eb7725d4c9 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -198,6 +198,22 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n $xmlWriter->writeElementBlock('c:idx', 'val', $index); $xmlWriter->writeElementBlock('c:order', 'val', $index); + $xmlWriter->startElement('c:dLbls'); + if ($this->options['type'] == "pie") + { + $xmlWriter->writeElementBlock('c:showVal', 'val', 0); + } + else{ + $xmlWriter->writeElementBlock('c:showVal', 'val', 1); + } + $xmlWriter->writeElementBlock('c:showLegendKey', 'val', 0); + $xmlWriter->writeElementBlock('c:showCatName', 'val', 1); + $xmlWriter->writeElementBlock('c:showSerName', 'val', 0); + $xmlWriter->writeElementBlock('c:showPercent', 'val', 1); + $xmlWriter->writeElementBlock('c:showBubbleSize', 'val', 0); + $xmlWriter->writeElementBlock('c:showLeaderLines', 'val', 1); + $xmlWriter->endElement(); // c:dLbls + if (isset($this->options['scatter'])) { $this->writeShape($xmlWriter); } From dc50a1124353fa51fa5d16081006911b22f9b644 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Tue, 16 Jan 2018 15:44:31 -0700 Subject: [PATCH 14/68] Testing connection --- src/PhpWord/Writer/Word2007/Part/Chart.php | 319 --------------------- 1 file changed, 319 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index f6b627db37..e69de29bb2 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -1,319 +0,0 @@ - array('type' => 'pie', 'colors' => 1), - 'doughnut' => array('type' => 'doughnut', 'colors' => 1, 'hole' => 75, 'no3d' => true), - 'bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'clustered'), - 'stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'stacked'), - 'column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'clustered'), - 'stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'stacked'), - 'line' => array('type' => 'line', 'colors' => 0, 'axes' => true), - 'area' => array('type' => 'area', 'colors' => 0, 'axes' => true), - 'radar' => array('type' => 'radar', 'colors' => 0, 'axes' => true, 'radar' => 'standard', 'no3d' => true), - 'scatter' => array('type' => 'scatter', 'colors' => 0, 'axes' => true, 'scatter' => 'marker', 'no3d' => true), - ); - - /** - * Chart options - * - * @var array - */ - private $options = array(); - - /** - * Set chart element. - * - * @param \PhpOffice\PhpWord\Element\Chart $element - */ - public function setElement(ChartElement $element) - { - $this->element = $element; - } - - /** - * Write part - * - * @return string - */ - public function write() - { - $xmlWriter = $this->getXmlWriter(); - - $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); - $xmlWriter->startElement('c:chartSpace'); - $xmlWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); - $xmlWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); - $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); - - $this->writeChart($xmlWriter); - $this->writeShape($xmlWriter); - - $xmlWriter->endElement(); // c:chartSpace - - return $xmlWriter->getData(); - } - - /** - * Write chart - * - * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_Chart.html - * @param \PhpOffice\Common\XMLWriter $xmlWriter - */ - private function writeChart(XMLWriter $xmlWriter) - { - $xmlWriter->startElement('c:chart'); - - $xmlWriter->writeElementBlock('c:autoTitleDeleted', 'val', 1); - - $this->writePlotArea($xmlWriter); - - $xmlWriter->endElement(); // c:chart - } - - /** - * Write plot area. - * - * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_PlotArea.html - * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_PieChart.html - * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_DoughnutChart.html - * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_BarChart.html - * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_LineChart.html - * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_AreaChart.html - * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_RadarChart.html - * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_ScatterChart.html - * @param \PhpOffice\Common\XMLWriter $xmlWriter - */ - private function writePlotArea(XMLWriter $xmlWriter) - { - $type = $this->element->getType(); - $style = $this->element->getStyle(); - $this->options = $this->types[$type]; - - $xmlWriter->startElement('c:plotArea'); - $xmlWriter->writeElement('c:layout'); - - // Chart - $chartType = $this->options['type']; - $chartType .= $style->is3d() && !isset($this->options['no3d']) ? '3D' : ''; - $chartType .= 'Chart'; - $xmlWriter->startElement("c:{$chartType}"); - - $xmlWriter->writeElementBlock('c:varyColors', 'val', $this->options['colors']); - if ($type == 'area') { - $xmlWriter->writeElementBlock('c:grouping', 'val', 'standard'); - } - if (isset($this->options['hole'])) { - $xmlWriter->writeElementBlock('c:holeSize', 'val', $this->options['hole']); - } - if (isset($this->options['bar'])) { - $xmlWriter->writeElementBlock('c:barDir', 'val', $this->options['bar']); // bar|col - $xmlWriter->writeElementBlock('c:grouping', 'val', $this->options['grouping']); // 3d; standard = percentStacked - } - if (isset($this->options['radar'])) { - $xmlWriter->writeElementBlock('c:radarStyle', 'val', $this->options['radar']); - } - if (isset($this->options['scatter'])) { - $xmlWriter->writeElementBlock('c:scatterStyle', 'val', $this->options['scatter']); - } - - // Series - $this->writeSeries($xmlWriter, isset($this->options['scatter'])); - - $xmlWriter->writeElementBlock('c:overlap', 'val', '100'); - - // Axes - if (isset($this->options['axes'])) { - $xmlWriter->writeElementBlock('c:axId', 'val', 1); - $xmlWriter->writeElementBlock('c:axId', 'val', 2); - } - - $xmlWriter->endElement(); // chart type - - // Axes - if (isset($this->options['axes'])) { - $this->writeAxis($xmlWriter, 'cat'); - $this->writeAxis($xmlWriter, 'val'); - } - - $xmlWriter->endElement(); // c:plotArea - } - - /** - * Write series. - * - * @param \PhpOffice\Common\XMLWriter $xmlWriter - * @param bool $scatter - */ - private function writeSeries(XMLWriter $xmlWriter, $scatter = false) - { - $series = $this->element->getSeries(); - - $index = 0; - foreach ($series as $seriesItem) { - $categories = $seriesItem['categories']; - $values = $seriesItem['values']; - - $xmlWriter->startElement('c:ser'); - - $xmlWriter->writeElementBlock('c:idx', 'val', $index); - $xmlWriter->writeElementBlock('c:order', 'val', $index); - - if (isset($this->options['scatter'])) { - $this->writeShape($xmlWriter); - } - - if ($scatter === true) { - $this->writeSeriesItem($xmlWriter, 'xVal', $categories); - $this->writeSeriesItem($xmlWriter, 'yVal', $values); - } else { - $this->writeSeriesItem($xmlWriter, 'cat', $categories); - $this->writeSeriesItem($xmlWriter, 'val', $values); - } - - $xmlWriter->endElement(); // c:ser - $index++; - } - } - - /** - * Write series items. - * - * @param \PhpOffice\Common\XMLWriter $xmlWriter - * @param string $type - * @param array $values - */ - private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values) - { - $types = array( - 'cat' => array('c:cat', 'c:strLit'), - 'val' => array('c:val', 'c:numLit'), - 'xVal' => array('c:xVal', 'c:strLit'), - 'yVal' => array('c:yVal', 'c:numLit'), - ); - list($itemType, $itemLit) = $types[$type]; - - $xmlWriter->startElement($itemType); - $xmlWriter->startElement($itemLit); - $xmlWriter->writeElementBlock('c:ptCount', 'val', count($values)); - - $index = 0; - foreach ($values as $value) { - $xmlWriter->startElement('c:pt'); - $xmlWriter->writeAttribute('idx', $index); - if (\PhpOffice\PhpWord\Settings::isOutputEscapingEnabled()) { - $xmlWriter->writeElement('c:v', $value); - } else { - $xmlWriter->startElement('c:v'); - $xmlWriter->writeRaw($value); - $xmlWriter->endElement(); // c:v - } - $xmlWriter->endElement(); // c:pt - $index++; - } - - $xmlWriter->endElement(); // $itemLit - $xmlWriter->endElement(); // $itemType - } - - /** - * Write axis - * - * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_CatAx.html - * @param \PhpOffice\Common\XMLWriter $xmlWriter - * @param string $type - */ - private function writeAxis(XMLWriter $xmlWriter, $type) - { - $types = array( - 'cat' => array('c:catAx', 1, 'b', 2), - 'val' => array('c:valAx', 2, 'l', 1), - ); - list($axisType, $axisId, $axisPos, $axisCross) = $types[$type]; - - $xmlWriter->startElement($axisType); - - $xmlWriter->writeElementBlock('c:axId', 'val', $axisId); - $xmlWriter->writeElementBlock('c:axPos', 'val', $axisPos); - $xmlWriter->writeElementBlock('c:crossAx', 'val', $axisCross); - $xmlWriter->writeElementBlock('c:auto', 'val', 1); - - if (isset($this->options['axes'])) { - $xmlWriter->writeElementBlock('c:delete', 'val', 0); - $xmlWriter->writeElementBlock('c:majorTickMark', 'val', 'none'); - $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'none'); // nextTo - $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); - } - if (isset($this->options['radar'])) { - $xmlWriter->writeElement('c:majorGridlines'); - } - - $xmlWriter->startElement('c:scaling'); - $xmlWriter->writeElementBlock('c:orientation', 'val', 'minMax'); - $xmlWriter->endElement(); // c:scaling - - $this->writeShape($xmlWriter, true); - - $xmlWriter->endElement(); // $axisType - } - - /** - * Write shape - * - * @see http://www.datypic.com/sc/ooxml/t-a_CT_ShapeProperties.html - * @param \PhpOffice\Common\XMLWriter $xmlWriter - * @param bool $line - */ - private function writeShape(XMLWriter $xmlWriter, $line = false) - { - $xmlWriter->startElement('c:spPr'); - $xmlWriter->startElement('a:ln'); - if ($line === true) { - $xmlWriter->writeElement('a:solidFill'); - } else { - $xmlWriter->writeElement('a:noFill'); - } - $xmlWriter->endElement(); // a:ln - $xmlWriter->endElement(); // c:spPr - } -} From 78a178c8976cdf6edb6e673f7031fa461f0ccae6 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 17 Jan 2018 08:56:43 -0700 Subject: [PATCH 15/68] gross workaround to make stacked chart series items use different colors --- src/PhpWord/Writer/Word2007/Part/Chart.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index eb7725d4c9..5eb56451ca 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -198,6 +198,8 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n $xmlWriter->writeElementBlock('c:idx', 'val', $index); $xmlWriter->writeElementBlock('c:order', 'val', $index); + // The c:dLbls was added to make word charts look more like the reports in SurveyGizmo + // This section needs to be made configurable before a pull request is made $xmlWriter->startElement('c:dLbls'); if ($this->options['type'] == "pie") { @@ -225,7 +227,12 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n $this->writeSeriesItem($xmlWriter, 'cat', $categories); $this->writeSeriesItem($xmlWriter, 'val', $values); + // this was taken from a comment on github. + // credit it? if(is_array($colors) && count($colors)) { + if($this->options['type'] == 'bar' && $this->options['grouping'] == 'stacked') { + $colors = array_slice($colors, $index); + } $colorIndex = 0; foreach ($colors as $color) { $xmlWriter->startElement('c:dPt'); From 92524110922430b1343fb2ab7c499055b5bffd8d Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 17 Jan 2018 09:29:17 -0700 Subject: [PATCH 16/68] only remove a single chart color at a time --- src/PhpWord/Writer/Word2007/Part/Chart.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 5eb56451ca..0236f06e83 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -201,11 +201,9 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n // The c:dLbls was added to make word charts look more like the reports in SurveyGizmo // This section needs to be made configurable before a pull request is made $xmlWriter->startElement('c:dLbls'); - if ($this->options['type'] == "pie") - { + if ($this->options['type'] == "pie") { $xmlWriter->writeElementBlock('c:showVal', 'val', 0); - } - else{ + } else { $xmlWriter->writeElementBlock('c:showVal', 'val', 1); } $xmlWriter->writeElementBlock('c:showLegendKey', 'val', 0); @@ -230,8 +228,9 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n // this was taken from a comment on github. // credit it? if(is_array($colors) && count($colors)) { + // This is a gross workaround to make each series in a stack chart use a different color if($this->options['type'] == 'bar' && $this->options['grouping'] == 'stacked') { - $colors = array_slice($colors, $index); + $colors = array_shift($colors); } $colorIndex = 0; foreach ($colors as $color) { From d1c9cd0ed66bab32d5882ebf090246d652dea620 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 17 Jan 2018 09:31:47 -0700 Subject: [PATCH 17/68] use array_shift properly --- src/PhpWord/Writer/Word2007/Part/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 0236f06e83..1fcd82a823 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -230,7 +230,7 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n if(is_array($colors) && count($colors)) { // This is a gross workaround to make each series in a stack chart use a different color if($this->options['type'] == 'bar' && $this->options['grouping'] == 'stacked') { - $colors = array_shift($colors); + array_shift($colors); } $colorIndex = 0; foreach ($colors as $color) { From 86bfa5bdf337b7edc51afa95001499b19889e236 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 17 Jan 2018 09:58:38 -0700 Subject: [PATCH 18/68] change axis options for SG charts --- src/PhpWord/Style/Chart.php | 10 +++++++++- src/PhpWord/Writer/Word2007/Part/Chart.php | 9 ++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index a5280db379..5763071b79 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -133,7 +133,8 @@ public function set3d($value = true) } /** - * get a list of colors to use in the chart. + * Get the list of colors to use in a chart. + * * @return array */ public function getColors() @@ -141,8 +142,15 @@ public function getColors() return $this->colors; } + /** + * Set the colors to use in a chart. + * + * @param array $value a list of colors to use in the chart + */ public function setColors($value = []) { $this->colors = $value; } + + public function } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 1fcd82a823..07e02af9a2 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -225,10 +225,9 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n $this->writeSeriesItem($xmlWriter, 'cat', $categories); $this->writeSeriesItem($xmlWriter, 'val', $values); - // this was taken from a comment on github. - // credit it? + // setting the chart colors was taken from https://github.com/PHPOffice/PHPWord/issues/494 if(is_array($colors) && count($colors)) { - // This is a gross workaround to make each series in a stack chart use a different color + // This is a workaround to make each series in a stack chart use a different color if($this->options['type'] == 'bar' && $this->options['grouping'] == 'stacked') { array_shift($colors); } @@ -316,9 +315,9 @@ private function writeAxis(XMLWriter $xmlWriter, $type) if (isset($this->options['axes'])) { $xmlWriter->writeElementBlock('c:delete', 'val', 0); - $xmlWriter->writeElementBlock('c:majorTickMark', 'val', 'none'); + $xmlWriter->writeElementBlock('c:majorTickMark', 'val', 'inside'); // SG edit: switched from none to inside $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'none'); // nextTo + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); } if (isset($this->options['radar'])) { From 4894d246750baaff750b4adac2fcc3946938756e Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 17 Jan 2018 11:11:50 -0700 Subject: [PATCH 19/68] remove broken code --- src/PhpWord/Style/Chart.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 5763071b79..a8e4af6151 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -151,6 +151,4 @@ public function setColors($value = []) { $this->colors = $value; } - - public function } From d82103d2dcca70836ad64cef946737e78155d9f6 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 17 Jan 2018 11:15:09 -0700 Subject: [PATCH 20/68] use correct property values --- src/PhpWord/Writer/Word2007/Part/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 07e02af9a2..f2a382fcd9 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -315,7 +315,7 @@ private function writeAxis(XMLWriter $xmlWriter, $type) if (isset($this->options['axes'])) { $xmlWriter->writeElementBlock('c:delete', 'val', 0); - $xmlWriter->writeElementBlock('c:majorTickMark', 'val', 'inside'); // SG edit: switched from none to inside + $xmlWriter->writeElementBlock('c:majorTickMark', 'val', 'in'); // SG edit: switched from none to inside $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); From 1902e5521204dff87f63d5cf7549722b81a3ab74 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Wed, 17 Jan 2018 14:45:39 -0700 Subject: [PATCH 21/68] Added variables and getters for xAxisLabels and yAxisLabels --- src/PhpWord/Style/Chart.php | 63 ++++++++++++++++++++++ src/PhpWord/Writer/Word2007/Part/Chart.php | 14 +++++ 2 files changed, 77 insertions(+) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index a8e4af6151..db007575a2 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -53,6 +53,49 @@ class Chart extends AbstractStyle */ private $colors = []; + /** + * A string that tells the writer to either + * "none" - skips writing axis labels + * "nextTo" - sets labels next to the axis (bar graphs on the left) + * "low" - labels on the left side of the graph + * "high" - labels on the right side of the graph + * + * @var string + */ + private xAxisLabels = "none"; + + /** + * A string that tells the writer to either + * "none" - skips writing axis labels + * "nextTo" - sets labels next to the axis (bar graphs on the bottom) + * "low" - labels are below the graph + * "high" - labels above the graph + * + * @var string + */ + private yAxisLabels = "none"; + + /** + * Get the xAxis Labels setting + * + * @return string + */ + public function getXAxisLabels() + { + return $this->xAxisLabels; + } + + /** + * Get the yAxis Labels setting + * + * @return string + */ + public function getYAxisLabels() + { + return $this->yAxisLabels; + } + + /** * Create a new instance * @@ -151,4 +194,24 @@ public function setColors($value = []) { $this->colors = $value; } + + /** + * Get the xAxis Labels setting + * + * @return string + */ + public function getXAxisLabels() + { + return $this->xAxisLabels; + } + + /** + * Get the yAxis Labels setting + * + * @return string + */ + public function getYAxisLabels() + { + return $this->yAxisLabels; + } } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index f2a382fcd9..d7b20d9c8b 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -320,6 +320,20 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); } + + echo "Rendering the axis"; + echo $style->getXAxisLabels(); + + // if($axisType){ + + // $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getXAxisLabels()); + // } + + // if($axisType){ + + // $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getYAxisLabels()); + // } + if (isset($this->options['radar'])) { $xmlWriter->writeElement('c:majorGridlines'); } From fa0a59e3678e4bd189f7671ac049f25c919f49db Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Wed, 17 Jan 2018 14:55:12 -0700 Subject: [PATCH 22/68] removing debugs for testing --- src/PhpWord/Writer/Word2007/Part/Chart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index d7b20d9c8b..dec8575712 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -321,8 +321,8 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); } - echo "Rendering the axis"; - echo $style->getXAxisLabels(); + // echo "Rendering the axis"; + // echo $style->getXAxisLabels(); // if($axisType){ From ac4d074333bbbd3672f09c455d74c3b9fa5a7ffe Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Wed, 17 Jan 2018 15:18:10 -0700 Subject: [PATCH 23/68] Fixed a syntax error --- src/PhpWord/Style/Chart.php | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index db007575a2..0945a3db09 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -62,7 +62,7 @@ class Chart extends AbstractStyle * * @var string */ - private xAxisLabels = "none"; + private $xAxisLabels = "none"; /** * A string that tells the writer to either @@ -73,28 +73,7 @@ class Chart extends AbstractStyle * * @var string */ - private yAxisLabels = "none"; - - /** - * Get the xAxis Labels setting - * - * @return string - */ - public function getXAxisLabels() - { - return $this->xAxisLabels; - } - - /** - * Get the yAxis Labels setting - * - * @return string - */ - public function getYAxisLabels() - { - return $this->yAxisLabels; - } - + private $yAxisLabels = "none"; /** * Create a new instance From a2e268f4a76d23845e85b7d264972f4d40e65fbb Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Wed, 17 Jan 2018 15:25:46 -0700 Subject: [PATCH 24/68] added a debug statement --- src/PhpWord/Writer/Word2007/Part/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index dec8575712..39042c0d1b 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -321,7 +321,7 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); } - // echo "Rendering the axis"; + echo "Rendering the axis"; // echo $style->getXAxisLabels(); // if($axisType){ From 9a6c8e4b42c1e83303d7864e1c6e45893af21f05 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Wed, 17 Jan 2018 15:33:42 -0700 Subject: [PATCH 25/68] more debug logs --- src/PhpWord/Writer/Word2007/Part/Chart.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 39042c0d1b..cee09a0ca0 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -321,8 +321,9 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); } - echo "Rendering the axis"; - // echo $style->getXAxisLabels(); + echo "Rendering the axis\n"; + echo $style->getXAxisLabels(); + echo "\n"; // if($axisType){ From 30916e0bcd9e2ba94fa5b581c669dc328bdc4a70 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Wed, 17 Jan 2018 15:35:32 -0700 Subject: [PATCH 26/68] added the style object to writeAxis --- src/PhpWord/Writer/Word2007/Part/Chart.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index cee09a0ca0..e5646ccc37 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -300,6 +300,7 @@ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values) */ private function writeAxis(XMLWriter $xmlWriter, $type) { + $style = $this->element->getStyle(); $types = array( 'cat' => array('c:catAx', 1, 'b', 2), 'val' => array('c:valAx', 2, 'l', 1), From f6b6b4ed059ae937e25ac1ecf405089c23acb5bd Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Wed, 17 Jan 2018 15:46:32 -0700 Subject: [PATCH 27/68] added debug statement for axisType --- src/PhpWord/Writer/Word2007/Part/Chart.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index e5646ccc37..56029bf4b8 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -318,13 +318,18 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:delete', 'val', 0); $xmlWriter->writeElementBlock('c:majorTickMark', 'val', 'in'); // SG edit: switched from none to inside $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo + $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); } echo "Rendering the axis\n"; echo $style->getXAxisLabels(); echo "\n"; + echo $axisType; + echo "\n"; + // if($axisType){ From 0e8ef73861e9bbff94fab61cae89a9c760cdbd4a Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Wed, 17 Jan 2018 16:06:57 -0700 Subject: [PATCH 28/68] writeAxis now reads from the style object --- src/PhpWord/Style/Chart.php | 28 ++++++++++++++++++++++ src/PhpWord/Writer/Word2007/Part/Chart.php | 25 ++++++------------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 0945a3db09..cee37dd97d 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -184,6 +184,20 @@ public function getXAxisLabels() return $this->xAxisLabels; } + /** + * Set the xAxis Labels setting + * "none" - skips writing axis labels + * "nextTo" - sets labels next to the axis (bar graphs on the left) + * "low" - labels on the left side of the graph + * "high" - labels on the right side of the graph + * + * @return string + */ + public function setXAxisLabels($label_position) + { + $this->xAxisLabels = $label_position; + } + /** * Get the yAxis Labels setting * @@ -193,4 +207,18 @@ public function getYAxisLabels() { return $this->yAxisLabels; } + + /** + * Set the yAxis Labels setting + * "none" - skips writing axis labels + * "nextTo" - sets labels next to the axis (bar graphs on the bottom) + * "low" - labels are below the graph + * "high" - labels above the graph + * + * @var string + */ + public function setYAxisLabels($label_position) + { + $this->yAxisLabels = $label_position; + } } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 56029bf4b8..0c2381ec63 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -319,28 +319,17 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:majorTickMark', 'val', 'in'); // SG edit: switched from none to inside $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo + if($axisType == "c:catAx"){ + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getXAxisLabels()); + } else if($axisType == "c:valAx"){ + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getYAxisLabels()); + } else { + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo + } $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); } - echo "Rendering the axis\n"; - echo $style->getXAxisLabels(); - echo "\n"; - echo $axisType; - echo "\n"; - - - // if($axisType){ - - // $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getXAxisLabels()); - // } - - // if($axisType){ - - // $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getYAxisLabels()); - // } - if (isset($this->options['radar'])) { $xmlWriter->writeElement('c:majorGridlines'); } From 5857cfd1558abd612146018d36d7f4f1351b740d Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 09:38:18 -0700 Subject: [PATCH 29/68] adding preliminary chart axis title functionality to XMLwriter --- src/PhpWord/Writer/Word2007/Part/Chart.php | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 0c2381ec63..8886ee68e5 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -327,6 +327,33 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo } + $xmlWriter->startElement('c:title'); //start title + + $value = "Cool Axis Title" + + $xmlWriter->writeRaw($value); + $xmlWriter->endElement(); // end title + + + // + // + // + // + // + // + // + // + // + // + // + // Percent + // + // + // + // + // + // + $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); } From bff874231f31bce8f7125ea6cf1db75a3b190426 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 09:47:10 -0700 Subject: [PATCH 30/68] simplified the title writer --- src/PhpWord/Writer/Word2007/Part/Chart.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 8886ee68e5..4a46f01e59 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -311,6 +311,16 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:axId', 'val', $axisId); $xmlWriter->writeElementBlock('c:axPos', 'val', $axisPos); + + //TITLE + $xmlWriter->startElement('c:title'); //start title + + // $value = "Cool Axis Title" + + // $xmlWriter->writeRaw($value); + $xmlWriter->endElement(); // end title + //END TITLE + $xmlWriter->writeElementBlock('c:crossAx', 'val', $axisCross); $xmlWriter->writeElementBlock('c:auto', 'val', 1); @@ -327,14 +337,6 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo } - $xmlWriter->startElement('c:title'); //start title - - $value = "Cool Axis Title" - - $xmlWriter->writeRaw($value); - $xmlWriter->endElement(); // end title - - // // // From 31a53788c420d3adcf2e1f1e7f09d3d0ea05ba3f Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 10:11:46 -0700 Subject: [PATCH 31/68] added more specific xml for axis title --- src/PhpWord/Writer/Word2007/Part/Chart.php | 63 ++++++++++++++-------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 4a46f01e59..7561bd5b2e 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -314,12 +314,46 @@ private function writeAxis(XMLWriter $xmlWriter, $type) //TITLE $xmlWriter->startElement('c:title'); //start title + $xmlWriter->startElement('c:tx'); + $xmlWriter->startElement('c:rich'); + $xmlWriter->writeElementBlock('a:bodyPr'); + $xmlWriter->writeElementBlock('a:lstStyle'); + $xmlWriter->startElement('a:p'); + $xmlWriter->startElement('a:pPr'); + $xmlWriter->writeElementBlock('a:defRPr'); + $xmlWriter->endElement(); // end a:pPr + $xmlWriter->startElement('a:r'); + $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); + $xmlWriter->startElement(''); + $xmlWriter->writeRaw('Cool Axis Title'); + $xmlWriter->endElement(); //end a:t + $xmlWriter->endElement(); // end a:r + $xmlWriter->endElement(); //end a:p + $xmlWriter->endElement(); //end c:rich + $xmlWriter->endElement(); // end c:tx + $xmlWriter->writeElementBlock('c:overlay', 'val', '0'); + $xmlWriter->endElement(); // end c:title + //END TITLE - // $value = "Cool Axis Title" + // + // + // + // + // + // + // + // + // + // + // + // Cool Axis Title + // + // + // + // + // + // - // $xmlWriter->writeRaw($value); - $xmlWriter->endElement(); // end title - //END TITLE $xmlWriter->writeElementBlock('c:crossAx', 'val', $axisCross); $xmlWriter->writeElementBlock('c:auto', 'val', 1); @@ -337,25 +371,6 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo } - // - // - // - // - // - // - // - // - // - // - // - // Percent - // - // - // - // - // - // - $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); } @@ -372,6 +387,8 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->endElement(); // $axisType } + + /** * Write shape * From 981a461813d4aa8f6cab72c12848315725284f96 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 10:48:03 -0700 Subject: [PATCH 32/68] debugging --- src/PhpWord/Writer/Word2007/Part/Chart.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 7561bd5b2e..169058764b 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -313,9 +313,9 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:axPos', 'val', $axisPos); //TITLE - $xmlWriter->startElement('c:title'); //start title - $xmlWriter->startElement('c:tx'); - $xmlWriter->startElement('c:rich'); + $xmlWriter->startElement('c:title'); //start c:title + $xmlWriter->startElement('c:tx'); //start c:tx + $xmlWriter->startElement('c:rich'); // start c:rich $xmlWriter->writeElementBlock('a:bodyPr'); $xmlWriter->writeElementBlock('a:lstStyle'); $xmlWriter->startElement('a:p'); @@ -323,10 +323,12 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('a:defRPr'); $xmlWriter->endElement(); // end a:pPr $xmlWriter->startElement('a:r'); - $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); + // $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); + $xmlWriter->startElement(''); - $xmlWriter->writeRaw('Cool Axis Title'); + $xmlWriter->writeRaw('Cool Axis Title'); $xmlWriter->endElement(); //end a:t + $xmlWriter->endElement(); // end a:r $xmlWriter->endElement(); //end a:p $xmlWriter->endElement(); //end c:rich From 7168c87bdbe637c122739a2786d8e4d87c69ff58 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Thu, 18 Jan 2018 10:48:53 -0700 Subject: [PATCH 33/68] expiriment to test if changing series names is possible --- src/PhpWord/Writer/Word2007/Part/Chart.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index c3703f9f6d..9f1e1c37fc 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -194,6 +194,20 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) $xmlWriter->writeElementBlock('c:idx', 'val', $index); $xmlWriter->writeElementBlock('c:order', 'val', $index); + $xmlWriter->startElement('c:tx'); + $xmlWriter->startElement('c:strRef'); + $xmlWriter->startElement('c:strCache'); + $xmlWriter->writeElementBlock('c:ptCount', 'val', 1); + $xmlWriter->startElement('c:pt'); + $xmlWriter->writeAttribute('idx', 0); + $xmlWriter->startElement('c:v'); + $this->writeText("THIS AM SERIES " . rand(0,10)); + $xmlWriter->endElement(); // c:v + $xmlWriter->endElement(); // c:pt + $xmlWriter->endElement(); // c:strCache + $xmlWriter->endElement(); // c:strRef + $xmlWriter->endElement(); // c:tx + if (isset($this->options['scatter'])) { $this->writeShape($xmlWriter); } From fa4c6e18536ae9f2180f82cdf5c45de37cef966e Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 10:50:58 -0700 Subject: [PATCH 34/68] fixed syntax error --- src/PhpWord/Writer/Word2007/Part/Chart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 169058764b..e3a8a21b78 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -323,9 +323,9 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('a:defRPr'); $xmlWriter->endElement(); // end a:pPr $xmlWriter->startElement('a:r'); - // $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); + $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); - $xmlWriter->startElement(''); + $xmlWriter->startElement('a:t'); $xmlWriter->writeRaw('Cool Axis Title'); $xmlWriter->endElement(); //end a:t From 9429a20e6389c12afc55daf51f4bba05a53155e2 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 10:57:00 -0700 Subject: [PATCH 35/68] removed some comments --- src/PhpWord/Writer/Word2007/Part/Chart.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index e3a8a21b78..cde7d2440a 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -337,25 +337,6 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->endElement(); // end c:title //END TITLE - // - // - // - // - // - // - // - // - // - // - // - // Cool Axis Title - // - // - // - // - // - // - $xmlWriter->writeElementBlock('c:crossAx', 'val', $axisCross); $xmlWriter->writeElementBlock('c:auto', 'val', 1); From d4cf322cd70946599daf3a93f6a63856ee2395c7 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Thu, 18 Jan 2018 11:09:49 -0700 Subject: [PATCH 36/68] do it RAW --- src/PhpWord/Writer/Word2007/Part/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 36af07e48d..7cf155a20c 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -206,7 +206,7 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n $xmlWriter->startElement('c:pt'); $xmlWriter->writeAttribute('idx', 0); $xmlWriter->startElement('c:v'); - $this->writeText("THIS AM SERIES " . rand(0,10)); + $this->writeRaw("THIS AM SERIES " . rand(0,10)); $xmlWriter->endElement(); // c:v $xmlWriter->endElement(); // c:pt $xmlWriter->endElement(); // c:strCache From 575051b53300244e36f133ed93834fd9571ce6e4 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Thu, 18 Jan 2018 11:11:44 -0700 Subject: [PATCH 37/68] do it RAW for real --- src/PhpWord/Writer/Word2007/Part/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 7cf155a20c..5ada7ec948 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -206,7 +206,7 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n $xmlWriter->startElement('c:pt'); $xmlWriter->writeAttribute('idx', 0); $xmlWriter->startElement('c:v'); - $this->writeRaw("THIS AM SERIES " . rand(0,10)); + $xmlWriter->writeRaw("THIS AM SERIES " . rand(0,10)); $xmlWriter->endElement(); // c:v $xmlWriter->endElement(); // c:pt $xmlWriter->endElement(); // c:strCache From bbba1f8304f084074738695a4113dca4bf489375 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 11:49:31 -0700 Subject: [PATCH 38/68] added getters and setters for Axis titles --- src/PhpWord/Style/Chart.php | 57 ++++++++++++++++++++-- src/PhpWord/Writer/Word2007/Part/Chart.php | 40 +++++++-------- 2 files changed, 73 insertions(+), 24 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index cee37dd97d..4bbab46d11 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -54,8 +54,8 @@ class Chart extends AbstractStyle private $colors = []; /** - * A string that tells the writer to either - * "none" - skips writing axis labels + * A string that tells the writer where to write chart labels or to skip + * "none" - skips writing axis labels (default) * "nextTo" - sets labels next to the axis (bar graphs on the left) * "low" - labels on the left side of the graph * "high" - labels on the right side of the graph @@ -65,8 +65,8 @@ class Chart extends AbstractStyle private $xAxisLabels = "none"; /** - * A string that tells the writer to either - * "none" - skips writing axis labels + * A string that tells the writer where to write chart labels or to skip + * "none" - skips writing axis labels (default) * "nextTo" - sets labels next to the axis (bar graphs on the bottom) * "low" - labels are below the graph * "high" - labels above the graph @@ -75,6 +75,20 @@ class Chart extends AbstractStyle */ private $yAxisLabels = "none"; + + /** + * + * + * @var string + */ + private $xAxisTitle = "Cool x Axis"; + + /** + * + * @var string + */ + private $yAxisLabels = "Cool y axis"; + /** * Create a new instance * @@ -221,4 +235,39 @@ public function setYAxisLabels($label_position) { $this->yAxisLabels = $label_position; } + + /** + * Get the xAxisTitle + * @return string + */ + public function getXAxisTitle(){ + return $this->$xAxisTitle; + } + + /** + * Set the xAxis title for the a chart + * @var $axis_title string + */ + public function setXAxisTitle($axis_title) + { + $this->$xAxisTitle = $axis_title; + } + + /** + * Get the yAxisTitle + * @return string + */ + public function getYAxisTitle(){ + return $this->$yAxisTitle; + } + + /** + * Set the yAxis title for the a chart + * @var $axis_title string + */ + public function setYAxisTitle($axis_title) + { + $this->$yAxisTitle = $axis_title; + } + } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index cde7d2440a..af3047a984 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -314,26 +314,26 @@ private function writeAxis(XMLWriter $xmlWriter, $type) //TITLE $xmlWriter->startElement('c:title'); //start c:title - $xmlWriter->startElement('c:tx'); //start c:tx - $xmlWriter->startElement('c:rich'); // start c:rich - $xmlWriter->writeElementBlock('a:bodyPr'); - $xmlWriter->writeElementBlock('a:lstStyle'); - $xmlWriter->startElement('a:p'); - $xmlWriter->startElement('a:pPr'); - $xmlWriter->writeElementBlock('a:defRPr'); - $xmlWriter->endElement(); // end a:pPr - $xmlWriter->startElement('a:r'); - $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); - - $xmlWriter->startElement('a:t'); - $xmlWriter->writeRaw('Cool Axis Title'); - $xmlWriter->endElement(); //end a:t - - $xmlWriter->endElement(); // end a:r - $xmlWriter->endElement(); //end a:p - $xmlWriter->endElement(); //end c:rich - $xmlWriter->endElement(); // end c:tx - $xmlWriter->writeElementBlock('c:overlay', 'val', '0'); + $xmlWriter->startElement('c:tx'); //start c:tx + $xmlWriter->startElement('c:rich'); // start c:rich + $xmlWriter->writeElementBlock('a:bodyPr'); + $xmlWriter->writeElementBlock('a:lstStyle'); + $xmlWriter->startElement('a:p'); + $xmlWriter->startElement('a:pPr'); + $xmlWriter->writeElementBlock('a:defRPr'); + $xmlWriter->endElement(); // end a:pPr + $xmlWriter->startElement('a:r'); + $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); + + $xmlWriter->startElement('a:t'); + $xmlWriter->writeRaw('Cool Axis Title'); + $xmlWriter->endElement(); //end a:t + + $xmlWriter->endElement(); // end a:r + $xmlWriter->endElement(); //end a:p + $xmlWriter->endElement(); //end c:rich + $xmlWriter->endElement(); // end c:tx + $xmlWriter->writeElementBlock('c:overlay', 'val', '0'); $xmlWriter->endElement(); // end c:title //END TITLE From 260e287561f5a0ab8d7044d50b8bce4aecaa8c5f Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 11:54:54 -0700 Subject: [PATCH 39/68] added use of getter in the writer --- src/PhpWord/Writer/Word2007/Part/Chart.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index af3047a984..14e42ca199 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -312,6 +312,8 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:axId', 'val', $axisId); $xmlWriter->writeElementBlock('c:axPos', 'val', $axisPos); + //addAxisTitle($style->getXAxisTitle()); + //TITLE $xmlWriter->startElement('c:title'); //start c:title $xmlWriter->startElement('c:tx'); //start c:tx @@ -326,7 +328,7 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); $xmlWriter->startElement('a:t'); - $xmlWriter->writeRaw('Cool Axis Title'); + $xmlWriter->writeRaw($style->getXAxisTitle()); $xmlWriter->endElement(); //end a:t $xmlWriter->endElement(); // end a:r From d839e0fef0b62800e38cd404ab210c9110734624 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Thu, 18 Jan 2018 12:49:58 -0700 Subject: [PATCH 40/68] make naming series possible --- src/PhpWord/Element/Chart.php | 12 ++++++--- src/PhpWord/Writer/Word2007/Part/Chart.php | 29 +++++++++++----------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/PhpWord/Element/Chart.php b/src/PhpWord/Element/Chart.php index 86eefdabc8..c830c93b53 100644 --- a/src/PhpWord/Element/Chart.php +++ b/src/PhpWord/Element/Chart.php @@ -62,10 +62,10 @@ class Chart extends AbstractElement * @param array $values * @param array $style */ - public function __construct($type, $categories, $values, $style = null) + public function __construct($type, $categories, $values, $style = null, $series_name = null) { $this->setType($type); - $this->addSeries($categories, $values); + $this->addSeries($categories, $values, $series_name); $this->style = $this->setNewStyle(new ChartStyle(), $style, true); } @@ -96,9 +96,13 @@ public function setType($value) * @param array $categories * @param array $values */ - public function addSeries($categories, $values) + public function addSeries($categories, $values, $name = null) { - $this->series[] = array('categories' => $categories, 'values' => $values); + $this->series[] = array( + 'categories' => $categories, + 'values' => $values, + 'name' => $name + ); } /** diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 5ada7ec948..9afb96f876 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -198,20 +198,21 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n $xmlWriter->writeElementBlock('c:idx', 'val', $index); $xmlWriter->writeElementBlock('c:order', 'val', $index); - // can I change series names? - $xmlWriter->startElement('c:tx'); - $xmlWriter->startElement('c:strRef'); - $xmlWriter->startElement('c:strCache'); - $xmlWriter->writeElementBlock('c:ptCount', 'val', 1); - $xmlWriter->startElement('c:pt'); - $xmlWriter->writeAttribute('idx', 0); - $xmlWriter->startElement('c:v'); - $xmlWriter->writeRaw("THIS AM SERIES " . rand(0,10)); - $xmlWriter->endElement(); // c:v - $xmlWriter->endElement(); // c:pt - $xmlWriter->endElement(); // c:strCache - $xmlWriter->endElement(); // c:strRef - $xmlWriter->endElement(); // c:tx + if(!is_null($seriesItem['name']) && $seriesItem['name'] != "") { + $xmlWriter->startElement('c:tx'); + $xmlWriter->startElement('c:strRef'); + $xmlWriter->startElement('c:strCache'); + $xmlWriter->writeElementBlock('c:ptCount', 'val', 1); + $xmlWriter->startElement('c:pt'); + $xmlWriter->writeAttribute('idx', 0); + $xmlWriter->startElement('c:v'); + $xmlWriter->writeRaw($seriesItem['name']); + $xmlWriter->endElement(); // c:v + $xmlWriter->endElement(); // c:pt + $xmlWriter->endElement(); // c:strCache + $xmlWriter->endElement(); // c:strRef + $xmlWriter->endElement(); // c:tx + } // The c:dLbls was added to make word charts look more like the reports in SurveyGizmo // This section needs to be made configurable before a pull request is made From e390c69e39a0020f56850c8ed098441d9f9b2ce8 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 13:25:43 -0700 Subject: [PATCH 41/68] fixed typo --- src/PhpWord/Style/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 4bbab46d11..9202d220de 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -87,7 +87,7 @@ class Chart extends AbstractStyle * * @var string */ - private $yAxisLabels = "Cool y axis"; + private $yAxisTitle = "Cool y axis"; /** * Create a new instance From f5f9f6720990dd6567e713922244ecb95a880bbf Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 13:34:21 -0700 Subject: [PATCH 42/68] syntax error fixes and renaming for clarity --- src/PhpWord/Style/Chart.php | 28 +++++++++++----------- src/PhpWord/Writer/Word2007/Part/Chart.php | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 9202d220de..c0df4692ce 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -62,7 +62,7 @@ class Chart extends AbstractStyle * * @var string */ - private $xAxisLabels = "none"; + private $xAxisLabelsPosition = "none"; /** * A string that tells the writer where to write chart labels or to skip @@ -73,7 +73,7 @@ class Chart extends AbstractStyle * * @var string */ - private $yAxisLabels = "none"; + private $yAxisLabelsPosition = "none"; /** @@ -193,9 +193,9 @@ public function setColors($value = []) * * @return string */ - public function getXAxisLabels() + public function getXAxisLabelsPosition() { - return $this->xAxisLabels; + return $this->xAxisLabelsPosition; } /** @@ -207,9 +207,9 @@ public function getXAxisLabels() * * @return string */ - public function setXAxisLabels($label_position) + public function setXAxisLabelsPosition($label_position) { - $this->xAxisLabels = $label_position; + $this->xAxisLabelsPosition = $label_position; } /** @@ -217,9 +217,9 @@ public function setXAxisLabels($label_position) * * @return string */ - public function getYAxisLabels() + public function getYAxisLabelsPosition() { - return $this->yAxisLabels; + return $this->yAxisLabelsPosition; } /** @@ -231,9 +231,9 @@ public function getYAxisLabels() * * @var string */ - public function setYAxisLabels($label_position) + public function setYAxisLabelsPosition($label_position) { - $this->yAxisLabels = $label_position; + $this->yAxisLabelsPosition = $label_position; } /** @@ -241,7 +241,7 @@ public function setYAxisLabels($label_position) * @return string */ public function getXAxisTitle(){ - return $this->$xAxisTitle; + return $this->xAxisTitle; } /** @@ -250,7 +250,7 @@ public function getXAxisTitle(){ */ public function setXAxisTitle($axis_title) { - $this->$xAxisTitle = $axis_title; + $this->xAxisTitle = $axis_title; } /** @@ -258,7 +258,7 @@ public function setXAxisTitle($axis_title) * @return string */ public function getYAxisTitle(){ - return $this->$yAxisTitle; + return $this->yAxisTitle; } /** @@ -267,7 +267,7 @@ public function getYAxisTitle(){ */ public function setYAxisTitle($axis_title) { - $this->$yAxisTitle = $axis_title; + $this->yAxisTitle = $axis_title; } } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 14e42ca199..a8d69d1a8c 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -349,9 +349,9 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); if($axisType == "c:catAx"){ - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getXAxisLabels()); + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getXAxisLabelsPosition()); } else if($axisType == "c:valAx"){ - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getYAxisLabels()); + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getYAxisLabelsPosition()); } else { $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo } From 241dca6c5a256f8bf648bd9e07c057debf4e14a3 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 13:37:56 -0700 Subject: [PATCH 43/68] naming change --- src/PhpWord/Style/Chart.php | 8 ++++---- src/PhpWord/Writer/Word2007/Part/Chart.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index c0df4692ce..af6f412fc7 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -193,7 +193,7 @@ public function setColors($value = []) * * @return string */ - public function getXAxisLabelsPosition() + public function getXAxisLabelPosition() { return $this->xAxisLabelsPosition; } @@ -207,7 +207,7 @@ public function getXAxisLabelsPosition() * * @return string */ - public function setXAxisLabelsPosition($label_position) + public function setXAxisLabelPosition($label_position) { $this->xAxisLabelsPosition = $label_position; } @@ -217,7 +217,7 @@ public function setXAxisLabelsPosition($label_position) * * @return string */ - public function getYAxisLabelsPosition() + public function getYAxisLabelPosition() { return $this->yAxisLabelsPosition; } @@ -231,7 +231,7 @@ public function getYAxisLabelsPosition() * * @var string */ - public function setYAxisLabelsPosition($label_position) + public function setYAxisLabelPosition($label_position) { $this->yAxisLabelsPosition = $label_position; } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index a8d69d1a8c..7bc32507f8 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -349,9 +349,9 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); if($axisType == "c:catAx"){ - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getXAxisLabelsPosition()); + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getXAxisLabelPosition()); } else if($axisType == "c:valAx"){ - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getYAxisLabelsPosition()); + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getYAxisLabelPosition()); } else { $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo } From e8e401f1c419f45d899c4cb04513696c2ce129de Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 14:03:39 -0700 Subject: [PATCH 44/68] abstracted title writing out into a new function --- src/PhpWord/Style/Chart.php | 4 +- src/PhpWord/Writer/Word2007/Part/Chart.php | 62 +++++++++++++--------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index af6f412fc7..58c3574bcd 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -81,13 +81,13 @@ class Chart extends AbstractStyle * * @var string */ - private $xAxisTitle = "Cool x Axis"; + private $xAxisTitle = "default x title"; /** * * @var string */ - private $yAxisTitle = "Cool y axis"; + private $yAxisTitle = "default y title"; /** * Create a new instance diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 7bc32507f8..c5f8dc9808 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -312,32 +312,18 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:axId', 'val', $axisId); $xmlWriter->writeElementBlock('c:axPos', 'val', $axisPos); - //addAxisTitle($style->getXAxisTitle()); + $xAxisTitle = $style->getXAxisTitle(); + $yAxisTitle = $style->getYAxisTitle(); - //TITLE - $xmlWriter->startElement('c:title'); //start c:title - $xmlWriter->startElement('c:tx'); //start c:tx - $xmlWriter->startElement('c:rich'); // start c:rich - $xmlWriter->writeElementBlock('a:bodyPr'); - $xmlWriter->writeElementBlock('a:lstStyle'); - $xmlWriter->startElement('a:p'); - $xmlWriter->startElement('a:pPr'); - $xmlWriter->writeElementBlock('a:defRPr'); - $xmlWriter->endElement(); // end a:pPr - $xmlWriter->startElement('a:r'); - $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); - - $xmlWriter->startElement('a:t'); - $xmlWriter->writeRaw($style->getXAxisTitle()); - $xmlWriter->endElement(); //end a:t - - $xmlWriter->endElement(); // end a:r - $xmlWriter->endElement(); //end a:p - $xmlWriter->endElement(); //end c:rich - $xmlWriter->endElement(); // end c:tx - $xmlWriter->writeElementBlock('c:overlay', 'val', '0'); - $xmlWriter->endElement(); // end c:title - //END TITLE + if($axisType == "c:catAx"){ + if(isset($xAxisTitle)){ + $this->writeAxisTitle($xmlWriter, $xAxisTitle); + } + } else if ($axisType == "c:valAx"){ + if(isset($yAxisTitle)){ + $this->writeAxisTitle($xmlWriter, $yAxisTitle); + } + } $xmlWriter->writeElementBlock('c:crossAx', 'val', $axisCross); @@ -393,4 +379,30 @@ private function writeShape(XMLWriter $xmlWriter, $line = false) $xmlWriter->endElement(); // a:ln $xmlWriter->endElement(); // c:spPr } + + + private function writeAxisTitle(XMLWriter $xmlWriter, $title){ + $xmlWriter->startElement('c:title'); //start c:title + $xmlWriter->startElement('c:tx'); //start c:tx + $xmlWriter->startElement('c:rich'); // start c:rich + $xmlWriter->writeElementBlock('a:bodyPr'); + $xmlWriter->writeElementBlock('a:lstStyle'); + $xmlWriter->startElement('a:p'); + $xmlWriter->startElement('a:pPr'); + $xmlWriter->writeElementBlock('a:defRPr'); + $xmlWriter->endElement(); // end a:pPr + $xmlWriter->startElement('a:r'); + $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); + + $xmlWriter->startElement('a:t'); + $xmlWriter->writeRaw($title); + $xmlWriter->endElement(); //end a:t + + $xmlWriter->endElement(); // end a:r + $xmlWriter->endElement(); //end a:p + $xmlWriter->endElement(); //end c:rich + $xmlWriter->endElement(); // end c:tx + $xmlWriter->writeElementBlock('c:overlay', 'val', '0'); + $xmlWriter->endElement(); // end c:title + } } From e3876169b78e6a3c0ecaefa75f74bccdb8de0891 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Thu, 18 Jan 2018 14:18:49 -0700 Subject: [PATCH 45/68] add data label options to chart styles, and another quick test --- src/PhpWord/Style/Chart.php | 42 +++++++++++++++++++++- src/PhpWord/Writer/Word2007/Part/Chart.php | 6 ++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index a8e4af6151..583590e24d 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -51,7 +51,22 @@ class Chart extends AbstractStyle * * @var array */ - private $colors = []; + private $colors = array(); + + /** + * A list of display options for data labels + * + * @var array + */ + private $dataLabelOptions = array( + "showCatName" => true, + "showVal" => true, + "showLegendKey" => false, + "showSeriesName" => false, + "showPercent" => false, + "showLeaderLines" => false, + "showBubbleSize" => false, + ); /** * Create a new instance @@ -150,5 +165,30 @@ public function getColors() public function setColors($value = []) { $this->colors = $value; + + return $this; + } + + /** + * get the list of options for data labels + * + * @return array + */ + public function getDataLabelOptions() { + return $this->dataLabelOptions; + } + + /** + * Set values for data label options. + * This will only change values for options defined in $this->dataLabelOptions, and cannot create new ones. + * + * @param array $values [description] + */ + public function setDataLabelOptions($values = array()) { + foreach(array_keys($this->dataLabelOptions) as $option) { + if(isset($values[$option])) { + $this->dataLabelOptions[$option] = $this->setBoolVal($values[$option], $this->dataLabelOptions[$option]); + } + } } } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 9afb96f876..3eb72122af 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -222,12 +222,12 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n } else { $xmlWriter->writeElementBlock('c:showVal', 'val', 1); } - $xmlWriter->writeElementBlock('c:showLegendKey', 'val', 0); + // $xmlWriter->writeElementBlock('c:showLegendKey', 'val', 0); $xmlWriter->writeElementBlock('c:showCatName', 'val', 1); $xmlWriter->writeElementBlock('c:showSerName', 'val', 0); $xmlWriter->writeElementBlock('c:showPercent', 'val', 1); - $xmlWriter->writeElementBlock('c:showBubbleSize', 'val', 0); - $xmlWriter->writeElementBlock('c:showLeaderLines', 'val', 1); + // $xmlWriter->writeElementBlock('c:showBubbleSize', 'val', 0); + // $xmlWriter->writeElementBlock('c:showLeaderLines', 'val', 1); $xmlWriter->endElement(); // c:dLbls if (isset($this->options['scatter'])) { From f1adb64f046dcce1b5231d72420e6d5d824348c1 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Thu, 18 Jan 2018 14:35:55 -0700 Subject: [PATCH 46/68] actually write data label options --- src/PhpWord/Style/Chart.php | 6 +++--- src/PhpWord/Writer/Word2007/Part/Chart.php | 20 ++++++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 583590e24d..922df2a0d7 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -59,10 +59,10 @@ class Chart extends AbstractStyle * @var array */ private $dataLabelOptions = array( - "showCatName" => true, - "showVal" => true, + "showVal" => true, // value + "showCatName" => true, // category name "showLegendKey" => false, - "showSeriesName" => false, + "showSerName" => false, // series name "showPercent" => false, "showLeaderLines" => false, "showBubbleSize" => false, diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 3eb72122af..172bfaa1ad 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -157,7 +157,7 @@ private function writePlotArea(XMLWriter $xmlWriter) } // Series - $this->writeSeries($xmlWriter, isset($this->options['scatter']), $style->getColors()); + $this->writeSeries($xmlWriter, isset($this->options['scatter'])); $xmlWriter->writeElementBlock('c:overlap', 'val', '100'); @@ -184,9 +184,11 @@ private function writePlotArea(XMLWriter $xmlWriter) * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param bool $scatter */ - private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = null) + private function writeSeries(XMLWriter $xmlWriter, $scatter = false) { $series = $this->element->getSeries(); + $style = $this->element->getStyle(); + $colors = $style->getColors(); $index = 0; foreach ($series as $seriesItem) { @@ -217,17 +219,11 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false, $colors = n // The c:dLbls was added to make word charts look more like the reports in SurveyGizmo // This section needs to be made configurable before a pull request is made $xmlWriter->startElement('c:dLbls'); - if ($this->options['type'] == "pie") { - $xmlWriter->writeElementBlock('c:showVal', 'val', 0); - } else { - $xmlWriter->writeElementBlock('c:showVal', 'val', 1); + + foreach($style->getDataLabelOptions() as $option => $val) { + $xmlWriter->writeElementBlock("c:{$option}", 'val', (int) $val); } - // $xmlWriter->writeElementBlock('c:showLegendKey', 'val', 0); - $xmlWriter->writeElementBlock('c:showCatName', 'val', 1); - $xmlWriter->writeElementBlock('c:showSerName', 'val', 0); - $xmlWriter->writeElementBlock('c:showPercent', 'val', 1); - // $xmlWriter->writeElementBlock('c:showBubbleSize', 'val', 0); - // $xmlWriter->writeElementBlock('c:showLeaderLines', 'val', 1); + $xmlWriter->endElement(); // c:dLbls if (isset($this->options['scatter'])) { From 18932527fcea73d18b66d5f4c37e94f341b0dd52 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 14:36:52 -0700 Subject: [PATCH 47/68] unsetting initial titles. if blank they will be omitted. --- src/PhpWord/Style/Chart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 58c3574bcd..80743e06ed 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -81,13 +81,13 @@ class Chart extends AbstractStyle * * @var string */ - private $xAxisTitle = "default x title"; + private $xAxisTitle; /** * * @var string */ - private $yAxisTitle = "default y title"; + private $yAxisTitle; /** * Create a new instance From 79a80615c38891545bdb0d859faa7715896f4097 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Thu, 18 Jan 2018 14:53:24 -0700 Subject: [PATCH 48/68] make setDataLabelOptions return --- src/PhpWord/Style/Chart.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 922df2a0d7..121fffe604 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -190,5 +190,7 @@ public function setDataLabelOptions($values = array()) { $this->dataLabelOptions[$option] = $this->setBoolVal($values[$option], $this->dataLabelOptions[$option]); } } + + return $this; } } From 8c3b3520dd53b7455e6fe11d00586d62c520f64f Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 15:39:18 -0700 Subject: [PATCH 49/68] Updated naming for clarity --- src/PhpWord/Style/Chart.php | 58 +++++++++++----------- src/PhpWord/Writer/Word2007/Part/Chart.php | 12 ++--- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 80743e06ed..84dea606a2 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -62,7 +62,7 @@ class Chart extends AbstractStyle * * @var string */ - private $xAxisLabelsPosition = "none"; + private $categoryAxisLabelsPosition = "none"; /** * A string that tells the writer where to write chart labels or to skip @@ -73,7 +73,7 @@ class Chart extends AbstractStyle * * @var string */ - private $yAxisLabelsPosition = "none"; + private $valueAxisLabelsPosition = "none"; /** @@ -81,13 +81,13 @@ class Chart extends AbstractStyle * * @var string */ - private $xAxisTitle; + private $categoryAxisTitle; /** * * @var string */ - private $yAxisTitle; + private $valueAxisTitle; /** * Create a new instance @@ -189,17 +189,17 @@ public function setColors($value = []) } /** - * Get the xAxis Labels setting + * Get the categoryAxisLabelsPosition setting * * @return string */ - public function getXAxisLabelPosition() + public function getCategoryAxisLabelsPosition() { - return $this->xAxisLabelsPosition; + return $this->categoryAxisLabelsPosition; } /** - * Set the xAxis Labels setting + * Set the categoryAxis Labels setting * "none" - skips writing axis labels * "nextTo" - sets labels next to the axis (bar graphs on the left) * "low" - labels on the left side of the graph @@ -207,23 +207,23 @@ public function getXAxisLabelPosition() * * @return string */ - public function setXAxisLabelPosition($label_position) + public function setCategoryAxisLabelsPosition($label_position) { - $this->xAxisLabelsPosition = $label_position; + $this->categoryAxisLabelsPosition = $label_position; } /** - * Get the yAxis Labels setting + * Get the valueAxisLabelPosition setting * * @return string */ - public function getYAxisLabelPosition() + public function getValueAxisLabelPosition() { - return $this->yAxisLabelsPosition; + return $this->valueAxisLabelsPosition; } - /** - * Set the yAxis Labels setting + /** + * Set the valueAxisLabelPosition setting * "none" - skips writing axis labels * "nextTo" - sets labels next to the axis (bar graphs on the bottom) * "low" - labels are below the graph @@ -231,43 +231,43 @@ public function getYAxisLabelPosition() * * @var string */ - public function setYAxisLabelPosition($label_position) + public function setValueAxisLabelPosition($label_position) { - $this->yAxisLabelsPosition = $label_position; + $this->valueAxisLabelsPosition = $label_position; } /** - * Get the xAxisTitle + * Get the categoryAxisTitle * @return string */ - public function getXAxisTitle(){ - return $this->xAxisTitle; + public function getCategoryAxisTitle(){ + return $this->categoryAxisTitle; } /** - * Set the xAxis title for the a chart + * Set the categoryAxisTitle title for the chart * @var $axis_title string */ - public function setXAxisTitle($axis_title) + public function setCategoryAxisTitle($axis_title) { - $this->xAxisTitle = $axis_title; + $this->categoryAxisTitle = $axis_title; } /** - * Get the yAxisTitle + * Get the valueAxisTitle * @return string */ - public function getYAxisTitle(){ - return $this->yAxisTitle; + public function getValueAxisTitle(){ + return $this->valueAxisTitle; } /** - * Set the yAxis title for the a chart + * Set the valueAxisTitle for the chart * @var $axis_title string */ - public function setYAxisTitle($axis_title) + public function setValueAxisTitle($axis_title) { - $this->yAxisTitle = $axis_title; + $this->valueAxisTitle = $axis_title; } } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index c5f8dc9808..a274fbc7f8 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -312,16 +312,16 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:axId', 'val', $axisId); $xmlWriter->writeElementBlock('c:axPos', 'val', $axisPos); - $xAxisTitle = $style->getXAxisTitle(); - $yAxisTitle = $style->getYAxisTitle(); + $categoryAxisTitle = $style->getCategoryAxisTitle(); + $valueAxisTitle = $style->getValueAxisTitle(); if($axisType == "c:catAx"){ - if(isset($xAxisTitle)){ - $this->writeAxisTitle($xmlWriter, $xAxisTitle); + if(isset($categoryAxisTitle)){ + $this->writeAxisTitle($xmlWriter, $categoryAxisTitle); } } else if ($axisType == "c:valAx"){ - if(isset($yAxisTitle)){ - $this->writeAxisTitle($xmlWriter, $yAxisTitle); + if(isset($valueAxisTitle)){ + $this->writeAxisTitle($xmlWriter, $valueAxisTitle); } } From 10a870e4b9eab56de5fc6d882cf92425b838b773 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 15:54:11 -0700 Subject: [PATCH 50/68] updating wording --- src/PhpWord/Style/Chart.php | 42 +++++++++++----------- src/PhpWord/Writer/Word2007/Part/Chart.php | 4 +-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 84dea606a2..db7b283eec 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -62,7 +62,7 @@ class Chart extends AbstractStyle * * @var string */ - private $categoryAxisLabelsPosition = "none"; + private $categoryLabelPosition = "none"; /** * A string that tells the writer where to write chart labels or to skip @@ -73,7 +73,7 @@ class Chart extends AbstractStyle * * @var string */ - private $valueAxisLabelsPosition = "none"; + private $valueLabelPosition = "none"; /** @@ -189,27 +189,27 @@ public function setColors($value = []) } /** - * Get the categoryAxisLabelsPosition setting + * Get the categoryLabelsPosition setting * * @return string */ - public function getCategoryAxisLabelsPosition() + public function getCategoryLabelPosition() { - return $this->categoryAxisLabelsPosition; + return $this->categoryLabelPosition; } /** - * Set the categoryAxis Labels setting - * "none" - skips writing axis labels - * "nextTo" - sets labels next to the axis (bar graphs on the left) + * Set the category Labels setting + * "none" - skips writing labels + * "nextTo" - sets labels next to the (bar graphs on the left) * "low" - labels on the left side of the graph * "high" - labels on the right side of the graph * * @return string */ - public function setCategoryAxisLabelsPosition($label_position) + public function setCategoryLabelPosition($label_position) { - $this->categoryAxisLabelsPosition = $label_position; + $this->categoryLabelPosition = $label_position; } /** @@ -217,23 +217,23 @@ public function setCategoryAxisLabelsPosition($label_position) * * @return string */ - public function getValueAxisLabelPosition() + public function getValueLabelPosition() { - return $this->valueAxisLabelsPosition; + return $this->valueLabelPosition; } /** - * Set the valueAxisLabelPosition setting - * "none" - skips writing axis labels - * "nextTo" - sets labels next to the axis (bar graphs on the bottom) - * "low" - labels are below the graph - * "high" - labels above the graph + * Set the valueLabelPosition setting + * "none" - skips writing labels + * "nextTo" - sets labels next to the value + * "low" - sets labels are below the graph + * "high" - sets labels above the graph * * @var string */ - public function setValueAxisLabelPosition($label_position) + public function setValueLabelPosition($label_position) { - $this->valueAxisLabelsPosition = $label_position; + $this->valueLabelPosition = $label_position; } /** @@ -245,7 +245,7 @@ public function getCategoryAxisTitle(){ } /** - * Set the categoryAxisTitle title for the chart + * Set the title that appears on the category side of the chart * @var $axis_title string */ public function setCategoryAxisTitle($axis_title) @@ -262,7 +262,7 @@ public function getValueAxisTitle(){ } /** - * Set the valueAxisTitle for the chart + * Set the title that appears on the value side of the chart * @var $axis_title string */ public function setValueAxisTitle($axis_title) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index a274fbc7f8..5497ee12fc 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -335,9 +335,9 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); if($axisType == "c:catAx"){ - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getXAxisLabelPosition()); + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getCategoryLabelPosition()); } else if($axisType == "c:valAx"){ - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getYAxisLabelPosition()); + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getValueLabelPosition()); } else { $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo } From db2428c37fa82919578476fbaa4b5669d3adaae1 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 16:24:59 -0700 Subject: [PATCH 51/68] updated a comment --- src/PhpWord/Style/Chart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index db7b283eec..57a5c4d84a 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -189,7 +189,7 @@ public function setColors($value = []) } /** - * Get the categoryLabelsPosition setting + * Get the categoryLabelPosition setting * * @return string */ @@ -199,7 +199,7 @@ public function getCategoryLabelPosition() } /** - * Set the category Labels setting + * Set the categoryLabelPosition setting * "none" - skips writing labels * "nextTo" - sets labels next to the (bar graphs on the left) * "low" - labels on the left side of the graph From ee90b450ef1bdb8bf5a426151f09142905086b7d Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 18 Jan 2018 16:30:26 -0700 Subject: [PATCH 52/68] changed setters to return this. --- src/PhpWord/Style/Chart.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 32854eec63..0e20e1007d 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -252,6 +252,8 @@ public function getCategoryLabelPosition() public function setCategoryLabelPosition($label_position) { $this->categoryLabelPosition = $label_position; + + return $this; } /** @@ -276,6 +278,8 @@ public function getValueLabelPosition() public function setValueLabelPosition($label_position) { $this->valueLabelPosition = $label_position; + + return $this; } /** @@ -293,6 +297,8 @@ public function getCategoryAxisTitle(){ public function setCategoryAxisTitle($axis_title) { $this->categoryAxisTitle = $axis_title; + + return $this; } /** @@ -310,6 +316,8 @@ public function getValueAxisTitle(){ public function setValueAxisTitle($axis_title) { $this->valueAxisTitle = $axis_title; + + return $this; } } From 6a497e84d9a5638695a59f705b6418f3fe0f9b12 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Wed, 31 Jan 2018 15:28:52 -0700 Subject: [PATCH 53/68] added tests for Charts --- tests/PhpWord/Style/ChartTest.php | 159 ++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 tests/PhpWord/Style/ChartTest.php diff --git a/tests/PhpWord/Style/ChartTest.php b/tests/PhpWord/Style/ChartTest.php new file mode 100644 index 0000000000..067432740f --- /dev/null +++ b/tests/PhpWord/Style/ChartTest.php @@ -0,0 +1,159 @@ +assertEquals($chart->getWidth(), 1000000); + + $chart->setWidth(200); + + $this->assertEquals($chart->getWidth(), 200); + + } + + public function testSetGetHeight() { + $chart = new Chart(); + + $this->assertEquals($chart->getHeight(), 1000000); + + $chart->setHeight(200); + + $this->assertEquals($chart->getHeight(), 200); + } + + public function testSetIs3d() { + $chart = new Chart(); + + $this->assertEquals($chart->is3d(), false); + + $chart->set3d(true); + + $this->assertEquals($chart->is3d(), true); + } + + public function testSetGetColors() { + $chart = new Chart(); + + $this->assertInternalType('array', $chart->getColors()); + + $this->assertEquals(count($chart->getColors()), 0); + + $chart->setColors(['FFFFFFFF', 'FF000000', 'FFFF0000']); + + $this->assertEquals($chart->getColors(), ['FFFFFFFF', 'FF000000', 'FFFF0000']); + } + + public function testSetGetDataLabelOptions() { + + $chart = new Chart(); + + $originalDataLabelOptions = array( + "showVal" => true, + "showCatName" => true, + "showLegendKey" => false, + "showSerName" => false, + "showPercent" => false, + "showLeaderLines" => false, + "showBubbleSize" => false, + ); + + $this->assertEquals($chart->getDataLabelOptions(), $originalDataLabelOptions); + + $changedDataLabelOptions = array( + "showVal" => false, + "showCatName" => false, + "showLegendKey" => true, + "showSerName" => true, + "showPercent" => true, + "showLeaderLines" => true, + "showBubbleSize" => true, + ); + + $chart->setDataLabelOptions( + array( + "showVal" => false, + "showCatName" => false, + "showLegendKey" => true, + "showSerName" => true, + "showPercent" => true, + "showLeaderLines" => true, + "showBubbleSize" => true, + )); + $this->assertEquals($chart->getDataLabelOptions(), $changedDataLabelOptions); + } + + public function testSetGetCategoryLabelPosition() { + $chart = new Chart(); + + $this->assertEquals($chart->getCategoryLabelPosition(), "none"); + + $chart->setCategoryLabelPosition("nextTo"); + + $this->assertEquals($chart->getCategoryLabelPosition(), "nextTo"); + + } + /** + * DOOD WRITE THESSSE + * @return [type] [description] + */ + public function testSetGetValueLabelPosition() { + $chart = new Chart(); + + $this->assertEquals($chart->getValueLabelPosition(), "none"); + + $chart->setValueLabelPosition("low"); + + $this->assertEquals($chart->getValueLabelPosition(), "low"); + + } + + public function testSetGetCategoryAxisTitle() { + $chart = new Chart(); + + $chart->getCategoryAxisTitle(); + + $this->assertEquals($chart->getCategoryAxisTitle(), NULL); + + $chart->setCategoryAxisTitle("Test Category Axis Title"); + + $this->assertEquals($chart->getCategoryAxisTitle(), "Test Category Axis Title"); + } + + public function testSetGetValueAxisTitle() { + $chart = new Chart(); + + $chart->getValueAxisTitle(); + + $this->assertEquals($chart->getValueAxisTitle(), NULL); + + $chart->setValueAxisTitle("Test Value Axis Title"); + + $this->assertEquals($chart->getValueAxisTitle(), "Test Value Axis Title"); + } +} From e12cb522a83df613d6d51c82fb4510ca33757da8 Mon Sep 17 00:00:00 2001 From: Cooper Heinrichs Date: Thu, 1 Feb 2018 10:42:58 -0700 Subject: [PATCH 54/68] edited tests with descriptions --- src/PhpWord/Style/Chart.php | 10 ++++------ tests/PhpWord/Style/ChartTest.php | 27 +++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 0e20e1007d..c714c1b06d 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * - * @see https://github.com/PHPOffice/PHPWord - * @copyright 2010-2017 PHPWord contributors - * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 + * @copyright 2010-2017 PHPWord contributors + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 + * @see https://github.com/PHPOffice/PHPWord */ namespace PhpOffice\PhpWord\Style; @@ -61,7 +61,7 @@ class Chart extends AbstractStyle private $dataLabelOptions = array( "showVal" => true, // value "showCatName" => true, // category name - "showLegendKey" => false, + "showLegendKey" => false, //show the cart legend "showSerName" => false, // series name "showPercent" => false, "showLeaderLines" => false, @@ -126,7 +126,6 @@ public function getWidth() /** * Set width - * * @param int $value * @return self */ @@ -172,7 +171,6 @@ public function is3d() /** * Set 3D - * * @param bool $value * @return self */ diff --git a/tests/PhpWord/Style/ChartTest.php b/tests/PhpWord/Style/ChartTest.php index 067432740f..85c8f7fa96 100644 --- a/tests/PhpWord/Style/ChartTest.php +++ b/tests/PhpWord/Style/ChartTest.php @@ -25,6 +25,9 @@ */ class ChartTest extends \PHPUnit\Framework\TestCase { + /** + * Testing getter and setter for chart width + */ public function testSetGetWidth() { $chart = new Chart(); @@ -37,6 +40,9 @@ public function testSetGetWidth() { } + /** + * Testing getter and setter for chart height + */ public function testSetGetHeight() { $chart = new Chart(); @@ -47,6 +53,9 @@ public function testSetGetHeight() { $this->assertEquals($chart->getHeight(), 200); } + /** + * Testing getter and setter for is3d + */ public function testSetIs3d() { $chart = new Chart(); @@ -57,6 +66,9 @@ public function testSetIs3d() { $this->assertEquals($chart->is3d(), true); } + /** + * Testing getter and setter for chart colors + */ public function testSetGetColors() { $chart = new Chart(); @@ -69,6 +81,9 @@ public function testSetGetColors() { $this->assertEquals($chart->getColors(), ['FFFFFFFF', 'FF000000', 'FFFF0000']); } + /** + * Testing getter and setter for dataLabelOptions + */ public function testSetGetDataLabelOptions() { $chart = new Chart(); @@ -108,6 +123,9 @@ public function testSetGetDataLabelOptions() { $this->assertEquals($chart->getDataLabelOptions(), $changedDataLabelOptions); } + /** + * Testing categoryLabelPosition getter and setter + */ public function testSetGetCategoryLabelPosition() { $chart = new Chart(); @@ -119,8 +137,7 @@ public function testSetGetCategoryLabelPosition() { } /** - * DOOD WRITE THESSSE - * @return [type] [description] + * Testing valueLabelPosition getter and setter */ public function testSetGetValueLabelPosition() { $chart = new Chart(); @@ -133,6 +150,9 @@ public function testSetGetValueLabelPosition() { } + /** + * Testing categoryAxisTitle getter and setter + */ public function testSetGetCategoryAxisTitle() { $chart = new Chart(); @@ -145,6 +165,9 @@ public function testSetGetCategoryAxisTitle() { $this->assertEquals($chart->getCategoryAxisTitle(), "Test Category Axis Title"); } + /** + * Testing valueAxisTitle getter and setter + */ public function testSetGetValueAxisTitle() { $chart = new Chart(); From 3a8ebb86a8fcf9c3e0ac70417c50c5cd492ea997 Mon Sep 17 00:00:00 2001 From: blakeface Date: Thu, 1 Mar 2018 09:45:49 -0700 Subject: [PATCH 55/68] added percent_stacked to available types array --- src/PhpWord/Element/Chart.php | 2 +- src/PhpWord/Writer/Word2007/Part/Chart.php | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/PhpWord/Element/Chart.php b/src/PhpWord/Element/Chart.php index c830c93b53..884c54c0e0 100644 --- a/src/PhpWord/Element/Chart.php +++ b/src/PhpWord/Element/Chart.php @@ -86,7 +86,7 @@ public function getType() */ public function setType($value) { - $enum = array('pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'column', 'stacked_column', 'area', 'radar', 'scatter'); + $enum = array('pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'percent_stacked_bar', 'column', 'stacked_column', 'percent_stacked_column', 'area', 'radar', 'scatter'); $this->type = $this->setEnumVal($value, $enum, 'pie'); } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 3efc581317..2f1e34e74b 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -41,16 +41,18 @@ class Chart extends AbstractPart * @var array */ private $types = array( - 'pie' => array('type' => 'pie', 'colors' => 1), - 'doughnut' => array('type' => 'doughnut', 'colors' => 1, 'hole' => 75, 'no3d' => true), - 'bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'clustered'), - 'stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'stacked'), - 'column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'clustered'), - 'stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'stacked'), - 'line' => array('type' => 'line', 'colors' => 0, 'axes' => true), - 'area' => array('type' => 'area', 'colors' => 0, 'axes' => true), - 'radar' => array('type' => 'radar', 'colors' => 0, 'axes' => true, 'radar' => 'standard', 'no3d' => true), - 'scatter' => array('type' => 'scatter', 'colors' => 0, 'axes' => true, 'scatter' => 'marker', 'no3d' => true), + 'pie' => array('type' => 'pie', 'colors' => 1), + 'doughnut' => array('type' => 'doughnut', 'colors' => 1, 'hole' => 75, 'no3d' => true), + 'bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'clustered'), + 'stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'stacked'), + 'percent_stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'percentStacked'), + 'column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'clustered'), + 'stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'stacked'), + 'percent_stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'percentStacked'), + 'line' => array('type' => 'line', 'colors' => 0, 'axes' => true), + 'area' => array('type' => 'area', 'colors' => 0, 'axes' => true), + 'radar' => array('type' => 'radar', 'colors' => 0, 'axes' => true, 'radar' => 'standard', 'no3d' => true), + 'scatter' => array('type' => 'scatter', 'colors' => 0, 'axes' => true, 'scatter' => 'marker', 'no3d' => true), ); /** From 4efd88e52cb9dff8dc2cb212d8a3cb3aa278f4c1 Mon Sep 17 00:00:00 2001 From: blakeface Date: Thu, 1 Mar 2018 10:16:11 -0700 Subject: [PATCH 56/68] apply color hack to 100% stacked bar --- src/PhpWord/Writer/Word2007/Part/Chart.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 2f1e34e74b..16e2e89415 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -242,20 +242,20 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) // setting the chart colors was taken from https://github.com/PHPOffice/PHPWord/issues/494 if(is_array($colors) && count($colors)) { // This is a workaround to make each series in a stack chart use a different color - if($this->options['type'] == 'bar' && $this->options['grouping'] == 'stacked') { + if($this->options['type'] == 'bar' && strstr($this->options['grouping'], 'stacked')) { array_shift($colors); } $colorIndex = 0; foreach ($colors as $color) { - $xmlWriter->startElement('c:dPt'); - $xmlWriter->writeElementBlock('c:idx', 'val', $colorIndex); - $xmlWriter->startElement('c:spPr'); - $xmlWriter->startElement('a:solidFill'); - $xmlWriter->writeElementBlock('a:srgbClr', 'val', $color); - $xmlWriter->endElement(); // a:solidFill - $xmlWriter->endElement(); // c:spPr - $xmlWriter->endElement(); // c:dPt - $colorIndex++; + $xmlWriter->startElement('c:dPt'); + $xmlWriter->writeElementBlock('c:idx', 'val', $colorIndex); + $xmlWriter->startElement('c:spPr'); + $xmlWriter->startElement('a:solidFill'); + $xmlWriter->writeElementBlock('a:srgbClr', 'val', $color); + $xmlWriter->endElement(); // a:solidFill + $xmlWriter->endElement(); // c:spPr + $xmlWriter->endElement(); // c:dPt + $colorIndex++; } } } From 3919560e4679df35bde899c1f457c5acb91fc8ef Mon Sep 17 00:00:00 2001 From: blakeface Date: Thu, 1 Mar 2018 14:34:59 -0700 Subject: [PATCH 57/68] used case insensitive string matching --- src/PhpWord/Writer/Word2007/Part/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 16e2e89415..3c1c3edce4 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -242,7 +242,7 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) // setting the chart colors was taken from https://github.com/PHPOffice/PHPWord/issues/494 if(is_array($colors) && count($colors)) { // This is a workaround to make each series in a stack chart use a different color - if($this->options['type'] == 'bar' && strstr($this->options['grouping'], 'stacked')) { + if ($this->options['type'] == 'bar' && stristr($this->options['grouping'], 'stacked')) { array_shift($colors); } $colorIndex = 0; From f119724209f0a29a746d2ce4a411cf00508b9576 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 14 Mar 2018 13:34:45 -0600 Subject: [PATCH 58/68] Make tick mark and tick label positions configurable --- src/PhpWord/Style/Chart.php | 30 ++++++++++++++++++---- src/PhpWord/Writer/Word2007/Part/Chart.php | 6 ++--- tests/PhpWord/Style/ChartTest.php | 4 +-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index c714c1b06d..c3743aa903 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -104,6 +104,9 @@ class Chart extends AbstractStyle */ private $valueAxisTitle; + + private $majorTickMarkPos = "none" + /** * Create a new instance * @@ -249,7 +252,8 @@ public function getCategoryLabelPosition() */ public function setCategoryLabelPosition($label_position) { - $this->categoryLabelPosition = $label_position; + $enum = array("none", "nextTo", "low", "high"); + $this->categoryLabelPosition = $this->setEnumVal($label_position, $enum, $this->categoryLabelPosition); return $this; } @@ -271,11 +275,12 @@ public function getValueLabelPosition() * "low" - sets labels are below the graph * "high" - sets labels above the graph * - * @var string + * @param string */ public function setValueLabelPosition($label_position) { - $this->valueLabelPosition = $label_position; + $enum = array("none", "nextTo", "low", "high"); + $this->valueLabelPosition = $this->setEnumVal($label_position, $enum, $this->valueLabelPosition); return $this; } @@ -290,7 +295,7 @@ public function getCategoryAxisTitle(){ /** * Set the title that appears on the category side of the chart - * @var $axis_title string + * @param string $axis_title */ public function setCategoryAxisTitle($axis_title) { @@ -309,7 +314,7 @@ public function getValueAxisTitle(){ /** * Set the title that appears on the value side of the chart - * @var $axis_title string + * @param string $axis_title */ public function setValueAxisTitle($axis_title) { @@ -318,4 +323,19 @@ public function setValueAxisTitle($axis_title) return $this; } + public function getMajorTickPosition() + { + return $this->majorTickMarkPos; + } + + /** + * set the position for major tick marks + * @param string $position [description] + */ + public function setMajorTickPosition($position) + { + $enum = array("in", "out", "cross", "none"); + $this->majorTickMarkPos = $this->setEnumVal($position, $enum, $this->majorTickMarkPos); + } + } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 3efc581317..3c7eeb388d 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -343,15 +343,13 @@ private function writeAxis(XMLWriter $xmlWriter, $type) if (isset($this->options['axes'])) { $xmlWriter->writeElementBlock('c:delete', 'val', 0); - $xmlWriter->writeElementBlock('c:majorTickMark', 'val', 'in'); // SG edit: switched from none to inside + $xmlWriter->writeElementBlock('c:majorTickMark', 'val', $style->getMajorTickPosition()); $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); if($axisType == "c:catAx"){ $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getCategoryLabelPosition()); - } else if($axisType == "c:valAx"){ - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getValueLabelPosition()); } else { - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', 'nextTo'); // nextTo // SG edit: switched from none to nextTo + $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getValueLabelPosition()); } $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); diff --git a/tests/PhpWord/Style/ChartTest.php b/tests/PhpWord/Style/ChartTest.php index 85c8f7fa96..e50abd9121 100644 --- a/tests/PhpWord/Style/ChartTest.php +++ b/tests/PhpWord/Style/ChartTest.php @@ -76,9 +76,9 @@ public function testSetGetColors() { $this->assertEquals(count($chart->getColors()), 0); - $chart->setColors(['FFFFFFFF', 'FF000000', 'FFFF0000']); + $chart->setColors(array('FFFFFFFF', 'FF000000', 'FFFF0000')); - $this->assertEquals($chart->getColors(), ['FFFFFFFF', 'FF000000', 'FFFF0000']); + $this->assertEquals($chart->getColors(), array('FFFFFFFF', 'FF000000', 'FFFF0000')); } /** From 7c6d3c5a2532c2f71eaebb7f9814470863262e01 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 14 Mar 2018 15:26:30 -0600 Subject: [PATCH 59/68] I accidentally a semicolon --- src/PhpWord/Style/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index c3743aa903..918be590d2 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -105,7 +105,7 @@ class Chart extends AbstractStyle private $valueAxisTitle; - private $majorTickMarkPos = "none" + private $majorTickMarkPos = "none"; /** * Create a new instance From 7fa341fd0c1a0dbeb7861851d89b5c71cdee952c Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 14 Mar 2018 17:09:05 -0600 Subject: [PATCH 60/68] accidentally removed a comment's end --- src/PhpWord/Style/Chart.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index fd588b289e..39fed9b5e9 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -13,6 +13,7 @@ * @see https://github.com/PHPOffice/PHPWord * @copyright 2010-2018 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 + */ namespace PhpOffice\PhpWord\Style; From f5eb35221af42c280cf1eec21d10b7254137dd43 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 4 Apr 2018 13:21:50 -0600 Subject: [PATCH 61/68] formatting --- src/PhpWord/Style/Chart.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 39fed9b5e9..0a1a515d3e 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -15,7 +15,6 @@ * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ - namespace PhpOffice\PhpWord\Style; /** @@ -130,6 +129,7 @@ public function getWidth() /** * Set width + * * @param int $value * @return self */ @@ -175,6 +175,7 @@ public function is3d() /** * Set 3D + * * @param bool $value * @return self */ From fb6800e5b81ad09b9ca0d79e32ed1ec1b89dda35 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 4 Apr 2018 14:09:22 -0600 Subject: [PATCH 62/68] fix some style stuff --- src/PhpWord/Element/Chart.php | 8 +- src/PhpWord/Style/Chart.php | 70 +++++++------ src/PhpWord/Writer/Word2007/Part/Chart.php | 45 ++++----- tests/PhpWord/Style/ChartTest.php | 110 +++++++++++---------- 4 files changed, 118 insertions(+), 115 deletions(-) diff --git a/src/PhpWord/Element/Chart.php b/src/PhpWord/Element/Chart.php index 6c7ef0b3a8..d651c80be3 100644 --- a/src/PhpWord/Element/Chart.php +++ b/src/PhpWord/Element/Chart.php @@ -61,11 +61,12 @@ class Chart extends AbstractElement * @param array $categories * @param array $values * @param array $style + * @param null|mixed $series_name */ - public function __construct($type, $categories, $values, $style = null, $series_name = null) + public function __construct($type, $categories, $values, $style = null, $seriesName = null) { $this->setType($type); - $this->addSeries($categories, $values, $series_name); + $this->addSeries($categories, $values, $seriesN ame); $this->style = $this->setNewStyle(new ChartStyle(), $style, true); } @@ -95,13 +96,14 @@ public function setType($value) * * @param array $categories * @param array $values + * @param null|mixed $name */ public function addSeries($categories, $values, $name = null) { $this->series[] = array( 'categories' => $categories, 'values' => $values, - 'name' => $name + 'name' => $name, ); } diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 39fed9b5e9..971f8af19f 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -15,7 +15,6 @@ * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ - namespace PhpOffice\PhpWord\Style; /** @@ -46,7 +45,6 @@ class Chart extends AbstractStyle */ private $is3d = false; - /** * A list of colors to use in the chart * @@ -60,13 +58,13 @@ class Chart extends AbstractStyle * @var array */ private $dataLabelOptions = array( - "showVal" => true, // value - "showCatName" => true, // category name - "showLegendKey" => false, //show the cart legend - "showSerName" => false, // series name - "showPercent" => false, - "showLeaderLines" => false, - "showBubbleSize" => false, + 'showVal' => true, // value + 'showCatName' => true, // category name + 'showLegendKey' => false, //show the cart legend + 'showSerName' => false, // series name + 'showPercent' => false, + 'showLeaderLines' => false, + 'showBubbleSize' => false, ); /** @@ -78,7 +76,7 @@ class Chart extends AbstractStyle * * @var string */ - private $categoryLabelPosition = "none"; + private $categoryLabelPosition = 'none'; /** * A string that tells the writer where to write chart labels or to skip @@ -89,24 +87,19 @@ class Chart extends AbstractStyle * * @var string */ - private $valueLabelPosition = "none"; - + private $valueLabelPosition = 'none'; /** - * - * * @var string */ private $categoryAxisTitle; /** - * * @var string */ private $valueAxisTitle; - - private $majorTickMarkPos = "none"; + private $majorTickMarkPos = 'none'; /** * Create a new instance @@ -200,7 +193,7 @@ public function getColors() * * @param array $value a list of colors to use in the chart */ - public function setColors($value = []) + public function setColors($value = array()) { $this->colors = $value; @@ -212,7 +205,8 @@ public function setColors($value = []) * * @return array */ - public function getDataLabelOptions() { + public function getDataLabelOptions() + { return $this->dataLabelOptions; } @@ -222,9 +216,10 @@ public function getDataLabelOptions() { * * @param array $values [description] */ - public function setDataLabelOptions($values = array()) { - foreach(array_keys($this->dataLabelOptions) as $option) { - if(isset($values[$option])) { + public function setDataLabelOptions($values = array()) + { + foreach (array_keys($this->dataLabelOptions) as $option) { + if (isset($values[$option])) { $this->dataLabelOptions[$option] = $this->setBoolVal($values[$option], $this->dataLabelOptions[$option]); } } @@ -249,12 +244,13 @@ public function getCategoryLabelPosition() * "low" - labels on the left side of the graph * "high" - labels on the right side of the graph * + * @param mixed $label_position * @return string */ - public function setCategoryLabelPosition($label_position) + public function setCategoryLabelPosition($labelPosition) { - $enum = array("none", "nextTo", "low", "high"); - $this->categoryLabelPosition = $this->setEnumVal($label_position, $enum, $this->categoryLabelPosition); + $enum = array('none', 'nextTo', 'low', 'high'); + $this->categoryLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->categoryLabelPosition); return $this; } @@ -277,11 +273,12 @@ public function getValueLabelPosition() * "high" - sets labels above the graph * * @param string + * @param mixed $label_position */ - public function setValueLabelPosition($label_position) + public function setValueLabelPosition($labelPosition) { - $enum = array("none", "nextTo", "low", "high"); - $this->valueLabelPosition = $this->setEnumVal($label_position, $enum, $this->valueLabelPosition); + $enum = array('none', 'nextTo', 'low', 'high'); + $this->valueLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->valueLabelPosition); return $this; } @@ -290,7 +287,8 @@ public function setValueLabelPosition($label_position) * Get the categoryAxisTitle * @return string */ - public function getCategoryAxisTitle(){ + public function getCategoryAxisTitle() + { return $this->categoryAxisTitle; } @@ -298,9 +296,9 @@ public function getCategoryAxisTitle(){ * Set the title that appears on the category side of the chart * @param string $axis_title */ - public function setCategoryAxisTitle($axis_title) + public function setCategoryAxisTitle($axisTitle) { - $this->categoryAxisTitle = $axis_title; + $this->categoryAxisTitle = $axisTitle; return $this; } @@ -309,7 +307,8 @@ public function setCategoryAxisTitle($axis_title) * Get the valueAxisTitle * @return string */ - public function getValueAxisTitle(){ + public function getValueAxisTitle() + { return $this->valueAxisTitle; } @@ -317,9 +316,9 @@ public function getValueAxisTitle(){ * Set the title that appears on the value side of the chart * @param string $axis_title */ - public function setValueAxisTitle($axis_title) + public function setValueAxisTitle($axisTitle) { - $this->valueAxisTitle = $axis_title; + $this->valueAxisTitle = $axisTitle; return $this; } @@ -335,8 +334,7 @@ public function getMajorTickPosition() */ public function setMajorTickPosition($position) { - $enum = array("in", "out", "cross", "none"); + $enum = array('in', 'out', 'cross', 'none'); $this->majorTickMarkPos = $this->setEnumVal($position, $enum, $this->majorTickMarkPos); } - } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index b993282952..1bfcbd2aad 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -41,18 +41,18 @@ class Chart extends AbstractPart * @var array */ private $types = array( - 'pie' => array('type' => 'pie', 'colors' => 1), - 'doughnut' => array('type' => 'doughnut', 'colors' => 1, 'hole' => 75, 'no3d' => true), - 'bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'clustered'), - 'stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'stacked'), - 'percent_stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'percentStacked'), - 'column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'clustered'), - 'stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'stacked'), + 'pie' => array('type' => 'pie', 'colors' => 1), + 'doughnut' => array('type' => 'doughnut', 'colors' => 1, 'hole' => 75, 'no3d' => true), + 'bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'clustered'), + 'stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'stacked'), + 'percent_stacked_bar' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'bar', 'grouping' => 'percentStacked'), + 'column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'clustered'), + 'stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'stacked'), 'percent_stacked_column' => array('type' => 'bar', 'colors' => 0, 'axes' => true, 'bar' => 'col', 'grouping' => 'percentStacked'), - 'line' => array('type' => 'line', 'colors' => 0, 'axes' => true), - 'area' => array('type' => 'area', 'colors' => 0, 'axes' => true), - 'radar' => array('type' => 'radar', 'colors' => 0, 'axes' => true, 'radar' => 'standard', 'no3d' => true), - 'scatter' => array('type' => 'scatter', 'colors' => 0, 'axes' => true, 'scatter' => 'marker', 'no3d' => true), + 'line' => array('type' => 'line', 'colors' => 0, 'axes' => true), + 'area' => array('type' => 'area', 'colors' => 0, 'axes' => true), + 'radar' => array('type' => 'radar', 'colors' => 0, 'axes' => true, 'radar' => 'standard', 'no3d' => true), + 'scatter' => array('type' => 'scatter', 'colors' => 0, 'axes' => true, 'scatter' => 'marker', 'no3d' => true), ); /** @@ -202,7 +202,7 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) $xmlWriter->writeElementBlock('c:idx', 'val', $index); $xmlWriter->writeElementBlock('c:order', 'val', $index); - if(!is_null($seriesItem['name']) && $seriesItem['name'] != "") { + if (!is_null($seriesItem['name']) && $seriesItem['name'] != '') { $xmlWriter->startElement('c:tx'); $xmlWriter->startElement('c:strRef'); $xmlWriter->startElement('c:strCache'); @@ -222,7 +222,7 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) // This section needs to be made configurable before a pull request is made $xmlWriter->startElement('c:dLbls'); - foreach($style->getDataLabelOptions() as $option => $val) { + foreach ($style->getDataLabelOptions() as $option => $val) { $xmlWriter->writeElementBlock("c:{$option}", 'val', (int) $val); } @@ -240,7 +240,7 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) $this->writeSeriesItem($xmlWriter, 'val', $values); // setting the chart colors was taken from https://github.com/PHPOffice/PHPWord/issues/494 - if(is_array($colors) && count($colors)) { + if (is_array($colors) && count($colors)) { // This is a workaround to make each series in a stack chart use a different color if ($this->options['type'] == 'bar' && stristr($this->options['grouping'], 'stacked')) { array_shift($colors); @@ -329,17 +329,16 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $categoryAxisTitle = $style->getCategoryAxisTitle(); $valueAxisTitle = $style->getValueAxisTitle(); - if($axisType == "c:catAx"){ - if(isset($categoryAxisTitle)){ + if ($axisType == 'c:catAx') { + if (isset($categoryAxisTitle)) { $this->writeAxisTitle($xmlWriter, $categoryAxisTitle); } - } else if ($axisType == "c:valAx"){ - if(isset($valueAxisTitle)){ + } elseif ($axisType == 'c:valAx') { + if (isset($valueAxisTitle)) { $this->writeAxisTitle($xmlWriter, $valueAxisTitle); } } - $xmlWriter->writeElementBlock('c:crossAx', 'val', $axisCross); $xmlWriter->writeElementBlock('c:auto', 'val', 1); @@ -348,7 +347,7 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:majorTickMark', 'val', $style->getMajorTickPosition()); $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); - if($axisType == "c:catAx"){ + if ($axisType == 'c:catAx') { $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getCategoryLabelPosition()); } else { $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getValueLabelPosition()); @@ -370,8 +369,6 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->endElement(); // $axisType } - - /** * Write shape * @@ -392,8 +389,8 @@ private function writeShape(XMLWriter $xmlWriter, $line = false) $xmlWriter->endElement(); // c:spPr } - - private function writeAxisTitle(XMLWriter $xmlWriter, $title){ + private function writeAxisTitle(XMLWriter $xmlWriter, $title) + { $xmlWriter->startElement('c:title'); //start c:title $xmlWriter->startElement('c:tx'); //start c:tx $xmlWriter->startElement('c:rich'); // start c:rich diff --git a/tests/PhpWord/Style/ChartTest.php b/tests/PhpWord/Style/ChartTest.php index e50abd9121..a267d28ef1 100644 --- a/tests/PhpWord/Style/ChartTest.php +++ b/tests/PhpWord/Style/ChartTest.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. For the full list of * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * - * @see https://github.com/PHPOffice/PHPWord - * @copyright 2010-2017 PHPWord contributors - * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 + * @see https://github.com/PHPOffice/PHPWord + * @copyright 2010-2017 PHPWord contributors + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Style; @@ -20,7 +20,7 @@ /** * Test class for PhpOffice\PhpWord\Style\Chart * - * @coversDefaultClass \PhpOffice\PhpWord\Style\Chart + * @coversDefaultClass \PhpOffice\PhpWord\Style\Chart * @runTestsInSeparateProcesses */ class ChartTest extends \PHPUnit\Framework\TestCase @@ -28,8 +28,8 @@ class ChartTest extends \PHPUnit\Framework\TestCase /** * Testing getter and setter for chart width */ - public function testSetGetWidth() { - + public function testSetGetWidth() + { $chart = new Chart(); $this->assertEquals($chart->getWidth(), 1000000); @@ -37,13 +37,13 @@ public function testSetGetWidth() { $chart->setWidth(200); $this->assertEquals($chart->getWidth(), 200); - } /** * Testing getter and setter for chart height */ - public function testSetGetHeight() { + public function testSetGetHeight() + { $chart = new Chart(); $this->assertEquals($chart->getHeight(), 1000000); @@ -56,7 +56,8 @@ public function testSetGetHeight() { /** * Testing getter and setter for is3d */ - public function testSetIs3d() { + public function testSetIs3d() + { $chart = new Chart(); $this->assertEquals($chart->is3d(), false); @@ -69,7 +70,8 @@ public function testSetIs3d() { /** * Testing getter and setter for chart colors */ - public function testSetGetColors() { + public function testSetGetColors() + { $chart = new Chart(); $this->assertInternalType('array', $chart->getColors()); @@ -84,99 +86,103 @@ public function testSetGetColors() { /** * Testing getter and setter for dataLabelOptions */ - public function testSetGetDataLabelOptions() { - + public function testSetGetDataLabelOptions() + { $chart = new Chart(); $originalDataLabelOptions = array( - "showVal" => true, - "showCatName" => true, - "showLegendKey" => false, - "showSerName" => false, - "showPercent" => false, - "showLeaderLines" => false, - "showBubbleSize" => false, + 'showVal' => true, + 'showCatName' => true, + 'showLegendKey' => false, + 'showSerName' => false, + 'showPercent' => false, + 'showLeaderLines' => false, + 'showBubbleSize' => false, ); $this->assertEquals($chart->getDataLabelOptions(), $originalDataLabelOptions); $changedDataLabelOptions = array( - "showVal" => false, - "showCatName" => false, - "showLegendKey" => true, - "showSerName" => true, - "showPercent" => true, - "showLeaderLines" => true, - "showBubbleSize" => true, + 'showVal' => false, + 'showCatName' => false, + 'showLegendKey' => true, + 'showSerName' => true, + 'showPercent' => true, + 'showLeaderLines' => true, + 'showBubbleSize' => true, ); $chart->setDataLabelOptions( array( - "showVal" => false, - "showCatName" => false, - "showLegendKey" => true, - "showSerName" => true, - "showPercent" => true, - "showLeaderLines" => true, - "showBubbleSize" => true, - )); + 'showVal' => false, + 'showCatName' => false, + 'showLegendKey' => true, + 'showSerName' => true, + 'showPercent' => true, + 'showLeaderLines' => true, + 'showBubbleSize' => true, + ) + ); $this->assertEquals($chart->getDataLabelOptions(), $changedDataLabelOptions); } /** * Testing categoryLabelPosition getter and setter */ - public function testSetGetCategoryLabelPosition() { + public function testSetGetCategoryLabelPosition() + { $chart = new Chart(); - $this->assertEquals($chart->getCategoryLabelPosition(), "none"); + $this->assertEquals($chart->getCategoryLabelPosition(), 'none'); - $chart->setCategoryLabelPosition("nextTo"); - - $this->assertEquals($chart->getCategoryLabelPosition(), "nextTo"); + $chart->setCategoryLabelPosition('nextTo'); + $this->assertEquals($chart->getCategoryLabelPosition(), 'nextTo'); } + /** * Testing valueLabelPosition getter and setter */ - public function testSetGetValueLabelPosition() { + public function testSetGetValueLabelPosition() + { $chart = new Chart(); - $this->assertEquals($chart->getValueLabelPosition(), "none"); - - $chart->setValueLabelPosition("low"); + $this->assertEquals($chart->getValueLabelPosition(), 'none'); - $this->assertEquals($chart->getValueLabelPosition(), "low"); + $chart->setValueLabelPosition('low'); + $this->assertEquals($chart->getValueLabelPosition(), 'low'); } /** * Testing categoryAxisTitle getter and setter */ - public function testSetGetCategoryAxisTitle() { + public function testSetGetCategoryAxisTitle() + { $chart = new Chart(); $chart->getCategoryAxisTitle(); - $this->assertEquals($chart->getCategoryAxisTitle(), NULL); + $this->assertEquals($chart->getCategoryAxisTitle(), null); - $chart->setCategoryAxisTitle("Test Category Axis Title"); + $chart->setCategoryAxisTitle('Test Category Axis Title'); - $this->assertEquals($chart->getCategoryAxisTitle(), "Test Category Axis Title"); + $this->assertEquals($chart->getCategoryAxisTitle(), 'Test Category Axis Title'); } /** * Testing valueAxisTitle getter and setter */ - public function testSetGetValueAxisTitle() { + public function testSetGetValueAxisTitle() + { $chart = new Chart(); $chart->getValueAxisTitle(); - $this->assertEquals($chart->getValueAxisTitle(), NULL); + $this->assertEquals($chart->getValueAxisTitle(), null); - $chart->setValueAxisTitle("Test Value Axis Title"); + $chart->setValueAxisTitle('Test Value Axis Title'); - $this->assertEquals($chart->getValueAxisTitle(), "Test Value Axis Title"); + $this->assertEquals($chart->getValueAxisTitle(), 'Test Value Axis Title'); } } From cc450e53e83b8509ba1dccb2bbb5a69ea5b700a6 Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 4 Apr 2018 14:11:10 -0600 Subject: [PATCH 63/68] fix comments to match the code --- src/PhpWord/Style/Chart.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 971f8af19f..19d5f63522 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -244,7 +244,7 @@ public function getCategoryLabelPosition() * "low" - labels on the left side of the graph * "high" - labels on the right side of the graph * - * @param mixed $label_position + * @param mixed $labelPosition * @return string */ public function setCategoryLabelPosition($labelPosition) @@ -273,7 +273,7 @@ public function getValueLabelPosition() * "high" - sets labels above the graph * * @param string - * @param mixed $label_position + * @param mixed $labelPosition */ public function setValueLabelPosition($labelPosition) { @@ -294,7 +294,7 @@ public function getCategoryAxisTitle() /** * Set the title that appears on the category side of the chart - * @param string $axis_title + * @param string $axisTitle */ public function setCategoryAxisTitle($axisTitle) { @@ -314,7 +314,7 @@ public function getValueAxisTitle() /** * Set the title that appears on the value side of the chart - * @param string $axis_title + * @param string $axisTitle */ public function setValueAxisTitle($axisTitle) { From 9a7cf4b9ae44f9cd571f2de7896a15e642cd141a Mon Sep 17 00:00:00 2001 From: Jake Salgado Date: Wed, 4 Apr 2018 14:22:03 -0600 Subject: [PATCH 64/68] fix comments to match the code... again --- src/PhpWord/Element/Chart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Element/Chart.php b/src/PhpWord/Element/Chart.php index d651c80be3..92152c877d 100644 --- a/src/PhpWord/Element/Chart.php +++ b/src/PhpWord/Element/Chart.php @@ -61,12 +61,12 @@ class Chart extends AbstractElement * @param array $categories * @param array $values * @param array $style - * @param null|mixed $series_name + * @param null|mixed $seriesName */ public function __construct($type, $categories, $values, $style = null, $seriesName = null) { $this->setType($type); - $this->addSeries($categories, $values, $seriesN ame); + $this->addSeries($categories, $values, $seriesName); $this->style = $this->setNewStyle(new ChartStyle(), $style, true); } From 2c337b1ab0616bfde77bad0e8df121f09a3e1922 Mon Sep 17 00:00:00 2001 From: troosan Date: Thu, 19 Apr 2018 06:51:19 +0200 Subject: [PATCH 65/68] scrutinizer fixes --- src/PhpWord/Style/Chart.php | 2 +- src/PhpWord/Writer/Word2007/Part/Chart.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 01f40089ed..5b02e63631 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -310,7 +310,7 @@ public function getCategoryLabelPosition() * "high" - labels on the right side of the graph * * @param mixed $labelPosition - * @return string + * @return self */ public function setCategoryLabelPosition($labelPosition) { diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index bd43981299..3759aaed1d 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -406,11 +406,11 @@ private function writeAxisTitle(XMLWriter $xmlWriter, $title) $xmlWriter->startElement('c:title'); //start c:title $xmlWriter->startElement('c:tx'); //start c:tx $xmlWriter->startElement('c:rich'); // start c:rich - $xmlWriter->writeElementBlock('a:bodyPr'); - $xmlWriter->writeElementBlock('a:lstStyle'); + $xmlWriter->writeElement('a:bodyPr'); + $xmlWriter->writeElement('a:lstStyle'); $xmlWriter->startElement('a:p'); $xmlWriter->startElement('a:pPr'); - $xmlWriter->writeElementBlock('a:defRPr'); + $xmlWriter->writeElement('a:defRPr'); $xmlWriter->endElement(); // end a:pPr $xmlWriter->startElement('a:r'); $xmlWriter->writeElementBlock('a:rPr', 'lang', 'en-US'); From baab3c9ce109997f0577da3a2e41014025705e91 Mon Sep 17 00:00:00 2001 From: troosan Date: Thu, 19 Apr 2018 17:26:20 +0200 Subject: [PATCH 66/68] update changelog --- CHANGELOG.md | 1 + samples/Sample_32_Chart.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dcefac29b..7f2b381867 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ v0.15.0 (?? ??? 2018) - Added support for Image text wrapping distance @troosan #1310 - Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316 - Added the ability to enable gridlines and axislabels on charts @FrankMeyer #576 +- Several improvements to charts @JAEK-S #1332 ### Fixed - Fix reading of docx default style - @troosan #1238 diff --git a/samples/Sample_32_Chart.php b/samples/Sample_32_Chart.php index 87d6f3e38f..5ada68d7bb 100644 --- a/samples/Sample_32_Chart.php +++ b/samples/Sample_32_Chart.php @@ -16,8 +16,8 @@ $section->addTitle('2D charts', 1); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); -$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar'); -$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar'); +$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column'); +$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column'); $threeSeries = array('bar', 'line'); $categories = array('A', 'B', 'C', 'D', 'E'); $series1 = array(1, 3, 2, 5, 4); From d7118a04e1f634ec6802dfc36d4972a12f4e6945 Mon Sep 17 00:00:00 2001 From: troosan Date: Thu, 19 Apr 2018 17:30:18 +0200 Subject: [PATCH 67/68] restore radar --- samples/Sample_32_Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Sample_32_Chart.php b/samples/Sample_32_Chart.php index 5ada68d7bb..c24a6f8e37 100644 --- a/samples/Sample_32_Chart.php +++ b/samples/Sample_32_Chart.php @@ -16,7 +16,7 @@ $section->addTitle('2D charts', 1); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); -$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column'); +$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column'); $twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column'); $threeSeries = array('bar', 'line'); $categories = array('A', 'B', 'C', 'D', 'E'); From 41cbc5e6d9d149a5658a58274eabeb0852e2f745 Mon Sep 17 00:00:00 2001 From: troosan Date: Wed, 25 Apr 2018 22:30:44 +0200 Subject: [PATCH 68/68] fix radar chart --- src/PhpWord/Writer/Word2007/Part/Chart.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 3759aaed1d..17c1fd54ac 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -346,17 +346,6 @@ private function writeAxis(XMLWriter $xmlWriter, $type) $xmlWriter->writeElementBlock('c:delete', 'val', 0); $xmlWriter->writeElementBlock('c:majorTickMark', 'val', $style->getMajorTickPosition()); $xmlWriter->writeElementBlock('c:minorTickMark', 'val', 'none'); - - if ($axisType == 'c:catAx') { - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getCategoryLabelPosition()); - } else { - $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getValueLabelPosition()); - } - - $xmlWriter->writeElementBlock('c:crosses', 'val', 'autoZero'); - } - - if (isset($this->options['radar'])) { if ($style->showAxisLabels()) { if ($axisType == 'c:catAx') { $xmlWriter->writeElementBlock('c:tickLblPos', 'val', $style->getCategoryLabelPosition());