Issues (459)

src/graph/RadarLinearTicks.php (2 issues)

Severity
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 RadarLinear
13
 * // Description: Linear ticks
14
 */
15
class RadarLinearTicks extends Ticks
16
{
17
    private $minor_step    = 1;
18
    private $major_step    = 2;
19
    private $xlabel_offset = 0;
0 ignored issues
show
The private property $xlabel_offset is not used, and could be removed.
Loading history...
20
    private $xtick_offset  = 0;
0 ignored issues
show
The private property $xtick_offset is not used, and could be removed.
Loading history...
21
22
    public function __construct()
23
    {
24
        // Empty
25
    }
26
27
    // Return major step size in world coordinates
28
    public function GetMajor()
29
    {
30
        return $this->major_step;
31
    }
32
33
    // Return minor step size in world coordinates
34
    public function GetMinor()
35
    {
36
        return $this->minor_step;
37
    }
38
39
    // Set Minor and Major ticks (in world coordinates)
40
    public function Set($aMajStep, $aMinStep = false)
41
    {
42
        if ($aMinStep == false) {
43
            $aMinStep = $aMajStep;
44
        }
45
46
        if ($aMajStep <= 0 || $aMinStep <= 0) {
47
            Util\JpGraphError::RaiseL(25064);
48
            //Util\JpGraphError::Raise(" Minor or major step size is 0. Check that you haven't got an accidental SetTextTicks(0) in your code. If this is not the case you might have stumbled upon a bug in JpGraph. Please report this and if possible include the data that caused the problem.");
49
        }
50
51
        $this->major_step = $aMajStep;
52
        $this->minor_step = $aMinStep;
53
        $this->is_set     = true;
54
    }
55
56
    public function Stroke($aImg, &$grid, $aPos, $aAxisAngle, $aScale, &$aMajPos, &$aMajLabel)
57
    {
58
        // Prepare to draw linear ticks
59
        $maj_step_abs = abs($aScale->scale_factor * $this->major_step);
60
        $min_step_abs = abs($aScale->scale_factor * $this->minor_step);
61
        $nbrmaj       = round($aScale->world_abs_size / $maj_step_abs);
62
        $nbrmin       = round($aScale->world_abs_size / $min_step_abs);
63
        $skip         = round($nbrmin / $nbrmaj); // Don't draw minor on top of major
64
65
        // Draw major ticks
66
        $ticklen2 = $this->major_abs_size;
67
        $dx       = round(sin($aAxisAngle) * $ticklen2);
68
        $dy       = round(cos($aAxisAngle) * $ticklen2);
69
        $label    = $aScale->scale[0] + $this->major_step;
70
71
        $aImg->SetLineWeight($this->weight);
72
73
        $aMajPos   = [];
74
        $aMajLabel = [];
75
76
        for ($i = 1; $i <= $nbrmaj; ++$i) {
77
            $xt = round($i * $maj_step_abs * cos($aAxisAngle)) + $aScale->scale_abs[0];
78
            $yt = $aPos - round($i * $maj_step_abs * sin($aAxisAngle));
79
80
            if ($this->label_formfunc != '') {
81
                $f = $this->label_formfunc;
82
                $l = call_user_func($f, $label);
83
            } else {
84
                $l = $label;
85
            }
86
87
            $aMajLabel[] = $l;
88
            $label += $this->major_step;
89
            $grid[]                    = $xt;
90
            $grid[]                    = $yt;
91
            $aMajPos[($i - 1) * 2]     = $xt + 2 * $dx;
92
            $aMajPos[($i - 1) * 2 + 1] = $yt - $aImg->GetFontheight() / 2;
93
            if (!$this->supress_tickmarks) {
94
                if ($this->majcolor != '') {
95
                    $aImg->PushColor($this->majcolor);
96
                }
97
                $aImg->Line($xt + $dx, $yt + $dy, $xt - $dx, $yt - $dy);
98
                if ($this->majcolor != '') {
99
                    $aImg->PopColor();
100
                }
101
            }
102
        }
103
104
        // Draw minor ticks
105
        $ticklen2 = $this->minor_abs_size;
106
        $dx       = round(sin($aAxisAngle) * $ticklen2);
107
        $dy       = round(cos($aAxisAngle) * $ticklen2);
108
        if (!$this->supress_tickmarks && !$this->supress_minor_tickmarks) {
109
            if ($this->mincolor != '') {
110
                $aImg->PushColor($this->mincolor);
111
            }
112
            for ($i = 1; $i <= $nbrmin; ++$i) {
113
                if (($i % $skip) == 0) {
114
                    continue;
115
                }
116
                $xt = round($i * $min_step_abs * cos($aAxisAngle)) + $aScale->scale_abs[0];
117
                $yt = $aPos - round($i * $min_step_abs * sin($aAxisAngle));
118
                $aImg->Line($xt + $dx, $yt + $dy, $xt - $dx, $yt - $dy);
119
            }
120
            if ($this->mincolor != '') {
121
                $aImg->PopColor();
122
            }
123
        }
124
    }
125
}
126