Issues (459)

src/plot/PiePlotC.php (2 issues)

1
<?php
2
3
/**
4
 * JPGraph v4.0.3
5
 */
6
7
namespace Amenadiel\JpGraph\Plot;
8
9
use Amenadiel\JpGraph\Text;
10
11
/**
12
 * @class PiePlotC
13
 * // Description: Same as a normal pie plot but with a
14
 * // filled circle in the center
15
 */
16
class PiePlotC extends PiePlot
17
{
18
    private $imidsize            = 0.5; // Fraction of total width
19
    private $imidcolor           = 'white';
20
    public $midtitle             = '';
21
    private $middlecsimtarget    = '';
22
    private $middlecsimwintarget = '';
23
    private $middlecsimalt       = '';
24
25
    public function __construct($data, $aCenterTitle = '')
0 ignored issues
show
The parameter $aCenterTitle 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

25
    public function __construct($data, /** @scrutinizer ignore-unused */ $aCenterTitle = '')

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...
26
    {
27
        parent::__construct($data);
28
        $this->midtitle = new Text\Text();
29
        $this->midtitle->ParagraphAlign('center');
30
    }
31
32
    public function SetMid($aTitle, $aColor = 'white', $aSize = 0.5)
33
    {
34
        $this->midtitle->Set($aTitle);
35
36
        $this->imidsize  = $aSize;
37
        $this->imidcolor = $aColor;
38
    }
39
40
    public function SetMidTitle($aTitle)
41
    {
42
        $this->midtitle->Set($aTitle);
43
    }
44
45
    public function SetMidSize($aSize)
46
    {
47
        $this->imidsize = $aSize;
48
    }
49
50
    public function SetMidColor($aColor)
51
    {
52
        $this->imidcolor = $aColor;
53
    }
54
55
    public function SetMidCSIM($aTarget, $aAlt = '', $aWinTarget = '')
56
    {
57
        $this->middlecsimtarget    = $aTarget;
58
        $this->middlecsimwintarget = $aWinTarget;
59
        $this->middlecsimalt       = $aAlt;
60
    }
61
62
    public function AddSliceToCSIM($i, $xc, $yc, $radius, $sa, $ea)
63
    {
64
        //Slice number, ellipse centre (x,y), radius, start angle, end angle
65
        while ($sa > 2 * M_PI) {
66
            $sa = $sa - 2 * M_PI;
67
        }
68
69
        while ($ea > 2 * M_PI) {
70
            $ea = $ea - 2 * M_PI;
71
        }
72
73
        $sa = 2 * M_PI - $sa;
74
        $ea = 2 * M_PI - $ea;
75
76
        // Special case when we have only one slice since then both start and end
77
        // angle will be == 0
78
        if (abs($sa - $ea) < 0.0001) {
79
            $sa = 2 * M_PI;
80
            $ea = 0;
81
        }
82
83
        // Add inner circle first point
84
        $xp     = floor(($this->imidsize * $radius * cos($ea)) + $xc);
85
        $yp     = floor($yc - ($this->imidsize * $radius * sin($ea)));
86
        $coords = "${xp}, ${yp}";
87
88
        //add coordinates every 0.25 radians
89
        $a = $ea + 0.25;
90
91
        // If we cross the 360-limit with a slice we need to handle
92
        // the fact that end angle is smaller than start
93
        if ($sa < $ea) {
94
            while ($a <= 2 * M_PI) {
95
                $xp = floor($radius * cos($a) + $xc);
96
                $yp = floor($yc - $radius * sin($a));
97
                $coords .= ", ${xp}, ${yp}";
98
                $a += 0.25;
99
            }
100
            $a -= 2 * M_PI;
101
        }
102
103
        while ($a < $sa) {
104
            $xp = floor(($this->imidsize * $radius * cos($a) + $xc));
105
            $yp = floor($yc - ($this->imidsize * $radius * sin($a)));
106
            $coords .= ", ${xp}, ${yp}";
107
            $a += 0.25;
108
        }
109
110
        // Make sure we end at the last point
111
        $xp = floor(($this->imidsize * $radius * cos($sa) + $xc));
112
        $yp = floor($yc - ($this->imidsize * $radius * sin($sa)));
113
        $coords .= ", ${xp}, ${yp}";
114
115
        // Straight line to outer circle
116
        $xp = floor($radius * cos($sa) + $xc);
117
        $yp = floor($yc - $radius * sin($sa));
118
        $coords .= ", ${xp}, ${yp}";
119
120
        //add coordinates every 0.25 radians
121
        $a = $sa - 0.25;
122
        while ($a > $ea) {
123
            $xp = floor($radius * cos($a) + $xc);
124
            $yp = floor($yc - $radius * sin($a));
125
            $coords .= ", ${xp}, ${yp}";
126
            $a -= 0.25;
127
        }
128
129
        //Add the last point on the arc
130
        $xp = floor($radius * cos($ea) + $xc);
131
        $yp = floor($yc - $radius * sin($ea));
132
        $coords .= ", ${xp}, ${yp}";
133
134
        // Close the arc
135
        $xp = floor(($this->imidsize * $radius * cos($ea)) + $xc);
136
        $yp = floor($yc - ($this->imidsize * $radius * sin($ea)));
137
        $coords .= ", ${xp}, ${yp}";
138
139
        if (!empty($this->csimtargets[$i])) {
140
            $this->csimareas .= "<area shape=\"poly\" coords=\"${coords}\" href=\"" .
141
            $this->csimtargets[$i] . '"';
142
            if (!empty($this->csimwintargets[$i])) {
143
                $this->csimareas .= ' target="' . $this->csimwintargets[$i] . '" ';
144
            }
145
            if (!empty($this->csimalts[$i])) {
146
                $tmp = sprintf($this->csimalts[$i], $this->data[$i]);
147
                $this->csimareas .= " title=\"${tmp}\"  alt=\"${tmp}\" ";
148
            }
149
            $this->csimareas .= " />\n";
150
        }
151
    }
152
153
    public function Stroke($img, $aaoption = 0)
154
    {
155
        // Stroke the pie but don't stroke values
156
        $tmp               = $this->value->show;
157
        $this->value->show = false;
158
        parent::Stroke($img, $aaoption);
159
        $this->value->show = $tmp;
160
161
        $xc = round($this->posx * $img->width);
162
        $yc = round($this->posy * $img->height);
163
164
        $radius = floor($this->radius * min($img->width, $img->height));
165
166
        if ($this->imidsize > 0 && $aaoption !== 2) {
167
            if ($this->ishadowcolor != '') {
168
                $img->SetColor($this->ishadowcolor);
169
                $img->FilledCircle(
170
                    $xc + $this->ishadowdrop,
171
                    $yc + $this->ishadowdrop,
172
                    round($radius * $this->imidsize)
173
                );
174
            }
175
176
            $img->SetColor($this->imidcolor);
177
            $img->FilledCircle($xc, $yc, round($radius * $this->imidsize));
178
179
            if ($this->pie_border && $aaoption === 0) {
180
                $img->SetColor($this->color);
181
                $img->Circle($xc, $yc, round($radius * $this->imidsize));
182
            }
183
184
            if (!empty($this->middlecsimtarget)) {
185
                $this->AddMiddleCSIM($xc, $yc, round($radius * $this->imidsize));
186
            }
187
        }
188
189
        if ($this->value->show && $aaoption !== 1) {
190
            $this->StrokeAllLabels($img, $xc, $yc, $radius);
191
            $this->midtitle->SetPos($xc, $yc, 'center', 'center');
192
            $this->midtitle->Stroke($img);
193
        }
194
    }
195
196
    public function AddMiddleCSIM($xc, $yc, $r)
197
    {
198
        $xc = round($xc);
199
        $yc = round($yc);
200
        $r  = round($r);
201
        $this->csimareas .= "<area shape=\"circle\" coords=\"${xc},${yc},${r}\" href=\"" .
202
        $this->middlecsimtarget . '"';
203
        if (!empty($this->middlecsimwintarget)) {
204
            $this->csimareas .= ' target="' . $this->middlecsimwintarget . '"';
205
        }
206
        if (!empty($this->middlecsimalt)) {
207
            $tmp = $this->middlecsimalt;
208
            $this->csimareas .= " title=\"${tmp}\" alt=\"${tmp}\" ";
209
        }
210
        $this->csimareas .= " />\n";
211
    }
212
213
    public function StrokeLabel($label, $img, $xc, $yc, $a, $r)
214
    {
215
        if ($this->ilabelposadj === 'auto') {
0 ignored issues
show
The condition $this->ilabelposadj === 'auto' is always false.
Loading history...
216
            $this->ilabelposadj = (1 - $this->imidsize) / 2 + $this->imidsize;
217
        }
218
219
        parent::StrokeLabel($label, $img, $xc, $yc, $a, $r);
220
    }
221
}
222