StackedAreaTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use UnitTester;
  7. class StackedAreaTest extends Unit
  8. {
  9. /**
  10. * @var UnitTester
  11. */
  12. protected $tester;
  13. public function testChartRender()
  14. {
  15. $data = new Data();
  16. $data->addPoints([4, 0, 0, 12, 8, 3, 0, 12, 8], "Frontend #1");
  17. $data->addPoints([3, 12, 15, 8, 5, 5, 12, 15, 8], "Frontend #2");
  18. $data->addPoints([2, 7, 5, 18, 19, 22, 7, 5, 18], "Frontend #3");
  19. $data->setAxisName(0, "Average Usage");
  20. $data->addPoints(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jui", "Aug", "Sep"], "Labels");
  21. $data->setSerieDescription("Labels", "Months");
  22. $data->setAbscissa("Labels");
  23. $data->normalize(100, "%");
  24. $image = new Image(700, 230, $data);
  25. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, ["StartR" => 240, "StartG" => 240, "StartB" => 240, "EndR" => 180, "EndG" => 180, "EndB" => 180, "Alpha" => 100]);
  26. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_HORIZONTAL, ["StartR" => 240, "StartG" => 240, "StartB" => 240, "EndR" => 180, "EndG" => 180, "EndB" => 180, "Alpha" => 20]);
  27. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  28. $image->setGraphArea(60, 20, 680, 190);
  29. $image->drawScale(["XMargin" => 2, "DrawSubTicks" => true, "Mode" => SCALE_MODE_ADDALL]);
  30. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  31. $image->drawStackedAreaChart(["Surrounding" => 60]);
  32. $image->setShadow(false);
  33. $image->drawLegend(480, 210, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
  34. $filename = $this->tester->getOutputPathForChart('drawStackedArea.png');
  35. $image->render($filename);
  36. $image->stroke();
  37. $this->tester->seeFileFound($filename);
  38. }
  39. }