StockTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use CpChart\Chart\Stock;
  7. use UnitTester;
  8. class StockTest extends Unit
  9. {
  10. /**
  11. * @var UnitTester
  12. */
  13. protected $tester;
  14. public function testChartRender()
  15. {
  16. $data = new Data();
  17. $data->addPoints([34, 55, 15, 62, 38, 42], "Open");
  18. $data->addPoints([42, 25, 40, 38, 49, 36], "Close");
  19. $data->addPoints([27, 14, 12, 25, 32, 32], "Min");
  20. $data->addPoints([45, 59, 47, 65, 64, 48], "Max");
  21. $data->setAxisDisplay(0, AXIS_FORMAT_CURRENCY, "$");
  22. $data->addPoints(["8h", "10h", "12h", "14h", "16h", "18h"], "Time");
  23. $data->setAbscissa("Time");
  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->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  30. $image->setFontProperties(["FontName" => "../fonts/Forgotte.ttf", "FontSize" => 11]);
  31. $image->drawText(60, 45, "Stock price", ["FontSize" => 28, "Align" => TEXT_ALIGN_BOTTOMLEFT]);
  32. $image->setGraphArea(60, 60, 450, 190);
  33. $image->drawFilledRectangle(60, 60, 450, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
  34. $image->drawScale(["DrawSubTicks" => true, "CycleBackground" => true]);
  35. $stockChart = new Stock($image, $data);
  36. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 30]);
  37. $stockChart->drawStockChart();
  38. $data->setAxisDisplay(0, AXIS_FORMAT_DEFAULT);
  39. $image->setShadow(false);
  40. $image->setGraphArea(500, 60, 670, 190);
  41. $image->drawFilledRectangle(500, 60, 670, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
  42. $image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => true]);
  43. $stockChart = new Stock($image, $data);
  44. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 30]);
  45. $stockChart->drawStockChart();
  46. $filename = $this->tester->getOutputPathForChart('drawStock.png');
  47. $image->render($filename);
  48. $image->stroke();
  49. $this->tester->seeFileFound($filename);
  50. }
  51. }