SpringTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Image;
  5. use CpChart\Chart\Spring;
  6. use UnitTester;
  7. class SpringTest extends Unit
  8. {
  9. /**
  10. * @var UnitTester
  11. */
  12. protected $tester;
  13. public function testChartRender()
  14. {
  15. $image = new Image(300, 300);
  16. $image->drawGradientArea(0, 0, 300, 300, DIRECTION_HORIZONTAL, ["StartR" => 217, "StartG" => 250, "StartB" => 116, "EndR" => 181, "EndG" => 209, "EndB" => 27, "Alpha" => 100]);
  17. $image->drawGradientArea(0, 0, 300, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100]);
  18. $image->drawRectangle(0, 0, 299, 299, ["R" => 0, "G" => 0, "B" => 0]);
  19. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  20. $image->drawText(10, 13, "pSpring - Draw spring charts", ["R" => 255, "G" => 255, "B" => 255]);
  21. $image->setGraphArea(20, 20, 280, 280);
  22. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 9, "R" => 80, "G" => 80, "B" => 80]);
  23. $image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  24. $SpringChart = new Spring();
  25. $SpringChart->addNode(0, ["Shape" => NODE_SHAPE_SQUARE, "FreeZone" => 60, "Size" => 20, "NodeType" => NODE_TYPE_CENTRAL]);
  26. $SpringChart->addNode(1, ["Connections" => "0"]);
  27. $SpringChart->addNode(2, ["Connections" => "0"]);
  28. $SpringChart->addNode(3, ["Shape" => NODE_SHAPE_TRIANGLE, "Connections" => "1"]);
  29. $SpringChart->addNode(4, ["Shape" => NODE_SHAPE_TRIANGLE, "Connections" => "1"]);
  30. $SpringChart->addNode(5, ["Shape" => NODE_SHAPE_TRIANGLE, "Connections" => "1"]);
  31. $SpringChart->addNode(6, ["Connections" => "2"]);
  32. $SpringChart->addNode(7, ["Connections" => "2"]);
  33. $SpringChart->addNode(8, ["Connections" => "2"]);
  34. $SpringChart->setNodesColor(0, ["R" => 215, "G" => 163, "B" => 121, "BorderR" => 166, "BorderG" => 115, "BorderB" => 74]);
  35. $SpringChart->setNodesColor([1, 2], ["R" => 150, "G" => 215, "B" => 121, "Surrounding" => -30]);
  36. $SpringChart->setNodesColor([3, 4, 5], ["R" => 216, "G" => 166, "B" => 14, "Surrounding" => -30]);
  37. $SpringChart->setNodesColor([6, 7, 8], ["R" => 179, "G" => 121, "B" => 215, "Surrounding" => -30]);
  38. $SpringChart->linkProperties(0, 1, ["R" => 255, "G" => 0, "B" => 0, "Ticks" => 2]);
  39. $SpringChart->linkProperties(0, 2, ["R" => 255, "G" => 0, "B" => 0, "Ticks" => 2]);
  40. $SpringChart->drawSpring($image);
  41. $filename = $this->tester->getOutputPathForChart('drawSpring.png');
  42. $image->render($filename);
  43. $image->stroke();
  44. $this->tester->seeFileFound($filename);
  45. }
  46. }