1<?php
2namespace Amenadiel\JpGraph\Plot;
3
4use Amenadiel\JpGraph\Graph;
5
6class GanttVLine extends GanttPlotObject
7{
8    private $iLine;
9    private $title_margin         = 3;
10    private $iDayOffset           = 0.5;
11    private $iStartRow            = -1;
12    private $iEndRow              = -1;
13
14    //---------------
15    // CONSTRUCTOR
16    public function __construct($aDate, $aTitle = "", $aColor = "darkred", $aWeight = 2, $aStyle = "solid")
17    {
18        GanttPlotObject::__construct();
19        $this->iLine = new Graph\LineProperty();
20        $this->iLine->SetColor($aColor);
21        $this->iLine->SetWeight($aWeight);
22        $this->iLine->SetStyle($aStyle);
23        $this->iStart = $aDate;
24        $this->title  = new TextPropertyBelow();
25        $this->title->Set($aTitle);
26    }
27
28    //---------------
29    // PUBLIC METHODS
30
31    // Set start and end rows for the VLine. By default the entire heigh of the
32    // Gantt chart is used
33    public function SetRowSpan($aStart, $aEnd = -1)
34    {
35        $this->iStartRow = $aStart;
36        $this->iEndRow   = $aEnd;
37    }
38
39    public function SetDayOffset($aOff = 0.5)
40    {
41        if ($aOff < 0.0 || $aOff > 1.0) {
42            Util\JpGraphError::RaiseL(6029);
43            //("Offset for vertical line must be in range [0,1]");
44        }
45        $this->iDayOffset = $aOff;
46    }
47
48    public function SetTitleMargin($aMarg)
49    {
50        $this->title_margin = $aMarg;
51    }
52
53    public function SetWeight($aWeight)
54    {
55        $this->iLine->SetWeight($aWeight);
56    }
57
58    public function Stroke($aImg, $aScale)
59    {
60        $d = $aScale->NormalizeDate($this->iStart);
61        if ($d < $aScale->iStartDate || $d > $aScale->iEndDate) {
62            return;
63        }
64
65        if ($this->iDayOffset != 0.0) {
66            $d += 24 * 60 * 60 * $this->iDayOffset;
67        }
68
69        $x = $aScale->TranslateDate($d); //d=1006858800,
70
71        if ($this->iStartRow > -1) {
72            $y1 = $aScale->TranslateVertPos($this->iStartRow, true);
73        } else {
74            $y1 = $aScale->iVertHeaderSize + $aImg->top_margin;
75        }
76
77        if ($this->iEndRow > -1) {
78            $y2 = $aScale->TranslateVertPos($this->iEndRow);
79        } else {
80            $y2 = $aImg->height - $aImg->bottom_margin;
81        }
82
83        $this->iLine->Stroke($aImg, $x, $y1, $x, $y2);
84        $this->title->Align("center", "top");
85        $this->title->Stroke($aImg, $x, $y2 + $this->title_margin);
86    }
87}
88