LineTest.php 2.0 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 LineTest extends Unit
  8. {
  9. /**
  10. * @var UnitTester
  11. */
  12. protected $tester;
  13. public function testChartRender()
  14. {
  15. $data = new Data();
  16. $data->addPoints([-4, VOID, VOID, 12, 8, 3], "Probe 1");
  17. $data->addPoints([3, 12, 15, 8, 5, -5], "Probe 2");
  18. $data->addPoints([2, 7, 5, 18, 19, 22], "Probe 3");
  19. $data->setSerieTicks("Probe 2", 4);
  20. $data->setSerieWeight("Probe 3", 2);
  21. $data->setAxisName(0, "Temperatures");
  22. $data->addPoints(["Jan", "Feb", "Mar", "Apr", "May", "Jun"], "Labels");
  23. $data->setSerieDescription("Labels", "Months");
  24. $data->setAbscissa("Labels");
  25. $image = new Image(700, 230, $data);
  26. $image->setGraphArea(60, 60, 450, 190);
  27. $image->drawFilledRectangle(60, 60, 450, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
  28. $image->drawScale(["DrawSubTicks" => true]);
  29. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  30. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  31. $image->drawLineChart(["DisplayValues" => true, "DisplayColor" => DISPLAY_AUTO]);
  32. $image->setShadow(false);
  33. $image->setGraphArea(500, 60, 670, 190);
  34. $image->drawFilledRectangle(500, 60, 670, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
  35. $image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => true]);
  36. $image->setShadow(true, ["X" => -1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  37. $image->drawLineChart();
  38. $image->setShadow(false);
  39. $image->drawLegend(510, 205, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
  40. $filename = $this->tester->getOutputPathForChart('drawLine.png');
  41. $image->render($filename);
  42. $image->stroke();
  43. $this->tester->seeFileFound($filename);
  44. }
  45. }