1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * JPGraph v4.0.3 |
||||||
5 | */ |
||||||
6 | |||||||
7 | namespace Amenadiel\JpGraph\Graph; |
||||||
8 | |||||||
9 | use Amenadiel\JpGraph\Text; |
||||||
10 | |||||||
11 | /** |
||||||
12 | * @class RadarAxis |
||||||
13 | * // Description: Implements axis for the radar graph |
||||||
14 | */ |
||||||
15 | class RadarAxis extends AxisPrototype |
||||||
16 | { |
||||||
17 | public $title; |
||||||
18 | private $title_color = 'navy'; |
||||||
0 ignored issues
–
show
introduced
by
![]() |
|||||||
19 | private $len = 0; |
||||||
20 | |||||||
21 | public function __construct($img, $aScale, $color = [0, 0, 0]) |
||||||
22 | { |
||||||
23 | parent::__construct($img, $aScale, $color); |
||||||
24 | $this->len = $img->plotheight; |
||||||
25 | $this->title = new Text\Text(); |
||||||
26 | $this->title->SetFont(FF_FONT1, FS_BOLD); |
||||||
27 | $this->color = [0, 0, 0]; |
||||||
28 | } |
||||||
29 | |||||||
30 | // Stroke the axis |
||||||
31 | // $pos = Vertical position of axis |
||||||
32 | // $aAxisAngle = Axis angle |
||||||
33 | // $grid = Returns an array with positions used to draw the grid |
||||||
34 | // $lf = Label flag, TRUE if the axis should have labels |
||||||
35 | public function Stroke($pos, $aAxisAngle, &$grid, $title, $lf) |
||||||
36 | { |
||||||
37 | $this->img->SetColor($this->color); |
||||||
38 | |||||||
39 | // Determine end points for the axis |
||||||
40 | $x = round($this->scale->world_abs_size * cos($aAxisAngle) + $this->scale->scale_abs[0]); |
||||||
41 | $y = round($pos - $this->scale->world_abs_size * sin($aAxisAngle)); |
||||||
42 | |||||||
43 | // Draw axis |
||||||
44 | $this->img->SetColor($this->color); |
||||||
45 | $this->img->SetLineWeight($this->weight); |
||||||
46 | if (!$this->hide) { |
||||||
47 | $this->img->Line($this->scale->scale_abs[0], $pos, $x, $y); |
||||||
48 | } |
||||||
49 | |||||||
50 | $this->scale->ticks->Stroke($this->img, $grid, $pos, $aAxisAngle, $this->scale, $majpos, $majlabel); |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Comprehensibility
Best Practice
introduced
by
|
|||||||
51 | $ncolor = 0; |
||||||
52 | if (isset($this->ticks_label_colors)) { |
||||||
53 | $ncolor = safe_count($this->ticks_label_colors); |
||||||
54 | } |
||||||
55 | |||||||
56 | // Draw labels |
||||||
57 | if ($lf && !$this->hide) { |
||||||
58 | $this->img->SetFont($this->font_family, $this->font_style, $this->font_size); |
||||||
59 | $this->img->SetTextAlign('left', 'top'); |
||||||
60 | $this->img->SetColor($this->label_color); |
||||||
61 | |||||||
62 | // majpos contains (x,y) coordinates for labels |
||||||
63 | if (!$this->hide_labels) { |
||||||
64 | $n = floor(safe_count($majpos) / 2); |
||||||
65 | for ($i = 0; $i < $n; ++$i) { |
||||||
66 | // Set specific label color if specified |
||||||
67 | if ($ncolor > 0) { |
||||||
68 | $this->img->SetColor($this->ticks_label_colors[$i % $ncolor]); |
||||||
69 | } |
||||||
70 | |||||||
71 | if ($this->ticks_label != null && isset($this->ticks_label[$i])) { |
||||||
72 | $this->img->StrokeText($majpos[$i * 2], $majpos[$i * 2 + 1], $this->ticks_label[$i]); |
||||||
73 | } else { |
||||||
74 | $this->img->StrokeText($majpos[$i * 2], $majpos[$i * 2 + 1], $majlabel[$i]); |
||||||
75 | } |
||||||
76 | } |
||||||
77 | } |
||||||
78 | } |
||||||
79 | $this->_StrokeAxisTitle($pos, $aAxisAngle, $title); |
||||||
80 | } |
||||||
81 | |||||||
82 | public function _StrokeAxisTitle($pos, $aAxisAngle, $title) |
||||||
83 | { |
||||||
84 | $this->title->Set($title); |
||||||
85 | $marg = 6 + $this->title->margin; |
||||||
86 | $xt = round(($this->scale->world_abs_size + $marg) * cos($aAxisAngle) + $this->scale->scale_abs[0]); |
||||||
87 | $yt = round($pos - ($this->scale->world_abs_size + $marg) * sin($aAxisAngle)); |
||||||
88 | |||||||
89 | // Position the axis title. |
||||||
90 | // dx, dy is the offset from the top left corner of the bounding box that sorrounds the text |
||||||
91 | // that intersects with the extension of the corresponding axis. The code looks a little |
||||||
92 | // bit messy but this is really the only way of having a reasonable position of the |
||||||
93 | // axis titles. |
||||||
94 | if ($this->title->iWordwrap > 0) { |
||||||
95 | $title = wordwrap($title, $this->title->iWordwrap, "\n"); |
||||||
96 | } |
||||||
97 | |||||||
98 | $h = $this->img->GetTextHeight($title) * 1.2; |
||||||
99 | $w = $this->img->GetTextWidth($title) * 1.2; |
||||||
100 | |||||||
101 | while ($aAxisAngle > 2 * M_PI) { |
||||||
102 | $aAxisAngle -= 2 * M_PI; |
||||||
103 | } |
||||||
104 | |||||||
105 | // Around 3 a'clock |
||||||
106 | if ($aAxisAngle >= 7 * M_PI / 4 || $aAxisAngle <= M_PI / 4) { |
||||||
107 | $dx = -0.15; |
||||||
108 | } |
||||||
109 | // Small trimming to make the dist to the axis more even |
||||||
110 | |||||||
111 | // Around 12 a'clock |
||||||
112 | if ($aAxisAngle >= M_PI / 4 && $aAxisAngle <= 3 * M_PI / 4) { |
||||||
113 | $dx = ($aAxisAngle - M_PI / 4) * 2 / M_PI; |
||||||
114 | } |
||||||
115 | |||||||
116 | // Around 9 a'clock |
||||||
117 | if ($aAxisAngle >= 3 * M_PI / 4 && $aAxisAngle <= 5 * M_PI / 4) { |
||||||
118 | $dx = 1; |
||||||
119 | } |
||||||
120 | |||||||
121 | // Around 6 a'clock |
||||||
122 | if ($aAxisAngle >= 5 * M_PI / 4 && $aAxisAngle <= 7 * M_PI / 4) { |
||||||
123 | $dx = (1 - ($aAxisAngle - M_PI * 5 / 4) * 2 / M_PI); |
||||||
124 | } |
||||||
125 | |||||||
126 | if ($aAxisAngle >= 7 * M_PI / 4) { |
||||||
127 | $dy = (($aAxisAngle - M_PI) - 3 * M_PI / 4) * 2 / M_PI; |
||||||
128 | } |
||||||
129 | |||||||
130 | if ($aAxisAngle <= M_PI / 12) { |
||||||
131 | $dy = (0.5 - $aAxisAngle * 2 / M_PI); |
||||||
132 | } |
||||||
133 | |||||||
134 | if ($aAxisAngle <= M_PI / 4 && $aAxisAngle > M_PI / 12) { |
||||||
135 | $dy = (1 - $aAxisAngle * 2 / M_PI); |
||||||
136 | } |
||||||
137 | |||||||
138 | if ($aAxisAngle >= M_PI / 4 && $aAxisAngle <= 3 * M_PI / 4) { |
||||||
139 | $dy = 1; |
||||||
140 | } |
||||||
141 | |||||||
142 | if ($aAxisAngle >= 3 * M_PI / 4 && $aAxisAngle <= 5 * M_PI / 4) { |
||||||
143 | $dy = (1 - ($aAxisAngle - 3 * M_PI / 4) * 2 / M_PI); |
||||||
144 | } |
||||||
145 | |||||||
146 | if ($aAxisAngle >= 5 * M_PI / 4 && $aAxisAngle <= 7 * M_PI / 4) { |
||||||
147 | $dy = 0; |
||||||
148 | } |
||||||
149 | |||||||
150 | if (!$this->hide) { |
||||||
151 | $this->title->Stroke($this->img, $xt - $dx * $w, $yt - $dy * $h, $title); |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Comprehensibility
Best Practice
introduced
by
The call to
Amenadiel\JpGraph\Text\Text::Stroke() has too many arguments starting with $title .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
152 | } |
||||||
153 | } |
||||||
154 | } // @class |
||||||
155 |