| Conditions | 14 |
| Paths | 128 |
| Total Lines | 133 |
| Code Lines | 93 |
| 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 // content="text/plain; charset=utf-8" |
||
| 118 | private function Init() |
||
| 119 | { |
||
| 120 | |||
| 121 | // Setup limits for color indications |
||
| 122 | $lowx = $this->iXMin; |
||
| 123 | $highx = $this->iXMax; |
||
| 124 | $lowy = $this->iYMin; |
||
| 125 | $highy = $this->iYMax; |
||
| 126 | $width = $this->iWidth; |
||
| 127 | $height = $this->iHeight; |
||
| 128 | |||
| 129 | // Margins |
||
| 130 | $lm = 50; |
||
| 131 | $rm = 40; |
||
| 132 | $tm = 60; |
||
| 133 | $bm = 40; |
||
| 134 | |||
| 135 | if ($width <= 300 || $height <= 250) { |
||
| 136 | $labelsize = 8; |
||
| 137 | $lm = 25; |
||
| 138 | $rm = 25; |
||
| 139 | $tm = 45; |
||
| 140 | $bm = 25; |
||
| 141 | } elseif ($width <= 450 || $height <= 300) { |
||
| 142 | $labelsize = 8; |
||
| 143 | $lm = 30; |
||
| 144 | $rm = 30; |
||
| 145 | $tm = 50; |
||
| 146 | $bm = 30; |
||
| 147 | } elseif ($width <= 600 || $height <= 400) { |
||
| 148 | $labelsize = 9; |
||
| 149 | } else { |
||
| 150 | $labelsize = 11; |
||
| 151 | } |
||
| 152 | |||
| 153 | if ($this->iSubTitle == '') { |
||
| 154 | $tm -= $labelsize + 4; |
||
| 155 | } |
||
| 156 | |||
| 157 | $graph = new Graph\Graph($width, $height); |
||
| 158 | $graph->SetScale('intint', $lowy, $highy, $lowx, $highx); |
||
| 159 | $graph->SetMargin($lm, $rm, $tm, $bm); |
||
| 160 | $graph->SetMarginColor($this->iMarginColor[$this->iColorMap]); |
||
| 161 | $graph->SetClipping(); |
||
| 162 | |||
| 163 | $graph->title->Set($this->iTitle); |
||
| 164 | $graph->subtitle->Set($this->iSubTitle); |
||
| 165 | |||
| 166 | $graph->title->SetFont(FF_ARIAL, FS_BOLD, $labelsize + 4); |
||
| 167 | $graph->subtitle->SetFont(FF_ARIAL, FS_BOLD, $labelsize + 1); |
||
| 168 | |||
| 169 | $graph->SetBox(true, '[email protected]'); |
||
| 170 | |||
| 171 | $graph->xaxis->SetFont(FF_ARIAL, FS_BOLD, $labelsize); |
||
| 172 | $graph->yaxis->SetFont(FF_ARIAL, FS_BOLD, $labelsize); |
||
| 173 | |||
| 174 | $graph->xaxis->scale->ticks->Set(CCBPGraph::TickStep, CCBPGraph::TickStep); |
||
| 175 | $graph->yaxis->scale->ticks->Set(CCBPGraph::TickStep, CCBPGraph::TickStep); |
||
| 176 | |||
| 177 | $graph->xaxis->HideZeroLabel(); |
||
| 178 | $graph->yaxis->HideZeroLabel(); |
||
| 179 | |||
| 180 | $graph->xaxis->SetLabelFormatString('%d%%'); |
||
| 181 | $graph->yaxis->SetLabelFormatString('%d%%'); |
||
| 182 | |||
| 183 | // For the x-axis we adjust the color so labels on the left of the Y-axis are in black |
||
| 184 | $n1 = floor(abs($this->iXMin / 25)) + 1; |
||
| 185 | $n2 = floor($this->iXMax / 25); |
||
| 186 | if ($this->iColorMap == 0) { |
||
| 187 | $xlcolors = array(); |
||
| 188 | for ($i = 0; $i < $n1; ++$i) { |
||
| 189 | $xlcolors[$i] = 'black'; |
||
| 190 | } |
||
| 191 | for ($i = 0; $i < $n2; ++$i) { |
||
| 192 | $xlcolors[$n1 + $i] = 'lightgray:1.5'; |
||
| 193 | } |
||
| 194 | $graph->xaxis->SetColor('gray', $xlcolors); |
||
| 195 | $graph->yaxis->SetColor('gray', 'lightgray:1.5'); |
||
| 196 | } else { |
||
| 197 | $graph->xaxis->SetColor('darkgray', 'darkgray:0.8'); |
||
| 198 | $graph->yaxis->SetColor('darkgray', 'darkgray:0.8'); |
||
| 199 | } |
||
| 200 | $graph->SetGridDepth(DEPTH_FRONT); |
||
| 201 | $graph->ygrid->SetColor('[email protected]'); |
||
| 202 | $graph->ygrid->SetLineStyle('dotted'); |
||
| 203 | |||
| 204 | $graph->ygrid->Show(); |
||
| 205 | |||
| 206 | $graph->xaxis->SetWeight(1); |
||
| 207 | $graph->yaxis->SetWeight(1); |
||
| 208 | |||
| 209 | $ytitle = new Text(CCBPGraph::YTitle, floor($lm * .75), ($height - $tm - $bm) / 2 + $tm); |
||
| 210 | #$ytitle->SetFont(FF_VERA,FS_BOLD,$labelsize+1); |
||
| 211 | $ytitle->SetAlign('right', 'center'); |
||
| 212 | $ytitle->SetAngle(90); |
||
| 213 | $graph->Add($ytitle); |
||
| 214 | |||
| 215 | $xtitle = new Text(CCBPGraph::XTitle, ($width - $lm - $rm) / 2 + $lm, $height - 10); |
||
| 216 | #$xtitle->SetFont(FF_VERA,FS_BOLD,$labelsize); |
||
| 217 | $xtitle->SetAlign('center', 'bottom'); |
||
| 218 | $graph->Add($xtitle); |
||
| 219 | |||
| 220 | $df = 'D j:S M, Y'; |
||
| 221 | if ($width < 400) { |
||
| 222 | $df = 'D j:S M'; |
||
| 223 | } |
||
| 224 | |||
| 225 | $time = new Text(date($df), $width - 10, $height - 10); |
||
| 226 | $time->SetAlign('right', 'bottom'); |
||
| 227 | #$time->SetFont(FF_VERA,FS_NORMAL,$labelsize-1); |
||
| 228 | $time->SetColor('darkgray'); |
||
| 229 | $graph->Add($time); |
||
| 230 | |||
| 231 | // Use an accumulated fille line graph to create the colored bands |
||
| 232 | |||
| 233 | $n = 3; |
||
| 234 | for ($i = 0; $i < $n; ++$i) { |
||
| 235 | $b = $this->iColorInd[$i][0]; |
||
| 236 | $k = ($this->iColorInd[$i][1] - $this->iColorInd[$i][0]) / $this->iXMax; |
||
| 237 | $colarea[$i] = array(array($lowx, $lowx * $k + $b), array($highx, $highx * $k + $b)); |
||
| 238 | } |
||
| 239 | $colarea[3] = array(array($lowx, $highy), array($highx, $highy)); |
||
| 240 | |||
| 241 | $cb = array(); |
||
| 242 | for ($i = 0; $i < 4; ++$i) { |
||
| 243 | $cb[$i] = new Plot\LinePlot(array($colarea[$i][0][1], $colarea[$i][1][1]), |
||
| 244 | array($colarea[$i][0][0], $colarea[$i][1][0])); |
||
| 245 | $cb[$i]->SetFillColor($this->iColorSpec[$this->iColorMap][$i]); |
||
| 246 | $cb[$i]->SetFillFromYMin(); |
||
| 247 | } |
||
| 248 | |||
| 249 | $graph->Add(array_slice(array_reverse($cb), 0, 4)); |
||
| 250 | $this->graph = $graph; |
||
| 251 | } |
||
| 281 |