| Conditions | 35 |
| Paths | 1968 |
| Total Lines | 137 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 138 | public function StrokeLabels($aPos, $aMinor = false, $aAbsLabel = false) |
||
| 139 | { |
||
| 140 | if (is_array($this->label_color) && safe_count($this->label_color) > 3) { |
||
| 141 | $this->ticks_label_colors = $this->label_color; |
||
| 142 | $this->img->SetColor($this->label_color[0]); |
||
| 143 | } else { |
||
| 144 | $this->img->SetColor($this->label_color); |
||
| 145 | } |
||
| 146 | $this->img->SetFont($this->font_family, $this->font_style, $this->font_size); |
||
| 147 | $yoff = $this->img->GetFontHeight() / 2; |
||
| 148 | |||
| 149 | // Only draw labels at major tick marks |
||
| 150 | $nbr = safe_count($this->scale->ticks->maj_ticks_label); |
||
| 151 | |||
| 152 | // We have the option to not-display the very first mark |
||
| 153 | // (Usefull when the first label might interfere with another |
||
| 154 | // axis.) |
||
| 155 | $i = $this->show_first_label ? 0 : 1; |
||
| 156 | if (!$this->show_last_label) { |
||
| 157 | --$nbr; |
||
| 158 | } |
||
| 159 | // Now run through all labels making sure we don't overshoot the end |
||
| 160 | // of the scale. |
||
| 161 | $ncolor = 0; |
||
| 162 | if (isset($this->ticks_label_colors)) { |
||
| 163 | $ncolor = safe_count($this->ticks_label_colors); |
||
| 164 | } |
||
| 165 | while ($i < $nbr) { |
||
| 166 | // $tpos holds the absolute text position for the label |
||
| 167 | $tpos = $this->scale->ticks->maj_ticklabels_pos[$i]; |
||
| 168 | |||
| 169 | // Note. the $limit is only used for the x axis since we |
||
| 170 | // might otherwise overshoot if the scale has been centered |
||
| 171 | // This is due to us "loosing" the last tick mark if we center. |
||
| 172 | if ($this->scale->type == 'x' && $tpos > $this->img->width - $this->img->right_margin + 1) { |
||
| 173 | return; |
||
| 174 | } |
||
| 175 | // we only draw every $label_step label |
||
| 176 | if (($i % $this->label_step) == 0) { |
||
| 177 | // Set specific label color if specified |
||
| 178 | if ($ncolor > 0) { |
||
| 179 | $this->img->SetColor($this->ticks_label_colors[$i % $ncolor]); |
||
| 180 | } |
||
| 181 | |||
| 182 | // If the label has been specified use that and in other case |
||
| 183 | // just label the mark with the actual scale value |
||
| 184 | $m = $this->scale->ticks->GetMajor(); |
||
| 185 | |||
| 186 | // ticks_label has an entry for each data point and is the array |
||
| 187 | // that holds the labels set by the user. If the user hasn't |
||
| 188 | // specified any values we use whats in the automatically asigned |
||
| 189 | // labels in the maj_ticks_label |
||
| 190 | if (isset($this->ticks_label[$i * $m])) { |
||
| 191 | $label = $this->ticks_label[$i * $m]; |
||
| 192 | } else { |
||
| 193 | if ($aAbsLabel) { |
||
| 194 | $label = abs($this->scale->ticks->maj_ticks_label[$i]); |
||
| 195 | } else { |
||
| 196 | $label = $this->scale->ticks->maj_ticks_label[$i]; |
||
| 197 | } |
||
| 198 | |||
| 199 | // We number the scale from 1 and not from 0 so increase by one |
||
| 200 | if ($this->scale->textscale && |
||
| 201 | $this->scale->ticks->label_formfunc == '' && |
||
| 202 | !$this->scale->ticks->HaveManualLabels()) { |
||
| 203 | ++$label; |
||
| 204 | } |
||
| 205 | } |
||
| 206 | |||
| 207 | if ($this->scale->type == 'x') { |
||
| 208 | if ($this->labelPos == SIDE_DOWN) { |
||
| 209 | if ($this->label_angle == 0 || $this->label_angle == 90) { |
||
| 210 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
| 211 | $this->img->SetTextAlign('center', 'top'); |
||
| 212 | } else { |
||
| 213 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
| 214 | } |
||
| 215 | } else { |
||
| 216 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
| 217 | $this->img->SetTextAlign('right', 'top'); |
||
| 218 | } else { |
||
| 219 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
| 220 | } |
||
| 221 | } |
||
| 222 | $this->img->StrokeText( |
||
| 223 | $tpos, |
||
| 224 | $aPos + $this->tick_label_margin, |
||
| 225 | $label, |
||
| 226 | $this->label_angle, |
||
| 227 | $this->label_para_align |
||
| 228 | ); |
||
| 229 | } else { |
||
| 230 | if ($this->label_angle == 0 || $this->label_angle == 90) { |
||
| 231 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
| 232 | $this->img->SetTextAlign('center', 'bottom'); |
||
| 233 | } else { |
||
| 234 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
| 235 | } |
||
| 236 | } else { |
||
| 237 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
| 238 | $this->img->SetTextAlign('right', 'bottom'); |
||
| 239 | } else { |
||
| 240 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
| 241 | } |
||
| 242 | } |
||
| 243 | $this->img->StrokeText( |
||
| 244 | $tpos, |
||
| 245 | $aPos - $this->tick_label_margin - 1, |
||
| 246 | $label, |
||
| 247 | $this->label_angle, |
||
| 248 | $this->label_para_align |
||
| 249 | ); |
||
| 250 | } |
||
| 251 | } else { |
||
| 252 | // scale->type == "y" |
||
| 253 | //if( $this->label_angle!=0 ) |
||
| 254 | //Util\JpGraphError::Raise(" Labels at an angle are not supported on Y-axis"); |
||
| 255 | if ($this->labelPos == SIDE_LEFT) { |
||
| 256 | // To the left of y-axis |
||
| 257 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
| 258 | $this->img->SetTextAlign('right', 'center'); |
||
| 259 | } else { |
||
| 260 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
| 261 | } |
||
| 262 | $this->img->StrokeText($aPos - $this->tick_label_margin, $tpos, $label, $this->label_angle, $this->label_para_align); |
||
| 263 | } else { |
||
| 264 | // To the right of the y-axis |
||
| 265 | if ($this->label_halign == '' && $this->label_valign == '') { |
||
| 266 | $this->img->SetTextAlign('left', 'center'); |
||
| 267 | } else { |
||
| 268 | $this->img->SetTextAlign($this->label_halign, $this->label_valign); |
||
| 269 | } |
||
| 270 | $this->img->StrokeText($aPos + $this->tick_label_margin, $tpos, $label, $this->label_angle, $this->label_para_align); |
||
| 271 | } |
||
| 272 | } |
||
| 273 | } |
||
| 274 | ++$i; |
||
| 275 | } |
||
| 278 |