Skip to content

Commit

Permalink
#171 : PowerPoint2007 : Interval Unit in Axis-X
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Jul 29, 2021
1 parent f8c8206 commit 9ab6c58
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 13 deletions.
3 changes: 3 additions & 0 deletions docs/changes/1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
- Support for defining ticks label position for Axis in Chart - @Web-Mobiledev GH-591 & @Progi1986 GH-660
- ODPresentation Writer
- PowerPoint2007 Writer
- Support for interval unit for Chart's Axis - @Progi1984 GH-546
- ODPresentation Writer
- PowerPoint2007 Writer

## Project Management
- Migrated from Travis CI to Github Actions - @Progi1984 GH-635
Expand Down
27 changes: 18 additions & 9 deletions samples/Sample_05_Chart_Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,22 @@

// Generate sample data for chart
echo date('H:i:s') . ' Generate sample data for chart' . EOL;
$seriesData = [
'Monday' => 12,
'Tuesday' => 15,
'Wednesday' => 13,
'Thursday' => 17,
'Friday' => 14,
'Saturday' => 9,
'Sunday' => 7,
];
$seriesData = array(
'Monday 01' => 12,
'Tuesday 02' => 15,
'Wednesday 03' => 13,
'Thursday 04' => 17,
'Friday 05' => 14,
'Saturday 06' => 9,
'Sunday 07' => 7,
'Monday 08' => 8,
'Tuesday 09' => 8,
'Wednesday 10' => 15,
'Thursday 11' => 16,
'Friday 12' => 14,
'Saturday 13' => 14,
'Sunday 14' => 13,
);

// Create templated slide
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
Expand Down Expand Up @@ -71,6 +78,8 @@
$shape->getView3D()->setPerspective(30);
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getLegend()->getFont()->setItalic(true);
$shape->getPlotArea()->getAxisX()->setMajorUnit(3);
$shape->getPlotArea()->getAxisY()->setMajorUnit(5);

