1 | <?php |
||
2 | |||
3 | /** |
||
4 | * JPGraph v4.0.3 |
||
5 | */ |
||
6 | |||
7 | namespace Amenadiel\JpGraph\Plot; |
||
8 | |||
9 | use Amenadiel\JpGraph\Graph; |
||
10 | use Amenadiel\JpGraph\Util; |
||
11 | |||
12 | /** |
||
13 | * @class ScatterPlot |
||
14 | * // Description: Render X and Y plots |
||
15 | */ |
||
16 | class ScatterPlot extends Plot |
||
17 | { |
||
18 | public $mark; |
||
19 | public $link; |
||
20 | private $impuls = false; |
||
21 | |||
22 | /** |
||
23 | * CONSTRUCTOR. |
||
24 | * |
||
25 | * @param mixed $datay |
||
26 | * @param mixed $datax |
||
27 | */ |
||
28 | 2 | public function __construct($datay, $datax = false) |
|
29 | { |
||
30 | 2 | if ((safe_count($datax) != safe_count($datay)) && is_array($datax)) { |
|
31 | Util\JpGraphError::RaiseL(20003); //("Scatterplot must have equal number of X and Y points."); |
||
32 | } |
||
33 | 2 | parent::__construct($datay, $datax); |
|
34 | 2 | $this->mark = new PlotMark(); |
|
35 | 2 | $this->mark->SetType(MARK_SQUARE); |
|
36 | 2 | $this->mark->SetColor($this->color); |
|
37 | 2 | $this->value->SetAlign('center', 'center'); |
|
38 | 2 | $this->value->SetMargin(0); |
|
39 | 2 | $this->link = new Graph\LineProperty(1, 'black', 'solid'); |
|
40 | 2 | $this->link->iShow = false; |
|
41 | 2 | } |
|
42 | |||
43 | /** |
||
44 | * PUBLIC METHODS. |
||
45 | * |
||
46 | * @param mixed $f |
||
47 | */ |
||
48 | 1 | public function SetImpuls($f = true) |
|
49 | { |
||
50 | 1 | $this->impuls = $f; |
|
51 | 1 | } |
|
52 | |||
53 | public function SetStem($f = true) |
||
54 | { |
||
55 | $this->impuls = $f; |
||
56 | } |
||
57 | |||
58 | // Combine the scatter plot points with a line |
||
59 | 1 | public function SetLinkPoints($aFlag = true, $aColor = 'black', $aWeight = 1, $aStyle = 'solid') |
|
60 | { |
||
61 | 1 | $this->link->iShow = $aFlag; |
|
62 | 1 | $this->link->iColor = $aColor; |
|
63 | 1 | $this->link->iWeight = $aWeight; |
|
64 | 1 | $this->link->iStyle = $aStyle; |
|
65 | 1 | } |
|
66 | |||
67 | 2 | public function Stroke($img, $xscale, $yscale) |
|
68 | { |
||
69 | 2 | $ymin = $yscale->scale_abs[0]; |
|
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
70 | 2 | if ($yscale->scale[0] < 0) { |
|
71 | 2 | $yzero = $yscale->Translate(0); |
|
72 | } else { |
||
73 | 1 | $yzero = $yscale->scale_abs[0]; |
|
74 | } |
||
75 | |||
76 | 2 | $this->csimareas = ''; |
|
77 | 2 | for ($i = 0; $i < $this->numpoints; ++$i) { |
|
78 | // Skip null values |
||
79 | 2 | if ($this->coords[0][$i] === '' || $this->coords[0][$i] === '-' || $this->coords[0][$i] === 'x') { |
|
80 | continue; |
||
81 | } |
||
82 | |||
83 | 2 | if (isset($this->coords[1])) { |
|
84 | 2 | $xt = $xscale->Translate($this->coords[1][$i]); |
|
85 | } else { |
||
86 | 1 | $xt = $xscale->Translate($i); |
|
87 | } |
||
88 | |||
89 | 2 | $yt = $yscale->Translate($this->coords[0][$i]); |
|
90 | |||
91 | 2 | if ($this->link->iShow && isset($yt_old)) { |
|
92 | 1 | $img->SetColor($this->link->iColor); |
|
93 | 1 | $img->SetLineWeight($this->link->iWeight); |
|
94 | 1 | $old = $img->SetLineStyle($this->link->iStyle); |
|
95 | 1 | $img->StyleLine($xt_old, $yt_old, $xt, $yt); |
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
96 | 1 | $img->SetLineStyle($old); |
|
97 | } |
||
98 | |||
99 | 2 | if ($this->impuls) { |
|
100 | 1 | $img->SetColor($this->color); |
|
101 | 1 | $img->SetLineWeight($this->weight); |
|
102 | 1 | $img->Line($xt, $yzero, $xt, $yt); |
|
103 | } |
||
104 | |||
105 | 2 | if (!empty($this->csimtargets[$i])) { |
|
106 | if (!empty($this->csimwintargets[$i])) { |
||
107 | $this->mark->SetCSIMTarget($this->csimtargets[$i], $this->csimwintargets[$i]); |
||
108 | } else { |
||
109 | $this->mark->SetCSIMTarget($this->csimtargets[$i]); |
||
110 | } |
||
111 | $this->mark->SetCSIMAlt($this->csimalts[$i]); |
||
112 | } |
||
113 | |||
114 | 2 | if (isset($this->coords[1])) { |
|
115 | 2 | $this->mark->SetCSIMAltVal($this->coords[0][$i], $this->coords[1][$i]); |
|
116 | } else { |
||
117 | 1 | $this->mark->SetCSIMAltVal($this->coords[0][$i], $i); |
|
118 | } |
||
119 | |||
120 | 2 | $this->mark->Stroke($img, $xt, $yt); |
|
121 | |||
122 | 2 | $this->csimareas .= $this->mark->GetCSIMAreas(); |
|
123 | 2 | $this->value->Stroke($img, $this->coords[0][$i], $xt, $yt); |
|
124 | |||
125 | 2 | $xt_old = $xt; |
|
126 | 2 | $yt_old = $yt; |
|
127 | } |
||
128 | 2 | } |
|
129 | |||
130 | // Framework function |
||
131 | 2 | public function Legend($aGraph) |
|
132 | { |
||
133 | 2 | if ($this->legend != '') { |
|
134 | 1 | $aGraph->legend->Add( |
|
135 | 1 | $this->legend, |
|
136 | 1 | $this->mark->fill_color, |
|
137 | 1 | $this->mark, |
|
138 | 1 | 0, |
|
139 | 1 | $this->legendcsimtarget, |
|
140 | 1 | $this->legendcsimalt, |
|
141 | 1 | $this->legendcsimwintarget |
|
142 | ); |
||
143 | } |
||
144 | 2 | } |
|
145 | } // @class |
||
146 | /* EOF */ |
||
147 |