|
1
|
|
|
<?php |
|
2
|
|
|
namespace Amenadiel\JpGraph\Graph; |
|
3
|
|
|
|
|
4
|
|
|
use Amenadiel\JpGraph\Util; |
|
5
|
|
|
use \Amenadiel\JpGraph\ImgTrans; |
|
6
|
|
|
|
|
7
|
|
|
//=================================================== |
|
8
|
|
|
// CLASS RadarGraph |
|
9
|
|
|
// Description: Main container for a radar graph |
|
10
|
|
|
//=================================================== |
|
11
|
|
|
class RadarGraph extends Graph |
|
12
|
|
|
{ |
|
13
|
|
|
public $grid; |
|
14
|
|
|
public $axis = null; |
|
15
|
|
|
private $posx; |
|
16
|
|
|
private $posy; |
|
17
|
|
|
private $len; |
|
18
|
|
|
private $axis_title = null; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct($width = 300, $height = 200, $cachedName = "", $timeout = 0, $inline = 1) |
|
21
|
|
|
{ |
|
22
|
|
|
parent::__construct($width, $height, $cachedName, $timeout, $inline); |
|
|
|
|
|
|
23
|
|
|
$this->posx = $width / 2; |
|
24
|
|
|
$this->posy = $height / 2; |
|
25
|
|
|
$this->len = min($width, $height) * 0.35; |
|
26
|
|
|
$this->SetColor([255, 255, 255]); |
|
27
|
|
|
$this->SetTickDensity(TICKD_NORMAL); |
|
28
|
|
|
$this->SetScale('lin'); |
|
29
|
|
|
$this->SetGridDepth(DEPTH_FRONT); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function HideTickMarks($aFlag = true) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->axis->scale->ticks->SupressTickMarks($aFlag); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function ShowMinorTickmarks($aFlag = true) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->yscale->ticks->SupressMinorTickMarks(!$aFlag); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function SetScale($axtype, $ymin = 1, $ymax = 1, $dummy1 = null, $dumy2 = null) |
|
43
|
|
|
{ |
|
44
|
|
|
if ($axtype != 'lin' && $axtype != 'log') { |
|
45
|
|
|
Util\JpGraphError::RaiseL(18003, $axtype); |
|
46
|
|
|
//("Illegal scale for radarplot ($axtype). Must be \"lin\" or \"log\""); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
if ($axtype == 'lin') { |
|
49
|
|
|
$this->yscale = new LinearScale($ymin, $ymax); |
|
50
|
|
|
$this->yscale->ticks = new RadarLinearTicks(); |
|
51
|
|
|
$this->yscale->ticks->SupressMinorTickMarks(); |
|
52
|
|
|
} elseif ($axtype == 'log') { |
|
53
|
|
|
$this->yscale = new LogScale($ymin, $ymax); |
|
54
|
|
|
$this->yscale->ticks = new RadarLogTicks(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->axis = new RadarAxis($this->img, $this->yscale); |
|
58
|
|
|
$this->grid = new RadarGrid(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function SetSize($aSize) |
|
62
|
|
|
{ |
|
63
|
|
|
if ($aSize < 0.1 || $aSize > 1) { |
|
64
|
|
|
Util\JpGraphError::RaiseL(18004, $aSize); |
|
65
|
|
|
//("Radar Plot size must be between 0.1 and 1. (Your value=$s)"); |
|
66
|
|
|
} |
|
67
|
|
|
$this->len = min($this->img->width, $this->img->height) * $aSize / 2; |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function SetPlotSize($aSize) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->SetSize($aSize); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function SetTickDensity($densy = TICKD_NORMAL, $dummy1 = null) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->ytick_factor = 25; |
|
78
|
|
View Code Duplication |
switch ($densy) { |
|
|
|
|
|
|
79
|
|
|
case TICKD_DENSE: |
|
80
|
|
|
$this->ytick_factor = 12; |
|
81
|
|
|
break; |
|
82
|
|
|
case TICKD_NORMAL: |
|
83
|
|
|
$this->ytick_factor = 25; |
|
84
|
|
|
break; |
|
85
|
|
|
case TICKD_SPARSE: |
|
86
|
|
|
$this->ytick_factor = 40; |
|
87
|
|
|
break; |
|
88
|
|
|
case TICKD_VERYSPARSE: |
|
89
|
|
|
$this->ytick_factor = 70; |
|
90
|
|
|
break; |
|
91
|
|
|
default: |
|
92
|
|
|
Util\JpGraphError::RaiseL(18005, $densy); |
|
93
|
|
|
//("RadarPlot Unsupported Tick density: $densy"); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function SetPos($px, $py = 0.5) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->SetCenter($px, $py); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function SetCenter($px, $py = 0.5) |
|
103
|
|
|
{ |
|
104
|
|
|
if ($px >= 0 && $px <= 1) { |
|
105
|
|
|
$this->posx = $this->img->width * $px; |
|
|
|
|
|
|
106
|
|
|
} else { |
|
107
|
|
|
$this->posx = $px; |
|
108
|
|
|
} |
|
109
|
|
|
if ($py >= 0 && $py <= 1) { |
|
110
|
|
|
$this->posy = $this->img->height * $py; |
|
|
|
|
|
|
111
|
|
|
} else { |
|
112
|
|
|
$this->posy = $py; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function SetColor($aColor) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->SetMarginColor($aColor); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function SetTitles($aTitleArray) |
|
122
|
|
|
{ |
|
123
|
|
|
$this->axis_title = $aTitleArray; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function Add($aPlot) |
|
127
|
|
|
{ |
|
128
|
|
|
if ($aPlot == null) { |
|
129
|
|
|
Util\JpGraphError::RaiseL(25010); //("Graph::Add() You tried to add a null plot to the graph."); |
|
130
|
|
|
} |
|
131
|
|
View Code Duplication |
if (is_array($aPlot) && count($aPlot) > 0) { |
|
|
|
|
|
|
132
|
|
|
$cl = $aPlot[0]; |
|
133
|
|
|
} else { |
|
134
|
|
|
$cl = $aPlot; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
View Code Duplication |
if ($cl instanceof Text) { |
|
|
|
|
|
|
138
|
|
|
$this->AddText($aPlot); |
|
139
|
|
|
} elseif (class_exists('IconPlot', false) && ($cl instanceof IconPlot)) { |
|
|
|
|
|
|
140
|
|
|
$this->AddIcon($aPlot); |
|
141
|
|
|
} else { |
|
142
|
|
|
$this->plots[] = $aPlot; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function GetPlotsYMinMax($aPlots) |
|
147
|
|
|
{ |
|
148
|
|
|
$min = $aPlots[0]->Min(); |
|
149
|
|
|
$max = $aPlots[0]->Max(); |
|
150
|
|
|
foreach ($this->plots as $p) { |
|
151
|
|
|
$max = max($max, $p->Max()); |
|
152
|
|
|
$min = min($min, $p->Min()); |
|
153
|
|
|
} |
|
154
|
|
|
if ($min < 0) { |
|
155
|
|
|
Util\JpGraphError::RaiseL(18006, $min); |
|
156
|
|
|
//("Minimum data $min (Radar plots should only be used when all data points > 0)"); |
|
157
|
|
|
} |
|
158
|
|
|
return [$min, $max]; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
View Code Duplication |
public function StrokeIcons() |
|
|
|
|
|
|
162
|
|
|
{ |
|
163
|
|
|
if ($this->iIcons != null) { |
|
164
|
|
|
$n = count($this->iIcons); |
|
165
|
|
|
for ($i = 0; $i < $n; ++$i) { |
|
166
|
|
|
$this->iIcons[$i]->Stroke($this->img); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
View Code Duplication |
public function StrokeTexts() |
|
|
|
|
|
|
172
|
|
|
{ |
|
173
|
|
|
if ($this->texts != null) { |
|
174
|
|
|
$n = count($this->texts); |
|
175
|
|
|
for ($i = 0; $i < $n; ++$i) { |
|
176
|
|
|
$this->texts[$i]->Stroke($this->img); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
// Stroke the Radar graph |
|
182
|
|
|
public function Stroke($aStrokeFileName = '') |
|
183
|
|
|
{ |
|
184
|
|
|
|
|
185
|
|
|
// If the filename is the predefined value = '_csim_special_' |
|
186
|
|
|
// we assume that the call to stroke only needs to do enough |
|
187
|
|
|
// to correctly generate the CSIM maps. |
|
188
|
|
|
// We use this variable to skip things we don't strictly need |
|
189
|
|
|
// to do to generate the image map to improve performance |
|
190
|
|
|
// a best we can. Therefor you will see a lot of tests !$_csim in the |
|
191
|
|
|
// code below. |
|
192
|
|
|
$_csim = ($aStrokeFileName === _CSIM_SPECIALFILE); |
|
193
|
|
|
|
|
194
|
|
|
// We need to know if we have stroked the plot in the |
|
195
|
|
|
// GetCSIMareas. Otherwise the CSIM hasn't been generated |
|
196
|
|
|
// and in the case of GetCSIM called before stroke to generate |
|
197
|
|
|
// CSIM without storing an image to disk GetCSIM must call Stroke. |
|
198
|
|
|
$this->iHasStroked = true; |
|
199
|
|
|
|
|
200
|
|
|
$n = count($this->plots); |
|
201
|
|
|
// Set Y-scale |
|
202
|
|
|
|
|
203
|
|
|
if (!$this->yscale->IsSpecified() && count($this->plots) > 0) { |
|
204
|
|
|
list($min, $max) = $this->GetPlotsYMinMax($this->plots); |
|
|
|
|
|
|
205
|
|
|
$this->yscale->AutoScale($this->img, 0, $max, $this->len / $this->ytick_factor); |
|
206
|
|
|
} elseif ($this->yscale->IsSpecified() && |
|
207
|
|
|
($this->yscale->auto_ticks || !$this->yscale->ticks->IsSpecified())) { |
|
208
|
|
|
|
|
209
|
|
|
// The tick calculation will use the user suplied min/max values to determine |
|
210
|
|
|
// the ticks. If auto_ticks is false the exact user specifed min and max |
|
211
|
|
|
// values will be used for the scale. |
|
212
|
|
|
// If auto_ticks is true then the scale might be slightly adjusted |
|
213
|
|
|
// so that the min and max values falls on an even major step. |
|
214
|
|
|
$min = $this->yscale->scale[0]; |
|
215
|
|
|
$max = $this->yscale->scale[1]; |
|
216
|
|
|
$this->yscale->AutoScale($this->img, $min, $max, |
|
217
|
|
|
$this->len / $this->ytick_factor, |
|
218
|
|
|
$this->yscale->auto_ticks); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
// Set start position end length of scale (in absolute pixels) |
|
222
|
|
|
$this->yscale->SetConstants($this->posx, $this->len); |
|
223
|
|
|
|
|
224
|
|
|
// We need as many axis as there are data points |
|
225
|
|
|
$nbrpnts = $this->plots[0]->GetCount(); |
|
226
|
|
|
|
|
227
|
|
|
// If we have no titles just number the axis 1,2,3,... |
|
228
|
|
|
if ($this->axis_title == null) { |
|
229
|
|
|
for ($i = 0; $i < $nbrpnts; ++$i) { |
|
230
|
|
|
$this->axis_title[$i] = $i + 1; |
|
231
|
|
|
} |
|
232
|
|
|
} elseif (count($this->axis_title) < $nbrpnts) { |
|
233
|
|
|
Util\JpGraphError::RaiseL(18007); |
|
234
|
|
|
// ("Number of titles does not match number of points in plot."); |
|
235
|
|
|
} |
|
236
|
|
|
for ($i = 0; $i < $n; ++$i) { |
|
237
|
|
|
if ($nbrpnts != $this->plots[$i]->GetCount()) { |
|
238
|
|
|
Util\JpGraphError::RaiseL(18008); |
|
239
|
|
|
//("Each radar plot must have the same number of data points."); |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
if (!$_csim) { |
|
244
|
|
|
if ($this->background_image != '') { |
|
245
|
|
|
$this->StrokeFrameBackground(); |
|
246
|
|
|
} else { |
|
247
|
|
|
$this->StrokeFrame(); |
|
248
|
|
|
$this->StrokeBackgroundGrad(); |
|
249
|
|
|
} |
|
250
|
|
|
} |
|
251
|
|
|
$astep = 2 * M_PI / $nbrpnts; |
|
|
|
|
|
|
252
|
|
|
|
|
253
|
|
|
if (!$_csim) { |
|
254
|
|
|
if ($this->iIconDepth == DEPTH_BACK) { |
|
255
|
|
|
$this->StrokeIcons(); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
// Prepare legends |
|
259
|
|
|
for ($i = 0; $i < $n; ++$i) { |
|
260
|
|
|
$this->plots[$i]->Legend($this); |
|
261
|
|
|
} |
|
262
|
|
|
$this->legend->Stroke($this->img); |
|
263
|
|
|
$this->footer->Stroke($this->img); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
if (!$_csim) { |
|
267
|
|
View Code Duplication |
if ($this->grid_depth == DEPTH_BACK) { |
|
|
|
|
|
|
268
|
|
|
// Draw axis and grid |
|
269
|
|
|
for ($i = 0, $a = M_PI / 2; $i < $nbrpnts; ++$i, $a += $astep) { |
|
270
|
|
|
$this->axis->Stroke($this->posy, $a, $grid[$i], $this->axis_title[$i], $i == 0); |
|
|
|
|
|
|
271
|
|
|
} |
|
272
|
|
|
$this->grid->Stroke($this->img, $grid); |
|
273
|
|
|
} |
|
274
|
|
|
if ($this->iIconDepth == DEPTH_BACK) { |
|
275
|
|
|
$this->StrokeIcons(); |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
// Plot points |
|
280
|
|
|
$a = M_PI / 2; |
|
281
|
|
View Code Duplication |
for ($i = 0; $i < $n; ++$i) { |
|
|
|
|
|
|
282
|
|
|
$this->plots[$i]->Stroke($this->img, $this->posy, $this->yscale, $a); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
if (!$_csim) { |
|
286
|
|
View Code Duplication |
if ($this->grid_depth != DEPTH_BACK) { |
|
|
|
|
|
|
287
|
|
|
// Draw axis and grid |
|
288
|
|
|
for ($i = 0, $a = M_PI / 2; $i < $nbrpnts; ++$i, $a += $astep) { |
|
289
|
|
|
$this->axis->Stroke($this->posy, $a, $grid[$i], $this->axis_title[$i], $i == 0); |
|
290
|
|
|
} |
|
291
|
|
|
$this->grid->Stroke($this->img, $grid); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
$this->StrokeTitles(); |
|
295
|
|
|
$this->StrokeTexts(); |
|
296
|
|
|
if ($this->iIconDepth == DEPTH_FRONT) { |
|
297
|
|
|
$this->StrokeIcons(); |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
// Should we do any final image transformation |
|
302
|
|
View Code Duplication |
if ($this->iImgTrans && !$_csim) { |
|
|
|
|
|
|
303
|
|
|
$tform = new ImgTrans($this->img->img); |
|
304
|
|
|
$this->img->img = $tform->Skew3D($this->iImgTransHorizon, $this->iImgTransSkewDist, |
|
305
|
|
|
$this->iImgTransDirection, $this->iImgTransHighQ, |
|
306
|
|
|
$this->iImgTransMinSize, $this->iImgTransFillColor, |
|
307
|
|
|
$this->iImgTransBorder); |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
View Code Duplication |
if (!$_csim) { |
|
|
|
|
|
|
311
|
|
|
// If the filename is given as the special "__handle" |
|
312
|
|
|
// then the image handler is returned and the image is NOT |
|
313
|
|
|
// streamed back |
|
314
|
|
|
if ($aStrokeFileName == _IMG_HANDLER) { |
|
315
|
|
|
return $this->img->img; |
|
316
|
|
|
} else { |
|
317
|
|
|
// Finally stream the generated picture |
|
318
|
|
|
$this->cache->PutAndStream($this->img, $this->cache_name, $this->inline, $aStrokeFileName); |
|
319
|
|
|
} |
|
320
|
|
|
} |
|
321
|
|
|
} |
|
322
|
|
|
} // Class |
|
323
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: