source: branches/dev/html/admin/total/class/SC_GraphBase.php @ 166

Revision 166, 6.6 KB checked in by naka, 19 years ago (diff)
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7/*
8$SC_GRAPHPIE_DIR = realpath(dirname( __FILE__));
9require_once($SC_GRAPHPIE_DIR . "/config.php");
10require_once($SC_GRAPHPIE_DIR . "/lib.php");   
11*/
12require_once(realpath(dirname( __FILE__)) . "/config.php");
13require_once(realpath(dirname( __FILE__)) . "/lib.php");   
14
15// SC_Graph¶¦ÄÌ¥¯¥é¥¹
16class SC_GraphBase {
17    var $arrRGB;
18    var $arrColor;
19    var $arrDarkColor;
20    var $image;
21    var $left;
22    var $top;
23    var $shade_color;
24    var $flame_color;
25    var $shade_on;
26    var $text_color;
27    var $labelbg_color;
28    var $bgw;
29    var $bgh;
30    var $clabelbg_color;
31    var $title_color;
32    var $text_top;
33    var $mark_color;
34    var $arrLegend;
35   
36    // ¥³¥ó¥¹¥È¥é¥¯¥¿
37    function SC_GraphBase($bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left, $top) {
38        global $ARR_GRAPH_RGB;
39        global $ARR_BG_COLOR;
40        global $ARR_SHADE_COLOR;
41        global $ARR_FLAME_COLOR;
42        global $ARR_TEXT_COLOR;
43        global $ARR_LABELBG_COLOR;
44        global $ARR_LEGENDBG_COLOR;
45        global $ARR_TITLE_COLOR;
46        global $ARR_GRID_COLOR;
47       
48        // ²èÁüºîÀ®
49        $this->bgw = $bgw;
50        $this->bgh = $bgh; 
51        $this->image = imagecreatetruecolor($bgw, $bgh);
52        // ¥¢¥ó¥Á¥¨¥¤¥ê¥¢¥¹Í­¸ú
53        if (function_exists("imageantialias")) imageantialias($this->image, true);
54        // ÇØ·Ê¿§¤ò¥»¥Ã¥È
55        imagefill($this->image, 0, 0, lfGetImageColor($this->image, $ARR_BG_COLOR));
56       
57        // »ÈÍÑ¿§¤ÎÀ¸À®
58        $this->setColorList($ARR_GRAPH_RGB);
59        // ¥°¥é¥ÕÉÁ²è°ÌÃÖ¤ÎÀßÄê
60        $this->left = $left;
61        $this->top = $top;
62        $this->shade_color = lfGetImageColor($this->image, $ARR_SHADE_COLOR);
63        $this->flame_color = lfGetImageColor($this->image, $ARR_FLAME_COLOR);
64        $this->text_color = lfGetImageColor($this->image, $ARR_TEXT_COLOR);
65        $this->labelbg_color = lfGetImageColor($this->image, $ARR_LABELBG_COLOR);
66        $this->clabelbg_color = lfGetImageColor($this->image, $ARR_LEGENDBG_COLOR);
67        $this->title_color = lfGetImageColor($this->image, $ARR_TITLE_COLOR);
68        $this->grid_color = lfGetImageColor($this->image, $ARR_GRID_COLOR);
69           
70        // ±Æ¤¢¤ê
71        $this->shade_on = true;
72    }
73   
74    // ¥ê¥µ¥ó¥×¥ë
75    function resampled() {
76        if(imagecopyresampled($tmp_image, $this->image, 0, 0, $this->bgw, $this->bgh, $this->bgw, $this-bgh)) {
77            $this->image = $tmp_image;
78        }
79    }
80   
81   
82    // ¥ª¥Ö¥¸¥§¥¯¥È¥«¥é¡¼¤ÎÀßÄê
83    function setColorList($arrRGB) {
84        $this->arrRGB = $arrRGB;
85        $count = count($this->arrRGB);
86        // Ä̾￧¤ÎÀßÄê
87        for($i = 0; $i < $count; $i++) {
88            $this->arrColor[$i] = lfGetImageColor($this->image, $this->arrRGB[$i]);
89        }
90        // °Å¿§¤ÎÀßÄê
91        for($i = 0; $i < $count; $i++) {
92            $this->arrDarkColor[$i] = lfGetImageDarkColor($this->image, $this->arrRGB[$i]);
93        }       
94    }
95   
96    // ±Æ¤Î¤¢¤ê¤Ê¤·
97    function setShadeOn($shade_on) {
98        $this->shade_on = $shade_on;
99    }
100   
101    // ²èÁü¤ò½ÐÎϤ¹¤ë
102    function outputGraph($header = true, $filename = "") {
103        if($header) {
104            header('Content-type: image/png');
105        }
106       
107        if ($filename != "") {
108            imagepng($this->image, $filename);
109        }else{
110            imagepng($this->image);
111        }
112
113        imagedestroy($this->image);
114    }
115
116    // ÉÁ²è»þ¤Î¥Æ¥­¥¹¥ÈÉý¤òµá¤á¤ë
117    function getTextWidth($text, $font_size) {
118        $text_len = strlen($text);
119        $ret = $font_size * $text_len * TEXT_RATE; 
120        /*
121            ¢¨Àµ³Î¤ÊÃͤ¬¼èÆÀ¤Ç¤­¤Ê¤«¤Ã¤¿¤Î¤ÇÇÑ»ß
122            // ¥Æ¥­¥¹¥ÈÉý¤Î¼èÆÀ
123            $arrPos = imagettfbbox($font_size, 0, FONT_PATH, $text);
124            $ret = $arrPos[2] - $arrPos[0];
125        */
126        return $ret;
127    }
128   
129    // ¥Æ¥­¥¹¥È¤ò½ÐÎϤ¹¤ë
130    function setText($font_size, $left, $top, $text, $color = NULL, $angle = 0, $labelbg = false) {
131        // »þ·×²ó¤ê¤Ë³ÑÅÙ¤òÊѹ¹
132        $angle = -$angle;       
133        // ¥é¥Ù¥ëÇØ·Ê
134        if($labelbg) {
135            $text_width = $this->getTextWidth($text, $font_size);
136            imagefilledrectangle($this->image, $left - 2, $top - 2, $left + $text_width + 2, $top + $font_size + 2, $this->labelbg_color);
137        }
138        //$text = mb_convert_encoding($text, "UTF-8", CHAR_CODE);
139        $text = mb_convert_encoding($text, CHAR_CODE);
140        if($color != NULL) {
141            ImageTTFText($this->image, $font_size, $angle, $left, $top + $font_size, $color, FONT_PATH, $text);
142        } else {
143            ImageTTFText($this->image, $font_size, $angle, $left, $top + $font_size, $this->text_color, FONT_PATH, $text);         
144        }
145    }
146   
147    // ¥¿¥¤¥È¥ë¤ò½ÐÎϤ¹¤ë
148    function drawTitle($text, $font_size = TITLE_FONT_SIZE) {
149        // ½ÐÎϰÌÃ֤λ»½Ð
150        $text_width = $this->getTextWidth($text, $font_size);
151        $left = ($this->bgw - $text_width) / 2;
152        $top = TITLE_TOP;
153        $this->setText($font_size, $left, $top, $text, $this->title_color);     
154    }
155   
156    // ¥í¥°¤ò½ÐÎϤ¹¤ë
157    function debugPrint($text) {
158        $text = mb_convert_encoding($text, "UTF-8", CHAR_CODE);
159        if(!isset($this->text_top)) {
160            $this->text_top = FONT_SIZE + LINE_PAD;
161        }       
162        // ¥Æ¥­¥¹¥ÈÉÁ²è
163        ImageTTFText($this->image, FONT_SIZE, 0, LINE_PAD, $this->text_top, $this->text_color, FONT_PATH, $text);
164        $this->text_top += FONT_SIZE + LINE_PAD;
165    }
166       
167    // ¥«¥é¡¼¥é¥Ù¥ë¤òÉÁ²è
168    function drawLegend($legend_max = "", $clabelbg = true) {
169        // ËÞÎ㤬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤ÐÃæ»ß
170        if(count($this->arrLegend) <= 0) {
171            return;
172        }       
173       
174        if($legend_max != "") {
175            $label_max = $legend_max;
176        } else {
177            $label_max = count($this->arrLegend);
178        }
179
180        $height_max = 0;
181        $text_max = 0;
182        $width_max = 0;
183       
184        // °ìÈÖʸ»ú¿ô¤¬Â¿¤¤¤â¤Î¤ò¼èÆÀ
185        for($i = 0; $i < $label_max; $i++) {
186            $text_len = strlen($this->arrLegend[$i]);
187            if($text_max < $text_len) {
188                $text_max = $text_len;
189            }
190            $height_max += FONT_SIZE + LINE_PAD;
191        }
192        $width_max = FONT_SIZE * $text_max * TEXT_RATE;     
193
194        //  ¥«¥é¡¼¥¢¥¤¥³¥ó¤Èʸ»ú´Ö¤ò´Þ¤á¤¿Éý
195        $width_max += FONT_SIZE + (LINE_PAD * 2);   
196        $left = $this->bgw - $width_max - LEGEND_RIGHT;
197        $top = LEGEND_TOP;
198        // ¥«¥é¡¼¥é¥Ù¥ëÇØ·Ê¤ÎÉÁ²è
199        if($clabelbg) {
200            $this->drawClabelBG($left - LINE_PAD, $top, $left + $width_max, $top + $height_max + LINE_PAD);
201        }
202        $top += LINE_PAD;
203               
204        // ¿§¿ô¤Î¼èÆÀ
205        $c_max = count($this->arrColor);
206        for($i = 0; $i < $label_max; $i++) {           
207            // ¥«¥é¡¼¥¢¥¤¥³¥ó¤Îɽ¼¨
208            imagerectangle($this->image, $left, $top, $left + FONT_SIZE, $top + FONT_SIZE, $this->flame_color);
209            imagefilledrectangle($this->image, $left + 1, $top + 1, $left + FONT_SIZE - 1, $top + FONT_SIZE - 1, $this->arrColor[($i % $c_max)]);
210            // ¥é¥Ù¥ë¤Îɽ¼¨
211            $this->setText(FONT_SIZE, $left + FONT_SIZE + LINE_PAD, $top, $this->arrLegend[$i]);
212            $top += FONT_SIZE + LINE_PAD;
213        }
214    }
215   
216    // ¥«¥é¡¼¥é¥Ù¥ëÇØ·Ê¤ÎÉÁ²è
217    function drawClabelBG($left, $top, $right, $bottom) {
218        // ±Æ¤ÎÉÁ²è
219        if($this->shade_on) {
220            imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom + 2, $this->shade_color);
221        }
222        // ¥«¥é¡¼¥é¥Ù¥ëÇØ·Ê¤ÎÉÁ²è
223        imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->clabelbg_color);
224        imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color);
225    }
226   
227    // ËÞÎã¤ò¥»¥Ã¥È¤¹¤ë
228    function setLegend($arrLegend) {
229        $this->arrLegend = array_values((array)$arrLegend);
230    }
231
232}
233
234?>
Note: See TracBrowser for help on using the repository browser.