source: temp/trunk/html/admin/total/class/SC_GraphLine.php @ 5410

Revision 5410, 8.1 KB checked in by kakinaka, 20 years ago (diff)

blank

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?
2$SC_GRAPHLINE_DIR = realpath(dirname( __FILE__));
3require_once($SC_GRAPHLINE_DIR . "/SC_GraphBase.php"); 
4
5// ÀÞ¤ìÀþ¥°¥é¥ÕÀ¸À®¥¯¥é¥¹
6class SC_GraphLine extends SC_GraphBase{
7    var $area_width;
8    var $area_height;
9    var $ygrid_on;
10    var $graph_max;     // ¥°¥é¥Õ¤Î¥¨¥ê¥¢ºÇÂçÃÍ(Y¼´ÄºÅÀ¤ÎÃÍ)
11    var $arrXLabel;
12    var $XLabelAngle;   // X¼´¥é¥Ù¥ë³ÑÅÙ   
13    var $XTitle;        // X¼´¥¿¥¤¥È¥ë
14    var $YTitle;        // Y¼´¥¿¥¤¥È¥ë
15    var $arrDataList;   // ¥°¥é¥Õ¥Ç¡¼¥¿¤ò³ÊǼ
16    var $arrPointList;  // ÀÞ¤ìÀþºÂɸ¤ò³ÊǼ
17    var $line_max;      // Ê£¿ô¤ÎÉÁ²è¤Î¾ì¹ç¤Ë²Ã»»¤·¤Æ¤¤¤¯
18   
19    var $x_margin;
20    var $y_margin;
21           
22    // ¥³¥ó¥¹¥È¥é¥¯¥¿
23    function SC_GraphLine(
24        $bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = LINE_LEFT, $top = LINE_TOP,
25        $area_width = LINE_AREA_WIDTH, $area_height = LINE_AREA_HEIGHT) {
26        parent::SC_GraphBase($bgw, $bgh, $left, $top); 
27        $this->area_width = $area_width;
28        $this->area_height = $area_height;
29        $this->ygrid_on = true;
30        $this->line_max = 0;
31        $this->graph_max = 0;
32        $this->XLabelAngle = 0;
33        $this->x_margin = 0;
34        $this->y_margin = 0;
35    }
36   
37    // X¼´¥é¥Ù¥ë¤Î³ÑÅÙ¥»¥Ã¥È
38    function setXLabelAngle($Angle) {
39        $this->XLabelAngle = $Angle;
40    }
41   
42    // Y¼´¥¿¥¤¥È¥ë
43    function drawYTitle() {
44        // Y¼´¤Ë¥¿¥¤¥È¥ë¤òÆþ¤ì¤ë
45        if($this->YTitle != "") {
46            $text_width = $this->getTextWidth($this->YTitle, FONT_SIZE);
47            $x_pos = $this->left - ($text_width / 2);
48            $y_pos = $this->top - FONT_SIZE - LINE_YTITLE_PAD;     
49            $this->setText(FONT_SIZE, $x_pos, $y_pos, $this->YTitle);
50        }
51    }
52   
53    // X¼´¥¿¥¤¥È¥ë
54    function drawXTitle() {
55        // Y¼´¤Ë¥¿¥¤¥È¥ë¤òÆþ¤ì¤ë
56        if($this->XTitle != "") {
57            $text_width = $this->getTextWidth($this->XTitle, FONT_SIZE);
58            $x_pos = $this->left + $this->area_width - ($text_width / 2) + 30;
59            $y_pos = $this->top + $this->area_height + LINE_XTITLE_PAD;
60            $this->setText(FONT_SIZE, $x_pos, $y_pos, $this->XTitle);
61        }
62    }
63   
64    // Y¼´¤ÎÉÁ²è
65    function drawYLine() {
66        imageline($this->image, $this->left, $this->top, $this->left, $this->top + $this->area_height, $this->flame_color);
67        // ÌÜÀ¹¤êÉý¤òµá¤á¤ë(Ãæ´ÖÅÀ¤Ï¼«Æ°)
68        $size = $this->area_height / (LINE_Y_SCALE * 2);
69        // ¾å¤«¤éÌÜÀ¹¤ê¤òÆþ¤ì¤Æ¤¤¤¯
70        $pos = 0;
71        for($i = 0; $i < (LINE_Y_SCALE * 2); $i++) {
72            // ÌÜÀ¹¤êÉý
73            if(($i % 2) == 0) {
74                $sw = LINE_SCALE_SIZE;
75                if($this->ygrid_on) {
76                    imageline($this->image, $this->left, $this->top + $pos, $this->left + $this->area_width, $this->top + $pos, $this->grid_color);
77                }
78            } else {
79                $sw = LINE_SCALE_SIZE / 2;
80            }
81            imageline($this->image, $this->left, $this->top + $pos, $this->left + $sw, $this->top + $pos, $this->flame_color);
82            $pos += $size;
83        }
84        // Y¼´¤ËÌÜÀ¹¤êÃͤòÆþ¤ì¤ë
85        $this->setYScale();
86        $this->drawYTitle();   
87    }
88   
89    // X¼´¤ÎÉÁ²è
90    function drawXLine($bar = false) {
91        imageline($this->image, $this->left, $this->top + $this->area_height, $this->left + $this->area_width, $this->top + $this->area_height, $this->flame_color);
92        $arrPointList = $this->arrPointList[0];
93        $count = count($arrPointList);
94       
95        // ËÀ¥°¥é¥Õ¤Î¾ì¹ç¤ÏȾÌÜÀ¹¤ê¤º¤é¤¹
96        if($bar) {
97            $half_scale = intval($this->area_width / ($count + 1) / 2);
98        } else {
99            $half_scale = 0;
100        }
101       
102        // ¥é¥Ù¥ë¤Îɽ¼¨¥¤¥ó¥¿¡¼¥Ð¥ë¤ò»»½Ð
103        $interval = ceil($count / LINE_XLABEL_MAX); // ÀÚ¤ê¾å¤²             
104        for($i = 0; $i < $count; $i++) {
105            // X¼´¤ËÌÜÀ¹¤ê¤òÆþ¤ì¤ë
106            $x = $arrPointList[$i][0];
107            $pos = $this->top + $this->area_height;
108            imageline($this->image, $x - $half_scale, $pos, $x - $half_scale, $pos - LINE_SCALE_SIZE,  $this->flame_color);         
109            // ¥é¥Ù¥ë¤òÆþ¤ì¤ë
110            if(($i % $interval) == 0) {
111                $text_width = $this->getTextWidth($this->arrXLabel[$i], FONT_SIZE);
112                $x_pos = $x;
113               
114                if ($bar) $bar_margin = -15;
115
116                $this->setText(FONT_SIZE, $x_pos + $this->x_margin + $bar_margin, $pos + FONT_SIZE + $this->y_margin, $this->arrXLabel[$i], NULL, $this->XLabelAngle);
117            }
118        }
119       
120        // ËÀ¥°¥é¥Õ¤Î¾ì¹ç¤ÏºÇ¸å¤ÎÌÜÀ¹¤ê¤ò°ì¤ÄÄɲ乤ë
121        if($bar) {
122            imageline($this->image, $x + $half_scale, $pos, $x + $half_scale, $pos - LINE_SCALE_SIZE,  $this->flame_color);
123        }
124       
125        $this->drawXTitle();
126    }
127       
128    // ¥°¥ê¥Ã¥Éɽ¼¨
129    function setYGridOn($ygrid_on) {
130        $this->ygrid_on = $ygrid_on;
131    }
132   
133    // ¥Ý¥¤¥ó¥È¤ÎÉÁ²è
134    function setMark($line_no, $left, $top, $size = LINE_MARK_SIZE) {
135        // ¶ö¿ô¤ËÊÑ´¹¤·¤Æ¤ª¤¯
136        $size += $size % 2;
137        $array = array(
138            $left, $top - ($size / 2),
139            $left + ($size / 2), $top,
140            $left, $top + ($size / 2),
141            $left - ($size / 2), $top,
142        );     
143        imagefilledpolygon($this->image, $array, 4, $this->arrColor[$line_no]);
144        imagepolygon($this->image, $array, 4, $this->flame_color);
145        imagesetpixel ($this->image, $left, $top + ($size / 2), $this->flame_color);
146    }   
147   
148    // Y¼´ÌÜÀ¹¤ê¤ËÃͤòÆþ¤ì¤ë
149    function setYScale() {
150        // 1ÌÜÀ¹¤ê¤ÎÃÍ
151        $number = intval($this->graph_max / LINE_Y_SCALE);             
152        // ÌÜÀ¹¤êÉý¤òµá¤á¤ë
153        $size = $this->area_height / LINE_Y_SCALE;
154        $pos = 0;
155        for($i = 0; $i <= LINE_Y_SCALE; $i++) {
156            $snumber = $number * (LINE_Y_SCALE - $i);
157            $disp_number = number_format($snumber);
158            $num_width = $this->getTextWidth($disp_number, FONT_SIZE);
159            $this->setText(FONT_SIZE, $this->left - $num_width - 2, $this->top + $pos - (FONT_SIZE / 2), $disp_number);
160            $pos += $size;
161        }
162    }
163   
164    //
165    function setMax($arrData) {
166        // ¥Ç¡¼¥¿¤ÎºÇÂçÃͤò¼èÆÀ¤¹¤ë¡£
167        $data_max = max($arrData);
168        // 10¤Î²¿Çܤ«¤ò¼èÆÀ
169        $figure = strlen($data_max) - 1;
170        // ¼¡¤Î·å¤ò·×»»¤¹¤ë
171        $tenval = pow(10, $figure);
172        // ¥°¥é¥Õ¾å¤Ç¤ÎºÇÂçÃͤòµá¤á¤ë
173        $this->graph_max = $tenval * (intval($data_max / $tenval) + 1);
174        // ºÇÂçÃͤ¬10̤Ëþ¤Î¾ì¹ç¤ÎÂбþ
175        if($this->graph_max < 10) {
176            $this->graph_max = 10;
177        }   
178    }
179   
180    // ¥°¥é¥Õ¤ÎÉÁ²è
181    function drawGraph() {
182        // ¥°¥é¥ÕÇØ·Ê¤òÉÁ²è
183        $this->drawYLine();
184        $this->drawXLine();
185       
186        // ÀÞ¤ìÀþ¥°¥é¥ÕÉÁ²è
187        for($i = 0; $i < $this->line_max; $i++) {
188            $this->drawLine($i);
189        }
190       
191        // ¥Þ¡¼¥¯¤òÉÁ²è
192        for($i = 0; $i < $this->line_max; $i++) {
193            $this->drawMark($i);
194        }
195       
196        // ¥é¥Ù¥ë¤òÉÁ²è
197        for($i = 0; $i < $this->line_max; $i++) {
198            $this->drawLabel($i);       
199        }
200
201        // ËÞÎã¤ÎÉÁ²è
202        $this->drawLegend();   
203    }
204   
205    // ¥é¥¤¥ó¤òÉÁ²è¤¹¤ë
206    function drawLine($line_no) {
207        $arrPointList = $this->arrPointList[$line_no];
208       
209        $count = count($arrPointList);
210        for($i = 0; $i < $count; $i++) {
211            $x = $arrPointList[$i][0];
212            $y = $arrPointList[$i][1];
213            if(isset($arrPointList[$i + 1])) {
214                $next_x = $arrPointList[$i + 1][0];
215                $next_y = $arrPointList[$i + 1][1];
216                imageline($this->image, $x, $y, $next_x, $next_y, $this->arrColor[$line_no]);
217            }
218        }
219    }
220   
221    // ¥Þ¡¼¥¯¤òÉÁ²è¤¹¤ë
222    function drawMark($line_no) {
223        $arrPointList = $this->arrPointList[$line_no];
224        $count = count($arrPointList);
225        for($i = 0; $i < $count; $i++) {
226            $x = $arrPointList[$i][0];
227            $y = $arrPointList[$i][1];         
228            $this->setMark($line_no, $x, $y);
229        }
230    }
231   
232    // ¥é¥Ù¥ë¤òÉÁ²è¤¹¤ë
233    function drawLabel($line_no) {
234        $arrData = $this->arrDataList[$line_no];
235        $arrPointList = $this->arrPointList[$line_no];
236        $count = count($arrPointList);
237        for($i = 0; $i < $count; $i++) {
238            $x = $arrPointList[$i][0];
239            $y = $arrPointList[$i][1];
240            $text_width = $this->getTextWidth(number_format($arrData[$i]), FONT_SIZE);
241            $y_pos = $y - FONT_SIZE - 5;
242            $x_pos = $x - $text_width / 2;
243            $this->setText(FONT_SIZE, $x_pos, $y_pos, number_format($arrData[$i]));
244        }
245    }
246   
247    // ¥Ç¡¼¥¿¤ò¥»¥Ã¥È¤¹¤ë
248    function setData($arrData) {
249        $this->arrDataList[$this->line_max] = array_values((array)$arrData);
250        $this->setMax($this->arrDataList[$this->line_max]);
251        // ÃͤÎÉÁ²èÊÑ´¹Î¨
252        $rate = $this->area_height / $this->graph_max;
253        // ÉÁ²èΨ¤ò·×»»
254        $count = count($this->arrDataList[$this->line_max]);
255        $scale_width = $this->area_width / ($count + 1);       
256        $this->arrPointList[$this->line_max] = array();
257        for($i = 0; $i < $count; $i++) {
258            // XºÂɸ¤òµá¤á¤ë
259            $x = intval($this->left + ($scale_width * ($i + 1)));
260            // YºÂɸ¤òµá¤á¤ë
261            $y = intval($this->top + $this->area_height - ($this->arrDataList[$this->line_max][$i] * $rate));
262            // XYºÂɸ¤òÊݸ¤¹¤ë
263            $this->arrPointList[$this->line_max][] = array($x, $y);
264        }
265        $this->line_max++;
266    }
267   
268    // X¼´¥é¥Ù¥ë¤ò¥»¥Ã¥È¤¹¤ë
269    function setXLabel($arrXLabel) {
270        $this->arrXLabel = array_values((array)$arrXLabel);
271    }
272   
273    // X¼´¥¿¥¤¥È¥ë¤ò¥»¥Ã¥È¤¹¤ë
274    function setXTitle($title) {
275        $this->XTitle = $title;
276    }
277   
278    // Y¼´¥¿¥¤¥È¥ë¤ò¥»¥Ã¥È¤¹¤ë
279    function setYTitle($title) {
280        $this->YTitle = $title;
281    }   
282}
283?>
Note: See TracBrowser for help on using the repository browser.