HuasoFoundries /
jpgraph
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * JPGraph v4.0.3 |
||
| 5 | */ |
||
| 6 | |||
| 7 | namespace Amenadiel\JpGraph\Plot; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @class RadarPlot |
||
| 11 | * // Description: Plot a radarplot |
||
| 12 | */ |
||
| 13 | class RadarPlot |
||
| 14 | { |
||
| 15 | public $mark; |
||
| 16 | public $legend = ''; |
||
| 17 | public $legendcsimtarget = ''; |
||
| 18 | public $legendcsimalt = ''; |
||
| 19 | public $csimtargets = []; // Array of targets for CSIM |
||
| 20 | public $csimareas = ''; // Resultant CSIM area tags |
||
| 21 | public $csimalts; // ALT:s for corresponding target |
||
| 22 | private $data = []; |
||
| 23 | private $fill = false; |
||
| 24 | private $fill_color = [200, 170, 180]; |
||
| 25 | private $color = [0, 0, 0]; |
||
| 26 | private $weight = 1; |
||
| 27 | private $linestyle = 'solid'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * CONSTRUCTOR. |
||
| 31 | * |
||
| 32 | * @param mixed $data |
||
| 33 | */ |
||
| 34 | public function __construct($data) |
||
| 35 | { |
||
| 36 | $this->data = $data; |
||
| 37 | $this->mark = new PlotMark(); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function Min() |
||
| 41 | { |
||
| 42 | return min($this->data); |
||
| 43 | } |
||
| 44 | |||
| 45 | public function Max() |
||
| 46 | { |
||
| 47 | return max($this->data); |
||
| 48 | } |
||
| 49 | |||
| 50 | public function SetLegend($legend) |
||
| 51 | { |
||
| 52 | $this->legend = $legend; |
||
| 53 | } |
||
| 54 | |||
| 55 | public function SetLineStyle($aStyle) |
||
| 56 | { |
||
| 57 | $this->linestyle = $aStyle; |
||
| 58 | } |
||
| 59 | |||
| 60 | public function SetLineWeight($w) |
||
| 61 | { |
||
| 62 | $this->weight = $w; |
||
| 63 | } |
||
| 64 | |||
| 65 | public function SetFillColor($aColor) |
||
| 66 | { |
||
| 67 | $this->fill_color = $aColor; |
||
| 68 | $this->fill = true; |
||
| 69 | } |
||
| 70 | |||
| 71 | public function SetFill($f = true) |
||
| 72 | { |
||
| 73 | $this->fill = $f; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function SetColor($aColor, $aFillColor = false) |
||
| 77 | { |
||
| 78 | $this->color = $aColor; |
||
| 79 | if ($aFillColor) { |
||
| 80 | $this->SetFillColor($aFillColor); |
||
| 81 | $this->fill = true; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | // Set href targets for CSIM |
||
| 86 | public function SetCSIMTargets($aTargets, $aAlts = null) |
||
| 87 | { |
||
| 88 | $this->csimtargets = $aTargets; |
||
| 89 | $this->csimalts = $aAlts; |
||
| 90 | } |
||
| 91 | |||
| 92 | // Get all created areas |
||
| 93 | public function GetCSIMareas() |
||
| 94 | { |
||
| 95 | return $this->csimareas; |
||
| 96 | } |
||
| 97 | |||
| 98 | public function Stroke($img, $pos, $scale, $startangle) |
||
| 99 | { |
||
| 100 | $nbrpnts = safe_count($this->data); |
||
| 101 | $astep = 2 * M_PI / $nbrpnts; |
||
| 102 | $a = $startangle; |
||
| 103 | |||
| 104 | for ($i = 0; $i < $nbrpnts; ++$i) { |
||
| 105 | // Rotate each non null point to the correct axis-angle |
||
| 106 | $cs = $scale->RelTranslate($this->data[$i]); |
||
| 107 | $x = round($cs * cos($a) + $scale->scale_abs[0]); |
||
| 108 | $y = round($pos - $cs * sin($a)); |
||
| 109 | |||
| 110 | $pnts[$i * 2] = $x; |
||
| 111 | $pnts[$i * 2 + 1] = $y; |
||
| 112 | |||
| 113 | // If the next point is null then we draw this polygon segment |
||
| 114 | // to the center, skip the next and draw the next segment from |
||
| 115 | // the center up to the point on the axis with the first non-null |
||
| 116 | // value and continues from that point. Some additoinal logic is necessary |
||
| 117 | // to handle the boundary conditions |
||
| 118 | if ($i < $nbrpnts - 1) { |
||
| 119 | if (is_null($this->data[$i + 1])) { |
||
| 120 | $cs = 0; |
||
| 121 | $x = round($cs * cos($a) + $scale->scale_abs[0]); |
||
| 122 | $y = round($pos - $cs * sin($a)); |
||
| 123 | $pnts[$i * 2] = $x; |
||
| 124 | $pnts[$i * 2 + 1] = $y; |
||
| 125 | $a += $astep; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | $a += $astep; |
||
| 130 | } |
||
| 131 | |||
| 132 | if ($this->fill) { |
||
| 133 | $img->SetColor($this->fill_color); |
||
| 134 | $img->FilledPolygon($pnts); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 135 | } |
||
| 136 | |||
| 137 | $img->SetLineWeight($this->weight); |
||
| 138 | $img->SetColor($this->color); |
||
| 139 | $img->SetLineStyle($this->linestyle); |
||
| 140 | $pnts[] = $pnts[0]; |
||
| 141 | $pnts[] = $pnts[1]; |
||
| 142 | $img->Polygon($pnts); |
||
| 143 | $img->SetLineStyle('solid'); // Reset line style to default |
||
| 144 | |||
| 145 | // Add plotmarks on top |
||
| 146 | if ($this->mark->show) { |
||
| 147 | for ($i = 0; $i < $nbrpnts; ++$i) { |
||
| 148 | if (isset($this->csimtargets[$i])) { |
||
| 149 | $this->mark->SetCSIMTarget($this->csimtargets[$i]); |
||
| 150 | $this->mark->SetCSIMAlt($this->csimalts[$i]); |
||
| 151 | $this->mark->SetCSIMAltVal($pnts[$i * 2], $pnts[$i * 2 + 1]); |
||
| 152 | $this->mark->Stroke($img, $pnts[$i * 2], $pnts[$i * 2 + 1]); |
||
| 153 | $this->csimareas .= $this->mark->GetCSIMAreas(); |
||
| 154 | } else { |
||
| 155 | $this->mark->Stroke($img, $pnts[$i * 2], $pnts[$i * 2 + 1]); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | public function GetCount() |
||
| 162 | { |
||
| 163 | return safe_count($this->data); |
||
| 164 | } |
||
| 165 | |||
| 166 | public function Legend($graph) |
||
| 167 | { |
||
| 168 | if ($this->legend == '') { |
||
| 169 | return; |
||
| 170 | } |
||
| 171 | if ($this->fill) { |
||
| 172 | $graph->legend->Add($this->legend, $this->fill_color, $this->mark); |
||
| 173 | } else { |
||
| 174 | $graph->legend->Add($this->legend, $this->color, $this->mark); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } // @class |
||
| 178 |