SurfaceTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Image;
  5. use CpChart\Chart\Surface;
  6. use UnitTester;
  7. class SurfaceTest extends Unit
  8. {
  9. /**
  10. * @var UnitTester
  11. */
  12. protected $tester;
  13. public function testSurfaceChartRender()
  14. {
  15. $image = new Image(400, 400);
  16. $settings = ["R" => 179, "G" => 217, "B" => 91, "Dash" => 1, "DashR" => 199, "DashG" => 237, "DashB" => 111];
  17. $image->drawFilledRectangle(0, 0, 400, 400, $settings);
  18. $settings = ["StartR" => 194, "StartG" => 231, "StartB" => 44, "EndR" => 43, "EndG" => 107, "EndB" => 58, "Alpha" => 50];
  19. $image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings);
  20. $image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100]);
  21. $image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
  22. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  23. $image->drawText(10, 13, "pSurface() :: 2D surface charts", ["R" => 255, "G" => 255, "B" => 255]);
  24. $image->setGraphArea(20, 40, 380, 380);
  25. $image->drawFilledRectangle(20, 40, 380, 380, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 20]);
  26. $image->setShadow(true, ["X" => 1, "Y" => 1]);
  27. $surfaceChart = new Surface($image);
  28. $surfaceChart->setGrid(20, 20);
  29. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  30. $surfaceChart->writeXLabels();
  31. $surfaceChart->writeYLabels();
  32. for ($i = 0; $i <= 50; $i++) {
  33. $surfaceChart->addPoint(rand(0, 20), rand(0, 20), rand(0, 100));
  34. }
  35. $surfaceChart->computeMissing();
  36. $surfaceChart->drawSurface(["Border" => true, "Surrounding" => 40]);
  37. $filename = $this->tester->getOutputPathForChart('drawSurface.png');
  38. $image->render($filename);
  39. $image->stroke();
  40. $this->tester->seeFileFound($filename);
  41. }
  42. public function testContourChartRender()
  43. {
  44. $image = new Image(400,400);
  45. $image->drawFilledRectangle(0, 0, 400, 400, [
  46. "R" => 179,
  47. "G" => 217,
  48. "B" => 91,
  49. "Dash" => 1,
  50. "DashR" => 199,
  51. "DashG" => 237,
  52. "DashB" => 111
  53. ]);
  54. $image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [
  55. "StartR" => 194,
  56. "StartG" => 231,
  57. "StartB" => 44,
  58. "EndR" => 43,
  59. "EndG" => 107,
  60. "EndB" => 58,
  61. "Alpha" => 50
  62. ]);
  63. $image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
  64. "StartR" => 0,
  65. "StartG" => 0,
  66. "StartB" => 0,
  67. "EndR" => 50,
  68. "EndG" => 50,
  69. "EndB" => 50,
  70. "Alpha" => 100
  71. ]);
  72. $image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
  73. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  74. $image->drawText(10, 13, "pSurface() :: 2D surface charts", [
  75. "R" => 255,
  76. "G" => 255,
  77. "B" => 255
  78. ]);
  79. $image->setGraphArea(20, 40, 380, 380);
  80. $image->drawFilledRectangle(20, 40, 380, 380, [
  81. "R" => 255,
  82. "G" => 255,
  83. "B" => 255,
  84. "Surrounding" => -200,
  85. "Alpha" => 20
  86. ]);
  87. $image->setShadow(true, ["X" => 1, "Y" => 1]);
  88. $surfaceChart = new Surface($image);
  89. $surfaceChart->setGrid(20, 20);
  90. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  91. $surfaceChart->writeXLabels(["Position" => LABEL_POSITION_BOTTOM]);
  92. $surfaceChart->writeYLabels();
  93. for ($i = 0; $i <= 50; $i++) {
  94. $surfaceChart->addPoint(rand(0, 20), rand(0, 20), rand(0, 100));
  95. }
  96. $surfaceChart->computeMissing();
  97. $surfaceChart->drawSurface(["Border" => true, "Surrounding" => 40]);
  98. $surfaceChart->drawContour(50, ["R" => 0, "G" => 0, "B" => 0]);
  99. $filename = $this->tester->getOutputPathForChart('drawContour.png');
  100. $image->render($filename);
  101. $image->stroke();
  102. $this->tester->seeFileFound($filename);
  103. }
  104. }