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