PlotTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use UnitTester;
  7. class PlotTest extends Unit
  8. {
  9. /**
  10. * @var UnitTester
  11. */
  12. protected $tester;
  13. public function testChartRender()
  14. {
  15. $data = new Data();
  16. for ($i = 0; $i <= 20; $i++) {
  17. $data->addPoints(rand(0, 20), "Probe 1");
  18. }
  19. for ($i = 0; $i <= 20; $i++) {
  20. $data->addPoints(rand(0, 20), "Probe 2");
  21. }
  22. $data->setSerieShape("Probe 1", SERIE_SHAPE_FILLEDTRIANGLE);
  23. $data->setSerieShape("Probe 2", SERIE_SHAPE_FILLEDSQUARE);
  24. $data->setAxisName(0, "Temperatures");
  25. $image = new Image(700, 230, $data);
  26. $image->Antialias = false;
  27. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  28. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
  29. $image->drawText(150, 35, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
  30. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  31. $image->setGraphArea(60, 40, 650, 200);
  32. $scaleSettings = ["XMargin" => 10, "YMargin" => 10, "Floating" => true, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => true, "CycleBackground" => true];
  33. $image->drawScale($scaleSettings);
  34. $image->Antialias = true;
  35. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  36. $image->drawPlotChart();
  37. $image->drawLegend(580, 20, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
  38. $filename = $this->tester->getOutputPathForChart('drawPlot.png');
  39. $image->render($filename);
  40. $image->stroke();
  41. $this->tester->seeFileFound($filename);
  42. }
  43. }