StackedBarTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Data;
  5. use CpChart\Image;
  6. use UnitTester;
  7. class StackedBarTest extends Unit
  8. {
  9. /**
  10. * @var UnitTester
  11. */
  12. protected $tester;
  13. public function testChartRender()
  14. {
  15. $data = new Data();
  16. $data->addPoints([-7, -8, -15, -20, -18, -12, 8, -19, 9, 16, -20, 8, 10, -10, -14, -20, 8, -9, -19], "Probe 3");
  17. $data->addPoints([19, 0, -8, 8, -8, 12, -19, -10, 5, 12, -20, -8, 10, -11, -12, 8, -17, -14, 0], "Probe 4");
  18. $data->setAxisName(0, "Temperatures");
  19. $data->addPoints([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22], "Time");
  20. $data->setSerieDescription("Time", "Hour of the day");
  21. $data->setAbscissa("Time");
  22. $data->setXAxisUnit("h");
  23. $image = new Image(700, 230, $data);
  24. $settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
  25. $image->drawFilledRectangle(0, 0, 700, 230, $settings);
  26. $settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
  27. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
  28. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  29. $image->setGraphArea(60, 30, 650, 190);
  30. $image->drawScale(["CycleBackground" => true, "DrawSubTicks" => true, "GridR" => 0, "GridG" => 0, "GridB" => 0, "GridAlpha" => 10, "Mode" => SCALE_MODE_ADDALL]);
  31. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
  32. $image->setShadow(false);
  33. $image->drawThreshold(-40, ["WriteCaption" => true, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 4]);
  34. $image->drawThreshold(28, ["WriteCaption" => true, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 4]);
  35. $image->drawStackedBarChart(["Rounded" => true, "DisplayValues" => true, "DisplayColor" => DISPLAY_AUTO, "DisplaySize" => 6, "BorderR" => 255, "BorderG" => 255, "BorderB" => 255]);
  36. $image->drawLegend(570, 212, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
  37. $filename = $this->tester->getOutputPathForChart('drawStackedChart.png');
  38. $image->render($filename);
  39. $image->stroke();
  40. $this->tester->seeFileFound($filename);
  41. }
  42. }