FilledStepTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use UnitTester;
  7. class FilledStepTest extends Unit
  8. {
  9. /**
  10. * @var UnitTester
  11. */
  12. protected $tester;
  13. public function testChartRender()
  14. {
  15. $data = new Data();
  16. $data->addPoints([-4, 2, 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->setAxisName(0, "Temperatures");
  21. $data->addPoints(["Jan", "Feb", "Mar", "Apr", "May", "Jun"], "Labels");
  22. $data->setSerieDescription("Labels", "Months");
  23. $data->setAbscissa("Labels");
  24. $image = new Image(700, 230, $data);
  25. $settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
  26. $image->drawFilledRectangle(0, 0, 700, 230, $settings);
  27. $settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
  28. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
  29. $image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80]);
  30. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  31. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  32. $image->drawText(10, 13, "drawFilledStepChart() - draw a filled step chart", ["R" => 255, "G" => 255, "B" => 255]);
  33. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
  34. $image->drawText(250, 55, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
  35. $image->setGraphArea(60, 60, 450, 190);
  36. $image->drawFilledRectangle(60, 60, 450, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
  37. $image->drawScale(["DrawSubTicks" => true]);
  38. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  39. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  40. $image->drawFilledStepChart(["ForceTransparency" => 40, "DisplayValues" => true, "DisplayColor" => DISPLAY_AUTO]);
  41. $image->setShadow(false);
  42. $image->setGraphArea(500, 60, 670, 190);
  43. $image->drawFilledRectangle(500, 60, 670, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
  44. $image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => true]);
  45. $image->setShadow(true, ["X" => -1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  46. $image->drawFilledStepChart(["ForceTransparency" => 40]);
  47. $image->setShadow(false);
  48. $image->drawLegend(510, 205, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
  49. $filename = $this->tester->getOutputPathForChart('drawFilledStepChart.png');
  50. $image->render($filename);
  51. $image->stroke();
  52. $this->tester->seeFileFound($filename);
  53. }
  54. }