ZoneTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use UnitTester;
  7. class ZoneTest 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 <= 10; $i = $i + .2) {
  17. $data->addPoints(log($i + 1) * 10, "Bounds 1");
  18. $data->addPoints(log($i + 3) * 10 + rand(0, 2) - 1, "Probe");
  19. $data->addPoints(log($i + 6) * 10, "Bounds 2");
  20. $data->addPoints($i * 10, "Labels");
  21. }
  22. $data->setAxisName(0, "Size (cm)");
  23. $data->setSerieDescription("Labels", "Months");
  24. $data->setAbscissa("Labels");
  25. $data->setAbscissaName("Time (years)");
  26. $image = new Image(700, 230, $data);
  27. $image->Antialias = false;
  28. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  29. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
  30. $image->drawText(150, 35, "Size by time generations", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
  31. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  32. $image->setGraphArea(40, 40, 680, 200);
  33. $scaleSettings = ["LabelSkip" => 4, "XMargin" => 10, "YMargin" => 10, "Floating" => true, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => true, "CycleBackground" => true];
  34. $image->drawScale($scaleSettings);
  35. $image->Antialias = true;
  36. $image->drawZoneChart("Bounds 1", "Bounds 2");
  37. $data->setSerieDrawable(["Bounds 1", "Bounds 2"], false);
  38. $image->drawStepChart();
  39. $image->drawLegend(640, 20, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
  40. $filename = $this->tester->getOutputPathForChart('drawZone.png');
  41. $image->render($filename);
  42. $image->stroke();
  43. $this->tester->seeFileFound($filename);
  44. }
  45. }