SplitPathTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use CpChart\Chart\Split;
  7. use UnitTester;
  8. class SplitPathTest extends Unit
  9. {
  10. /**
  11. * @var UnitTester
  12. */
  13. protected $tester;
  14. public function testChartRender()
  15. {
  16. $image = new Image(700, 230);
  17. $settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
  18. $image->drawFilledRectangle(0, 0, 700, 230, $settings);
  19. $settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
  20. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
  21. $image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80]);
  22. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  23. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  24. $image->drawText(10, 13, "pSplit - Draw splitted path charts", ["R" => 255, "G" => 255, "B" => 255]);
  25. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80]);
  26. $image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  27. $data = new Data();
  28. $data->addPoints([30, 20, 15, 10, 8, 4], "Score");
  29. $data->addPoints(["End of visit", "Home Page", "Product Page", "Sales", "Statistics", "Prints"], "Labels");
  30. $data->setAbscissa("Labels");
  31. $SplitChart = new Split();
  32. $settings = ["TextPos" => TEXT_POS_RIGHT, "TextPadding" => 10, "Spacing" => 20, "Surrounding" => 40];
  33. $image->setGraphArea(10, 20, 340, 230);
  34. $SplitChart->drawSplitPath($image, $data, $settings);
  35. $data2 = new Data();
  36. $data2->addPoints([30, 20, 15], "Score");
  37. $data2->addPoints(["UK", "FR", "ES"], "Labels");
  38. $data2->setAbscissa("Labels");
  39. $settings = ["TextPadding" => 4, "Spacing" => 30, "Surrounding" => 20];
  40. $image->setGraphArea(350, 50, 690, 200);
  41. $SplitChart->drawSplitPath($image, $data2, $settings);
  42. $filename = $this->tester->getOutputPathForChart('drawSplit.png');
  43. $image->render($filename);
  44. $image->stroke();
  45. $this->tester->seeFileFound($filename);
  46. }
  47. }