BubbleTest.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Chart\Bubble;
  5. use CpChart\Data;
  6. use CpChart\Image;
  7. use UnitTester;
  8. class BubbleTest 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], "Probe1");
  18. $data->addPoints([5, 10, 8, 9, 15, 10], "Probe1Weight");
  19. $data->addPoints([5, 10, -5, -1, 0, -10], "Probe2");
  20. $data->addPoints([6, 10, 14, 10, 14, 6], "Probe2Weight");
  21. $data->setSerieDescription("Probe1", "This year");
  22. $data->setSerieDescription("Probe2", "Last year");
  23. $data->setAxisName(0, "Current stock");
  24. $data->addPoints(["Apple", "Banana", "Orange", "Lemon", "Peach", "Strawberry"], "Product");
  25. $data->setAbscissa("Product");
  26. /* Create the pChart object */
  27. $image = new Image(700, 230, $data);
  28. $settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
  29. $image->drawFilledRectangle(0, 0, 700, 230, $settings);
  30. $settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
  31. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
  32. $image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80]);
  33. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  34. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  35. $image->drawText(10, 13, "drawBubbleChart() - draw a linear bubble chart", ["R" => 255, "G" => 255, "B" => 255]);
  36. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
  37. $image->drawText(40, 55, "Current Stock / Needs chart", ["FontSize" => 14, "Align" => TEXT_ALIGN_BOTTOMLEFT]);
  38. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  39. $bubbleChart = new Bubble($image, $data);
  40. $bubbleDataSeries = ["Probe1", "Probe2"];
  41. $bubbleWeightSeries = ["Probe1Weight", "Probe2Weight"];
  42. $bubbleChart->bubbleScale($bubbleDataSeries, $bubbleWeightSeries);
  43. $image->setGraphArea(40, 60, 430, 190);
  44. $image->drawFilledRectangle(40, 60, 430, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
  45. $image->drawScale(["DrawSubTicks" => true, "CycleBackground" => true]);
  46. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 30]);
  47. $bubbleChart->drawBubbleChart($bubbleDataSeries, $bubbleWeightSeries);
  48. $image->setShadow(false);
  49. $image->setGraphArea(500, 60, 670, 190);
  50. $image->drawFilledRectangle(500, 60, 670, 190, ["R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10]);
  51. $image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => true]);
  52. $image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 30]);
  53. $bubbleChart->drawbubbleChart($bubbleDataSeries, $bubbleWeightSeries);
  54. $image->drawLegend(550, 215, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
  55. $filename = $this->tester->getOutputPathForChart('drawBubble.png');
  56. $image->render($filename);
  57. $image->stroke();
  58. $this->tester->seeFileFound($filename);
  59. }
  60. }