PptChart 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. <?php
  2. namespace PhpPresentation\Tests\Writer\PowerPoint2007;
  3. use \Exception;
  4. use PhpOffice\Common\Drawing;
  5. use PhpOffice\PhpPresentation\PhpPresentation;
  6. use PhpOffice\PhpPresentation\Shape\Chart\Axis;
  7. use PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
  8. use PhpOffice\PhpPresentation\Shape\Chart\Marker;
  9. use PhpOffice\PhpPresentation\Shape\Chart\Series;
  10. use PhpOffice\PhpPresentation\Shape\Chart\Type\Area;
  11. use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar;
  12. use PhpOffice\PhpPresentation\Shape\Chart\Type\Bar3D;
  13. use PhpOffice\PhpPresentation\Shape\Chart\Type\Line;
  14. use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie;
  15. use PhpOffice\PhpPresentation\Shape\Chart\Type\Pie3D;
  16. use PhpOffice\PhpPresentation\Shape\Chart\Type\Scatter;
  17. use PhpOffice\PhpPresentation\Style\Color;
  18. use PhpOffice\PhpPresentation\Style\Font;
  19. use PhpOffice\PhpPresentation\Style\Fill;
  20. use PhpOffice\PhpPresentation\Style\Outline;
  21. use PhpOffice\PhpPresentation\Tests\PhpPresentationTestCase;
  22. class PptChartsTest extends PhpPresentationTestCase
  23. {
  24. protected $writerName = 'PowerPoint2007';
  25. /**
  26. * @var array
  27. */
  28. protected $seriesData = array(
  29. 'A' => 1,
  30. 'B' => 2,
  31. 'C' => 4,
  32. 'D' => 3,
  33. 'E' => 2,
  34. );
  35. /**
  36. * @expectedException Exception
  37. * @expectedExceptionMessage The chart type provided could not be rendered
  38. */
  39. public function testPlotAreaBadType()
  40. {
  41. $oSlide = $this->oPresentation->getActiveSlide();
  42. $oShape = $oSlide->createChartShape();
  43. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  44. $stub = $this->getMockForAbstractClass('PhpOffice\PhpPresentation\Shape\Chart\Type\AbstractType');
  45. $oShape->getPlotArea()->setType($stub);
  46. $this->writePresentationFile($this->oPresentation, 'PowerPoint2007');
  47. }
  48. public function testTitleVisibilityTrue()
  49. {
  50. $element = '/c:chartSpace/c:chart/c:autoTitleDeleted';
  51. $oSlide = $this->oPresentation->getActiveSlide();
  52. $oShape = $oSlide->createChartShape();
  53. $oLine = new Line();
  54. $oShape->getPlotArea()->setType($oLine);
  55. // Default
  56. $this->assertTrue($oShape->getTitle()->isVisible());
  57. // Set Visible : TRUE
  58. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\Chart\Title', $oShape->getTitle()->setVisible(true));
  59. $this->assertTrue($oShape->getTitle()->isVisible());
  60. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  61. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '0');
  62. }
  63. public function testTitleVisibilityFalse()
  64. {
  65. $element = '/c:chartSpace/c:chart/c:autoTitleDeleted';
  66. $oSlide = $this->oPresentation->getActiveSlide();
  67. $oShape = $oSlide->createChartShape();
  68. $oLine = new Line();
  69. $oShape->getPlotArea()->setType($oLine);
  70. // Set Visible : FALSE
  71. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\Chart\Title', $oShape->getTitle()->setVisible(false));
  72. $this->assertFalse($oShape->getTitle()->isVisible());
  73. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  74. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '1');
  75. }
  76. public function testAxisFont()
  77. {
  78. $oSlide = $this->oPresentation->getActiveSlide();
  79. $oShape = $oSlide->createChartShape();
  80. $oBar = new Bar();
  81. $oSeries = new Series('Downloads', $this->seriesData);
  82. $oBar->addSeries($oSeries);
  83. $oShape->getPlotArea()->setType($oBar);
  84. $oShape->getPlotArea()->getAxisX()->getFont()->getColor()->setRGB('AABBCC');
  85. $oShape->getPlotArea()->getAxisX()->getFont()->setItalic(true);
  86. $oShape->getPlotArea()->getAxisX()->getFont()->setStrikethrough(true);
  87. $oShape->getPlotArea()->getAxisY()->getFont()->getColor()->setRGB('00FF00');
  88. $oShape->getPlotArea()->getAxisY()->getFont()->setSize(16);
  89. $oShape->getPlotArea()->getAxisY()->getFont()->setUnderline(Font::UNDERLINE_DASH);
  90. $pathShape = 'ppt/charts/' . $oShape->getIndexedFilename();
  91. $element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr/a:solidFill/a:srgbClr';
  92. $this->assertZipXmlElementExists($pathShape, $element);
  93. $this->assertZipXmlAttributeEquals($pathShape, $element, 'val', 'AABBCC');
  94. $element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr';
  95. $this->assertZipXmlElementExists($pathShape, $element);
  96. $this->assertZipXmlAttributeEquals($pathShape, $element, 'i', 'true');
  97. $this->assertZipXmlAttributeEquals($pathShape, $element, 'sz', 1000);
  98. $this->assertZipXmlAttributeEquals($pathShape, $element, 'strike', 'sngStrike');
  99. $this->assertZipXmlAttributeEquals($pathShape, $element, 'u', Font::UNDERLINE_NONE);
  100. $element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr/a:solidFill/a:srgbClr';
  101. $this->assertZipXmlElementExists($pathShape, $element);
  102. $this->assertZipXmlAttributeEquals($pathShape, $element, 'val', '00FF00');
  103. $element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:title/c:tx/c:rich/a:p/a:pPr/a:defRPr';
  104. $this->assertZipXmlElementExists($pathShape, $element);
  105. $this->assertZipXmlAttributeEquals($pathShape, $element, 'i', 'false');
  106. $this->assertZipXmlAttributeEquals($pathShape, $element, 'sz', 1600);
  107. $this->assertZipXmlAttributeEquals($pathShape, $element, 'strike', 'noStrike');
  108. $this->assertZipXmlAttributeEquals($pathShape, $element, 'u', Font::UNDERLINE_DASH);
  109. }
  110. public function testAxisOutline()
  111. {
  112. $expectedWidthX = 2;
  113. $expectedColorX = 'ABCDEF';
  114. $expectedWidthY = 4;
  115. $expectedColorY = '012345';
  116. $oSlide = $this->oPresentation->getActiveSlide();
  117. $oShape = $oSlide->createChartShape();
  118. $oBar = new Bar();
  119. $oSeries = new Series('Downloads', $this->seriesData);
  120. $oBar->addSeries($oSeries);
  121. $oShape->getPlotArea()->setType($oBar);
  122. $oShape->getPlotArea()->getAxisX()->getOutline()->setWidth($expectedWidthX);
  123. $oShape->getPlotArea()->getAxisX()->getOutline()->getFill()->setFillType(Fill::FILL_SOLID);
  124. $oShape->getPlotArea()->getAxisX()->getOutline()->getFill()->getStartColor()->setRGB($expectedColorX);
  125. $oShape->getPlotArea()->getAxisY()->getOutline()->setWidth($expectedWidthY);
  126. $oShape->getPlotArea()->getAxisY()->getOutline()->getFill()->setFillType(Fill::FILL_SOLID);
  127. $oShape->getPlotArea()->getAxisY()->getOutline()->getFill()->getStartColor()->setRGB($expectedColorY);
  128. $element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:spPr';
  129. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  130. $element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:spPr/a:ln';
  131. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  132. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'w', Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidthX)));
  133. $element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:spPr/a:ln/a:solidFill/a:srgbClr';
  134. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  135. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $expectedColorX);
  136. $element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:spPr';
  137. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  138. $element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:spPr/a:ln';
  139. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  140. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'w', Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidthY)));
  141. $element = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:spPr/a:ln/a:solidFill/a:srgbClr';
  142. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  143. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $expectedColorY);
  144. }
  145. public function testAxisVisibilityFalse()
  146. {
  147. $element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:delete';
  148. $oSlide = $this->oPresentation->getActiveSlide();
  149. $oShape = $oSlide->createChartShape();
  150. $oLine = new Line();
  151. $oShape->getPlotArea()->setType($oLine);
  152. // Set Visible : FALSE
  153. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\Chart\Axis', $oShape->getPlotArea()->getAxisX()->setIsVisible(false));
  154. $this->assertFalse($oShape->getPlotArea()->getAxisX()->isVisible());
  155. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  156. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '1');
  157. }
  158. public function testAxisVisibilityTrue()
  159. {
  160. $element = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:delete';
  161. $oSlide = $this->oPresentation->getActiveSlide();
  162. $oShape = $oSlide->createChartShape();
  163. $oLine = new Line();
  164. $oShape->getPlotArea()->setType($oLine);
  165. // Set Visible : TRUE
  166. $this->assertInstanceOf('PhpOffice\PhpPresentation\Shape\Chart\Axis', $oShape->getPlotArea()->getAxisX()->setIsVisible(true));
  167. $this->assertTrue($oShape->getPlotArea()->getAxisX()->isVisible());
  168. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  169. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '0');
  170. }
  171. public function testTypeArea()
  172. {
  173. $oSlide = $this->oPresentation->getActiveSlide();
  174. $oShape = $oSlide->createChartShape();
  175. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  176. $oArea = new Area();
  177. $oSeries = new Series('Downloads', $this->seriesData);
  178. $oSeries->getFill()->setStartColor(new Color('FFAABBCC'));
  179. $oArea->addSeries($oSeries);
  180. $oShape->getPlotArea()->setType($oArea);
  181. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
  182. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  183. $element = '/c:chartSpace/c:chart/c:plotArea/c:areaChart';
  184. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  185. $element = '/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser';
  186. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  187. }
  188. public function testTypeAxisBounds()
  189. {
  190. $value = rand(0, 100);
  191. $oSeries = new Series('Downloads', $this->seriesData);
  192. $oSeries->getFill()->setStartColor(new Color('FFAABBCC'));
  193. $oLine = new Line();
  194. $oLine->addSeries($oSeries);
  195. $oShape = $this->oPresentation->getActiveSlide()->createChartShape();
  196. $oShape->getPlotArea()->setType($oLine);
  197. $elementMax = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:scaling/c:max';
  198. $elementMin = '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:scaling/c:min';
  199. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  200. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  201. $oShape->getPlotArea()->getAxisX()->setMinBounds($value);
  202. $this->resetPresentationFile();
  203. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  204. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  205. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', $value);
  206. $oShape->getPlotArea()->getAxisX()->setMinBounds(null);
  207. $oShape->getPlotArea()->getAxisX()->setMaxBounds($value);
  208. $this->resetPresentationFile();
  209. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  210. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  211. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value);
  212. $oShape->getPlotArea()->getAxisX()->setMinBounds($value);
  213. $oShape->getPlotArea()->getAxisX()->setMaxBounds($value);
  214. $this->resetPresentationFile();
  215. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  216. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', $value);
  217. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  218. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value);
  219. }
  220. public function testTypeAxisTickMark()
  221. {
  222. $value = Axis::TICK_MARK_CROSS;
  223. $oSeries = new Series('Downloads', $this->seriesData);
  224. $oSeries->getFill()->setStartColor(new Color('FFAABBCC'));
  225. $oLine = new Line();
  226. $oLine->addSeries($oSeries);
  227. $oShape = $this->oPresentation->getActiveSlide()->createChartShape();
  228. $oShape->getPlotArea()->setType($oLine);
  229. $elementMax = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:majorTickMark';
  230. $elementMin = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:minorTickMark';
  231. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  232. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', Axis::TICK_MARK_NONE);
  233. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  234. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', Axis::TICK_MARK_NONE);
  235. $oShape->getPlotArea()->getAxisY()->setMinorTickMark($value);
  236. $this->resetPresentationFile();
  237. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  238. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', Axis::TICK_MARK_NONE);
  239. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  240. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', $value);
  241. $oShape->getPlotArea()->getAxisY()->setMinorTickMark();
  242. $oShape->getPlotArea()->getAxisY()->setMajorTickMark($value);
  243. $this->resetPresentationFile();
  244. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  245. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', Axis::TICK_MARK_NONE);
  246. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  247. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value);
  248. $oShape->getPlotArea()->getAxisY()->setMinorTickMark($value);
  249. $oShape->getPlotArea()->getAxisY()->setMajorTickMark($value);
  250. $this->resetPresentationFile();
  251. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  252. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', $value);
  253. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  254. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value);
  255. }
  256. public function testTypeAxisUnit()
  257. {
  258. $value = rand(0, 100);
  259. $oSeries = new Series('Downloads', $this->seriesData);
  260. $oSeries->getFill()->setStartColor(new Color('FFAABBCC'));
  261. $oLine = new Line();
  262. $oLine->addSeries($oSeries);
  263. $oShape = $this->oPresentation->getActiveSlide()->createChartShape();
  264. $oShape->getPlotArea()->setType($oLine);
  265. $elementMax = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:majorUnit';
  266. $elementMin = '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:minorUnit';
  267. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  268. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  269. $oShape->getPlotArea()->getAxisY()->setMinorUnit($value);
  270. $this->resetPresentationFile();
  271. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  272. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  273. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', $value);
  274. $oShape->getPlotArea()->getAxisY()->setMinorUnit(null);
  275. $oShape->getPlotArea()->getAxisY()->setMajorUnit($value);
  276. $this->resetPresentationFile();
  277. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  278. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  279. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value);
  280. $oShape->getPlotArea()->getAxisY()->setMinorUnit($value);
  281. $oShape->getPlotArea()->getAxisY()->setMajorUnit($value);
  282. $this->resetPresentationFile();
  283. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin);
  284. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMin, 'val', $value);
  285. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax);
  286. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $elementMax, 'val', $value);
  287. }
  288. public function testTypeBar()
  289. {
  290. $valueGapWidthPercent = rand(0, 500);
  291. $oSlide = $this->oPresentation->getActiveSlide();
  292. $oShape = $oSlide->createChartShape();
  293. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  294. $oBar = new Bar();
  295. $oBar->setGapWidthPercent($valueGapWidthPercent);
  296. $oSeries = new Series('Downloads', $this->seriesData);
  297. $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
  298. $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
  299. $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKGREEN));
  300. $oSeries->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKRED));
  301. $oSeries->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKYELLOW));
  302. $oBar->addSeries($oSeries);
  303. $oShape->getPlotArea()->setType($oBar);
  304. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
  305. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  306. $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart';
  307. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  308. $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser';
  309. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  310. $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dPt/c:spPr';
  311. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  312. $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:tx/c:v';
  313. $this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
  314. $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:gapWidth';
  315. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $valueGapWidthPercent);
  316. }
  317. public function testTypeBar3D()
  318. {
  319. $valueGapWidthPercent = rand(0, 500);
  320. $oSlide = $this->oPresentation->getActiveSlide();
  321. $oShape = $oSlide->createChartShape();
  322. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  323. $oBar3D = new Bar3D();
  324. $oBar3D->setGapWidthPercent($valueGapWidthPercent);
  325. $oSeries = new Series('Downloads', $this->seriesData);
  326. $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
  327. $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
  328. $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKGREEN));
  329. $oSeries->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKRED));
  330. $oSeries->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKYELLOW));
  331. $oBar3D->addSeries($oSeries);
  332. $oShape->getPlotArea()->setType($oBar3D);
  333. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
  334. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  335. $element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart';
  336. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  337. $element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser';
  338. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  339. $element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:dPt/c:spPr';
  340. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  341. $element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:tx/c:v';
  342. $this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
  343. $element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:gapWidth';
  344. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $valueGapWidthPercent);
  345. }
  346. public function testTypeBar3DSubScript()
  347. {
  348. $oSlide = $this->oPresentation->getActiveSlide();
  349. $oShape = $oSlide->createChartShape();
  350. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  351. $oBar3D = new Bar3D();
  352. $oSeries = new Series('Downloads', $this->seriesData);
  353. $oSeries->getFont()->setSubScript(true);
  354. $oBar3D->addSeries($oSeries);
  355. $oShape->getPlotArea()->setType($oBar3D);
  356. $element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/a:defRPr';
  357. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  358. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'baseline', '-25000');
  359. }
  360. public function testTypeBar3DSuperScript()
  361. {
  362. $oSlide = $this->oPresentation->getActiveSlide();
  363. $oShape = $oSlide->createChartShape();
  364. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  365. $oBar3D = new Bar3D();
  366. $oSeries = new Series('Downloads', $this->seriesData);
  367. $oSeries->getFont()->setSuperScript(true);
  368. $oBar3D->addSeries($oSeries);
  369. $oShape->getPlotArea()->setType($oBar3D);
  370. $element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/a:defRPr';
  371. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  372. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'baseline', '30000');
  373. }
  374. public function testTypeBar3DBarDirection()
  375. {
  376. $oSlide = $this->oPresentation->getActiveSlide();
  377. $oShape = $oSlide->createChartShape();
  378. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  379. $oBar3D = new Bar3D();
  380. $oBar3D->setBarDirection(Bar3D::DIRECTION_HORIZONTAL);
  381. $oSeries = new Series('Downloads', $this->seriesData);
  382. $oBar3D->addSeries($oSeries);
  383. $oShape->getPlotArea()->setType($oBar3D);
  384. $element = '/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:barDir';
  385. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  386. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', Bar3D::DIRECTION_HORIZONTAL);
  387. }
  388. public function testTypeLine()
  389. {
  390. $oSlide = $this->oPresentation->getActiveSlide();
  391. $oShape = $oSlide->createChartShape();
  392. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  393. $oLine = new Line();
  394. $oSeries = new Series('Downloads', $this->seriesData);
  395. $oLine->addSeries($oSeries);
  396. $oShape->getPlotArea()->setType($oLine);
  397. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
  398. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  399. $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart';
  400. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  401. $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser';
  402. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  403. $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:tx/c:v';
  404. $this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
  405. }
  406. public function testTypeLineGridlines()
  407. {
  408. $arrayTests = array(
  409. array(
  410. 'methodAxis' => 'getAxisX',
  411. 'methodGrid' => 'setMajorGridlines',
  412. 'expectedElement' => '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:majorGridlines/c:spPr/a:ln',
  413. 'expectedElementColor' => '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:majorGridlines/c:spPr/a:ln/a:solidFill/a:srgbClr',
  414. ),
  415. array(
  416. 'methodAxis' => 'getAxisX',
  417. 'methodGrid' => 'setMinorGridlines',
  418. 'expectedElement' => '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:minorGridlines/c:spPr/a:ln',
  419. 'expectedElementColor' => '/c:chartSpace/c:chart/c:plotArea/c:catAx/c:minorGridlines/c:spPr/a:ln/a:solidFill/a:srgbClr',
  420. ),
  421. array(
  422. 'methodAxis' => 'getAxisY',
  423. 'methodGrid' => 'setMajorGridlines',
  424. 'expectedElement' => '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:majorGridlines/c:spPr/a:ln',
  425. 'expectedElementColor' => '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:majorGridlines/c:spPr/a:ln/a:solidFill/a:srgbClr',
  426. ),
  427. array(
  428. 'methodAxis' => 'getAxisY',
  429. 'methodGrid' => 'setMinorGridlines',
  430. 'expectedElement' => '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:minorGridlines/c:spPr/a:ln',
  431. 'expectedElementColor' => '/c:chartSpace/c:chart/c:plotArea/c:valAx/c:minorGridlines/c:spPr/a:ln/a:solidFill/a:srgbClr',
  432. ),
  433. );
  434. $expectedColor = new Color(Color::COLOR_BLUE);
  435. foreach ($arrayTests as $arrayTest) {
  436. $expectedSizePts = rand(1, 100);
  437. $expectedSizeEmu = round(Drawing::pointsToPixels(Drawing::pixelsToEmu($expectedSizePts)));
  438. $this->oPresentation->removeSlideByIndex()->createSlide();
  439. $oShape = $this->oPresentation->getActiveSlide()->createChartShape();
  440. $oLine = new Line();
  441. $oLine->addSeries(new Series('Downloads', array(
  442. 'A' => 1,
  443. 'B' => 2,
  444. 'C' => 4,
  445. 'D' => 3,
  446. 'E' => 2,
  447. )));
  448. $oShape->getPlotArea()->setType($oLine);
  449. $oGridlines = new Gridlines();
  450. $oGridlines->getOutline()->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor($expectedColor);
  451. $oGridlines->getOutline()->setWidth($expectedSizePts);
  452. $oShape->getPlotArea()->{$arrayTest['methodAxis']}()->{$arrayTest['methodGrid']}($oGridlines);
  453. $this->assertZipFileExists('ppt/charts/' . $oShape->getIndexedFilename());
  454. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $arrayTest['expectedElement']);
  455. $this->assertZipXmlAttributeExists('ppt/charts/' . $oShape->getIndexedFilename(), $arrayTest['expectedElement'], 'w');
  456. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $arrayTest['expectedElement'], 'w', $expectedSizeEmu);
  457. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $arrayTest['expectedElementColor']);
  458. $this->assertZipXmlAttributeExists('ppt/charts/' . $oShape->getIndexedFilename(), $arrayTest['expectedElementColor'], 'val');
  459. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $arrayTest['expectedElementColor'], 'val', $expectedColor->getRGB());
  460. $this->resetPresentationFile();
  461. }
  462. }
  463. public function testTypeLineMarker()
  464. {
  465. do {
  466. $expectedSymbol = array_rand(Marker::$arraySymbol);
  467. } while ($expectedSymbol == Marker::SYMBOL_NONE);
  468. $expectedSize = rand(2, 72);
  469. $expectedEltSymbol = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:marker/c:symbol';
  470. $expectedElementSize = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:marker/c:size';
  471. $oSlide = $this->oPresentation->getActiveSlide();
  472. $oShape = $oSlide->createChartShape();
  473. $oLine = new Line();
  474. $oSeries = new Series('Downloads', $this->seriesData);
  475. $oSeries->getMarker()->setSymbol($expectedSymbol)->setSize($expectedSize);
  476. $oLine->addSeries($oSeries);
  477. $oShape->getPlotArea()->setType($oLine);
  478. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedEltSymbol);
  479. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize);
  480. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $expectedEltSymbol, 'val', $expectedSymbol);
  481. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize, 'val', $expectedSize);
  482. $oSeries->getMarker()->setSize(1);
  483. $oLine->setSeries(array($oSeries));
  484. $this->resetPresentationFile();
  485. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize);
  486. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize, 'val', 2);
  487. $oSeries->getMarker()->setSize(73);
  488. $oLine->setSeries(array($oSeries));
  489. $this->resetPresentationFile();
  490. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize);
  491. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize, 'val', 72);
  492. $oSeries->getMarker()->setSymbol(Marker::SYMBOL_NONE);
  493. $oLine->setSeries(array($oSeries));
  494. $this->resetPresentationFile();
  495. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedEltSymbol);
  496. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize);
  497. }
  498. public function testTypeLineSeriesOutline()
  499. {
  500. $expectedWidth = rand(1, 100);
  501. $expectedWidthEmu = Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidth));
  502. $expectedElement = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:spPr/a:ln';
  503. $oOutline = new Outline();
  504. $oOutline->getFill()->setFillType(Fill::FILL_SOLID);
  505. $oOutline->getFill()->setStartColor(new Color(Color::COLOR_YELLOW));
  506. $oOutline->setWidth($expectedWidth);
  507. $oSlide = $this->oPresentation->getActiveSlide();
  508. $oShape = $oSlide->createChartShape();
  509. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  510. $oLine = new Line();
  511. $oSeries = new Series('Downloads', $this->seriesData);
  512. $oLine->addSeries($oSeries);
  513. $oShape->getPlotArea()->setType($oLine);
  514. $this->assertZipFileExists('ppt/charts/' . $oShape->getIndexedFilename());
  515. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElement);
  516. $oSeries->setOutline($oOutline);
  517. $oLine->setSeries(array($oSeries));
  518. $this->resetPresentationFile();
  519. $this->assertZipFileExists('ppt/charts/' . $oShape->getIndexedFilename());
  520. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElement);
  521. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElement, 'w', $expectedWidthEmu);
  522. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElement . '/a:solidFill');
  523. }
  524. public function testTypeLineSubScript()
  525. {
  526. $oSlide = $this->oPresentation->getActiveSlide();
  527. $oShape = $oSlide->createChartShape();
  528. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  529. $oLine = new Line();
  530. $oSeries = new Series('Downloads', $this->seriesData);
  531. $oSeries->getFont()->setSubScript(true);
  532. $oLine->addSeries($oSeries);
  533. $oShape->getPlotArea()->setType($oLine);
  534. $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/a:defRPr';
  535. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  536. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'baseline', '-25000');
  537. }
  538. public function testTypeLineSuperScript()
  539. {
  540. $oSlide = $this->oPresentation->getActiveSlide();
  541. $oShape = $oSlide->createChartShape();
  542. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  543. $oLine = new Line();
  544. $oSeries = new Series('Downloads', $this->seriesData);
  545. $oSeries->getFont()->setSuperScript(true);
  546. $oLine->addSeries($oSeries);
  547. $oShape->getPlotArea()->setType($oLine);
  548. $element = '/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/a:defRPr';
  549. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  550. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'baseline', '30000');
  551. }
  552. public function testTypePie()
  553. {
  554. $oSlide = $this->oPresentation->getActiveSlide();
  555. $oShape = $oSlide->createChartShape();
  556. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  557. $oPie = new Pie();
  558. $oSeries = new Series('Downloads', $this->seriesData);
  559. $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
  560. $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
  561. $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKGREEN));
  562. $oSeries->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKRED));
  563. $oSeries->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKYELLOW));
  564. $oPie->addSeries($oSeries);
  565. $oShape->getPlotArea()->setType($oPie);
  566. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
  567. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  568. $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart';
  569. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  570. $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser';
  571. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  572. $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dPt/c:spPr';
  573. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  574. $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:tx/c:v';
  575. $this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
  576. $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:showLegendKey';
  577. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  578. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 0);
  579. $oSeries->setShowLegendKey(true);
  580. $this->resetPresentationFile();
  581. $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:showLegendKey';
  582. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  583. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 1);
  584. }
  585. public function testTypePieSeparator()
  586. {
  587. $value = ';';
  588. $oSlide = $this->oPresentation->getActiveSlide();
  589. $oShape = $oSlide->createChartShape();
  590. $oPie = new Pie();
  591. $oSeries = new Series('Downloads', $this->seriesData);
  592. $oPie->addSeries($oSeries);
  593. $oShape->getPlotArea()->setType($oPie);
  594. $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:separator';
  595. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  596. $oSeries->setSeparator($value);
  597. $this->resetPresentationFile();
  598. $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:separator';
  599. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  600. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $value);
  601. }
  602. public function testTypePie3D()
  603. {
  604. $oSlide = $this->oPresentation->getActiveSlide();
  605. $oShape = $oSlide->createChartShape();
  606. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  607. $oPie3D = new Pie3D();
  608. $oSeries = new Series('Downloads', $this->seriesData);
  609. $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
  610. $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
  611. $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKGREEN));
  612. $oSeries->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKRED));
  613. $oSeries->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKYELLOW));
  614. $oPie3D->addSeries($oSeries);
  615. $oShape->getPlotArea()->setType($oPie3D);
  616. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
  617. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  618. $element = '/c:chartSpace/c:chart/c:plotArea/c:pie3DChart';
  619. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  620. $element = '/c:chartSpace/c:chart/c:plotArea/c:pie3DChart/c:ser';
  621. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  622. $element = '/c:chartSpace/c:chart/c:plotArea/c:pie3DChart/c:ser/c:dPt/c:spPr';
  623. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  624. $element = '/c:chartSpace/c:chart/c:plotArea/c:pie3DChart/c:ser/c:tx/c:v';
  625. $this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
  626. }
  627. public function testTypePie3DExplosion()
  628. {
  629. $value = rand(1, 100);
  630. $oSlide = $this->oPresentation->getActiveSlide();
  631. $oShape = $oSlide->createChartShape();
  632. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  633. $oPie3D = new Pie3D();
  634. $oPie3D->setExplosion($value);
  635. $oSeries = new Series('Downloads', $this->seriesData);
  636. $oPie3D->addSeries($oSeries);
  637. $oShape->getPlotArea()->setType($oPie3D);
  638. $element = '/c:chartSpace/c:chart/c:plotArea/c:pie3DChart/c:ser/c:explosion';
  639. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  640. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', $value);
  641. }
  642. public function testTypePie3DSubScript()
  643. {
  644. $oSlide = $this->oPresentation->getActiveSlide();
  645. $oShape = $oSlide->createChartShape();
  646. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  647. $oPie3D = new Pie3D();
  648. $oSeries = new Series('Downloads', $this->seriesData);
  649. $oSeries->getFont()->setSubScript(true);
  650. $oPie3D->addSeries($oSeries);
  651. $oShape->getPlotArea()->setType($oPie3D);
  652. $element = '/c:chartSpace/c:chart/c:plotArea/c:pie3DChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/a:defRPr';
  653. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  654. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'baseline', '-25000');
  655. }
  656. public function testTypePie3DSuperScript()
  657. {
  658. $oSlide = $this->oPresentation->getActiveSlide();
  659. $oShape = $oSlide->createChartShape();
  660. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  661. $oPie3D = new Pie3D();
  662. $oSeries = new Series('Downloads', $this->seriesData);
  663. $oSeries->getFont()->setSuperScript(true);
  664. $oPie3D->addSeries($oSeries);
  665. $oShape->getPlotArea()->setType($oPie3D);
  666. $element = '/c:chartSpace/c:chart/c:plotArea/c:pie3DChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/a:defRPr';
  667. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  668. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'baseline', '30000');
  669. }
  670. public function testTypeScatter()
  671. {
  672. $oSlide = $this->oPresentation->getActiveSlide();
  673. $oShape = $oSlide->createChartShape();
  674. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  675. $oScatter = new Scatter();
  676. $oSeries = new Series('Downloads', $this->seriesData);
  677. $oScatter->addSeries($oSeries);
  678. $oShape->getPlotArea()->setType($oScatter);
  679. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
  680. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  681. $element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart';
  682. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  683. $element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser';
  684. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  685. $element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:tx/c:v';
  686. $this->assertZipXmlElementEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, $oSeries->getTitle());
  687. $element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:dLbls/c:showLegendKey';
  688. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  689. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 0);
  690. $oSeries->setShowLegendKey(true);
  691. $this->resetPresentationFile();
  692. $element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:dLbls/c:showLegendKey';
  693. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  694. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', 1);
  695. }
  696. public function testTypeScatterMarker()
  697. {
  698. do {
  699. $expectedSymbol = array_rand(Marker::$arraySymbol);
  700. } while ($expectedSymbol == Marker::SYMBOL_NONE);
  701. $expectedSize = rand(2, 72);
  702. $expectedEltSymbol = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:marker/c:symbol';
  703. $expectedElementSize = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:marker/c:size';
  704. $oSlide = $this->oPresentation->getActiveSlide();
  705. $oShape = $oSlide->createChartShape();
  706. $oScatter = new Scatter();
  707. $oSeries = new Series('Downloads', $this->seriesData);
  708. $oSeries->getMarker()->setSymbol($expectedSymbol)->setSize($expectedSize);
  709. $oScatter->addSeries($oSeries);
  710. $oShape->getPlotArea()->setType($oScatter);
  711. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedEltSymbol);
  712. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize);
  713. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $expectedEltSymbol, 'val', $expectedSymbol);
  714. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize, 'val', $expectedSize);
  715. $oSeries->getMarker()->setSize(1);
  716. $oScatter->setSeries(array($oSeries));
  717. $this->resetPresentationFile();
  718. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize);
  719. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize, 'val', 2);
  720. $oSeries->getMarker()->setSize(73);
  721. $oScatter->setSeries(array($oSeries));
  722. $this->resetPresentationFile();
  723. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize);
  724. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize, 'val', 72);
  725. $oSeries->getMarker()->setSymbol(Marker::SYMBOL_NONE);
  726. $oScatter->setSeries(array($oSeries));
  727. $this->resetPresentationFile();
  728. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedEltSymbol);
  729. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElementSize);
  730. }
  731. public function testTypeScatterSeriesOutline()
  732. {
  733. $expectedWidth = rand(1, 100);
  734. $expectedWidthEmu = Drawing::pixelsToEmu(Drawing::pointsToPixels($expectedWidth));
  735. $expectedElement = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:spPr/a:ln';
  736. $oOutline = new Outline();
  737. // Define the color
  738. $oOutline->getFill()->setFillType(Fill::FILL_SOLID);
  739. $oOutline->getFill()->setStartColor(new Color(Color::COLOR_YELLOW));
  740. // Define the width (in points)
  741. $oOutline->setWidth($expectedWidth);
  742. $oSlide = $this->oPresentation->getActiveSlide();
  743. $oShape = $oSlide->createChartShape();
  744. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  745. $oScatter = new Scatter();
  746. $oSeries = new Series('Downloads', $this->seriesData);
  747. $oScatter->addSeries($oSeries);
  748. $oShape->getPlotArea()->setType($oScatter);
  749. $this->assertZipFileExists('ppt/charts/' . $oShape->getIndexedFilename());
  750. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElement);
  751. $oSeries->setOutline($oOutline);
  752. $oScatter->setSeries(array($oSeries));
  753. $this->resetPresentationFile();
  754. $this->assertZipFileExists('ppt/charts/' . $oShape->getIndexedFilename());
  755. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElement);
  756. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElement, 'w', $expectedWidthEmu);
  757. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $expectedElement . '/a:solidFill');
  758. }
  759. public function testTypeScatterSubScript()
  760. {
  761. $oSlide = $this->oPresentation->getActiveSlide();
  762. $oShape = $oSlide->createChartShape();
  763. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  764. $oScatter = new Scatter();
  765. $oSeries = new Series('Downloads', $this->seriesData);
  766. $oSeries->getFont()->setSubScript(true);
  767. $oScatter->addSeries($oSeries);
  768. $oShape->getPlotArea()->setType($oScatter);
  769. $element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/a:defRPr';
  770. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  771. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'baseline', '-25000');
  772. }
  773. public function testTypeScatterSuperScript()
  774. {
  775. $oSlide = $this->oPresentation->getActiveSlide();
  776. $oShape = $oSlide->createChartShape();
  777. $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
  778. $oScatter = new Scatter();
  779. $oSeries = new Series('Downloads', $this->seriesData);
  780. $oSeries->getFont()->setSuperScript(true);
  781. $oScatter->addSeries($oSeries);
  782. $oShape->getPlotArea()->setType($oScatter);
  783. $element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/a:defRPr';
  784. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  785. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'baseline', '30000');
  786. }
  787. public function testView3D()
  788. {
  789. $oSlide = $this->oPresentation->getActiveSlide();
  790. $oLine = new Line();
  791. $oLine->addSeries(new Series('Downloads', $this->seriesData));
  792. $oShape = $oSlide->createChartShape();
  793. $oShape->getPlotArea()->setType($oLine);
  794. $element = '/c:chartSpace/c:chart/c:view3D/c:hPercent';
  795. $this->assertZipXmlElementExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  796. $this->assertZipXmlAttributeEquals('ppt/charts/' . $oShape->getIndexedFilename(), $element, 'val', '100%');
  797. $oShape->getView3D()->setHeightPercent(null);
  798. $this->resetPresentationFile();
  799. $this->assertZipXmlElementNotExists('ppt/charts/' . $oShape->getIndexedFilename(), $element);
  800. }
  801. }