Passed
Push — all-contributors/add-formikaio ( 169f6c )
by
unknown
08:10 queued 05:51
created

RectPatternLDiag::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * JPGraph v4.0.3
5
 */
6
7
namespace Amenadiel\JpGraph\Graph;
8
9
/**
10
 * @class RectPatternLDiag
11
 * // Implements left diagonal pattern
12
 */
13
class RectPatternLDiag extends RectPattern
14
{
15
    public function __construct($aColor = 'black', $aWeight = 1, $aLineSpacing = 12)
16
    {
17
        $this->linespacing = $aLineSpacing;
18
        parent::__construct($aColor, $aWeight);
19
    }
20
21
    public function DoPattern($aImg)
22
    {
23
        //  --------------------
24
        //  |\   \   \   \   \ |
25
        //  | \   \   \   \   \|
26
        //  |  \   \   \   \   |
27
        //  |------------------|
28
        $xe = $this->rect->xe;
29
        $ye = $this->rect->ye;
30
        $x0 = $this->rect->x + round($this->linespacing / 2);
31
        $y0 = $this->rect->ye;
32
        $x1 = $this->rect->x;
33
        $y1 = $this->rect->ye - round($this->linespacing / 2);
34
35
        while ($x0 <= $xe && $y1 >= $this->rect->y) {
36
            $aImg->Line($x0, $y0, $x1, $y1);
37
            $x0 += $this->linespacing;
38
            $y1 -= $this->linespacing;
39
        }
40
        if ($xe - $x1 > $ye - $this->rect->y) {
41
            // Width larger than height
42
            $x1 = $this->rect->x + ($this->rect->y - $y1);
43
            $y0 = $ye;
44
            $y1 = $this->rect->y;
45
            while ($x0 <= $xe) {
46
                $aImg->Line($x0, $y0, $x1, $y1);
47
                $x0 += $this->linespacing;
48
                $x1 += $this->linespacing;
49
            }
50
51
            $y0 = $this->rect->ye - ($x0 - $xe);
52
            $x0 = $xe;
53
        } else {
54
            // Height larger than width
55
            $diff = $x0 - $xe;
56
            $y0   = $ye - $diff;
57
            $x0   = $xe;
58
            while ($y1 >= $this->rect->y) {
59
                $aImg->Line($x0, $y0, $x1, $y1);
60
                $y0 -= $this->linespacing;
61
                $y1 -= $this->linespacing;
62
            }
63
            $diff = $this->rect->y - $y1;
64
            $x1   = $this->rect->x + $diff;
65
            $y1   = $this->rect->y;
66
        }
67
        while ($y0 >= $this->rect->y) {
68
            $aImg->Line($x0, $y0, $x1, $y1);
69
            $y0 -= $this->linespacing;
70
            $x1 += $this->linespacing;
71
        }
72
    }
73
}
74