PieTest.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use CpChart\Chart\Pie;
  7. use UnitTester;
  8. class PieTest extends Unit
  9. {
  10. /**
  11. * @var UnitTester
  12. */
  13. protected $tester;
  14. public function test2dPieRender()
  15. {
  16. $data = new Data();
  17. $data->addPoints([40, 60, 15, 10, 6, 4], "ScoreA");
  18. $data->setSerieDescription("ScoreA", "Application A");
  19. $data->addPoints(["<10", "10<>20", "20<>40", "40<>60", "60<>80", ">80"], "Labels");
  20. $data->setAbscissa("Labels");
  21. $image = new Image(700, 230, $data);
  22. $image->drawFilledRectangle(0, 0, 700, 230, [
  23. "R" => 173, "G" => 152, "B" => 217, "Dash" => 1, "DashR" => 193,
  24. "DashG" => 172, "DashB" => 237
  25. ]);
  26. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, [
  27. "StartR" => 209, "StartG" => 150, "StartB" => 231, "EndR" => 111,
  28. "EndG" => 3, "EndB" => 138, "Alpha" => 50
  29. ]);
  30. $image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
  31. "StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50,
  32. "EndB" => 50, "Alpha" => 100
  33. ]);
  34. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  35. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  36. $image->drawText(10, 13, "pPie - Draw 2D pie charts", ["R" => 255, "G" => 255, "B" => 255]);
  37. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80]);
  38. $image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 150, "G" => 150, "B" => 150, "Alpha" => 100]);
  39. $pieChart = new Pie($image, $data);
  40. $pieChart->draw2DPie(140, 125, ["SecondPass" => false]);
  41. $pieChart->draw2DPie(340, 125, ["DrawLabels" => true, "Border" => true]);
  42. $pieChart->draw2DPie(540, 125, [
  43. "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => true,
  44. "BorderR" => 255, "BorderG" => 255, "BorderB" => 255
  45. ]);
  46. $image->setFontProperties(["FontName" => "MankSans.ttf", "FontSize" => 11]);
  47. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20]);
  48. $image->drawText(140, 200, "Single AA pass", [
  49. "R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE
  50. ]);
  51. $image->drawText(540, 200, "Extended AA pass / Splitted", [
  52. "R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE
  53. ]);
  54. $filename = $this->tester->getOutputPathForChart('draw2DPie.png');
  55. $pieChart->pChartObject->render($filename);
  56. $pieChart->pChartObject->stroke();
  57. $this->tester->seeFileFound($filename);
  58. }
  59. public function test2dRingRender()
  60. {
  61. $data = new Data();
  62. $data->addPoints([50, 2, 3, 4, 7, 10, 25, 48, 41, 10], "ScoreA");
  63. $data->setSerieDescription("ScoreA", "Application A");
  64. $data->addPoints(["A0", "B1", "C2", "D3", "E4", "F5", "G6", "H7", "I8", "J9"], "Labels");
  65. $data->setAbscissa("Labels");
  66. $image = new Image(300, 260, $data);
  67. $settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
  68. $image->drawFilledRectangle(0, 0, 300, 300, $settings);
  69. $settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
  70. $image->drawGradientArea(0, 0, 300, 260, DIRECTION_VERTICAL, $settings);
  71. $image->drawGradientArea(0, 0, 300, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100]);
  72. $image->drawRectangle(0, 0, 299, 259, ["R" => 0, "G" => 0, "B" => 0]);
  73. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  74. $image->drawText(10, 13, "pPie - Draw 2D ring charts", ["R" => 255, "G" => 255, "B" => 255]);
  75. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80]);
  76. $image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50]);
  77. $pieChart = new Pie($image, $data);
  78. $pieChart->draw2DRing(160, 140, ["DrawLabels" => true, "LabelStacked" => true, "Border" => true]);
  79. $image->setShadow(false);
  80. $pieChart->drawPieLegend(15, 40, ["Alpha" => 20]);
  81. $filename = $this->tester->getOutputPathForChart('draw2DRing.png');
  82. $pieChart->pChartObject->render($filename);
  83. $pieChart->pChartObject->stroke();
  84. $this->tester->seeFileFound($filename);
  85. }
  86. public function test3dPieRender()
  87. {
  88. $data = new Data();
  89. $data->addPoints([40, 30, 20], "ScoreA");
  90. $data->setSerieDescription("ScoreA", "Application A");
  91. $data->addPoints(["A", "B", "C"], "Labels");
  92. $data->setAbscissa("Labels");
  93. $image = new Image(700, 230, $data, true);
  94. $settings = ["R" => 173, "G" => 152, "B" => 217, "Dash" => 1, "DashR" => 193, "DashG" => 172, "DashB" => 237];
  95. $image->drawFilledRectangle(0, 0, 700, 230, $settings);
  96. $settings = ["StartR" => 209, "StartG" => 150, "StartB" => 231, "EndR" => 111, "EndG" => 3, "EndB" => 138, "Alpha" => 50];
  97. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
  98. $image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100]);
  99. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  100. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  101. $image->drawText(10, 13, "pPie - Draw 3D pie charts", ["R" => 255, "G" => 255, "B" => 255]);
  102. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80]);
  103. $pieChart = new Pie($image, $data);
  104. $pieChart->setSliceColor(0, ["R" => 143, "G" => 197, "B" => 0]);
  105. $pieChart->setSliceColor(1, ["R" => 97, "G" => 77, "B" => 63]);
  106. $pieChart->setSliceColor(2, ["R" => 97, "G" => 113, "B" => 63]);
  107. $pieChart->draw3DPie(120, 125, ["SecondPass" => false]);
  108. $pieChart->draw3DPie(340, 125, ["DrawLabels" => true, "Border" => true]);
  109. $image->setShadow(true, ["X" => 3, "Y" => 3, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  110. $pieChart->draw3DPie(560, 125, ["WriteValues" => true, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => true]);
  111. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  112. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20]);
  113. $image->drawText(120, 200, "Single AA pass", ["DrawBox" => true, "BoxRounded" => true, "R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE]);
  114. $image->drawText(440, 200, "Extended AA pass / Splitted", ["DrawBox" => true, "BoxRounded" => true, "R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE]);
  115. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6, "R" => 255, "G" => 255, "B" => 255]);
  116. $pieChart->drawPieLegend(600, 8, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
  117. $filename = $this->tester->getOutputPathForChart('draw3DPie.png');
  118. $pieChart->pChartObject->render($filename);
  119. $pieChart->pChartObject->stroke();
  120. $this->tester->seeFileFound($filename);
  121. }
  122. public function test3dRingRender()
  123. {
  124. $data = new Data();
  125. $data->addPoints([50, 2, 3, 4, 7, 10, 25, 48, 41, 10], "ScoreA");
  126. $data->setSerieDescription("ScoreA", "Application A");
  127. $data->addPoints(["A0", "B1", "C2", "D3", "E4", "F5", "G6", "H7", "I8", "J9"], "Labels");
  128. $data->setAbscissa("Labels");
  129. $image = new Image(400, 400, $data);
  130. $settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
  131. $image->drawFilledRectangle(0, 0, 400, 400, $settings);
  132. $settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
  133. $image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
  134. $image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100]);
  135. $image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
  136. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  137. $image->drawText(10, 13, "pPie - Draw 3D ring charts", ["R" => 255, "G" => 255, "B" => 255]);
  138. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80]);
  139. $image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50]);
  140. $pieChart = new Pie($image, $data);
  141. $pieChart->draw3DRing(200, 200, ["DrawLabels" => true, "LabelStacked" => true, "Border" => true]);
  142. $pieChart->drawPieLegend(80, 360, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER, "Alpha" => 20]);
  143. $filename = $this->tester->getOutputPathForChart('draw3DRing.png');
  144. $pieChart->pChartObject->render($filename);
  145. $pieChart->pChartObject->stroke();
  146. $this->tester->seeFileFound($filename);
  147. }
  148. }