Conditions | 60 |
Paths | > 20000 |
Total Lines | 266 |
Code Lines | 183 |
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 |
||
232 | public function Stroke($img, $xscale, $yscale) |
||
233 | { |
||
234 | $idx = 0; |
||
235 | $numpoints = safe_count($this->coords[0]); |
||
236 | if (isset($this->coords[1])) { |
||
237 | if (safe_count($this->coords[1]) != $numpoints) { |
||
238 | Util\JpGraphError::RaiseL(2003, safe_count($this->coords[1]), $numpoints); |
||
239 | //("Number of X and Y points are not equal. Number of X-points:". safe_count($this->coords[1])." Number of Y-points:$numpoints"); |
||
240 | } else { |
||
241 | $exist_x = true; |
||
242 | } |
||
243 | } else { |
||
244 | $exist_x = false; |
||
245 | } |
||
246 | |||
247 | if ($this->barcenter) { |
||
248 | $textadj = 0.5 - $xscale->text_scale_off; |
||
249 | } else { |
||
250 | $textadj = 0; |
||
251 | } |
||
252 | |||
253 | // Find the first numeric data point |
||
254 | $startpoint = 0; |
||
255 | while ($startpoint < $numpoints && !is_numeric($this->coords[0][$startpoint])) { |
||
256 | ++$startpoint; |
||
257 | } |
||
258 | |||
259 | // Bail out if no data points |
||
260 | if ($startpoint == $numpoints) { |
||
261 | return; |
||
262 | } |
||
263 | |||
264 | if ($this->iFastStroke) { |
||
265 | $this->FastStroke($img, $xscale, $yscale, $startpoint, $exist_x); |
||
266 | |||
267 | return; |
||
268 | } |
||
269 | |||
270 | if ($exist_x) { |
||
271 | $xs = $this->coords[1][$startpoint]; |
||
272 | } else { |
||
273 | $xs = $textadj + $startpoint; |
||
274 | } |
||
275 | |||
276 | $img->SetStartPoint( |
||
277 | $xscale->Translate($xs), |
||
278 | $yscale->Translate($this->coords[0][$startpoint]) |
||
279 | ); |
||
280 | |||
281 | if ($this->filled) { |
||
282 | if ($this->fillFromMax) { |
||
283 | //$max = $yscale->GetMaxVal(); |
||
284 | $cord[$idx++] = $xscale->Translate($xs); |
||
285 | $cord[$idx++] = $yscale->scale_abs[1]; |
||
286 | } else { |
||
287 | $min = $yscale->GetMinVal(); |
||
288 | if ($min > 0 || $this->fillFromMin) { |
||
289 | $fillmin = $yscale->scale_abs[0]; //Translate($min); |
||
290 | } else { |
||
291 | $fillmin = $yscale->Translate(0); |
||
292 | } |
||
293 | |||
294 | $cord[$idx++] = $xscale->Translate($xs); |
||
295 | $cord[$idx++] = $fillmin; |
||
296 | } |
||
297 | } |
||
298 | $xt = $xscale->Translate($xs); |
||
299 | $yt = $yscale->Translate($this->coords[0][$startpoint]); |
||
300 | $cord[$idx++] = $xt; |
||
301 | $cord[$idx++] = $yt; |
||
302 | $yt_old = $yt; |
||
303 | $xt_old = $xt; |
||
304 | $y_old = $this->coords[0][$startpoint]; |
||
305 | |||
306 | $this->value->Stroke($img, $this->coords[0][$startpoint], $xt, $yt); |
||
307 | |||
308 | $img->SetColor($this->color); |
||
309 | $img->SetLineWeight($this->weight); |
||
310 | $img->SetLineStyle($this->line_style); |
||
311 | $pnts = $startpoint + 1; |
||
312 | $firstnonumeric = false; |
||
313 | |||
314 | while ($pnts < $numpoints) { |
||
315 | if ($exist_x) { |
||
316 | $x = $this->coords[1][$pnts]; |
||
317 | } else { |
||
318 | $x = $pnts + $textadj; |
||
319 | } |
||
320 | $xt = $xscale->Translate($x); |
||
321 | $yt = $yscale->Translate($this->coords[0][$pnts]); |
||
322 | |||
323 | $y = $this->coords[0][$pnts]; |
||
324 | if ($this->step_style) { |
||
325 | // To handle null values within step style we need to record the |
||
326 | // first non numeric value so we know from where to start if the |
||
327 | // non value is '-'. |
||
328 | if (is_numeric($y)) { |
||
329 | $firstnonumeric = false; |
||
330 | if (is_numeric($y_old)) { |
||
331 | $img->StyleLine($xt_old, $yt_old, $xt, $yt_old); |
||
332 | $img->StyleLine($xt, $yt_old, $xt, $yt); |
||
333 | } elseif ($y_old == '-') { |
||
334 | $img->StyleLine($xt_first, $yt_first, $xt, $yt_first); |
||
335 | $img->StyleLine($xt, $yt_first, $xt, $yt); |
||
336 | } else { |
||
337 | $yt_old = $yt; |
||
338 | $xt_old = $xt; |
||
339 | } |
||
340 | $cord[$idx++] = $xt; |
||
341 | $cord[$idx++] = $yt_old; |
||
342 | $cord[$idx++] = $xt; |
||
343 | $cord[$idx++] = $yt; |
||
344 | } elseif ($firstnonumeric == false) { |
||
345 | $firstnonumeric = true; |
||
346 | $yt_first = $yt_old; |
||
347 | $xt_first = $xt_old; |
||
348 | } |
||
349 | } else { |
||
350 | $tmp1 = $y; |
||
351 | $prev = $this->coords[0][$pnts - 1]; |
||
352 | if ($tmp1 === '' || $tmp1 === null || $tmp1 === 'X') { |
||
353 | $tmp1 = 'x'; |
||
354 | } |
||
355 | |||
356 | if ($prev === '' || $prev === null || $prev === 'X') { |
||
357 | $prev = 'x'; |
||
358 | } |
||
359 | |||
360 | if (is_numeric($y) || (is_string($y) && $y != '-')) { |
||
361 | if (is_numeric($y) && (is_numeric($prev) || $prev === '-')) { |
||
362 | $img->StyleLineTo($xt, $yt); |
||
363 | } else { |
||
364 | $img->SetStartPoint($xt, $yt); |
||
365 | } |
||
366 | } |
||
367 | if ($this->filled && $tmp1 !== '-') { |
||
368 | if ($tmp1 === 'x') { |
||
369 | $cord[$idx++] = $cord[$idx - 3]; |
||
370 | $cord[$idx++] = $fillmin; |
||
371 | } elseif ($prev === 'x') { |
||
372 | $cord[$idx++] = $xt; |
||
373 | $cord[$idx++] = $fillmin; |
||
374 | $cord[$idx++] = $xt; |
||
375 | $cord[$idx++] = $yt; |
||
376 | } else { |
||
377 | $cord[$idx++] = $xt; |
||
378 | $cord[$idx++] = $yt; |
||
379 | } |
||
380 | } else { |
||
381 | if (is_numeric($tmp1) && (is_numeric($prev) || $prev === '-')) { |
||
382 | $cord[$idx++] = $xt; |
||
383 | $cord[$idx++] = $yt; |
||
384 | } |
||
385 | } |
||
386 | } |
||
387 | $yt_old = $yt; |
||
388 | $xt_old = $xt; |
||
389 | $y_old = $y; |
||
390 | |||
391 | $this->StrokeDataValue($img, $this->coords[0][$pnts], $xt, $yt); |
||
392 | |||
393 | ++$pnts; |
||
394 | } |
||
395 | |||
396 | if ($this->filled) { |
||
397 | $cord[$idx++] = $xt; |
||
398 | if ($this->fillFromMax) { |
||
399 | $cord[$idx++] = $yscale->scale_abs[1]; |
||
400 | } else { |
||
401 | if ($min > 0 || $this->fillFromMin) { |
||
402 | $cord[$idx++] = $yscale->Translate($min); |
||
403 | } else { |
||
404 | $cord[$idx++] = $yscale->Translate(0); |
||
405 | } |
||
406 | } |
||
407 | if ($this->fillgrad) { |
||
408 | $img->SetLineWeight(1); |
||
409 | $grad = new Gradient($img); |
||
410 | $grad->SetNumColors($this->fillgrad_numcolors); |
||
411 | $grad->FilledFlatPolygon($cord, $this->fillgrad_fromcolor, $this->fillgrad_tocolor); |
||
412 | $img->SetLineWeight($this->weight); |
||
413 | } else { |
||
414 | $img->SetColor($this->fill_color); |
||
415 | $img->FilledPolygon($cord); |
||
416 | } |
||
417 | if ($this->weight > 0) { |
||
418 | $img->SetLineWeight($this->weight); |
||
419 | $img->SetColor($this->color); |
||
420 | // Remove first and last coordinate before drawing the line |
||
421 | // sine we otherwise get the vertical start and end lines which |
||
422 | // doesn't look appropriate |
||
423 | $img->Polygon(array_slice($cord, 2, safe_count($cord) - 4)); |
||
424 | } |
||
425 | } |
||
426 | |||
427 | if (!empty($this->filledAreas)) { |
||
428 | $minY = $yscale->Translate($yscale->GetMinVal()); |
||
429 | $factor = ($this->step_style ? 4 : 2); |
||
430 | |||
431 | for ($i = 0; $i < safe_count($this->filledAreas); ++$i) { |
||
432 | // go through all filled area elements ordered by insertion |
||
433 | // fill polygon array |
||
434 | $areaCoords[] = $cord[$this->filledAreas[$i][0] * $factor]; |
||
435 | $areaCoords[] = $minY; |
||
436 | |||
437 | $areaCoords = |
||
438 | array_merge( |
||
439 | $areaCoords, |
||
440 | array_slice( |
||
441 | $cord, |
||
442 | $this->filledAreas[$i][0] * $factor, |
||
443 | ($this->filledAreas[$i][1] - $this->filledAreas[$i][0] + ($this->step_style ? 0 : 1)) * $factor |
||
444 | ) |
||
445 | ); |
||
446 | $areaCoords[] = $areaCoords[safe_count($areaCoords) - 2]; // last x |
||
447 | $areaCoords[] = $minY; // last y |
||
448 | |||
449 | if ($this->filledAreas[$i][3]) { |
||
450 | $img->SetColor($this->filledAreas[$i][2]); |
||
451 | $img->FilledPolygon($areaCoords); |
||
452 | $img->SetColor($this->color); |
||
453 | } |
||
454 | // Check if we should draw the frame. |
||
455 | // If not we still re-draw the line since it might have been |
||
456 | // partially overwritten by the filled area and it doesn't look |
||
457 | // very good. |
||
458 | if ($this->filledAreas[$i][4]) { |
||
459 | $img->Polygon($areaCoords); |
||
460 | } else { |
||
461 | $img->Polygon($cord); |
||
462 | } |
||
463 | |||
464 | $areaCoords = []; |
||
465 | } |
||
466 | } |
||
467 | |||
468 | if (!is_object($this->mark) || $this->mark->type == -1 || $this->mark->show == false) { |
||
469 | return; |
||
470 | } |
||
471 | |||
472 | for ($pnts = 0; $pnts < $numpoints; ++$pnts) { |
||
473 | if ($exist_x) { |
||
474 | $x = $this->coords[1][$pnts]; |
||
475 | } else { |
||
476 | $x = $pnts + $textadj; |
||
477 | } |
||
478 | $xt = $xscale->Translate($x); |
||
479 | $yt = $yscale->Translate($this->coords[0][$pnts]); |
||
480 | |||
481 | if (is_numeric($this->coords[0][$pnts])) { |
||
482 | if (!empty($this->csimtargets[$pnts])) { |
||
483 | if (!empty($this->csimwintargets[$pnts])) { |
||
484 | $this->mark->SetCSIMTarget($this->csimtargets[$pnts], $this->csimwintargets[$pnts]); |
||
485 | } else { |
||
486 | $this->mark->SetCSIMTarget($this->csimtargets[$pnts]); |
||
487 | } |
||
488 | $this->mark->SetCSIMAlt($this->csimalts[$pnts]); |
||
489 | } |
||
490 | if ($exist_x) { |
||
491 | $x = $this->coords[1][$pnts]; |
||
492 | } else { |
||
493 | $x = $pnts; |
||
494 | } |
||
495 | $this->mark->SetCSIMAltVal($this->coords[0][$pnts], $x); |
||
496 | $this->mark->Stroke($img, $xt, $yt); |
||
497 | $this->csimareas .= $this->mark->GetCSIMAreas(); |
||
498 | } |
||
502 |