RadarTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use CpChart\Chart\Radar;
  7. use UnitTester;
  8. class RadarTest extends Unit
  9. {
  10. /**
  11. * @var UnitTester
  12. */
  13. protected $tester;
  14. public function testChartRender()
  15. {
  16. $data = new Data();
  17. $data->addPoints([40, 20, 15, 10, 8, 4], "ScoreA");
  18. $data->addPoints([8, 10, 12, 20, 30, 15], "ScoreB");
  19. $data->setSerieDescription("ScoreA", "Application A");
  20. $data->setSerieDescription("ScoreB", "Application B");
  21. $data->addPoints(["Size", "Speed", "Reliability", "Functionalities", "Ease of use", "Weight"], "Labels");
  22. $data->setAbscissa("Labels");
  23. $image = new Image(700, 230, $data);
  24. $settings = ["R" => 179, "G" => 217, "B" => 91, "Dash" => 1, "DashR" => 199, "DashG" => 237, "DashB" => 111];
  25. $image->drawFilledRectangle(0, 0, 700, 230, $settings);
  26. $settings = ["StartR" => 194, "StartG" => 231, "StartB" => 44, "EndR" => 43, "EndG" => 107, "EndB" => 58, "Alpha" => 50];
  27. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
  28. $image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100]);
  29. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  30. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  31. $image->drawText(10, 13, "pRadar - Draw radar charts", ["R" => 255, "G" => 255, "B" => 255]);
  32. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80]);
  33. $image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  34. $radarChart = new Radar();
  35. $image->setGraphArea(10, 25, 340, 225);
  36. $options = ["Layout" => RADAR_LAYOUT_STAR, "BackgroundGradient" => ["StartR" => 255, "StartG" => 255, "StartB" => 255, "StartAlpha" => 100, "EndR" => 207, "EndG" => 227, "EndB" => 125, "EndAlpha" => 50]];
  37. $radarChart->drawRadar($image, $data, $options);
  38. $image->setGraphArea(350, 25, 690, 225);
  39. $options = ["Layout" => RADAR_LAYOUT_CIRCLE, "LabelPos" => RADAR_LABELS_HORIZONTAL, "BackgroundGradient" => ["StartR" => 255, "StartG" => 255, "StartB" => 255, "StartAlpha" => 50, "EndR" => 32, "EndG" => 109, "EndB" => 174, "EndAlpha" => 30]];
  40. $radarChart->drawRadar($image, $data, $options);
  41. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  42. $image->drawLegend(270, 205, ["Style" => LEGEND_BOX, "Mode" => LEGEND_HORIZONTAL]);
  43. $filename = $this->tester->getOutputPathForChart('drawRadar.png');
  44. $image->render($filename);
  45. $image->stroke();
  46. $this->tester->seeFileFound($filename);
  47. }
  48. }