// Create templated slide
echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
Expand Down
2 changes: 2 additions & 0 deletions src/PhpPresentation/Writer/ODPresentation/ObjectsChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ private function writeAxisMainStyle(Chart\Axis $axis, string $styleName, bool $i
$this->xmlContent->writeAttributeIf($isPieChart, 'chart:reverse-direction', 'true');
$this->xmlContent->writeAttributeIf(null !== $axis->getMinBounds(), 'chart:minimum', $axis->getMinBounds());
$this->xmlContent->writeAttributeIf(null !== $axis->getMaxBounds(), 'chart:maximum', $axis->getMaxBounds());
$this->xmlContent->writeAttributeIf(null !== $axis->getMajorUnit(), 'chart:interval-major', $axis->getMajorUnit());
$this->xmlContent->writeAttributeIf(null !== $axis->getMinorUnit(), 'chart:interval-minor-divisor', $axis->getMinorUnit());
switch ($axis->getTickLabelPosition()) {
case Axis::TICK_LABEL_POSITION_NEXT_TO:
$this->xmlContent->writeAttribute('chart:axis-label-position', 'near-axis');
Expand Down
7 changes: 7 additions & 0 deletions src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,13 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, string $ty
$objWriter->startElement('c:lblOffset');
$objWriter->writeAttribute('val', '100');
$objWriter->endElement();

// c:majorUnit
if ($oAxis->getMajorUnit() != null) {
$objWriter->startElement('c:tickLblSkip');
$objWriter->writeAttribute('val', $oAxis->getMajorUnit());
$objWriter->endElement();
}
}

if (Chart\Axis::AXIS_Y == $typeAxis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,59 @@ public function testTypeAxisBounds(): void
{
$value = mt_rand(0, 100);

$oSeries = new Series('Downloads', ['A' => '1', 'B' => '2', 'C' => '4', 'D' => '3', 'E' => '2']);
$oSeries->getFill()->setStartColor(new Color('FFAABBCC'));
$series = new Series('Downloads', $this->seriesData);
$line = new Line();
$line->addSeries($series);
$shape = $this->oPresentation->getActiveSlide()->createChartShape();
$shape->getPlotArea()->setType($line);

$element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleAxisX\']/style:chart-properties';

$this->assertZipXmlAttributeNotExists('Object 1/content.xml', $element, 'chart:interval-minor-divisor');
$this->assertZipXmlAttributeNotExists('Object 1/content.xml', $element, 'chart:interval-major');

// chart:title : Element chart failed to validate attributes
$this->assertIsSchemaOpenDocumentNotValid('1.2');

$shape->getPlotArea()->getAxisX()->setMinorUnit($value);
$this->resetPresentationFile();

$this->assertZipXmlAttributeNotExists('Object 1/content.xml', $element, 'chart:interval-major');
$this->assertZipXmlAttributeExists('Object 1/content.xml', $element, 'chart:interval-minor-divisor');
$this->assertZipXmlAttributeEquals('Object 1/content.xml', $element, 'chart:interval-minor-divisor', $value);

// chart:title : Element chart failed to validate attributes
$this->assertIsSchemaOpenDocumentNotValid('1.2');

$shape->getPlotArea()->getAxisX()->setMinorUnit(null);
$shape->getPlotArea()->getAxisX()->setMajorUnit($value);
$this->resetPresentationFile();

$this->assertZipXmlAttributeNotExists('Object 1/content.xml', $element, 'chart:interval-minor-divisor');
$this->assertZipXmlAttributeExists('Object 1/content.xml', $element, 'chart:interval-major');
$this->assertZipXmlAttributeEquals('Object 1/content.xml', $element, 'chart:interval-major', $value);

// chart:title : Element chart failed to validate attributes
$this->assertIsSchemaOpenDocumentNotValid('1.2');

$shape->getPlotArea()->getAxisX()->setMinorUnit($value);
$shape->getPlotArea()->getAxisX()->setMajorUnit($value);
$this->resetPresentationFile();

$this->assertZipXmlAttributeExists('Object 1/content.xml', $element, 'chart:interval-minor-divisor');
$this->assertZipXmlAttributeEquals('Object 1/content.xml', $element, 'chart:interval-minor-divisor', $value);
$this->assertZipXmlAttributeExists('Object 1/content.xml', $element, 'chart:interval-major');
$this->assertZipXmlAttributeEquals('Object 1/content.xml', $element, 'chart:interval-major', $value);

// chart:title : Element chart failed to validate attributes
$this->assertIsSchemaOpenDocumentNotValid('1.2');
}

public function testTypeAxisUnit(): void
{
$value = mt_rand(0, 100);

$oSeries = new Series('Downloads', $this->seriesData);
$oLine = new Line();
$oLine->addSeries($oSeries);
$oShape = $this->oPresentation->getActiveSlide()->createChartShape();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,36 @@ public function testTypeAxisTickMark(): void
$this->assertIsSchemaECMA376Valid();
}

public function testTypeAxisUnit(): void
public function testTypeAxisXUnit(): void
{
$value = mt_rand(0, 100);

$oSeries = new Series('Downloads', $this->seriesData);
$oLine = new Line();
$oLine->addSeries($oSeries);
$oShape = $this->oPresentation->getActiveSlide()->createChartShape();
$oShape->getPlotArea()->setType($oLine);

$elementMax = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:tickLblSkip';

$this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);

$this->assertIsSchemaECMA376Valid();

$oShape->getPlotArea()->getAxisX()->setMajorUnit($value);
$this->resetPresentationFile();

$this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
$this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value);

$this->assertIsSchemaECMA376Valid();
}

public function testTypeAxisYUnit(): void
{
$value = mt_rand(0, 100);

$oSeries = new Series('Downloads', $this->seriesData);
$oSeries->getFill()->setStartColor(new Color('FFAABBCC'));
$oLine = new Line();
$oLine->addSeries($oSeries);
$oShape = $this->oPresentation->getActiveSlide()->createChartShape();
Expand Down

0 comments on commit 9ab6c58

Please sign in to comment.