Issues (459)

src/graph/LogTicks.php (2 issues)

1
<?php
2
3
/**
4
 * JPGraph v4.0.3
5
 */
6
7
namespace Amenadiel\JpGraph\Graph;
8
9
use Amenadiel\JpGraph\Util;
10
11
/**
12
 * @class LogTicks
13
 * // Description:
14
 */
15
class LogTicks extends Ticks
16
{
17
    private $label_logtype  = LOGLABELS_MAGNITUDE;
18
    private $ticklabels_pos = [];
19
20
    /**
21
     * CONSTRUCTOR.
22
     */
23
    public function LogTicks()
24
    {
25
    }
26
27
    /**
28
     * PUBLIC METHODS.
29
     */
30
    public function IsSpecified()
31
    {
32
        return true;
33
    }
34
35
    public function SetLabelLogType($aType)
36
    {
37
        $this->label_logtype = $aType;
38
    }
39
40
    // For log scale it's meaningless to speak about a major step
41
    // We just return -1 to make the framework happy (specifically
42
    // StrokeLabels() )
43 3
    public function GetMajor()
44
    {
45 3
        return -1;
46
    }
47
48
    public function SetTextLabelStart($aStart)
0 ignored issues
show
The parameter $aStart is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
    public function SetTextLabelStart(/** @scrutinizer ignore-unused */ $aStart)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50
        Util\JpGraphError::RaiseL(11005);
51
        //('Specifying tick interval for a logarithmic scale is undefined. Remove any calls to SetTextLabelStart() or SetTextTickInterval() on the logarithmic scale.');
52
    }
53
54 1
    public function SetXLabelOffset($dummy)
0 ignored issues
show
The parameter $dummy is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

54
    public function SetXLabelOffset(/** @scrutinizer ignore-unused */ $dummy)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        // For log scales we dont care about XLabel offset
57 1
    }
58
59
    // Draw ticks on image "img" using scale "scale". The axis absolute
60
    // position in the image is specified in pos, i.e. for an x-axis
61
    // it specifies the absolute y-coord and for Y-ticks it specified the
62
    // absolute x-position.
63 3
    public function Stroke($img, $scale, $pos)
