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