1 | <?php |
||
2 | |||
3 | /** |
||
4 | * JPGraph v4.0.3 |
||
5 | */ |
||
6 | |||
7 | namespace Amenadiel\JpGraph\Graph; |
||
8 | |||
9 | use Amenadiel\JpGraph\Util; |
||
10 | |||
11 | class PolarGraph extends Graph |
||
12 | { |
||
13 | public $scale; |
||
14 | public $axis; |
||
15 | public $iType = POLAR_360; |
||
16 | private $iClockwise = false; |
||
17 | |||
18 | public function __construct($aWidth = 300, $aHeight = 200, $aCachedName = '', $aTimeOut = 0, $aInline = true) |
||
19 | { |
||
20 | parent::__construct($aWidth, $aHeight, $aCachedName, $aTimeOut, $aInline); |
||
21 | $this->SetDensity(TICKD_DENSE); |
||
22 | $this->SetBox(); |
||
23 | $this->SetMarginColor('white'); |
||
24 | } |
||
25 | |||
26 | public function SetDensity($aDense) |
||
27 | { |
||
28 | $this->SetTickDensity(TICKD_NORMAL, $aDense); |
||
29 | } |
||
30 | |||
31 | public function SetClockwise($aFlg) |
||
32 | { |
||
33 | $this->scale->SetClockwise($aFlg); |
||
34 | } |
||
35 | |||
36 | public function Set90AndMargin($lm = 0, $rm = 0, $tm = 0, $bm = 0) |
||
37 | { |
||
38 | $adj = ($this->img->height - $this->img->width) / 2; |
||
39 | $this->SetAngle(90); |
||
40 | $lm2 = -$adj + ($lm - $rm + $tm + $bm) / 2; |
||
41 | $rm2 = -$adj + (-$lm + $rm + $tm + $bm) / 2; |
||
42 | $tm2 = $adj + ($tm - $bm + $lm + $rm) / 2; |
||
43 | $bm2 = $adj + (-$tm + $bm + $lm + $rm) / 2; |
||
44 | $this->SetMargin($lm2, $rm2, $tm2, $bm2); |
||
45 | $this->axis->SetLabelAlign('right', 'center'); |
||
46 | } |
||
47 | |||
48 | public function SetScale($aScale, $rmax = 0, $dummy1 = 1, $dummy2 = 1, $dummy3 = 1) |
||
49 | { |
||
50 | if ($aScale == 'lin') { |
||
51 | $this->scale = new PolarScale($rmax, $this, $this->iClockwise); |
||
52 | } elseif ($aScale == 'log') { |
||
53 | $this->scale = new PolarLogScale($rmax, $this, $this->iClockwise); |
||
54 | } else { |
||
55 | Util\JpGraphError::RaiseL(17004); //('Unknown scale type for polar graph. Must be "lin" or "log"'); |
||
56 | } |
||
57 | |||
58 | $this->axis = new PolarAxis($this->img, $this->scale); |
||
59 | $this->SetMargin(40, 40, 50, 40); |
||
60 | } |
||
61 | |||
62 | public function SetType($aType) |
||
63 | { |
||
64 | $this->iType = $aType; |
||
65 | } |
||
66 | |||
67 | public function SetPlotSize($w, $h) |
||
68 | { |
||
69 | $this->SetMargin( |
||
70 | ($this->img->width - $w) / 2, |
||
71 | ($this->img->width - $w) / 2, |
||
72 | ($this->img->height - $h) / 2, |
||
73 | ($this->img->height - $h) / 2 |
||
74 | ); |
||
75 | } |
||
76 | |||
77 | // Private methods |
||
78 | public function GetPlotsMax() |
||
79 | { |
||
80 | $n = safe_count($this->plots); |
||
81 | $m = $this->plots[0]->Max(); |
||
82 | $i = 1; |
||
83 | while ($i < $n) { |
||
84 | $m = max($this->plots[$i]->Max(), $m); |
||
85 | ++$i; |
||
86 | } |
||
87 | |||
88 | return $m; |
||
89 | } |
||
90 | |||
91 | public function Stroke($aStrokeFileName = '') |
||
92 | { |
||
93 | // Start by adjusting the margin so that potential titles will fit. |
||
94 | $this->AdjustMarginsForTitles(); |
||
95 | |||
96 | // If the filename is the predefined value = '_csim_special_' |
||
97 | // we assume that the call to stroke only needs to do enough |
||
98 | // to correctly generate the CSIM maps. |
||
99 | // We use this variable to skip things we don't strictly need |
||
100 | // to do to generate the image map to improve performance |
||
101 | // a best we can. Therefor you will see a lot of tests !$_csim in the |
||
102 | // code below. |
||
103 | $_csim = ($aStrokeFileName === _CSIM_SPECIALFILE); |
||
104 | |||
105 | // We need to know if we have stroked the plot in the |
||
106 | // GetCSIMareas. Otherwise the CSIM hasn't been generated |
||
107 | // and in the case of GetCSIM called before stroke to generate |
||
108 | // CSIM without storing an image to disk GetCSIM must call Stroke. |
||
109 | $this->iHasStroked = true; |
||
110 | |||
111 | //Check if we should autoscale axis |
||
112 | if (!$this->scale->IsSpecified() && safe_count($this->plots) > 0) { |
||
113 | $max = $this->GetPlotsMax(); |
||
114 | $t1 = $this->img->plotwidth; |
||
115 | $this->img->plotwidth /= 2; |
||
116 | $t2 = $this->img->left_margin; |
||
117 | $this->img->left_margin += $this->img->plotwidth + 1; |
||
118 | $this->scale->AutoScale( |
||
119 | $this->img, |
||
120 | 0, |
||
121 | $max, |
||
122 | $this->img->plotwidth / $this->xtick_factor / 2 |
||
123 | ); |
||
124 | $this->img->plotwidth = $t1; |
||
125 | $this->img->left_margin = $t2; |
||
126 | } else { |
||
127 | // The tick calculation will use the user suplied min/max values to determine |
||
128 | // the ticks. If auto_ticks is false the exact user specifed min and max |
||
129 | // values will be used for the scale. |
||
130 | // If auto_ticks is true then the scale might be slightly adjusted |
||
131 | // so that the min and max values falls on an even major step. |
||
132 | //$min = 0; |
||
133 | $max = $this->scale->scale[1]; |
||
134 | $t1 = $this->img->plotwidth; |
||
135 | $this->img->plotwidth /= 2; |
||
136 | $t2 = $this->img->left_margin; |
||
137 | $this->img->left_margin += $this->img->plotwidth + 1; |
||
138 | $this->scale->AutoScale( |
||
139 | $this->img, |
||
140 | 0, |
||
141 | $max, |
||
142 | $this->img->plotwidth / $this->xtick_factor / 2 |
||
143 | ); |
||
144 | $this->img->plotwidth = $t1; |
||
145 | $this->img->left_margin = $t2; |
||
146 | } |
||
147 | |||
148 | if ($this->iType == POLAR_180) { |
||
149 | $pos = $this->img->height - $this->img->bottom_margin; |
||
150 | } else { |
||
151 | $pos = $this->img->plotheight / 2 + $this->img->top_margin; |
||
152 | } |
||
153 | |||
154 | if (!$_csim) { |
||
155 | $this->StrokePlotArea(); |
||
156 | } |
||
157 | |||
158 | $this->iDoClipping = true; |
||
159 | |||
160 | if ($this->iDoClipping) { |
||
161 | $oldimage = $this->img->CloneCanvasH(); |
||
162 | } |
||
163 | |||
164 | if (!$_csim) { |
||
165 | $this->axis->StrokeGrid($pos); |
||
166 | } |
||
167 | |||
168 | // Stroke all plots for Y1 axis |
||
169 | for ($i = 0; $i < safe_count($this->plots); ++$i) { |
||
170 | $this->plots[$i]->Stroke($this->img, $this->scale); |
||
171 | } |
||
172 | |||
173 | if ($this->iDoClipping) { |
||
174 | // Clipping only supports graphs at 0 and 90 degrees |
||
175 | if ($this->img->a == 0) { |
||
176 | $this->img->CopyCanvasH( |
||
177 | $oldimage, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
178 | $this->img->img, |
||
179 | $this->img->left_margin, |
||
180 | $this->img->top_margin, |
||
181 | $this->img->left_margin, |
||
182 | $this->img->top_margin, |
||
183 | $this->img->plotwidth + 1, |
||
184 | $this->img->plotheight + 1 |
||
185 | ); |
||
186 | } elseif ($this->img->a == 90) { |
||
187 | $adj1 = round(($this->img->height - $this->img->width) / 2); |
||
188 | $adj2 = round(($this->img->width - $this->img->height) / 2); |
||
189 | $lm = $this->img->left_margin; |
||
190 | $rm = $this->img->right_margin; |
||
191 | $tm = $this->img->top_margin; |
||
192 | $bm = $this->img->bottom_margin; |
||
193 | $this->img->CopyCanvasH( |
||
194 | $oldimage, |
||
195 | $this->img->img, |
||
196 | $adj2 + round(($lm - $rm + $tm + $bm) / 2), |
||
197 | $adj1 + round(($tm - $bm + $lm + $rm) / 2), |
||
198 | $adj2 + round(($lm - $rm + $tm + $bm) / 2), |
||
199 | $adj1 + round(($tm - $bm + $lm + $rm) / 2), |
||
200 | $this->img->plotheight + 1, |
||
201 | $this->img->plotwidth + 1 |
||
202 | ); |
||
203 | } |
||
204 | $this->img->Destroy(); |
||
205 | $this->img->SetCanvasH($oldimage); |
||
206 | } |
||
207 | |||
208 | if (!$_csim) { |
||
209 | $this->axis->Stroke($pos); |
||
210 | $this->axis->StrokeAngleLabels($pos, $this->iType); |
||
211 | } |
||
212 | |||
213 | if (!$_csim) { |
||
214 | $this->StrokePlotBox(); |
||
215 | $this->footer->Stroke($this->img); |
||
216 | |||
217 | // The titles and legends never gets rotated so make sure |
||
218 | // that the angle is 0 before stroking them |
||
219 | $aa = $this->img->SetAngle(0); |
||
220 | $this->StrokeTitles(); |
||
221 | } |
||
222 | |||
223 | for ($i = 0; $i < safe_count($this->plots); ++$i) { |
||
224 | $this->plots[$i]->Legend($this); |
||
225 | } |
||
226 | |||
227 | $this->legend->Stroke($this->img); |
||
228 | |||
229 | if (!$_csim) { |
||
230 | $this->StrokeTexts(); |
||
231 | $this->img->SetAngle($aa); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
232 | |||
233 | // Draw an outline around the image map |
||
234 | if (_JPG_DEBUG) { |
||
235 | $this->DisplayClientSideaImageMapAreas(); |
||
236 | } |
||
237 | |||
238 | // If the filename is given as the special "__handle" |
||
239 | // then the image handler is returned and the image is NOT |
||
240 | // streamed back |
||
241 | if ($aStrokeFileName == _IMG_HANDLER) { |
||
242 | return $this->img->img; |
||
243 | } |
||
244 | // Finally stream the generated picture |
||
245 | $this->cache->PutAndStream($this->img, $this->cache_name, $this->inline, $aStrokeFileName); |
||
246 | } |
||
247 | } |
||
248 | } |
||
249 |