source: branches/feature-module-update/html/admin/total/class/SC_GraphBase.php @ 15532

Revision 15532, 7.1 KB checked in by nanasess, 17 years ago (diff)

svn:mime-type 修正

  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
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.