Skip to content

Commit a58998b

Browse files
committed
#218 : PowerPoint2007 Writer : Support axis unit & axis tick mark in Chart
1 parent c121f2d commit a58998b

File tree

6 files changed

+301
-33
lines changed

6 files changed

+301
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- PowerPoint2007 Writer : Axis Bounds in Chart - @Progi1984 GH-269
2424
- PowerPoint2007 Writer : Implement Legend Key in Series for Chart - @Progi1984 GH-319
2525
- PowerPoint2007 Writer : Support text direction in Alignment for Table - @SeregPie GH-218
26+
- PowerPoint2007 Writer : Support tick mark & unit in Axis for Chart - @Faab GH-218
2627
- Misc : Added two methods for setting Border & Fill in Legend - @Progi1984 GH-265
2728

2829
## 0.7.0 - 2016-09-12

docs/shapes_chart.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,34 @@ For resetting them, you pass null as parameter to these methods.
4848
$oShape->getPlotArea()->getAxisX()->setMinBounds(0);
4949
$oShape->getPlotArea()->getAxisX()->setMaxBounds(200);
5050
51+
For Axis Y, you can define tick mark with `setMinorTickMark` & `setMajorTickMark` methods.
52+
For resetting them, you pass Axis::TICK_MARK_NONE as parameter to these methods.
53+
54+
.. code-block:: php
55+
56+
use \PhpOffice\PhpPresentation\Shape\Chart\Axis;
57+
58+
$oLine = new Line();
59+
60+
$oShape = $oSlide->createChartShape();
61+
$oShape->getPlotArea()->setType($oLine);
62+
$oShape->getPlotArea()->getAxisY()->setMinorTickMark(Axis::TICK_MARK_NONE);
63+
$oShape->getPlotArea()->getAxisY()->setMajorTickMark(Axis::TICK_MARK_INSIDE);
64+
65+
For Axis Y, you can define unit with `setMinorUnit` & `setMajorUnit` methods.
66+
For resetting them, you pass null as parameter to these methods.
67+
68+
.. code-block:: php
69+
70+
use \PhpOffice\PhpPresentation\Shape\Chart\Axis;
71+
72+
$oLine = new Line();
73+
74+
$oShape = $oSlide->createChartShape();
75+
$oShape->getPlotArea()->setType($oLine);
76+
$oShape->getPlotArea()->getAxisY()->setMinorUnit(null);
77+
$oShape->getPlotArea()->getAxisY()->setMajorUnit(0.05);
78+
5179
Title
5280
^^^^^
5381

src/PhpPresentation/Shape/Chart/Axis.php

Lines changed: 109 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class Axis implements ComparableInterface
2828
const AXIS_X = 'x';
2929
const AXIS_Y = 'y';
3030

31+
const TICK_MARK_NONE = 'none';
32+
const TICK_MARK_CROSS = 'cross';
33+
const TICK_MARK_INSIDE = 'in';
34+
const TICK_MARK_OUTSIDE = 'out';
35+
3136
/**
3237
* Title
3338
*
@@ -69,6 +74,26 @@ class Axis implements ComparableInterface
6974
*/
7075
protected $maxBounds;
7176

77+
/**
78+
* @var string
79+
*/
80+
protected $minorTickMark = self::TICK_MARK_NONE;
81+
82+
/**
83+
* @var string
84+
*/
85+
protected $majorTickMark = self::TICK_MARK_NONE;
86+
87+
/**
88+
* @var float
89+
*/
90+
protected $minorUnit;
91+
92+
/**
93+
* @var float
94+
*/
95+
protected $majorUnit;
96+
7297
/**
7398
* Create a new \PhpOffice\PhpPresentation\Shape\Chart\Axis instance
7499
*
@@ -149,6 +174,42 @@ public function setFormatCode($value = '')
149174
return $this;
150175
}
151176

177+
/**
178+
* @return int|null
179+
*/
180+
public function getMinBounds()
181+
{
182+
return $this->minBounds;
183+
}
184+
185+
/**
186+
* @param int|null $minBounds
187+
* @return Axis
188+
*/
189+
public function setMinBounds($minBounds = null)
190+
{
191+
$this->minBounds = is_null($minBounds) ? null : (int)$minBounds;
192+
return $this;
193+
}
194+
195+
/**
196+
* @return int|null
197+
*/
198+
public function getMaxBounds()
199+
{
200+
return $this->maxBounds;
201+
}
202+
203+
/**
204+
* @param int|null $maxBounds
205+
* @return Axis
206+
*/
207+
public function setMaxBounds($maxBounds = null)
208+
{
209+
$this->maxBounds = is_null($maxBounds) ? null : (int)$maxBounds;
210+
return $this;
211+
}
212+
152213
/**
153214
* @return Gridlines
154215
*/
@@ -186,38 +247,74 @@ public function setMinorGridlines(Gridlines $minorGridlines)
186247
}
187248

