Add Chart Axis Option textRotation (#2940)

Fix #2705. Add to Axis class, Reader Xlsx Chart, and Writer Xlsx Chart. Add feature to an existing 32* sample, to an existing 33* sample, and a formal unit test.
This commit is contained in:
oleibman 2022-07-17 06:46:22 -07:00 committed by GitHub
parent 4bf4278a39
commit 051598ecfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 1 deletions

View File

@ -124,6 +124,7 @@ $dataSeriesValues[2]->setScatterLines(false); // points not connected
$xAxis = new Axis();
//$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE );
$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true);
$xAxis->setAxisOption('textRotation', '45');
$yAxis = new Axis();
$yAxis->setLineStyleProperties(

View File

@ -60,6 +60,7 @@ class Axis extends Properties
'axis_labels' => self::AXIS_LABELS_NEXT_TO,
'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO,
'horizontal_crosses_value' => null,
'textRotation' => null,
];
/**
@ -136,7 +137,8 @@ class Axis extends Properties
?string $minimum = null,
?string $maximum = null,
?string $majorUnit = null,
?string $minorUnit = null
?string $minorUnit = null,
?string $textRotation = null
): void {
$this->axisOptions['axis_labels'] = $axisLabels;
$this->setAxisOption('horizontal_crosses_value', $horizontalCrossesValue);
@ -148,6 +150,7 @@ class Axis extends Properties
$this->setAxisOption('maximum', $maximum);
$this->setAxisOption('major_unit', $majorUnit);
$this->setAxisOption('minor_unit', $minorUnit);
$this->setAxisOption('textRotation', $textRotation);
}
/**

View File

@ -1279,5 +1279,15 @@ class Chart
if (isset($chartDetail->minorUnit)) {
$whichAxis->setAxisOption('minor_unit', (string) self::getAttribute($chartDetail->minorUnit, 'val', 'string'));
}
if (isset($chartDetail->txPr)) {
$children = $chartDetail->txPr->children($this->aNamespace);
if (isset($children->bodyPr)) {
/** @var string */
$textRotation = self::getAttribute($children->bodyPr, 'rot', 'string');
if (is_numeric($textRotation)) {
$whichAxis->setAxisOption('textRotation', (string) Properties::xmlToAngle($textRotation));
}
}
}
}
}

View File

@ -573,6 +573,23 @@ class Chart extends WriterPart
$objWriter->endElement();
}
$textRotation = $yAxis->getAxisOptionsProperty('textRotation');
if (is_numeric($textRotation)) {
$objWriter->startElement('c:txPr');
$objWriter->startElement('a:bodyPr');
$objWriter->writeAttribute('rot', Properties::angleToXml((float) $textRotation));
$objWriter->endElement(); // a:bodyPr
$objWriter->startElement('a:lstStyle');
$objWriter->endElement(); // a:lstStyle
$objWriter->startElement('a:p');
$objWriter->startElement('a:pPr');
$objWriter->startElement('a:defRPr');
$objWriter->endElement(); // a:defRPr
$objWriter->endElement(); // a:pPr
$objWriter->endElement(); // a:p
$objWriter->endElement(); // c:txPr
}
$objWriter->startElement('c:spPr');
$this->writeColor($objWriter, $yAxis->getFillColorObject());
$this->writeEffects($objWriter, $yAxis);
@ -748,6 +765,23 @@ class Chart extends WriterPart
$objWriter->endElement();
}
$textRotation = $xAxis->getAxisOptionsProperty('textRotation');
if (is_numeric($textRotation)) {
$objWriter->startElement('c:txPr');
$objWriter->startElement('a:bodyPr');
$objWriter->writeAttribute('rot', Properties::angleToXml((float) $textRotation));
$objWriter->endElement(); // a:bodyPr
$objWriter->startElement('a:lstStyle');
$objWriter->endElement(); // a:lstStyle
$objWriter->startElement('a:p');
$objWriter->startElement('a:pPr');
$objWriter->startElement('a:defRPr');
$objWriter->endElement(); // a:defRPr
$objWriter->endElement(); // a:pPr
$objWriter->endElement(); // a:p
$objWriter->endElement(); // c:txPr
}
$objWriter->startElement('c:spPr');
$this->writeColor($objWriter, $xAxis->getFillColorObject());
$this->writeLineStyles($objWriter, $xAxis);

View File

@ -391,6 +391,9 @@ class Charts32ScatterTest extends AbstractFunctional
$chart = $charts[0];
self::assertNotNull($chart);
$xAxis = $chart->getChartAxisX();
self::assertEquals(45, $xAxis->getAxisOptionsProperty('textRotation'));
$plotArea = $chart->getPlotArea();
self::assertNotNull($plotArea);
$plotSeries = $plotArea->getPlotGroup();