Use line width for data series when rendering Xlsx

Closes #329
This commit is contained in:
Michael Bollman 2018-01-09 16:12:38 -07:00 committed by Adrien Crivelli
parent 257c3eca58
commit 4e0344c3af
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
5 changed files with 61 additions and 8 deletions

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Support cell comments in HTML writer and reader - [#308](https://github.com/PHPOffice/PhpSpreadsheet/issues/308) - Support cell comments in HTML writer and reader - [#308](https://github.com/PHPOffice/PhpSpreadsheet/issues/308)
- Option to stop at a conditional styling, if it matches (only XLSX format) - [#292](https://github.com/PHPOffice/PhpSpreadsheet/pull/292) - Option to stop at a conditional styling, if it matches (only XLSX format) - [#292](https://github.com/PHPOffice/PhpSpreadsheet/pull/292)
- Support for line width for data series when rendering Xlsx - [#329](https://github.com/PHPOffice/PhpSpreadsheet/pull/329)
### Fixed ### Fixed

View File

@ -15,12 +15,12 @@ $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
['', 2010, 2011, 2012], ['', 2010, 2011, 2012],
['Q1', 12, 15, 21], ['Q1', 12, 15, 21],
['Q2', 56, 73, 86], ['Q2', 56, 73, 86],
['Q3', 52, 61, 69], ['Q3', 52, 61, 69],
['Q4', 30, 32, 0], ['Q4', 30, 32, 0],
] ]
); );
// Set the Labels for each data series we want to plot // Set the Labels for each data series we want to plot
@ -57,6 +57,7 @@ $dataSeriesValues = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4),
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4),
]; ];
$dataSeriesValues[2]->setLineWidth(60000);
// Build the dataseries // Build the dataseries
$series = new DataSeries( $series = new DataSeries(

View File

@ -66,6 +66,13 @@ class DataSeriesValues
*/ */
private $fillColor; private $fillColor;
/**
* Line Width.
*
* @var int
*/
private $lineWidth = 12700;
/** /**
* Create a new DataSeriesValues object. * Create a new DataSeriesValues object.
* *
@ -231,6 +238,31 @@ class DataSeriesValues
return $this; return $this;
} }
/**
* Get line width for series.
*
* @return int
*/
public function getLineWidth()
{
return $this->lineWidth;
}
/**
* Set line width for the series.
*
* @param int $width
*
* @return DataSeriesValues
*/
public function setLineWidth($width)
{
$minWidth = 12700;
$this->lineWidth = max($minWidth, $width);
return $this;
}
/** /**
* Identify if the Data Series is a multi-level or a simple series. * Identify if the Data Series is a multi-level or a simple series.
* *

View File

@ -1127,11 +1127,19 @@ class Chart extends WriterPart
$objWriter->endElement(); $objWriter->endElement();
} }
// Values
$plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
// Formatting for the points // Formatting for the points
if (($groupType == DataSeries::TYPE_LINECHART) || ($groupType == DataSeries::TYPE_STOCKCHART)) { if (($groupType == DataSeries::TYPE_LINECHART) || ($groupType == DataSeries::TYPE_STOCKCHART)) {
$plotLineWidth = 12700;
if ($plotSeriesValues) {
$plotLineWidth = $plotSeriesValues->getLineWidth();
}
$objWriter->startElement('c:spPr'); $objWriter->startElement('c:spPr');
$objWriter->startElement('a:ln'); $objWriter->startElement('a:ln');
$objWriter->writeAttribute('w', 12700); $objWriter->writeAttribute('w', $plotLineWidth);
if ($groupType == DataSeries::TYPE_STOCKCHART) { if ($groupType == DataSeries::TYPE_STOCKCHART) {
$objWriter->startElement('a:noFill'); $objWriter->startElement('a:noFill');
$objWriter->endElement(); $objWriter->endElement();
@ -1140,7 +1148,6 @@ class Chart extends WriterPart
$objWriter->endElement(); $objWriter->endElement();
} }
$plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
if ($plotSeriesValues) { if ($plotSeriesValues) {
$plotSeriesMarker = $plotSeriesValues->getPointMarker(); $plotSeriesMarker = $plotSeriesValues->getPointMarker();
if ($plotSeriesMarker) { if ($plotSeriesMarker) {

View File

@ -47,4 +47,16 @@ class DataSeriesValuesTest extends TestCase
$result = $testInstance->getDataType(); $result = $testInstance->getDataType();
self::assertEquals($dataTypeValue, $result); self::assertEquals($dataTypeValue, $result);
} }
public function testGetLineWidth()
{
$testInstance = new DataSeriesValues();
self::assertEquals(12700, $testInstance->getLineWidth(), 'should have default');
$testInstance->setLineWidth(40000);
self::assertEquals(40000, $testInstance->getLineWidth());
$testInstance->setLineWidth(1);
self::assertEquals(12700, $testInstance->getLineWidth(), 'should enforce minimum width');
}
} }