188249
/**
189-
* @return int|null
250+
* @return string
190251
*/
191-
public function getMinBounds()
252+
public function getMinorTickMark()
192253
{
193-
return $this->minBounds;
254+
return $this->minorTickMark;
194255
}
195256

196257
/**
197-
* @param int|null $minBounds
258+
* @param string $pTickMark
198259
* @return Axis
199260
*/
200-
public function setMinBounds($minBounds = null)
261+
public function setMinorTickMark($pTickMark = self::TICK_MARK_NONE)
201262
{
202-
$this->minBounds = is_null($minBounds) ? null : (int) $minBounds;
263+
$this->minorTickMark = $pTickMark;
203264
return $this;
204265
}
205266

206267
/**
207-
* @return int|null
268+
* @return string
208269
*/
209-
public function getMaxBounds()
270+
public function getMajorTickMark()
210271
{
211-
return $this->maxBounds;
272+
return $this->majorTickMark;
212273
}
213274

214275
/**
215-
* @param int|null $maxBounds
276+
* @param string $pTickMark
216277
* @return Axis
217278
*/
218-
public function setMaxBounds($maxBounds = null)
279+
public function setMajorTickMark($pTickMark = self::TICK_MARK_NONE)
280+
{
281+
$this->majorTickMark = $pTickMark;
282+
return $this;
283+
}
284+
285+
/**
286+
* @return float
287+
*/
288+
public function getMinorUnit()
289+
{
290+
return $this->minorUnit;
291+
}
292+
293+
/**
294+
* @param float $pUnit
295+
* @return Axis
296+
*/
297+
public function setMinorUnit($pUnit = null)
298+
{
299+
$this->minorUnit = $pUnit;
300+
return $this;
301+
}
302+
303+
/**
304+
* @return float
305+
*/
306+
public function getMajorUnit()
307+
{
308+
return $this->majorUnit;
309+
}
310+
311+
/**
312+
* @param float $pUnit
313+
* @return Axis
314+
*/
315+
public function setMajorUnit($pUnit = null)
219316
{
220-
$this->maxBounds = is_null($maxBounds) ? null : (int) $maxBounds;
317+
$this->majorUnit = $pUnit;
221318
return $this;
222319
}
223320

src/PhpPresentation/Writer/PowerPoint2007/PptCharts.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,12 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, $typeAxis,
20242024

20252025
// c:majorTickMark
20262026
$objWriter->startElement('c:majorTickMark');
2027-
$objWriter->writeAttribute('val', 'none');
2027+
$objWriter->writeAttribute('val', $oAxis->getMajorTickMark());
2028+
$objWriter->endElement();
2029+
2030+
// c:minorTickMark
2031+
$objWriter->startElement('c:minorTickMark');
2032+
$objWriter->writeAttribute('val', $oAxis->getMinorTickMark());
20282033
$objWriter->endElement();
20292034

20302035
// c:tickLblPos
@@ -2066,9 +2071,7 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, $typeAxis,
20662071

20672072
// Font - a:solidFill
20682073
$objWriter->startElement('a:solidFill');
2069-
20702074
$this->writeColor($objWriter, $oAxis->getFont()->getColor());
2071-
20722075
$objWriter->endElement();
20732076

