HuasoFoundries /
jpgraph
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * JPGraph v4.0.3 |
||
| 5 | */ |
||
| 6 | |||
| 7 | namespace Amenadiel\JpGraph\Image; |
||
| 8 | |||
| 9 | use Amenadiel\JpGraph\Util; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @class GanttLink |
||
| 13 | * // Handles the drawing of a link line between 2 points |
||
| 14 | */ |
||
| 15 | class GanttLink |
||
| 16 | { |
||
| 17 | private $ix1; |
||
| 18 | private $ix2; |
||
| 19 | private $iy1; |
||
| 20 | private $iy2; |
||
| 21 | private $iPathType = 2; |
||
| 22 | private $iPathExtend = 15; |
||
| 23 | private $iColor = 'black'; |
||
| 24 | private $iWeight = 1; |
||
| 25 | private $iArrowSize = ARROW_S2; |
||
| 26 | private $iArrowType = ARROWT_SOLID; |
||
| 27 | |||
| 28 | public function __construct($x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) |
||
| 29 | { |
||
| 30 | $this->ix1 = $x1; |
||
| 31 | $this->ix2 = $x2; |
||
| 32 | $this->iy1 = $y1; |
||
| 33 | $this->iy2 = $y2; |
||
| 34 | } |
||
| 35 | |||
| 36 | public function SetPos($x1, $y1, $x2, $y2) |
||
| 37 | { |
||
| 38 | $this->ix1 = $x1; |
||
| 39 | $this->ix2 = $x2; |
||
| 40 | $this->iy1 = $y1; |
||
| 41 | $this->iy2 = $y2; |
||
| 42 | } |
||
| 43 | |||
| 44 | public function SetPath($aPath) |
||
| 45 | { |
||
| 46 | $this->iPathType = $aPath; |
||
| 47 | } |
||
| 48 | |||
| 49 | public function SetColor($aColor) |
||
| 50 | { |
||
| 51 | $this->iColor = $aColor; |
||
| 52 | } |
||
| 53 | |||
| 54 | public function SetArrow($aSize, $aType = ARROWT_SOLID) |
||
| 55 | { |
||
| 56 | $this->iArrowSize = $aSize; |
||
| 57 | $this->iArrowType = $aType; |
||
| 58 | } |
||
| 59 | |||
| 60 | public function SetWeight($aWeight) |
||
| 61 | { |
||
| 62 | $this->iWeight = $aWeight; |
||
| 63 | } |
||
| 64 | |||
| 65 | public function Stroke($aImg) |
||
| 66 | { |
||
| 67 | // The way the path for the arrow is constructed is partly based |
||
| 68 | // on some heuristics. This is not an exact science but draws the |
||
| 69 | // path in a way that, for me, makes esthetic sence. For example |
||
| 70 | // if the start and end activities are very close we make a small |
||
| 71 | // detour to endter the target horixontally. If there are more |
||
| 72 | // space between axctivities then no suh detour is made and the |
||
| 73 | // target is "hit" directly vertical. I have tried to keep this |
||
| 74 | // simple. no doubt this could become almost infinitive complex |
||
| 75 | // and have some real AI. Feel free to modify this. |
||
| 76 | // This will no-doubt be tweaked as times go by. One design aim |
||
| 77 | // is to avoid having the user choose what types of arrow |
||
| 78 | // he wants. |
||
| 79 | |||
| 80 | // The arrow is drawn between (x1,y1) to (x2,y2) |
||
| 81 | $x1 = $this->ix1; |
||
| 82 | $x2 = $this->ix2; |
||
| 83 | $y1 = $this->iy1; |
||
| 84 | $y2 = $this->iy2; |
||
| 85 | |||
| 86 | // Depending on if the target is below or above we have to |
||
| 87 | // handle thi different. |
||
| 88 | if ($y2 > $y1) { |
||
| 89 | $arrowtype = ARROW_DOWN; |
||
| 90 | $midy = round(($y2 - $y1) / 2 + $y1); |
||
| 91 | if ($x2 > $x1) { |
||
| 92 | switch ($this->iPathType) { |
||
| 93 | case 0: |
||
| 94 | $c = [$x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2]; |
||
| 95 | |||
| 96 | break; |
||
| 97 | case 1: |
||
| 98 | case 2: |
||
| 99 | case 3: |
||
| 100 | $c = [$x1, $y1, $x2, $y1, $x2, $y2]; |
||
| 101 | |||
| 102 | break; |
||
| 103 | default: |
||
| 104 | Util\JpGraphError::RaiseL(6032, $this->iPathType); |
||
| 105 | //('Internal error: Unknown path type (='.$this->iPathType .') specified for link.'); |
||
| 106 | exit(1); |
||
|
0 ignored issues
–
show
|
|||
| 107 | |||
| 108 | break; |
||
| 109 | } |
||
| 110 | } else { |
||
| 111 | switch ($this->iPathType) { |
||
| 112 | case 0: |
||
| 113 | case 1: |
||
| 114 | $c = [$x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2]; |
||
| 115 | |||
| 116 | break; |
||
| 117 | case 2: |
||
| 118 | // Always extend out horizontally a bit from the first point |
||
| 119 | // If we draw a link back in time (end to start) and the bars |
||
| 120 | // are very close we also change the path so it comes in from |
||
| 121 | // the left on the activity |
||
| 122 | $c = [$x1, $y1, $x1 + $this->iPathExtend, $y1, |
||
| 123 | $x1 + $this->iPathExtend, $midy, |
||
| 124 | $x2, $midy, $x2, $y2, ]; |
||
| 125 | |||
| 126 | break; |
||
| 127 | case 3: |
||
| 128 | if ($y2 - $midy < 6) { |
||
| 129 | $c = [$x1, $y1, $x1, $midy, |
||
| 130 | $x2 - $this->iPathExtend, $midy, |
||
| 131 | $x2 - $this->iPathExtend, $y2, |
||
| 132 | $x2, $y2, ]; |
||
| 133 | $arrowtype = ARROW_RIGHT; |
||
| 134 | } else { |
||
| 135 | $c = [$x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2]; |
||
| 136 | } |
||
| 137 | |||
| 138 | break; |
||
| 139 | default: |
||
| 140 | Util\JpGraphError::RaiseL(6032, $this->iPathType); |
||
| 141 | //('Internal error: Unknown path type specified for link.'); |
||
| 142 | exit(1); |
||
|
0 ignored issues
–
show
|
|||
| 143 | |||
| 144 | break; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | $arrow = new LinkArrow($x2, $y2, $arrowtype); |
||
| 148 | } else { |
||
| 149 | // Y2 < Y1 |
||
| 150 | $arrowtype = ARROW_UP; |
||
| 151 | $midy = round(($y1 - $y2) / 2 + $y2); |
||
| 152 | if ($x2 > $x1) { |
||
| 153 | switch ($this->iPathType) { |
||
| 154 | case 0: |
||
| 155 | case 1: |
||
| 156 | $c = [$x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2]; |
||
| 157 | |||
| 158 | break; |
||
| 159 | case 3: |
||
| 160 | if ($midy - $y2 < 8) { |
||
| 161 | $arrowtype = ARROW_RIGHT; |
||
| 162 | $c = [$x1, $y1, $x1, $y2, $x2, $y2]; |
||
| 163 | } else { |
||
| 164 | $c = [$x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2]; |
||
| 165 | } |
||
| 166 | |||
| 167 | break; |
||
| 168 | default: |
||
| 169 | Util\JpGraphError::RaiseL(6032, $this->iPathType); |
||
| 170 | //('Internal error: Unknown path type specified for link.'); |
||
| 171 | break; |
||
| 172 | } |
||
| 173 | } else { |
||
| 174 | switch ($this->iPathType) { |
||
| 175 | case 0: |
||
| 176 | case 1: |
||
| 177 | $c = [$x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2]; |
||
| 178 | |||
| 179 | break; |
||
| 180 | case 2: |
||
| 181 | // Always extend out horizontally a bit from the first point |
||
| 182 | $c = [$x1, $y1, $x1 + $this->iPathExtend, $y1, |
||
| 183 | $x1 + $this->iPathExtend, $midy, |
||
| 184 | $x2, $midy, $x2, $y2, ]; |
||
| 185 | |||
| 186 | break; |
||
| 187 | case 3: |
||
| 188 | if ($midy - $y2 < 16) { |
||
| 189 | $arrowtype = ARROW_RIGHT; |
||
| 190 | $c = [$x1, $y1, $x1, $midy, $x2 - $this->iPathExtend, $midy, |
||
| 191 | $x2 - $this->iPathExtend, $y2, |
||
| 192 | $x2, $y2, ]; |
||
| 193 | } else { |
||
| 194 | $c = [$x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2]; |
||
| 195 | } |
||
| 196 | |||
| 197 | break; |
||
| 198 | default: |
||
| 199 | Util\JpGraphError::RaiseL(6032, $this->iPathType); |
||
| 200 | //('Internal error: Unknown path type specified for link.'); |
||
| 201 | break; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | $arrow = new LinkArrow($x2, $y2, $arrowtype); |
||
| 205 | } |
||
| 206 | $aImg->SetColor($this->iColor); |
||
| 207 | $aImg->SetLineWeight($this->iWeight); |
||
| 208 | $aImg->Polygon($c); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 209 | $aImg->SetLineWeight(1); |
||
| 210 | $arrow->SetColor($this->iColor); |
||
| 211 | $arrow->SetSize($this->iArrowSize); |
||
| 212 | $arrow->SetType($this->iArrowType); |
||
| 213 | $arrow->Stroke($aImg); |
||
| 214 | } |
||
| 215 | } |
||
| 216 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.