source: branches/comu/html/admin/total/class/SC_GraphBase.php @ 11730

Revision 11730, 6.8 KB checked in by nanasess, 17 years ago (diff)

r11729 の変更を取消

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        $new_width = $this->bgw * 0.8;
77        $new_height = $this->bgh * 0.8;     
78        $tmp_image = imagecreatetruecolor($new_width, $new_height);
79        if(imagecopyresampled($tmp_image, $this->image, 0, 0, 0, 0, $new_width, $new_height, $this->bgw, $this->bgh)) {
80            $this->image = $tmp_image;
81        }
82    }
83   
84   
85    // ¥ª¥Ö¥¸¥§¥¯¥È¥«¥é¡¼¤ÎÀßÄê
86    function setColorList($arrRGB) {
87        $this->arrRGB = $arrRGB;
88        $count = count($this->arrRGB);
89        // Ä̾￧¤ÎÀßÄê
90        for($i = 0; $i < $count; $i++) {
91            $this->arrColor[$i] = lfGetImageColor($this->image, $this->arrRGB[$i]);
92        }
93        // °Å¿§¤ÎÀßÄê
94        for($i = 0; $i < $count; $i++) {
95            $this->arrDarkColor[$i] = lfGetImageDarkColor($this->image, $this->arrRGB[$i]);
96        }       
97    }
98   
99    // ±Æ¤Î¤¢¤ê¤Ê¤·
100    function setShadeOn($shade_on) {
101        $this->shade_on = $shade_on;
102    }
103   
104    // ²èÁü¤ò½ÐÎϤ¹¤ë
105    function outputGraph($header = true, $filename = "") {
106        if($header) {
107            header('Content-type: image/png');
108        }
109       
110        if ($filename != "") {
111            imagepng($this->image, $filename);
112        }else{
113            imagepng($this->image);
114        }
115
116        imagedestroy($this->image);
117    }
118
119    // ÉÁ²è»þ¤Î¥Æ¥­¥¹¥ÈÉý¤òµá¤á¤ë
120    function getTextWidth($text, $font_size) {
121        $text_len = strlen($text);
122        $ret = $font_size * $text_len * TEXT_RATE; 
123        /*
124            ¢¨Àµ³Î¤ÊÃͤ¬¼èÆÀ¤Ç¤­¤Ê¤«¤Ã¤¿¤Î¤ÇÇÑ»ß
125            // ¥Æ¥­¥¹¥ÈÉý¤Î¼èÆÀ
126            $arrPos = imagettfbbox($font_size, 0, FONT_PATH, $text);
127            $ret = $arrPos[2] - $arrPos[0];
128        */
129        return $ret;
130    }
131   
132    // ¥Æ¥­¥¹¥È¤ò½ÐÎϤ¹¤ë
133    function setText($font_size, $left, $top, $text, $color = NULL, $angle = 0, $labelbg = false) {
134        // »þ·×²ó¤ê¤Ë³ÑÅÙ¤òÊѹ¹
135        $angle = -$angle;       
136        // ¥é¥Ù¥ëÇØ·Ê
137        if($labelbg) {
138            $text_width = $this->getTextWidth($text, $font_size);
139            imagefilledrectangle($this->image, $left - 2, $top - 2, $left + $text_width + 2, $top + $font_size + 2, $this->labelbg_color);
140        }
141        //$text = mb_convert_encoding($text, "UTF-8", CHAR_CODE);
142        $text = mb_convert_encoding($text, CHAR_CODE);
143        if($color != NULL) {
144            ImageTTFText($this->image, $font_size, $angle, $left, $top + $font_size, $color, FONT_PATH, $text);
145        } else {
146            ImageTTFText($this->image, $font_size, $angle, $left, $top + $font_size, $this->text_color, FONT_PATH, $text);         
147        }
148    }
149   
150    // ¥¿¥¤¥È¥ë¤ò½ÐÎϤ¹¤ë
151    function drawTitle($text, $font_size = TITLE_FONT_SIZE) {
152        // ½ÐÎÏ°ÌÃ֤λ»½Ð
153        $text_width = $this->getTextWidth($text, $font_size);
154        $left = ($this->bgw - $text_width) / 2;
155        $top = TITLE_TOP;
156        $this->setText($font_size, $left, $top, $text, $this->title_color);     
157    }
158   
159    // ¥í¥°¤ò½ÐÎϤ¹¤ë
160    function debugPrint($text) {
161        $text = mb_convert_encoding($text, "UTF-8", CHAR_CODE);
162        if(!isset($this->text_top)) {
163            $this->text_top = FONT_SIZE + LINE_PAD;
164        }       
165        // ¥Æ¥­¥¹¥ÈÉÁ²è
166        ImageTTFText($this->image, FONT_SIZE, 0, LINE_PAD, $this->text_top, $this->text_color, FONT_PATH, $text);
167        $this->text_top += FONT_SIZE + LINE_PAD;
168    }
169       
170    // ¥«¥é¡¼¥é¥Ù¥ë¤òÉÁ²è
171    function drawLegend($legend_max = "", $clabelbg = true) {
172        // ËÞÎ㤬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤ÐÃæ»ß
173        if(count($this->arrLegend) <= 0) {
174            return;
175        }       
176       
177        if($legend_max != "") {
178            $label_max = $legend_max;
179        } else {
180            $label_max = count($this->arrLegend);
181        }
182
183        $height_max = 0;
184        $text_max = 0;
185        $width_max = 0;
186       
187        // °ìÈÖʸ»ú¿ô¤¬Â¿¤¤¤â¤Î¤ò¼èÆÀ
188        for($i = 0; $i < $label_max; $i++) {
189            $text_len = strlen($this->arrLegend[$i]);
190            if($text_max < $text_len) {
191                $text_max = $text_len;
192            }
193            $height_max += FONT_SIZE + LINE_PAD;
194        }
195        $width_max = FONT_SIZE * $text_max * TEXT_RATE;     
196
197        //  ¥«¥é¡¼¥¢¥¤¥³¥ó¤Èʸ»ú´Ö¤ò´Þ¤á¤¿Éý
198        $width_max += FONT_SIZE + (LINE_PAD * 2);   
199        $left = $this->bgw - $width_max - LEGEND_RIGHT;
200        $top = LEGEND_TOP;
201        // ¥«¥é¡¼¥é¥Ù¥ëÇطʤÎÉÁ²è
202        if($clabelbg) {
203            $this->drawClabelBG($left - LINE_PAD, $top, $left + $width_max, $top + $height_max + LINE_PAD);
204        }
205        $top += LINE_PAD;
206               
207        // ¿§¿ô¤Î¼èÆÀ
208        $c_max = count($this->arrColor);
209        for($i = 0; $i < $label_max; $i++) {           
210            // ¥«¥é¡¼¥¢¥¤¥³¥ó¤Îɽ¼¨
211            imagerectangle($this->image, $left, $top, $left + FONT_SIZE, $top + FONT_SIZE, $this->flame_color);
212            imagefilledrectangle($this->image, $left + 1, $top + 1, $left + FONT_SIZE - 1, $top + FONT_SIZE - 1, $this->arrColor[($i % $c_max)]);
213            // ¥é¥Ù¥ë¤Îɽ¼¨
214            $this->setText(FONT_SIZE, $left + FONT_SIZE + LINE_PAD, $top, $this->arrLegend[$i]);
215            $top += FONT_SIZE + LINE_PAD;
216        }
217    }
218   
219    // ¥«¥é¡¼¥é¥Ù¥ëÇطʤÎÉÁ²è
220    function drawClabelBG($left, $top, $right, $bottom) {
221        // ±Æ¤ÎÉÁ²è
222        if($this->shade_on) {
223            imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom + 2, $this->shade_color);
224        }
225        // ¥«¥é¡¼¥é¥Ù¥ëÇطʤÎÉÁ²è
226        imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->clabelbg_color);
227        imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color);
228    }
229   
230    // ËÞÎã¤ò¥»¥Ã¥È¤¹¤ë
231    function setLegend($arrLegend) {
232        $this->arrLegend = array_values((array)$arrLegend);
233    }
234
235}
236
237?>
Note: See TracBrowser for help on using the repository browser.