AreaTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use UnitTester;
  7. class AreaTest 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 <= 30; $i++) {
  17. $data->addPoints(rand(1, 15), "Probe 1");
  18. }
  19. $data->setSerieTicks("Probe 2", 4);
  20. $data->setAxisName(0, "Temperatures");
  21. $image = new Image(700, 230, $data);
  22. $image->Antialias = false;
  23. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  24. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
  25. $image->drawText(150, 35, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
  26. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  27. $image->setGraphArea(60, 40, 650, 200);
  28. $scaleSettings = ["XMargin" => 10, "YMargin" => 10, "Floating" => true, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => true, "CycleBackground" => true];
  29. $image->drawScale($scaleSettings);
  30. $image->drawLegend(600, 20, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
  31. $image->Antialias = true;
  32. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  33. $threshold = [
  34. ["Min" => 0, "Max" => 5, "R" => 207, "G" => 240, "B" => 20, "Alpha" => 70],
  35. ["Min" => 5, "Max" => 10, "R" => 240, "G" => 232, "B" => 20, "Alpha" => 70],
  36. ["Min" => 10, "Max" => 20, "R" => 240, "G" => 191, "B" => 20, "Alpha" => 70]
  37. ];
  38. $image->drawAreaChart(["Threshold" => $threshold]);
  39. $image->drawThreshold(5, ["WriteCaption" => true, "Caption" => "Warn Zone", "Alpha" => 70, "Ticks" => 2, "R" => 0, "G" => 0, "B" => 255]);
  40. $image->drawThreshold(10, ["WriteCaption" => true, "Caption" => "Error Zone", "Alpha" => 70, "Ticks" => 2, "R" => 0, "G" => 0, "B" => 255]);
  41. $filename = $this->tester->getOutputPathForChart('drawAreaChart.threshold.png');
  42. $image->render($filename);
  43. $image->stroke();
  44. $this->tester->seeFileFound($filename);
  45. }
  46. }