Merge pull request #1433 from Tom-Magill/develop
Add feature to set Chart Title and Legend visibility
This commit is contained in:
commit
c177c55d07
|
|
@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
v0.16.0 (xx xxx 2018)
|
v0.16.0 (xx xxx 2018)
|
||||||
----------------------
|
----------------------
|
||||||
### Added
|
### Added
|
||||||
|
- Add setting Chart Title and Legend visibility @Tom-Magill #1433
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fix regex in `cloneBlock` function @nicoder #1269
|
- Fix regex in `cloneBlock` function @nicoder #1269
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,14 @@ Available Chart style options:
|
||||||
- ``width``. Width (in EMU).
|
- ``width``. Width (in EMU).
|
||||||
- ``height``. Height (in EMU).
|
- ``height``. Height (in EMU).
|
||||||
- ``3d``. Is 3D; applies to pie, bar, line, area, *true* or *false*.
|
- ``3d``. Is 3D; applies to pie, bar, line, area, *true* or *false*.
|
||||||
|
- ``colors``. A list of colors to use in the chart.
|
||||||
|
- ``title``. The title for the chart.
|
||||||
|
- ``showLegend``. Show legend, *true* or *false*.
|
||||||
|
- ``categoryLabelPosition``. Label position for categories, *nextTo* (default), *low* or *high*.
|
||||||
|
- ``valueLabelPosition``. Label position for values, *nextTo* (default), *low* or *high*.
|
||||||
|
- ``categoryAxisTitle``. The title for the category axis.
|
||||||
|
- ``valueAxisTitle``. The title for the values axis.
|
||||||
|
- ``majorTickMarkPos``. The position for major tick marks, *in*, *out*, *cross*, *none* (default).
|
||||||
- ``showAxisLabels``. Show labels for axis, *true* or *false*.
|
- ``showAxisLabels``. Show labels for axis, *true* or *false*.
|
||||||
- ``gridX``. Show Gridlines for X-Axis, *true* or *false*.
|
- ``gridX``. Show Gridlines for X-Axis, *true* or *false*.
|
||||||
- ``gridY``. Show Gridlines for Y-Axis, *true* or *false*.
|
- ``gridY``. Show Gridlines for Y-Axis, *true* or *false*.
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,20 @@ class Chart extends AbstractStyle
|
||||||
*/
|
*/
|
||||||
private $colors = array();
|
private $colors = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chart title
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $title = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chart legend visibility
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $showLegend = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of display options for data labels
|
* A list of display options for data labels
|
||||||
*
|
*
|
||||||
|
|
@ -97,9 +111,15 @@ class Chart extends AbstractStyle
|
||||||
*/
|
*/
|
||||||
private $valueAxisTitle;
|
private $valueAxisTitle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The position for major tick marks
|
||||||
|
* Possible values are 'in', 'out', 'cross', 'none'
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
private $majorTickMarkPos = 'none';
|
private $majorTickMarkPos = 'none';
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Show labels for axis
|
* Show labels for axis
|
||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
|
|
@ -221,6 +241,50 @@ class Chart extends AbstractStyle
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the chart title
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the chart title
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setTitle($value = null)
|
||||||
|
{
|
||||||
|
$this->title = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get chart legend visibility
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isShowLegend()
|
||||||
|
{
|
||||||
|
return $this->showLegend;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set chart legend visibility
|
||||||
|
*
|
||||||
|
* @param bool $value
|
||||||
|
*/
|
||||||
|
public function setShowLegend($value = false)
|
||||||
|
{
|
||||||
|
$this->showLegend = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Show labels for axis
|
* Show labels for axis
|
||||||
*
|
*
|
||||||
|
|
@ -394,8 +458,8 @@ class Chart extends AbstractStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the position for major tick marks
|
* Set the position for major tick marks
|
||||||
* @param string $position [description]
|
* @param string $position
|
||||||
*/
|
*/
|
||||||
public function setMajorTickPosition($position)
|
public function setMajorTickPosition($position)
|
||||||
{
|
{
|
||||||
|
|
@ -403,7 +467,7 @@ class Chart extends AbstractStyle
|
||||||
$this->majorTickMarkPos = $this->setEnumVal($position, $enum, $this->majorTickMarkPos);
|
$this->majorTickMarkPos = $this->setEnumVal($position, $enum, $this->majorTickMarkPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Show Gridlines for X-Axis
|
* Show Gridlines for X-Axis
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,6 @@ class Chart extends AbstractPart
|
||||||
{
|
{
|
||||||
$xmlWriter->startElement('c:chart');
|
$xmlWriter->startElement('c:chart');
|
||||||
|
|
||||||
$xmlWriter->writeElementBlock('c:autoTitleDeleted', 'val', 1);
|
|
||||||
|
|
||||||
$this->writePlotArea($xmlWriter);
|
$this->writePlotArea($xmlWriter);
|
||||||
|
|
||||||
$xmlWriter->endElement(); // c:chart
|
$xmlWriter->endElement(); // c:chart
|
||||||
|
|
@ -131,6 +129,34 @@ class Chart extends AbstractPart
|
||||||
$style = $this->element->getStyle();
|
$style = $this->element->getStyle();
|
||||||
$this->options = $this->types[$type];
|
$this->options = $this->types[$type];
|
||||||
|
|
||||||
|
$title = $style->getTitle();
|
||||||
|
$showLegend = $style->isShowLegend();
|
||||||
|
|
||||||
|
//Chart title
|
||||||
|
if ($title) {
|
||||||
|
$xmlWriter->startElement('c:title');
|
||||||
|
$xmlWriter->startElement('c:tx');
|
||||||
|
$xmlWriter->startElement('c:rich');
|
||||||
|
$xmlWriter->writeRaw('
|
||||||
|
<a:bodyPr/>
|
||||||
|
<a:lstStyle/>
|
||||||
|
<a:p>
|
||||||
|
<a:pPr>
|
||||||
|
<a:defRPr/></a:pPr><a:r><a:rPr/><a:t>' . $title . '</a:t></a:r>
|
||||||
|
<a:endParaRPr/>
|
||||||
|
</a:p>');
|
||||||
|
$xmlWriter->endElement(); // c:rich
|
||||||
|
$xmlWriter->endElement(); // c:tx
|
||||||
|
$xmlWriter->endElement(); // c:title
|
||||||
|
} else {
|
||||||
|
$xmlWriter->writeElementBlock('c:autoTitleDeleted', 'val', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Chart legend
|
||||||
|
if ($showLegend) {
|
||||||
|
$xmlWriter->writeRaw('<c:legend><c:legendPos val="r"/></c:legend>');
|
||||||
|
}
|
||||||
|
|
||||||
$xmlWriter->startElement('c:plotArea');
|
$xmlWriter->startElement('c:plotArea');
|
||||||
$xmlWriter->writeElement('c:layout');
|
$xmlWriter->writeElement('c:layout');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue