BestFitTest.php 1.7 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 BestFitTest 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(10, 30) + $i, "Probe 1");
  18. }
  19. for ($i = 0; $i <= 20; $i++) {
  20. $data->addPoints(rand(0, 10) + $i, "Probe 2");
  21. }
  22. $data->setAxisName(0, "Temperatures");
  23. $image = new Image(700, 230, $data);
  24. $image->Antialias = false;
  25. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  26. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
  27. $image->drawText(150, 35, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
  28. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  29. $image->setGraphArea(60, 40, 650, 200);
  30. $scaleSettings = ["XMargin" => 10, "YMargin" => 10, "Floating" => true, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => true, "CycleBackground" => true];
  31. $image->drawScale($scaleSettings);
  32. $image->Antialias = true;
  33. $image->drawBestFit();
  34. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  35. $image->drawPlotChart();
  36. $image->drawLegend(580, 20, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
  37. $filename = $this->tester->getOutputPathForChart('drawBestFit.png');
  38. $image->render($filename);
  39. $image->stroke();
  40. $this->tester->seeFileFound($filename);
  41. }
  42. }