| Conditions | 14 |
| Paths | 128 |
| Total Lines | 135 |
| Code Lines | 95 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 130 | private function Init() |
||
| 131 | { |
||
| 132 | // Setup limits for color indications |
||
| 133 | $lowx = $this->iXMin; |
||
| 134 | $highx = $this->iXMax; |
||
| 135 | $lowy = $this->iYMin; |
||
| 136 | $highy = $this->iYMax; |
||
| 137 | $width = $this->iWidth; |
||
| 138 | $height = $this->iHeight; |
||
| 139 | |||
| 140 | // Margins |
||
| 141 | $lm = 50; |
||
| 142 | $rm = 40; |
||
| 143 | $tm = 60; |
||
| 144 | $bm = 40; |
||
| 145 | |||
| 146 | if ($width <= 300 || $height <= 250) { |
||
| 147 | $labelsize = 8; |
||
| 148 | $lm = 25; |
||
| 149 | $rm = 25; |
||
| 150 | $tm = 45; |
||
| 151 | $bm = 25; |
||
| 152 | } elseif ($width <= 450 || $height <= 300) { |
||
| 153 | $labelsize = 8; |
||
| 154 | $lm = 30; |
||
| 155 | $rm = 30; |
||
| 156 | $tm = 50; |
||
| 157 | $bm = 30; |
||
| 158 | } elseif ($width <= 600 || $height <= 400) { |
||
| 159 | $labelsize = 9; |
||
| 160 | } else { |
||
| 161 | $labelsize = 11; |
||
| 162 | } |
||
| 163 | |||
| 164 | if ($this->iSubTitle == '') { |
||
| 165 | $tm -= $labelsize + 4; |
||
| 166 | } |
||
| 167 | |||
| 168 | $graph = new Graph($width, $height); |
||
| 169 | $graph->clearTheme(); |
||
| 170 | $graph->SetScale('intint', $lowy, $highy, $lowx, $highx); |
||
| 171 | $graph->SetMargin($lm, $rm, $tm, $bm); |
||
| 172 | $graph->SetMarginColor($this->iMarginColor[$this->iColorMap]); |
||
| 173 | $graph->SetClipping(); |
||
| 174 | |||
| 175 | $graph->title->Set($this->iTitle); |
||
| 176 | $graph->subtitle->Set($this->iSubTitle); |
||
| 177 | |||
| 178 | $graph->title->SetFont(FF_ARIAL, FS_BOLD, $labelsize + 4); |
||
| 179 | $graph->subtitle->SetFont(FF_ARIAL, FS_BOLD, $labelsize + 1); |
||
| 180 | |||
| 181 | $graph->SetBox(true, '[email protected]'); |
||
| 182 | |||
| 183 | $graph->xaxis->SetFont(FF_ARIAL, FS_BOLD, $labelsize); |
||
| 184 | $graph->yaxis->SetFont(FF_ARIAL, FS_BOLD, $labelsize); |
||
| 185 | |||
| 186 | $graph->xaxis->scale->ticks->Set(CCBPGraph::TickStep, CCBPGraph::TickStep); |
||
| 187 | $graph->yaxis->scale->ticks->Set(CCBPGraph::TickStep, CCBPGraph::TickStep); |
||
| 188 | |||
| 189 | $graph->xaxis->HideZeroLabel(); |
||
| 190 | $graph->yaxis->HideZeroLabel(); |
||
| 191 | |||
| 192 | $graph->xaxis->SetLabelFormatString('%d%%'); |
||
| 193 | $graph->yaxis->SetLabelFormatString('%d%%'); |
||
| 194 | |||
| 195 | // For the x-axis we adjust the color so labels on the left of the Y-axis are in black |
||
| 196 | $n1 = floor(abs($this->iXMin / 25)) + 1; |
||
| 197 | $n2 = floor($this->iXMax / 25); |
||
| 198 | if ($this->iColorMap == 0) { |
||
| 199 | $xlcolors = []; |
||
| 200 | for ($i = 0; $i < $n1; ++$i) { |
||
| 201 | $xlcolors[$i] = 'black'; |
||
| 202 | } |
||
| 203 | for ($i = 0; $i < $n2; ++$i) { |
||
| 204 | $xlcolors[$n1 + $i] = 'lightgray:1.5'; |
||
| 205 | } |
||
| 206 | $graph->xaxis->SetColor('gray', $xlcolors); |
||
| 207 | $graph->yaxis->SetColor('gray', 'lightgray:1.5'); |
||
| 208 | } else { |
||
| 209 | $graph->xaxis->SetColor('darkgray', 'darkgray:0.8'); |
||
| 210 | $graph->yaxis->SetColor('darkgray', 'darkgray:0.8'); |
||
| 211 | } |
||
| 212 | $graph->SetGridDepth(DEPTH_FRONT); |
||
| 213 | $graph->ygrid->SetColor('[email protected]'); |
||
| 214 | $graph->ygrid->SetLineStyle('dotted'); |
||
| 215 | |||
| 216 | $graph->ygrid->Show(); |
||
| 217 | |||
| 218 | $graph->xaxis->SetWeight(1); |
||
| 219 | $graph->yaxis->SetWeight(1); |
||
| 220 | |||
| 221 | $ytitle = new Text\Text(CCBPGraph::YTitle, floor($lm * .75), ($height - $tm - $bm) / 2 + $tm); |
||
| 222 | #$ytitle->SetFont(FF_VERA,FS_BOLD,$labelsize+1); |
||
| 223 | $ytitle->SetAlign('right', 'center'); |
||
| 224 | $ytitle->SetAngle(90); |
||
| 225 | $graph->Add($ytitle); |
||
| 226 | |||
| 227 | $xtitle = new Text\Text(CCBPGraph::XTitle, ($width - $lm - $rm) / 2 + $lm, $height - 10); |
||
| 228 | #$xtitle->SetFont(FF_VERA,FS_BOLD,$labelsize); |
||
| 229 | $xtitle->SetAlign('center', 'bottom'); |
||
| 230 | $graph->Add($xtitle); |
||
| 231 | |||
| 232 | $df = 'D j:S M, Y'; |
||
| 233 | if ($width < 400) { |
||
| 234 | $df = 'D j:S M'; |
||
| 235 | } |
||
| 236 | |||
| 237 | $time = new Text\Text(date($df), $width - 10, $height - 10); |
||
| 238 | $time->SetAlign('right', 'bottom'); |
||
| 239 | #$time->SetFont(FF_VERA,FS_NORMAL,$labelsize-1); |
||
| 240 | $time->SetColor('darkgray'); |
||
| 241 | $graph->Add($time); |
||
| 242 | |||
| 243 | // Use an accumulated fille line graph to create the colored bands |
||
| 244 | |||
| 245 | $n = 3; |
||
| 246 | for ($i = 0; $i < $n; ++$i) { |
||
| 247 | $b = $this->iColorInd[$i][0]; |
||
| 248 | $k = ($this->iColorInd[$i][1] - $this->iColorInd[$i][0]) / $this->iXMax; |
||
| 249 | $colarea[$i] = [[$lowx, $lowx * $k + $b], [$highx, $highx * $k + $b]]; |
||
| 250 | } |
||
| 251 | $colarea[3] = [[$lowx, $highy], [$highx, $highy]]; |
||
| 252 | |||
| 253 | $cb = []; |
||
| 254 | for ($i = 0; $i < 4; ++$i) { |
||
| 255 | $cb[$i] = new Plot\LinePlot( |
||
| 256 | [$colarea[$i][0][1], $colarea[$i][1][1]], |
||
|
|
|||
| 257 | [$colarea[$i][0][0], $colarea[$i][1][0]] |
||
| 258 | ); |
||
| 259 | $cb[$i]->SetFillColor($this->iColorSpec[$this->iColorMap][$i]); |
||
| 260 | $cb[$i]->SetFillFromYMin(); |
||
| 261 | } |
||
| 262 | |||
| 263 | $graph->Add(array_slice(array_reverse($cb), 0, 4)); |
||
| 264 | $this->graph = $graph; |
||
| 265 | } |
||
| 295 |