HuasoFoundries /
jpgraph
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * JPGraph v4.0.3 |
||
| 5 | */ |
||
| 6 | |||
| 7 | namespace Amenadiel\JpGraph\Graph; |
||
| 8 | |||
| 9 | /* |
||
| 10 | * File: JPGRAPH_RADAR.PHP |
||
| 11 | * // Description: Radar plot extension for JpGraph |
||
| 12 | * // Created: 2001-02-04 |
||
| 13 | * // Ver: $Id: jpgraph_radar.php 1783 2009-08-25 11:41:01Z ljp $ |
||
| 14 | * // |
||
| 15 | * // Copyright (c) Asial Corporation. All rights reserved. |
||
| 16 | */ |
||
| 17 | use Amenadiel\JpGraph\Plot; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @class RadarGrid |
||
| 21 | * // Description: Draws grid for the radar graph |
||
| 22 | */ |
||
| 23 | class RadarGrid |
||
| 24 | { |
||
| 25 | //extends Grid { |
||
| 26 | private $type = 'solid'; |
||
| 27 | private $grid_color = '#DDDDDD'; |
||
| 28 | private $show = false; |
||
| 29 | private $weight = 1; |
||
| 30 | |||
| 31 | public function __construct() |
||
| 32 | { |
||
| 33 | // Empty |
||
| 34 | } |
||
| 35 | |||
| 36 | public function SetColor($aMajColor) |
||
| 37 | { |
||
| 38 | $this->grid_color = $aMajColor; |
||
| 39 | } |
||
| 40 | |||
| 41 | public function SetWeight($aWeight) |
||
| 42 | { |
||
| 43 | $this->weight = $aWeight; |
||
| 44 | } |
||
| 45 | |||
| 46 | // Specify if grid should be dashed, dotted or solid |
||
| 47 | public function SetLineStyle($aType) |
||
| 48 | { |
||
| 49 | $this->type = $aType; |
||
| 50 | } |
||
| 51 | |||
| 52 | // Decide if both major and minor grid should be displayed |
||
| 53 | public function Show($aShowMajor = true) |
||
| 54 | { |
||
| 55 | $this->show = $aShowMajor; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function Stroke($img, $grid) |
||
| 59 | { |
||
| 60 | if (!$this->show) { |
||
| 61 | return; |
||
| 62 | } |
||
| 63 | |||
| 64 | $nbrticks = safe_count($grid[0]) / 2; |
||
| 65 | $nbrpnts = safe_count($grid); |
||
| 66 | $img->SetColor($this->grid_color); |
||
| 67 | $img->SetLineWeight($this->weight); |
||
| 68 | |||
| 69 | for ($i = 0; $i < $nbrticks; ++$i) { |
||
| 70 | for ($j = 0; $j < $nbrpnts; ++$j) { |
||
| 71 | $pnts[$j * 2] = $grid[$j][$i * 2]; |
||
| 72 | $pnts[$j * 2 + 1] = $grid[$j][$i * 2 + 1]; |
||
| 73 | } |
||
| 74 | for ($k = 0; $k < $nbrpnts; ++$k) { |
||
| 75 | $l = ($k + 1) % $nbrpnts; |
||
| 76 | if ($this->type == 'solid') { |
||
| 77 | $img->Line($pnts[$k * 2], $pnts[$k * 2 + 1], $pnts[$l * 2], $pnts[$l * 2 + 1]); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 78 | } elseif ($this->type == 'dotted') { |
||
| 79 | $img->DashedLine($pnts[$k * 2], $pnts[$k * 2 + 1], $pnts[$l * 2], $pnts[$l * 2 + 1], 1, 6); |
||
| 80 | } elseif ($this->type == 'dashed') { |
||
| 81 | $img->DashedLine($pnts[$k * 2], $pnts[$k * 2 + 1], $pnts[$l * 2], $pnts[$l * 2 + 1], 2, 4); |
||
| 82 | } elseif ($this->type == 'longdashed') { |
||
| 83 | $img->DashedLine($pnts[$k * 2], $pnts[$k * 2 + 1], $pnts[$l * 2], $pnts[$l * 2 + 1], 8, 6); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | $pnts = []; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } // @class |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @class RadarPlot |
||
| 93 | * // Description: Plot a radarplot |
||
| 94 | */ |
||
| 95 | class RadarPlot |
||
| 96 | { |
||
| 97 | public $mark; |
||
| 98 | public $legend = ''; |
||
| 99 | public $legendcsimtarget = ''; |
||
| 100 | public $legendcsimalt = ''; |
||
| 101 | public $csimtargets = []; // Array of targets for CSIM |
||
| 102 | public $csimareas = ''; // Resultant CSIM area tags |
||
| 103 | public $csimalts; // ALT:s for corresponding target |
||
| 104 | private $data = []; |
||
| 105 | private $fill = false; |
||
| 106 | private $fill_color = [200, 170, 180]; |
||
| 107 | private $color = [0, 0, 0]; |
||
| 108 | private $weight = 1; |
||
| 109 | private $linestyle = 'solid'; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * CONSTRUCTOR. |
||
| 113 | * |
||
| 114 | * @param mixed $data |
||
| 115 | */ |
||
| 116 | public function __construct($data) |
||
| 117 | { |
||
| 118 | $this->data = $data; |
||
| 119 | $this->mark = new Plot\PlotMark(); |
||
| 120 | } |
||
| 121 | |||
| 122 | public function Min() |
||
| 123 | { |
||
| 124 | return min($this->data); |
||
| 125 | } |
||
| 126 | |||
| 127 | public function Max() |
||
| 128 | { |
||
| 129 | return max($this->data); |
||
| 130 | } |
||
| 131 | |||
| 132 | public function SetLegend($legend) |
||
| 133 | { |
||
| 134 | $this->legend = $legend; |
||
| 135 | } |
||
| 136 | |||
| 137 | public function SetLineStyle($aStyle) |
||
| 138 | { |
||
| 139 | $this->linestyle = $aStyle; |
||
| 140 | } |
||
| 141 | |||
| 142 | public function SetLineWeight($w) |
||
| 143 | { |
||
| 144 | $this->weight = $w; |
||
| 145 | } |
||
| 146 | |||
| 147 | public function SetFillColor($aColor) |
||
| 148 | { |
||
| 149 | $this->fill_color = $aColor; |
||
| 150 | $this->fill = true; |
||
| 151 | } |
||
| 152 | |||
| 153 | public function SetFill($f = true) |
||
| 154 | { |
||
| 155 | $this->fill = $f; |
||
| 156 | } |
||
| 157 | |||
| 158 | public function SetColor($aColor, $aFillColor = false) |
||
| 159 | { |
||
| 160 | $this->color = $aColor; |
||
| 161 | if ($aFillColor) { |
||
| 162 | $this->SetFillColor($aFillColor); |
||
| 163 | $this->fill = true; |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | // Set href targets for CSIM |
||
| 168 | public function SetCSIMTargets($aTargets, $aAlts = null) |
||
| 169 | { |
||
| 170 | $this->csimtargets = $aTargets; |
||
| 171 | $this->csimalts = $aAlts; |
||
| 172 | } |
||
| 173 | |||
| 174 | // Get all created areas |
||
| 175 | public function GetCSIMareas() |
||
| 176 | { |
||
| 177 | return $this->csimareas; |
||
| 178 | } |
||
| 179 | |||
| 180 | public function Stroke($img, $pos, $scale, $startangle) |
||
| 181 | { |
||
| 182 | $nbrpnts = safe_count($this->data); |
||
| 183 | $astep = 2 * M_PI / $nbrpnts; |
||
| 184 | $a = $startangle; |
||
| 185 | |||
| 186 | for ($i = 0; $i < $nbrpnts; ++$i) { |
||
| 187 | // Rotate each non null point to the correct axis-angle |
||
| 188 | $cs = $scale->RelTranslate($this->data[$i]); |
||
| 189 | $x = round($cs * cos($a) + $scale->scale_abs[0]); |
||
| 190 | $y = round($pos - $cs * sin($a)); |
||
| 191 | |||
| 192 | $pnts[$i * 2] = $x; |
||
| 193 | $pnts[$i * 2 + 1] = $y; |
||
| 194 | |||
| 195 | // If the next point is null then we draw this polygon segment |
||
| 196 | // to the center, skip the next and draw the next segment from |
||
| 197 | // the center up to the point on the axis with the first non-null |
||
| 198 | // value and continues from that point. Some additoinal logic is necessary |
||
| 199 | // to handle the boundary conditions |
||
| 200 | if ($i < $nbrpnts - 1) { |
||
| 201 | if (is_null($this->data[$i + 1])) { |
||
| 202 | $cs = 0; |
||
| 203 | $x = round($cs * cos($a) + $scale->scale_abs[0]); |
||
| 204 | $y = round($pos - $cs * sin($a)); |
||
| 205 | $pnts[$i * 2] = $x; |
||
| 206 | $pnts[$i * 2 + 1] = $y; |
||
| 207 | $a += $astep; |
||
| 208 | } |
||
| 209 | } |
||
| 210 | |||
| 211 | $a += $astep; |
||
| 212 | } |
||
| 213 | |||
| 214 | if ($this->fill) { |
||
| 215 | $img->SetColor($this->fill_color); |
||
| 216 | $img->FilledPolygon($pnts); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 217 | } |
||
| 218 | |||
| 219 | $img->SetLineWeight($this->weight); |
||
| 220 | $img->SetColor($this->color); |
||
| 221 | $img->SetLineStyle($this->linestyle); |
||
| 222 | $pnts[] = $pnts[0]; |
||
| 223 | $pnts[] = $pnts[1]; |
||
| 224 | $img->Polygon($pnts); |
||
| 225 | $img->SetLineStyle('solid'); // Reset line style to default |
||
| 226 | |||
| 227 | // Add plotmarks on top |
||
| 228 | if ($this->mark->show) { |
||
| 229 | for ($i = 0; $i < $nbrpnts; ++$i) { |
||
| 230 | if (isset($this->csimtargets[$i])) { |
||
| 231 | $this->mark->SetCSIMTarget($this->csimtargets[$i]); |
||
| 232 | $this->mark->SetCSIMAlt($this->csimalts[$i]); |
||
| 233 | $this->mark->SetCSIMAltVal($pnts[$i * 2], $pnts[$i * 2 + 1]); |
||
| 234 | $this->mark->Stroke($img, $pnts[$i * 2], $pnts[$i * 2 + 1]); |
||
| 235 | $this->csimareas .= $this->mark->GetCSIMAreas(); |
||
| 236 | } else { |
||
| 237 | $this->mark->Stroke($img, $pnts[$i * 2], $pnts[$i * 2 + 1]); |
||
| 238 | } |
||
| 239 | } |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | public function GetCount() |
||
| 244 | { |
||
| 245 | return safe_count($this->data); |
||
| 246 | } |
||
| 247 | |||
| 248 | public function Legend($graph) |
||
| 249 | { |
||
| 250 | if ($this->legend == '') { |
||
| 251 | return; |
||
| 252 | } |
||
| 253 | if ($this->fill) { |
||
| 254 | $graph->legend->Add($this->legend, $this->fill_color, $this->mark); |
||
| 255 | } else { |
||
| 256 | $graph->legend->Add($this->legend, $this->color, $this->mark); |
||
| 257 | } |
||
| 258 | } |
||
| 259 | } // @class |
||
| 260 | |||
| 261 | /* EOF */ |
||
| 262 |