Skip to content

Commit dbab636

Browse files
mdbollmanFrederic Delaunay
authored and
Frederic Delaunay
committed
Use line width for data series when rendering Xlsx
Closes PHPOffice#329
1 parent 3191fca commit dbab636

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Support cell comments in HTML writer and reader - [#308](https://github.com/PHPOffice/PhpSpreadsheet/issues/308)
1313
- Option to stop at a conditional styling, if it matches (only XLSX format) - [#292](https://github.com/PHPOffice/PhpSpreadsheet/pull/292)
14+
- Support for line width for data series when rendering Xlsx - [#329](https://github.com/PHPOffice/PhpSpreadsheet/pull/329)
1415

1516
### Fixed
1617

samples/Chart/33_Chart_create_line.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
$worksheet = $spreadsheet->getActiveSheet();
1616
$worksheet->fromArray(
1717
[
18-
['', 2010, 2011, 2012],
19-
['Q1', 12, 15, 21],
20-
['Q2', 56, 73, 86],
21-
['Q3', 52, 61, 69],
22-
['Q4', 30, 32, 0],
23-
]
18+
['', 2010, 2011, 2012],
19+
['Q1', 12, 15, 21],
20+
['Q2', 56, 73, 86],
21+
['Q3', 52, 61, 69],
22+
['Q4', 30, 32, 0],
23+
]
2424
);
2525

2626
// Set the Labels for each data series we want to plot
@@ -57,6 +57,7 @@
5757
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4),
5858
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4),
5959
];
60+
$dataSeriesValues[2]->setLineWidth(60000);
6061

6162
// Build the dataseries
6263
$series = new DataSeries(

src/PhpSpreadsheet/Chart/DataSeriesValues.php

+32
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class DataSeriesValues
6666
*/
6767
private $fillColor;
6868

69+
/**
70+
* Line Width.
71+
*
72+
* @var int
73+
*/
74+
private $lineWidth = 12700;
75+
6976
/**
7077
* Create a new DataSeriesValues object.
7178
*
@@ -231,6 +238,31 @@ public function setFillColor($color)
231238
return $this;
232239
}
233240

241+
/**
242+
* Get line width for series.
243+
*
244+
* @return int
245+
*/
246+
public function getLineWidth()
247+
{
248+
return $this->lineWidth;
249+
}
250+
251+
/**
252+
* Set line width for the series.
253+
*
254+
* @param int $width
255+
*
256+
* @return DataSeriesValues
257+
*/
258+
public function setLineWidth($width)
259+
{
260+
$minWidth = 12700;
261+
$this->lineWidth = max($minWidth, $width);
262+
263+
return $this;
264+
}
265+
234266
/**
235267
* Identify if the Data Series is a multi-level or a simple series.
236268
*

src/PhpSpreadsheet/Writer/Xlsx/Chart.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -1127,11 +1127,19 @@ private function writePlotGroup($plotGroup, $groupType, $objWriter, &$catIsMulti
11271127
$objWriter->endElement();
11281128
}
11291129

1130+
// Values
1131+
$plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
1132+
11301133
// Formatting for the points
11311134
if (($groupType == DataSeries::TYPE_LINECHART) || ($groupType == DataSeries::TYPE_STOCKCHART)) {
1135+
$plotLineWidth = 12700;
1136+
if ($plotSeriesValues) {
1137+
$plotLineWidth = $plotSeriesValues->getLineWidth();
1138+
}
1139+
11321140
$objWriter->startElement('c:spPr');
11331141
$objWriter->startElement('a:ln');
1134-
$objWriter->writeAttribute('w', 12700);
1142+
$objWriter->writeAttribute('w', $plotLineWidth);
11351143
if ($groupType == DataSeries::TYPE_STOCKCHART) {
11361144
$objWriter->startElement('a:noFill');
11371145
$objWriter->endElement();
@@ -1140,7 +1148,6 @@ private function writePlotGroup($plotGroup, $groupType, $objWriter, &$catIsMulti
11401148
$objWriter->endElement();
11411149
}
11421150

1143-
$plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
11441151
if ($plotSeriesValues) {
11451152
$plotSeriesMarker = $plotSeriesValues->getPointMarker();
11461153
if ($plotSeriesMarker) {

tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,16 @@ public function testGetDataType()
4747
$result = $testInstance->getDataType();
4848
self::assertEquals($dataTypeValue, $result);
4949
}
50+
51+
public function testGetLineWidth()
52+
{
53+
$testInstance = new DataSeriesValues();
54+
self::assertEquals(12700, $testInstance->getLineWidth(), 'should have default');
55+
56+
$testInstance->setLineWidth(40000);
57+
self::assertEquals(40000, $testInstance->getLineWidth());
58+
59+
$testInstance->setLineWidth(1);
60+
self::assertEquals(12700, $testInstance->getLineWidth(), 'should enforce minimum width');
61+
}
5062
}

0 commit comments

Comments
 (0)