1 | <?php |
||
2 | |||
3 | /** |
||
4 | * JPGraph v4.0.3 |
||
5 | */ |
||
6 | |||
7 | namespace Amenadiel\JpGraph\Graph; |
||
8 | |||
9 | use Amenadiel\JpGraph\Text; |
||
10 | use Amenadiel\JpGraph\Util; |
||
11 | |||
12 | /** |
||
13 | * File: JPGRAPH_GANTT.PHP |
||
14 | * // Description: JpGraph Gantt plot extension |
||
15 | * // Created: 2001-11-12 |
||
16 | * // Ver: $Id: jpgraph_gantt.php 1809 2009-09-09 13:07:33Z ljp $ |
||
17 | * // |
||
18 | * // Copyright (c) Asial Corporation. All rights reserved. |
||
19 | */ |
||
20 | |||
21 | /** |
||
22 | * @class GanttActivityInfo |
||
23 | * // Description: |
||
24 | */ |
||
25 | class GanttActivityInfo |
||
26 | { |
||
27 | public $iShow = true; |
||
28 | public $iLeftColMargin = 4; |
||
29 | public $iRightColMargin = 1; |
||
30 | public $iTopColMargin = 1; |
||
31 | public $iBottomColMargin = 3; |
||
32 | public $vgrid; |
||
33 | private $iColor = 'black'; |
||
34 | private $iBackgroundColor = 'lightgray'; |
||
35 | private $iFFamily = FF_FONT1; |
||
36 | private $iFStyle = FS_NORMAL; |
||
37 | private $iFSize = 10; |
||
38 | private $iFontColor = 'black'; |
||
39 | private $iTitles = []; |
||
40 | private $iWidth = []; |
||
41 | private $iHeight = -1; |
||
42 | private $iTopHeaderMargin = 4; |
||
43 | private $iStyle = 1; |
||
44 | private $iHeaderAlign = 'center'; |
||
45 | |||
46 | public function __construct() |
||
47 | { |
||
48 | $this->vgrid = new LineProperty(); |
||
49 | } |
||
50 | |||
51 | public function Hide($aF = true) |
||
52 | { |
||
53 | $this->iShow = !$aF; |
||
54 | } |
||
55 | |||
56 | public function Show($aF = true) |
||
57 | { |
||
58 | $this->iShow = $aF; |
||
59 | } |
||
60 | |||
61 | // Specify font |
||
62 | public function SetFont($aFFamily, $aFStyle = FS_NORMAL, $aFSize = 10) |
||
63 | { |
||
64 | $this->iFFamily = $aFFamily; |
||
65 | $this->iFStyle = $aFStyle; |
||
66 | $this->iFSize = $aFSize; |
||
67 | } |
||
68 | |||
69 | public function SetStyle($aStyle) |
||
70 | { |
||
71 | $this->iStyle = $aStyle; |
||
72 | } |
||
73 | |||
74 | public function SetColumnMargin($aLeft, $aRight) |
||
75 | { |
||
76 | $this->iLeftColMargin = $aLeft; |
||
77 | $this->iRightColMargin = $aRight; |
||
78 | } |
||
79 | |||
80 | public function SetFontColor($aFontColor) |
||
81 | { |
||
82 | $this->iFontColor = $aFontColor; |
||
83 | } |
||
84 | |||
85 | public function SetColor($aColor) |
||
86 | { |
||
87 | $this->iColor = $aColor; |
||
88 | } |
||
89 | |||
90 | public function SetBackgroundColor($aColor) |
||
91 | { |
||
92 | $this->iBackgroundColor = $aColor; |
||
93 | } |
||
94 | |||
95 | public function SetColTitles($aTitles, $aWidth = null) |
||
96 | { |
||
97 | $this->iTitles = $aTitles; |
||
98 | $this->iWidth = $aWidth; |
||
99 | } |
||
100 | |||
101 | public function SetMinColWidth($aWidths) |
||
102 | { |
||
103 | $n = min(safe_count($this->iTitles), safe_count($aWidths)); |
||
104 | for ($i = 0; $i < $n; ++$i) { |
||
105 | if (!empty($aWidths[$i])) { |
||
106 | if (empty($this->iWidth[$i])) { |
||
107 | $this->iWidth[$i] = $aWidths[$i]; |
||
108 | } else { |
||
109 | $this->iWidth[$i] = max($this->iWidth[$i], $aWidths[$i]); |
||
110 | } |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | |||
115 | public function GetWidth($aImg) |
||
116 | { |
||
117 | $txt = new Text\TextProperty(); |
||
118 | $txt->SetFont($this->iFFamily, $this->iFStyle, $this->iFSize); |
||
119 | $n = safe_count($this->iTitles); |
||
120 | $rm = $this->iRightColMargin; |
||
121 | $w = 0; |
||
122 | for ($h = 0, $i = 0; $i < $n; ++$i) { |
||
123 | $w += $this->iLeftColMargin; |
||
124 | $txt->Set($this->iTitles[$i]); |
||
125 | if (!empty($this->iWidth[$i])) { |
||
126 | $w1 = max($txt->GetWidth($aImg) + $rm, $this->iWidth[$i]); |
||
127 | } else { |
||
128 | $w1 = $txt->GetWidth($aImg) + $rm; |
||
129 | } |
||
130 | $this->iWidth[$i] = $w1; |
||
131 | $w += $w1; |
||
132 | $h = max($h, $txt->GetHeight($aImg)); |
||
133 | } |
||
134 | $this->iHeight = $h + $this->iTopHeaderMargin; |
||
135 | $txt = ''; |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
136 | |||
137 | return $w; |
||
138 | } |
||
139 | |||
140 | public function GetColStart($aImg, &$aStart, $aAddLeftMargin = false) |
||
141 | { |
||
142 | $n = safe_count($this->iTitles); |
||
143 | $adj = $aAddLeftMargin ? $this->iLeftColMargin : 0; |
||
144 | $aStart = [$aImg->left_margin + $adj]; |
||
145 | for ($i = 1; $i < $n; ++$i) { |
||
146 | $aStart[$i] = $aStart[$i - 1] + $this->iLeftColMargin + $this->iWidth[$i - 1]; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | // Adjust headers left, right or centered |
||
151 | public function SetHeaderAlign($aAlign) |
||
152 | { |
||
153 | $this->iHeaderAlign = $aAlign; |
||
154 | } |
||
155 | |||
156 | public function Stroke($aImg, $aXLeft, $aYTop, $aXRight, $aYBottom, $aUseTextHeight = false) |
||
157 | { |
||
158 | if (!$this->iShow) { |
||
159 | return; |
||
160 | } |
||
161 | |||
162 | $txt = new Text\TextProperty(); |
||
163 | $txt->SetFont($this->iFFamily, $this->iFStyle, $this->iFSize); |
||
164 | $txt->SetColor($this->iFontColor); |
||
165 | $txt->SetAlign($this->iHeaderAlign, 'top'); |
||
166 | $n = safe_count($this->iTitles); |
||
167 | |||
168 | if ($n == 0) { |
||
169 | return; |
||
170 | } |
||
171 | |||
172 | $x = $aXLeft; |
||
173 | $h = $this->iHeight; |
||
174 | $yTop = $aUseTextHeight ? $aYBottom - $h - $this->iTopColMargin - $this->iBottomColMargin : $aYTop; |
||
175 | |||
176 | if ($h < 0) { |
||
177 | Util\JpGraphError::RaiseL(6001); |
||
178 | //('Internal error. Height for ActivityTitles is < 0'); |
||
179 | } |
||
180 | |||
181 | $aImg->SetLineWeight(1); |
||
182 | // Set background color |
||
183 | $aImg->SetColor($this->iBackgroundColor); |
||
184 | $aImg->FilledRectangle($aXLeft, $yTop, $aXRight, $aYBottom - 1); |
||
185 | |||
186 | if ($this->iStyle == 1) { |
||
187 | // Make a 3D effect |
||
188 | $aImg->SetColor('white'); |
||
189 | $aImg->Line($aXLeft, $yTop + 1, $aXRight, $yTop + 1); |
||
190 | } |
||
191 | |||
192 | for ($i = 0; $i < $n; ++$i) { |
||
193 | if ($this->iStyle == 1) { |
||
194 | // Make a 3D effect |
||
195 | $aImg->SetColor('white'); |
||
196 | $aImg->Line($x + 1, $yTop, $x + 1, $aYBottom); |
||
197 | } |
||
198 | $x += $this->iLeftColMargin; |
||
199 | $txt->Set($this->iTitles[$i]); |
||
200 | |||
201 | // Adjust the text anchor position according to the choosen alignment |
||
202 | $xp = $x; |
||
203 | if ($this->iHeaderAlign == 'center') { |
||
204 | $xp = (($x - $this->iLeftColMargin) + ($x + $this->iWidth[$i])) / 2; |
||
205 | } elseif ($this->iHeaderAlign == 'right') { |
||
206 | $xp = $x + $this->iWidth[$i] - $this->iRightColMargin; |
||
207 | } |
||
208 | |||
209 | $txt->Stroke($aImg, $xp, $yTop + $this->iTopHeaderMargin); |
||
210 | $x += $this->iWidth[$i]; |
||
211 | if ($i < $n - 1) { |
||
212 | $aImg->SetColor($this->iColor); |
||
213 | $aImg->Line($x, $yTop, $x, $aYBottom); |
||
214 | } |
||
215 | } |
||
216 | |||
217 | $aImg->SetColor($this->iColor); |
||
218 | $aImg->Line($aXLeft, $yTop, $aXRight, $yTop); |
||
219 | |||
220 | // Stroke vertical column dividers |
||
221 | $cols = []; |
||
222 | $this->GetColStart($aImg, $cols); |
||
223 | $n = safe_count($cols); |
||
224 | for ($i = 1; $i < $n; ++$i) { |
||
225 | $this->vgrid->Stroke( |
||
226 | $aImg, |
||
227 | $cols[$i], |
||
228 | $aYBottom, |
||
229 | $cols[$i], |
||
230 | $aImg->height - $aImg->bottom_margin |
||
231 | ); |
||
232 | } |
||
233 | } |
||
234 | } |
||
235 |