1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * JPGraph v4.0.3 |
||||
5 | */ |
||||
6 | |||||
7 | namespace Amenadiel\JpGraph\Plot; |
||||
8 | |||||
9 | 1 | require_once __DIR__ . '/../config.inc.php'; |
|||
10 | |||||
11 | use Amenadiel\JpGraph\Util; |
||||
12 | |||||
13 | /** |
||||
14 | * @class Plot |
||||
15 | * // Description: Abstract base class for all concrete plot classes |
||||
16 | */ |
||||
17 | class Plot |
||||
18 | { |
||||
19 | public $numpoints = 0; |
||||
20 | public $value; |
||||
21 | public $legend = ''; |
||||
22 | public $coords = []; |
||||
23 | public $color = 'black'; |
||||
24 | public $hidelegend = false; |
||||
25 | public $line_weight = 1; |
||||
26 | public $csimtargets = []; |
||||
27 | public $csimwintargets = []; // Array of targets for CSIM |
||||
28 | public $csimareas = ''; // Resultant CSIM area tags |
||||
29 | public $csimalts; // ALT:s for corresponding target |
||||
30 | public $legendcsimtarget = ''; |
||||
31 | public $legendcsimwintarget = ''; |
||||
32 | public $legendcsimalt = ''; |
||||
33 | protected $weight = 1; |
||||
34 | protected $center = false; |
||||
35 | |||||
36 | protected $inputValues; |
||||
37 | protected $isRunningClear = false; |
||||
38 | |||||
39 | 18 | public function __construct($aDatay, $aDatax = false) |
|||
40 | { |
||||
41 | 18 | $this->numpoints = safe_count($aDatay); |
|||
42 | 18 | if ($this->numpoints == 0) { |
|||
43 | Util\JpGraphError::RaiseL(25121); //("Empty input data array specified for plot. Must have at least one data point."); |
||||
44 | } |
||||
45 | |||||
46 | 18 | if (!$this->isRunningClear) { |
|||
47 | 18 | $this->inputValues = []; |
|||
48 | 18 | $this->inputValues['aDatay'] = $aDatay; |
|||
49 | 18 | $this->inputValues['aDatax'] = $aDatax; |
|||
50 | } |
||||
51 | |||||
52 | 18 | $this->coords[0] = $aDatay; |
|||
53 | 18 | if (is_array($aDatax)) { |
|||
54 | 7 | $this->coords[1] = $aDatax; |
|||
55 | 7 | $n = safe_count($aDatax); |
|||
56 | 7 | for ($i = 0; $i < $n; ++$i) { |
|||
57 | 7 | if (!is_numeric($aDatax[$i])) { |
|||
58 | Util\JpGraphError::RaiseL(25070); |
||||
59 | } |
||||
60 | } |
||||
61 | } |
||||
62 | 18 | $this->value = new DisplayValue(); |
|||
63 | 18 | } |
|||
64 | |||||
65 | // Stroke the plot |
||||
66 | // "virtual" function which must be implemented by |
||||
67 | // the subclasses |
||||
68 | public function Stroke($aImg, $aXScale, $aYScale) |
||||
0 ignored issues
–
show
The parameter
$aXScale 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
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
69 | { |
||||
70 | Util\JpGraphError::RaiseL(25122); //("JpGraph: Stroke() must be implemented by concrete subclass to class Plot"); |
||||
71 | } |
||||
72 | |||||
73 | public function HideLegend($f = true) |
||||
74 | { |
||||
75 | $this->hidelegend = $f; |
||||
76 | } |
||||
77 | |||||
78 | 19 | public function DoLegend($graph) |
|||
79 | { |
||||
80 | 19 | if (!$this->hidelegend) { |
|||
81 | 19 | $this->Legend($graph); |
|||
82 | } |
||||
83 | 19 | } |
|||
84 | |||||
85 | 16 | public function StrokeDataValue($img, $aVal, $x, $y) |
|||
86 | { |
||||
87 | 16 | $this->value->Stroke($img, $aVal, $x, $y); |
|||
88 | 16 | } |
|||
89 | |||||
90 | // Set href targets for CSIM |
||||
91 | public function SetCSIMTargets($aTargets, $aAlts = '', $aWinTargets = '') |
||||
92 | { |
||||
93 | $this->csimtargets = $aTargets; |
||||
94 | $this->csimwintargets = $aWinTargets; |
||||
95 | $this->csimalts = $aAlts; |
||||
96 | } |
||||
97 | |||||
98 | // Get all created areas |
||||
99 | public function GetCSIMareas() |
||||
100 | { |
||||
101 | return $this->csimareas; |
||||
102 | } |
||||
103 | |||||
104 | // "Virtual" function which gets called before any scale |
||||
105 | // or axis are stroked used to do any plot specific adjustment |
||||
106 | 6 | public function PreStrokeAdjust($aGraph) |
|||
107 | { |
||||
108 | 6 | if (substr($aGraph->axtype, 0, 4) == 'text' && (isset($this->coords[1]))) { |
|||
109 | Util\JpGraphError::RaiseL(25123); //("JpGraph: You can't use a text X-scale with specified X-coords. Use a \"int\" or \"lin\" scale instead."); |
||||
110 | } |
||||
111 | |||||
112 | 6 | return true; |
|||
113 | } |
||||
114 | |||||
115 | // Virtual function to the the concrete plot class to make any changes to the graph |
||||
116 | // and scale before the stroke process begins |
||||
117 | 18 | public function PreScaleSetup($aGraph) |
|||
118 | { |
||||
119 | // Empty |
||||
120 | 18 | } |
|||
121 | |||||
122 | // Get minimum values in plot |
||||
123 | 17 | public function Min() |
|||
124 | { |
||||
125 | 17 | if (isset($this->coords[1])) { |
|||
126 | 7 | $x = $this->coords[1]; |
|||
127 | } else { |
||||
128 | 13 | $x = ''; |
|||
129 | } |
||||
130 | 17 | if ($x != '' && safe_count($x) > 0) { |
|||
131 | 7 | $xm = min($x); |
|||
132 | } else { |
||||
133 | 13 | $xm = 0; |
|||
134 | } |
||||
135 | 17 | $y = $this->coords[0]; |
|||
136 | 17 | $cnt = safe_count($y); |
|||
137 | 17 | if ($cnt > 0) { |
|||
138 | 17 | $i = 0; |
|||
139 | 17 | while ($i < $cnt && !is_numeric($ym = $y[$i])) { |
|||
140 | ++$i; |
||||
141 | } |
||||
142 | 17 | while ($i < $cnt) { |
|||
143 | 17 | if (is_numeric($y[$i])) { |
|||
144 | 17 | $ym = min($ym, $y[$i]); |
|||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
145 | } |
||||
146 | 17 | ++$i; |
|||
147 | } |
||||
148 | } else { |
||||
149 | $ym = ''; |
||||
150 | } |
||||
151 | |||||
152 | 17 | return [$xm, $ym]; |
|||
153 | } |
||||
154 | |||||
155 | // Get maximum value in plot |
||||
156 | 17 | public function Max() |
|||
157 | { |
||||
158 | 17 | if (isset($this->coords[1])) { |
|||
159 | 7 | $x = $this->coords[1]; |
|||
160 | } else { |
||||
161 | 13 | $x = ''; |
|||
162 | } |
||||
163 | |||||
164 | 17 | if ($x != '' && safe_count($x) > 0) { |
|||
165 | 7 | $xm = max($x); |
|||
166 | } else { |
||||
167 | 13 | $xm = $this->numpoints - 1; |
|||
168 | } |
||||
169 | 17 | $y = $this->coords[0]; |
|||
170 | 17 | if (safe_count($y) > 0) { |
|||
171 | 17 | $cnt = safe_count($y); |
|||
172 | 17 | $i = 0; |
|||
173 | 17 | while ($i < $cnt && !is_numeric($ym = $y[$i])) { |
|||
174 | ++$i; |
||||
175 | } |
||||
176 | 17 | while ($i < $cnt) { |
|||
177 | 17 | if (is_numeric($y[$i])) { |
|||
178 | 17 | $ym = max($ym, $y[$i]); |
|||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
179 | } |
||||
180 | 17 | ++$i; |
|||
181 | } |
||||
182 | } else { |
||||
183 | $ym = ''; |
||||
184 | } |
||||
185 | |||||
186 | 17 | return [$xm, $ym]; |
|||
187 | } |
||||
188 | |||||
189 | 15 | public function SetColor($aColor) |
|||
190 | { |
||||
191 | 15 | $this->color = $aColor; |
|||
192 | 15 | } |
|||
193 | |||||
194 | 12 | public function SetLegend($aLegend, $aCSIM = '', $aCSIMAlt = '', $aCSIMWinTarget = '') |
|||
195 | { |
||||
196 | 12 | $this->legend = $aLegend; |
|||
197 | 12 | $this->legendcsimtarget = $aCSIM; |
|||
198 | 12 | $this->legendcsimwintarget = $aCSIMWinTarget; |
|||
199 | 12 | $this->legendcsimalt = $aCSIMAlt; |
|||
200 | 12 | } |
|||
201 | |||||
202 | 9 | public function SetWeight($aWeight) |
|||
203 | { |
||||
204 | 9 | $this->weight = $aWeight; |
|||
205 | 9 | } |
|||
206 | |||||
207 | 1 | public function SetLineWeight($aWeight = 1) |
|||
208 | { |
||||
209 | 1 | $this->line_weight = $aWeight; |
|||
210 | 1 | } |
|||
211 | |||||
212 | 5 | public function SetCenter($aCenter = true) |
|||
213 | { |
||||
214 | 5 | $this->center = $aCenter; |
|||
215 | 5 | } |
|||
216 | |||||
217 | // This method gets called by Graph class to plot anything that should go |
||||
218 | // into the margin after the margin color has been set. |
||||
219 | 19 | public function StrokeMargin($aImg) |
|||
0 ignored issues
–
show
The parameter
$aImg 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
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
220 | { |
||||
221 | 19 | return true; |
|||
222 | } |
||||
223 | |||||
224 | // Framework function the chance for each plot class to set a legend |
||||
225 | 2 | public function Legend($aGraph) |
|||
226 | { |
||||
227 | 2 | if ($this->legend != '') { |
|||
228 | $aGraph->legend->Add($this->legend, $this->color, '', 0, $this->legendcsimtarget, $this->legendcsimalt, $this->legendcsimwintarget); |
||||
229 | } |
||||
230 | 2 | } |
|||
231 | |||||
232 | public function Clear() |
||||
233 | { |
||||
234 | $this->isRunningClear = true; |
||||
235 | $this->__construct($this->inputValues['aDatay'], $this->inputValues['aDatax']); |
||||
236 | $this->isRunningClear = false; |
||||
237 | } |
||||
238 | } // @class |
||||
239 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.