Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/PHPOffice/PHPWord into d…
Browse files Browse the repository at this point in the history
…evelop_upstream
  • Loading branch information
troosan committed May 27, 2018
2 parents 0c9626c + c5d0f71 commit e02c5f7
Show file tree
Hide file tree
Showing 11 changed files with 539 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ v0.15.0 (?? ??? 2018)
- Added the ability to enable gridlines and axislabels on charts @FrankMeyer #576
- Add support for table indent (tblInd) @Trainmaster #1343
- Added parsing of internal links in HTML reader @lalop #1336
- Several improvements to charts @JAEK-S #1332

### Fixed
- Fix reading of docx default style - @troosan #1238
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword)
[![Build Status](https://travis-ci.org/PHPOffice/PHPWord.svg?branch=master)](https://travis-ci.org/PHPOffice/PHPWord)
[![Code Quality](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/badges/quality-score.png?s=b5997ce59ac2816b4514f3a38de9900f6d492c1d)](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/)
[![Code Coverage](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/badges/coverage.png?s=742a98745725c562955440edc8d2c39d7ff5ae25)](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/)
[![Coverage Status](https://coveralls.io/repos/github/PHPOffice/PHPWord/badge.svg?branch=develop)](https://coveralls.io/github/PHPOffice/PHPWord?branch=develop)
[![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword)
[![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword)
[![Join the chat at https://gitter.im/PHPOffice/PHPWord](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/PHPOffice/PHPWord)
Expand Down
2 changes: 1 addition & 1 deletion samples/Sample_07_TemplateCloneRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
echo date('H:i:s'), ' Saving the result document...', EOL;
$templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx');

echo getEndingNotes(array('Word2007' => 'docx'));
echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_07_TemplateCloneRow.docx');
if (!CLI) {
include_once 'Sample_Footer.php';
}
2 changes: 1 addition & 1 deletion samples/Sample_23_TemplateBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
echo date('H:i:s'), ' Saving the result document...', EOL;
$templateProcessor->saveAs('results/Sample_23_TemplateBlock.docx');

echo getEndingNotes(array('Word2007' => 'docx'));
echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_23_TemplateBlock.docx');
if (!CLI) {
include_once 'Sample_Footer.php';
}
4 changes: 2 additions & 2 deletions samples/Sample_32_Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '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');
$series1 = array(1, 3, 2, 5, 4);
Expand Down
16 changes: 11 additions & 5 deletions src/PhpWord/Element/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ class Chart extends AbstractElement
* @param array $categories
* @param array $values
* @param array $style
* @param null|mixed $seriesName
*/
public function __construct($type, $categories, $values, $style = null)
public function __construct($type, $categories, $values, $style = null, $seriesName = null)
{
$this->setType($type);
$this->addSeries($categories, $values);
$this->addSeries($categories, $values, $seriesName);
$this->style = $this->setNewStyle(new ChartStyle(), $style, true);
}

Expand All @@ -86,7 +87,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', 'percent_stacked_bar', 'column', 'stacked_column', 'percent_stacked_column', 'area', 'radar', 'scatter');
$this->type = $this->setEnumVal($value, $enum, 'pie');
}

Expand All @@ -95,10 +96,15 @@ public function setType($value)
*
* @param array $categories
* @param array $values
* @param null|mixed $name
*/
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,
);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ private function findPossibleAttribute(XMLReader $xmlReader, \DOMElement $node,
return $possibleAttribute;
}
}

return null;
}

return $attributes;
Expand Down
4 changes: 3 additions & 1 deletion src/PhpWord/Reader/Word2007/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ protected function setDocumentProtection(XMLReader $xmlReader, PhpWord $phpWord,
$documentProtection = $phpWord->getSettings()->getDocumentProtection();

$edit = $xmlReader->getAttribute('w:edit', $node);
$documentProtection->setEditing($edit);
if ($edit !== null) {
$documentProtection->setEditing($edit);
}
}

/**
Expand Down
212 changes: 212 additions & 0 deletions src/PhpWord/Style/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,60 @@ class Chart extends AbstractStyle
private $is3d = false;

/**
* A list of colors to use in the chart
*
* @var array
*/
private $colors = array();

/**
* A list of display options for data labels
*
* @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,
);

/**
* A string that tells the writer where to write chart labels or to skip
* "nextTo" - sets labels next to the axis (bar graphs on the left) (default)
* "low" - labels on the left side of the graph
* "high" - labels on the right side of the graph
*
* @var string
*/
private $categoryLabelPosition = 'nextTo';

/**
* A string that tells the writer where to write chart labels or to skip
* "nextTo" - sets labels next to the axis (bar graphs on the bottom) (default)
* "low" - labels are below the graph
* "high" - labels above the graph
*
* @var string
*/
private $valueLabelPosition = 'nextTo';

/**
* @var string
*/
private $categoryAxisTitle;

/**
* @var string
*/
private $valueAxisTitle;

private $majorTickMarkPos = 'none';

/*
* Show labels for axis
*
* @var bool
Expand Down Expand Up @@ -146,6 +200,28 @@ public function set3d($value = true)
}

/**
* Get the list of colors to use in a chart.
*
* @return array
*/
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 = array())
{
$this->colors = $value;

return $this;
}

/*
* Show labels for axis
*
* @return bool
Expand All @@ -169,6 +245,31 @@ public function setShowAxisLabels($value = true)
}

/**
* 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]);
}
}
}

/*
* Show Gridlines for Y-Axis
*
* @return bool
Expand All @@ -192,6 +293,117 @@ public function setShowGridY($value = true)
}

/**
* Get the categoryLabelPosition setting
*
* @return string
*/
public function getCategoryLabelPosition()
{
return $this->categoryLabelPosition;
}

/**
* 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
* "high" - labels on the right side of the graph
*
* @param mixed $labelPosition
* @return self
*/
public function setCategoryLabelPosition($labelPosition)
{
$enum = array('nextTo', 'low', 'high');
$this->categoryLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->categoryLabelPosition);

return $this;
}

/**
* Get the valueAxisLabelPosition setting
*
* @return string
*/
public function getValueLabelPosition()
{
return $this->valueLabelPosition;
}

/**
* 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
*
* @param string
* @param mixed $labelPosition
*/
public function setValueLabelPosition($labelPosition)
{
$enum = array('nextTo', 'low', 'high');
$this->valueLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->valueLabelPosition);

return $this;
}

/**
* Get the categoryAxisTitle
* @return string
*/
public function getCategoryAxisTitle()
{
return $this->categoryAxisTitle;
}

/**
* Set the title that appears on the category side of the chart
* @param string $axisTitle
*/
public function setCategoryAxisTitle($axisTitle)
{
$this->categoryAxisTitle = $axisTitle;

return $this;
}

/**
* Get the valueAxisTitle
* @return string
*/
public function getValueAxisTitle()
{
return $this->valueAxisTitle;
}

/**
* Set the title that appears on the value side of the chart
* @param string $axisTitle
*/
public function setValueAxisTitle($axisTitle)
{
$this->valueAxisTitle = $axisTitle;

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);
}

/*
* Show Gridlines for X-Axis
*
* @return bool
Expand Down
Loading

0 comments on commit e02c5f7

Please sign in to comment.