source: temp/trunk/html/admin/total/class/SC_GraphBase.php @ 5107

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