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