20742077
// Font - a:latin
@@ -2147,6 +2150,20 @@ protected function writeAxis(XMLWriter $objWriter, Chart\Axis $oAxis, $typeAxis,
21472150
$objWriter->writeAttribute('val', 'between');
21482151
}
21492152
$objWriter->endElement();
2153+
2154+
// c:majorUnit
2155+
if ($oAxis->getMajorUnit() != null) {
2156+
$objWriter->startElement('c:majorUnit');
2157+
$objWriter->writeAttribute('val', $oAxis->getMajorUnit());
2158+
$objWriter->endElement();
2159+
}
2160+
2161+
// c:minorUnit
2162+
if ($oAxis->getMinorUnit() != null) {
2163+
$objWriter->startElement('c:minorUnit');
2164+
$objWriter->writeAttribute('val', $oAxis->getMinorUnit());
2165+
$objWriter->endElement();
2166+
}
21502167
}
21512168

21522169
$objWriter->endElement();

tests/PhpPresentation/Tests/Shape/Chart/AxisTest.php

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ public function testConstruct()
3737
$this->assertNull($object->getMajorGridlines());
3838
}
3939

40+
public function testBounds()
41+
{
42+
$value = rand(0, 100);
43+
$object = new Axis();
44+
45+
$this->assertNull($object->getMinBounds());
46+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinBounds($value));
47+
$this->assertEquals($value, $object->getMinBounds());
48+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinBounds());
49+
$this->assertNull($object->getMinBounds());
50+
51+
$this->assertNull($object->getMaxBounds());
52+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMaxBounds($value));
53+
$this->assertEquals($value, $object->getMaxBounds());
54+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMaxBounds());
55+
$this->assertNull($object->getMaxBounds());
56+
}
57+
4058
public function testFont()
4159
{
4260
$object = new Axis();
@@ -68,24 +86,6 @@ public function testGridLines()
6886
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Gridlines', $object->getMinorGridlines());
6987
}
7088

71-
public function testBounds()
72-
{
73-
$value = rand(0, 100);
74-
$object = new Axis();
75-
76-
$this->assertNull($object->getMinBounds());
77-
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinBounds($value));
78-
$this->assertEquals($value, $object->getMinBounds());
79-
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinBounds());
80-
$this->assertNull($object->getMinBounds());
81-
82-
$this->assertNull($object->getMaxBounds());
83-
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMaxBounds($value));
84-
$this->assertEquals($value, $object->getMaxBounds());
85-
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMaxBounds());
86-
$this->assertNull($object->getMaxBounds());
87-
}
88-
8989
public function testHashIndex()
9090
{
9191
$object = new Axis();
@@ -103,4 +103,40 @@ public function testTitle()
103103
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setTitle('AAAA'));
104104
$this->assertEquals('AAAA', $object->getTitle());
105105
}
106+
107+
public function testTickMark()
108+
{
109+
$value = Axis::TICK_MARK_INSIDE;
110+
$object = new Axis();
111+
112+
$this->assertEquals(Axis::TICK_MARK_NONE, $object->getMinorTickMark());
113+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinorTickMark($value));
114+
$this->assertEquals($value, $object->getMinorTickMark());
115+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinorTickMark());
116+
$this->assertEquals(Axis::TICK_MARK_NONE, $object->getMinorTickMark());
117+
118+
$this->assertEquals(Axis::TICK_MARK_NONE, $object->getMajorTickMark());
119+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMajorTickMark($value));
120+
$this->assertEquals($value, $object->getMajorTickMark());
121+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMajorTickMark());
122+
$this->assertEquals(Axis::TICK_MARK_NONE, $object->getMajorTickMark());
123+
}
124+
125+
public function testUnit()
126+
{
127+
$value = rand(0, 100);
128+
$object = new Axis();
129+
130+
$this->assertNull($object->getMinorUnit());
131+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinorUnit($value));
132+
$this->assertEquals($value, $object->getMinorUnit());
133+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMinorUnit());
134+
$this->assertNull($object->getMinorUnit());
135+
136+
$this->assertNull($object->getMajorUnit());
137+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMajorUnit($value));
138+
$this->assertEquals($value, $object->getMajorUnit());
139+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Axis', $object->setMajorUnit());
140+
$this->assertNull($object->getMajorUnit());
141+
}
106142
}

0 commit comments

Comments
 (0)