64
    {
65 3
        $start     = $scale->GetMinVal();
66 3
        $limit     = $scale->GetMaxVal();
67 3
        $nextMajor = 10 * $start;
68 3
        $step      = $nextMajor / 10.0;
69
70 3
        $img->SetLineWeight($this->weight);
71
72 3
        if ($scale->type == 'y') {
73
            // member direction specified if the ticks should be on
74
            // left or right side.
75 3
            $a  = $pos + $this->direction * $this->GetMinTickAbsSize();
76 3
            $a2 = $pos + $this->direction * $this->GetMajTickAbsSize();
77
78 3
            $count                       = 1;
79 3
            $this->maj_ticks_pos[0]      = $scale->Translate($start);
80 3
            $this->maj_ticklabels_pos[0] = $scale->Translate($start);
81 3
            if ($this->supress_first) {
82 1
                $this->maj_ticks_label[0] = '';
83
            } else {
84 3
                if ($this->label_formfunc != '') {
85
                    $f                        = $this->label_formfunc;
86
                    $this->maj_ticks_label[0] = call_user_func($f, $start);
87 3
                } elseif ($this->label_logtype == LOGLABELS_PLAIN) {
88
                    $this->maj_ticks_label[0] = $start;
89
                } else {
90 3
                    $this->maj_ticks_label[0] = '10^' . round(log10($start));
91
                }
92
            }
93 3
            $i = 1;
94 3
            for ($y = $start; $y <= $limit; $y += $step, ++$count) {
95 3
                $ys                     = $scale->Translate($y);
96 3
                $this->ticks_pos[]      = $ys;
97 3
                $this->ticklabels_pos[] = $ys;
98 3
                if ($count % 10 == 0) {
99 3
                    if (!$this->supress_tickmarks) {
100 1
                        if ($this->majcolor != '') {
101
                            $img->PushColor($this->majcolor);
102
                            $img->Line($pos, $ys, $a2, $ys);
103
                            $img->PopColor();
104
                        } else {
105 1
                            $img->Line($pos, $ys, $a2, $ys);
106
                        }
107
                    }
108
109 3
                    $this->maj_ticks_pos[$i]      = $ys;
110 3
                    $this->maj_ticklabels_pos[$i] = $ys;
111
112 3
                    if ($this->label_formfunc != '') {
113
                        $f                         = $this->label_formfunc;
114
                        $this->maj_ticks_label[$i] = call_user_func($f, $nextMajor);
115 3
                    } elseif ($this->label_logtype == 0) {
116
                        $this->maj_ticks_label[$i] = $nextMajor;
117
                    } else {
118 3
                        $this->maj_ticks_label[$i] = '10^' . round(log10($nextMajor));
119
                    }
120 3
                    ++$i;
121 3
                    $nextMajor *= 10;
122 3
                    $step *= 10;
123 3
                    $count = 1;
124
                } else {
125 3
                    if (!$this->supress_tickmarks && !$this->supress_minor_tickmarks) {
126 1
                        if ($this->mincolor != '') {
127
                            $img->PushColor($this->mincolor);
128
                        }
129 1
                        $img->Line($pos, $ys, $a, $ys);
130 1
                        if ($this->mincolor != '') {
131
                            $img->PopColor();
132
                        }
133
                    }
134
                }
135
            }
136
        } else {
137 1
            $a                           = $pos - $this->direction * $this->GetMinTickAbsSize();
138 1
            $a2                          = $pos - $this->direction * $this->GetMajTickAbsSize();
139 1
            $count                       = 1;
140 1
            $this->maj_ticks_pos[0]      = $scale->Translate($start);
141 1
            $this->maj_ticklabels_pos[0] = $scale->Translate($start);
142 1
            if ($this->supress_first) {
143
                $this->maj_ticks_label[0] = '';
144
            } else {
145 1
                if ($this->label_formfunc != '') {
146
                    $f                        = $this->label_formfunc;
147
                    $this->maj_ticks_label[0] = call_user_func($f, $start);
148 1
                } elseif ($this->label_logtype == 0) {
149
                    $this->maj_ticks_label[0] = $start;
150
                } else {
151 1
                    $this->maj_ticks_label[0] = '10^' . round(log10($start));
152
                }
153
            }
154 1
            $i = 1;
155 1
            for ($x = $start; $x <= $limit; $x += $step, ++$count) {
156 1
                $xs                     = $scale->Translate($x);
157 1
                $this->ticks_pos[]      = $xs;
158 1
                $this->ticklabels_pos[] = $xs;
159 1
                if ($count % 10 == 0) {
160 1
                    if (!$this->supress_tickmarks) {
161
                        $img->Line($xs, $pos, $xs, $a2);
162
                    }
163 1
                    $this->maj_ticks_pos[$i]      = $xs;
164 1
                    $this->maj_ticklabels_pos[$i] = $xs;
165
166 1
                    if ($this->label_formfunc != '') {
167
                        $f                         = $this->label_formfunc;
168
                        $this->maj_ticks_label[$i] = call_user_func($f, $nextMajor);
169 1
                    } elseif ($this->label_logtype == 0) {
170
                        $this->maj_ticks_label[$i] = $nextMajor;
171
                    } else {
172 1
                        $this->maj_ticks_label[$i] = '10^' . round(log10($nextMajor));
173
                    }
174 1
                    ++$i;
175 1
                    $nextMajor *= 10;
176 1
                    $step *= 10;
177 1
                    $count = 1;
178
                } else {
179 1
                    if (!$this->supress_tickmarks && !$this->supress_minor_tickmarks) {
180
                        $img->Line($xs, $pos, $xs, $a);
181
                    }
182
                }
183
            }
184
        }
185
186 3
        return true;
187
    }
188
} // @class
189
/* EOF */
190