| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright (C) 2022 Graham Breach |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU Lesser General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
/** |
| 19 |
* For more information, please contact <graham@goat1000.com> |
| 20 |
*/ |
| 21 |
|
| 22 |
namespace Goat1000\SVGGraph; |
| 23 |
|
| 24 |
/** |
| 25 |
* A class for drawing arrows |
| 26 |
*/ |
| 27 |
class GanttArrow extends Arrow { |
| 28 |
|
| 29 |
protected $type = 0; |
| 30 |
protected $vsplit = false; |
| 31 |
protected $space = 10; |
| 32 |
|
| 33 |
public function __construct(Point $a, Point $b, $wa, $ha, $wb, $hb, $type, $sp) |
| 34 |
{ |
| 35 |
switch($type) { |
| 36 |
|
| 37 |
case 'SS': |
| 38 |
$this->vsplit = ($a->x < $b->x); |
| 39 |
break; |
| 40 |
|
| 41 |
case 'FF': |
| 42 |
$a->x += $wa; |
| 43 |
$b->x += $wb; |
| 44 |
$this->vsplit = ($a->x > $b->x); |
| 45 |
break; |
| 46 |
|
| 47 |
case 'SF': |
| 48 |
$b->x += $wb; |
| 49 |
$this->vsplit = ($a->x < $b->x); |
| 50 |
break; |
| 51 |
|
| 52 |
case 'FS': |
| 53 |
default: |
| 54 |
$a->x += $wa; |
| 55 |
$this->vsplit = ($a->x > $b->x); |
| 56 |
} |
| 57 |
$a->y += $ha; |
| 58 |
|
| 59 |
// only start horizontal if the first element has some width |
| 60 |
if($wa < 1) |
| 61 |
$this->vsplit = true; |
| 62 |
|
| 63 |
parent::__construct($a, $b); |
| 64 |
$this->type = $type; |
| 65 |
$this->space = max(5, $sp); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Returns the PathData for an arrow line |
| 70 |
*/ |
| 71 |
protected function getArrowPath() |
| 72 |
{ |
| 73 |
$p = new PathData('M', $this->a); |
| 74 |
$dx = $this->b->x - $this->a->x; |
| 75 |
$dy = $this->b->y - $this->a->y; |
| 76 |
|
| 77 |
if($dx && $this->vsplit) { |
| 78 |
$v1 = new Number($dy - $this->space); |
| 79 |
$v2 = new Number($this->space); |
| 80 |
$p->add('v', $v1); |
| 81 |
$p->add('h', new Number($dx)); |
| 82 |
$p->add('v', $v2); |
| 83 |
|
| 84 |
} else { |
| 85 |
// if horizontal very small, ignore it |
| 86 |
if(abs($dx) > 0.1) |
| 87 |
$p->add('h', new Number($dx)); |
| 88 |
$p->add('v', new Number($this->b->y - $this->a->y)); |
| 89 |
} |
| 90 |
return $p; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
|