Initial repo created
[timetracker.git] / WEB-INF / lib / libchart / classes / view / caption / Caption.php
1 <?php
2         /* Libchart - PHP chart library
3          * Copyright (C) 2005-2008 Jean-Marc Trémeaux (jm.tremeaux at gmail.com)
4          * 
5          * This program is free software: you can redistribute it and/or modify
6          * it under the terms of the GNU 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 General Public License for more details.
14          *
15          * You should have received a copy of the GNU General Public License
16          * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17          * 
18          */
19         
20         /**
21          * Caption.
22          *
23          * @author Jean-Marc Trémeaux (jm.tremeaux at gmail.com)
24          * Created on 30 july 2007
25          */
26         class Caption {
27                 protected $labelBoxWidth;
28                 protected $labelBoxHeight;
29         
30                 // Plot
31                 protected $plot;
32                 
33                 // Label list
34                 protected $labelList;
35                 
36                 // Color set
37                 protected $colorSet;
38                 
39                 /**
40                  * Constructor of Caption
41                  */
42                 public function Caption() {
43                         $this->labelBoxWidth = 15;
44                         $this->labelBoxHeight = 15;
45                 }
46                 
47                 /**
48                  * Render the caption.
49                  */
50                 public function render() {
51                         // Get graphical obects
52                         $img = $this->plot->getImg();
53                         $palette = $this->plot->getPalette();
54                         $text = $this->plot->getText();
55                         $primitive = $this->plot->getPrimitive();
56                         
57                         // Get the caption area
58                         $captionArea = $this->plot->getCaptionArea();
59
60                         // Get the pie color set
61                         $colorSet = $this->colorSet;
62                         $colorSet->reset();
63                         
64                         $i = 0;
65                         foreach ($this->labelList as $label) {
66                                 // Get the next color
67                                 $color = $colorSet->currentColor();
68                                 $colorSet->next();
69
70                                 $boxX1 = $captionArea->x1;
71                                 $boxX2 = $boxX1 + $this->labelBoxWidth;
72                                 $boxY1 = $captionArea->y1 + 5 + $i * ($this->labelBoxHeight + 5);
73                                 $boxY2 = $boxY1 + $this->labelBoxHeight;
74
75                                 $primitive->outlinedBox($boxX1, $boxY1, $boxX2, $boxY2, $palette->axisColor[0], $palette->axisColor[1]);
76                                 imagefilledrectangle($img, $boxX1 + 2, $boxY1 + 2, $boxX2 - 2, $boxY2 - 2, $color->getColor($img));
77
78                                 $text->printText($img, $boxX2 + 5, $boxY1 + $this->labelBoxHeight / 2, $this->plot->getTextColor(), $label, $text->fontCondensed, $text->VERTICAL_CENTER_ALIGN);
79
80                                 $i++;
81                         }
82                 }
83
84                 /**
85                  * Sets the plot.
86                  *
87                  * @param Plot The plot
88                  */
89                 public function setPlot($plot) {
90                         $this->plot = $plot;
91                 }
92                 
93                 /**
94                  * Sets the label list.
95                  *
96                  * @param Array label list
97                  */
98                 public function setLabelList($labelList) {
99                         $this->labelList = $labelList;
100                 }
101                 
102                 
103                 /**
104                  * Sets the color set.
105                  *
106                  * @param Array Color set
107                  */
108                 public function setColorSet($colorSet) {
109                         $this->colorSet = $colorSet;
110                 }
111         }
112 ?>