Fix/chart axis titles (#1760)
* use axPos value to determine whether an axis title is mapped to the XaxisLabel or YaxisLabel * update changelog * Fix php-cs-fixer violations Co-authored-by: Darren Maczka <dkm@utk.edu> Co-authored-by: Mark Baker <mark@lange.demon.co.uk>
This commit is contained in:
parent
44248cd04e
commit
c82ff2526c
|
|
@ -32,6 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
|||
|
||||
### Fixed
|
||||
|
||||
- Fix for Xlsx Chart axis titles mapping to correct X or Y axis label when only one is present.
|
||||
- Resolve Google Sheets Xlsx charts issue. Google Sheets uses oneCellAnchor positioning and does not include *Cache values in the exported Xlsx.
|
||||
- Fix For Null Exception on ODS Read of Page Settings. [#1772](https://github.com/PHPOffice/PhpSpreadsheet/issues/1772)
|
||||
- Fix Xlsx reader overriding manually set number format with builtin number format. [PR #1805](https://github.com/PHPOffice/PhpSpreadsheet/pull/1805)
|
||||
- Fix Xlsx reader cell alignment. [PR #1710](https://github.com/PHPOffice/PhpSpreadsheet/pull/1710)
|
||||
|
|
@ -58,7 +60,6 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
|||
|
||||
### Fixed
|
||||
|
||||
- Resolve Google Sheets Xlsx charts issue. Google Sheets uses oneCellAnchor positioning and does not include *Cache values in the exported Xlsx.
|
||||
- Fix for Xls Reader when SST has a bad length [#1592](https://github.com/PHPOffice/PhpSpreadsheet/issues/1592)
|
||||
- Resolve Xlsx loader issue whe hyperlinks don't have a destination
|
||||
- Resolve issues when printer settings resources IDs clash with drawing IDs
|
||||
|
|
|
|||
|
|
@ -91,7 +91,21 @@ class Chart
|
|||
break;
|
||||
case 'valAx':
|
||||
if (isset($chartDetail->title)) {
|
||||
$YaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta);
|
||||
$axisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta);
|
||||
$axPos = self::getAttribute($chartDetail->axPos, 'val', 'string');
|
||||
|
||||
switch ($axPos) {
|
||||
case 't':
|
||||
case 'b':
|
||||
$XaxisLabel = $axisLabel;
|
||||
|
||||
break;
|
||||
case 'r':
|
||||
case 'l':
|
||||
$YaxisLabel = $axisLabel;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
function getTitleText($title)
|
||||
{
|
||||
if (null === $title || null === $title->getCaption()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return implode("\n", array_map(function ($rt) {
|
||||
return $rt->getPlainText();
|
||||
}, $title->getCaption()));
|
||||
}
|
||||
|
||||
class ChartsTitleTest extends TestCase
|
||||
{
|
||||
public function testChartTitles(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLSX/excelChartsTest.xlsx';
|
||||
$reader = IOFactory::createReader('Xlsx')->setIncludeCharts(true);
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$worksheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$charts = $worksheet->getChartCollection();
|
||||
self::assertEquals(5, $worksheet->getChartCount());
|
||||
self::assertCount(5, $charts);
|
||||
|
||||
// No title or axis labels
|
||||
$chart1 = $charts[0];
|
||||
$title = getTitleText($chart1->getTitle());
|
||||
self::assertEmpty($title);
|
||||
self::assertEmpty(getTitleText($chart1->getXAxisLabel()));
|
||||
self::assertEmpty(getTitleText($chart1->getYAxisLabel()));
|
||||
|
||||
// Title, no axis labels
|
||||
$chart2 = $charts[1];
|
||||
|
||||
self::assertEquals('Chart with Title and no Axis Labels', getTitleText($chart2->getTitle()));
|
||||
self::assertEmpty(getTitleText($chart2->getXAxisLabel()));
|
||||
self::assertEmpty(getTitleText($chart2->getYAxisLabel()));
|
||||
|
||||
// No title, only horizontal axis label
|
||||
$chart3 = $charts[2];
|
||||
self::assertEmpty(getTitleText($chart3->getTitle()));
|
||||
self::assertEquals('Horizontal Axis Title Only', getTitleText($chart3->getXAxisLabel()));
|
||||
self::assertEmpty(getTitleText($chart3->getYAxisLabel()));
|
||||
|
||||
// No title, only vertical axis label
|
||||
$chart4 = $charts[3];
|
||||
self::assertEmpty(getTitleText($chart4->getTitle()));
|
||||
self::assertEquals('Vertical Axis Title Only', getTitleText($chart4->getYAxisLabel()));
|
||||
self::assertEmpty(getTitleText($chart4->getXAxisLabel()));
|
||||
|
||||
// Title and both axis labels
|
||||
$chart5 = $charts[4];
|
||||
self::assertEquals('Complete Annotations', getTitleText($chart5->getTitle()));
|
||||
self::assertEquals('Horizontal Axis Title', getTitleText($chart5->getXAxisLabel()));
|
||||
self::assertEquals('Vertical Axis Title', getTitleText($chart5->getYAxisLabel()));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue