1<?php 2namespace Amenadiel\JpGraph\Graph; 3 4use Amenadiel\JpGraph\Util; 5 6//============================================================ 7// CLASS WindroseGraph 8//============================================================ 9class WindroseGraph extends Graph 10{ 11 private $posx; 12 private $posy; 13 public $plots = []; 14 15 public function __construct($width = 300, $height = 200, $cachedName = "", $timeout = 0, $inline = 1) 16 { 17 parent::__construct($width, $height, $cachedName, $timeout, $inline); 18 $this->posx = $width / 2; 19 $this->posy = $height / 2; 20 $this->SetColor('white'); 21 $this->title->SetFont(FF_VERDANA, FS_NORMAL, 12); 22 $this->title->SetMargin(8); 23 $this->subtitle->SetFont(FF_VERDANA, FS_NORMAL, 10); 24 $this->subtitle->SetMargin(0); 25 $this->subsubtitle->SetFont(FF_VERDANA, FS_NORMAL, 8); 26 $this->subsubtitle->SetMargin(0); 27 } 28 29 public function StrokeTexts() 30 { 31 if ($this->texts != null) { 32 $n = count($this->texts); 33 for ($i = 0; $i < $n; ++$i) { 34 $this->texts[$i]->Stroke($this->img); 35 } 36 } 37 } 38 39 public function StrokeIcons() 40 { 41 if ($this->iIcons != null) { 42 $n = count($this->iIcons); 43 for ($i = 0; $i < $n; ++$i) { 44 // Since Windrose graphs doesn't have any linear scale the position of 45 // each icon has to be given as absolute coordinates 46 $this->iIcons[$i]->_Stroke($this->img); 47 } 48 } 49 } 50 51 //--------------- 52 // PUBLIC METHODS 53 public function Add($aObj) 54 { 55 if (is_array($aObj) && count($aObj) > 0) { 56 $cl = $aObj[0]; 57 } else { 58 $cl = $aObj; 59 } 60 if ($cl instanceof Text) { 61 $this->AddText($aObj); 62 } elseif ($cl instanceof IconPlot) { 63 $this->AddIcon($aObj); 64 } elseif (($cl instanceof WindrosePlot) || ($cl instanceof LayoutRect) || ($cl instanceof LayoutHor)) { 65 $this->plots[] = $aObj; 66 } else { 67 Util\JpGraphError::RaiseL(22021); 68 } 69 } 70 71 public function AddText($aTxt, $aToY2 = false) 72 { 73 parent::AddText($aTxt); 74 } 75 76 public function SetColor($c) 77 { 78 $this->SetMarginColor($c); 79 } 80 81 // Method description 82 public function Stroke($aStrokeFileName = "") 83 { 84 85 // If the filename is the predefined value = '_csim_special_' 86 // we assume that the call to stroke only needs to do enough 87 // to correctly generate the CSIM maps. 88 // We use this variable to skip things we don't strictly need 89 // to do to generate the image map to improve performance 90 // as best we can. Therefore you will see a lot of tests !$_csim in the 91 // code below. 92 $_csim = ($aStrokeFileName === _CSIM_SPECIALFILE); 93 94 // We need to know if we have stroked the plot in the 95 // GetCSIMareas. Otherwise the CSIM hasn't been generated 96 // and in the case of GetCSIM called before stroke to generate 97 // CSIM without storing an image to disk GetCSIM must call Stroke. 98 $this->iHasStroked = true; 99 100 if ($this->background_image != "" || $this->background_cflag != "") { 101 $this->StrokeFrameBackground(); 102 } else { 103 $this->StrokeFrame(); 104 } 105 106 // n holds number of plots 107 $n = count($this->plots); 108 for ($i = 0; $i < $n; ++$i) { 109 $this->plots[$i]->Stroke($this); 110 } 111 112 $this->footer->Stroke($this->img); 113 $this->StrokeIcons(); 114 $this->StrokeTexts(); 115 $this->StrokeTitles(); 116 117 // If the filename is given as the special "__handle" 118 // then the image handler is returned and the image is NOT 119 // streamed back 120 if ($aStrokeFileName == _IMG_HANDLER) { 121 return $this->img->img; 122 } else { 123 // Finally stream the generated picture 124 $this->cache->PutAndStream($this->img, $this->cache_name, $this->inline, 125 $aStrokeFileName); 126 } 127 } 128} // Class 129