Ignore:
Timestamp:
2007/09/04 20:20:40 (17 years ago)
Author:
nanasess
Message:

リファクタリング

  • config.php と lib.php を SC_GraphBase.php にマージ
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-module-update/data/class/graph/SC_GraphBase.php

    r15597 r15598  
    55 * http://www.lockon.co.jp/ 
    66 */ 
    7 /* 
    8 $SC_GRAPHPIE_DIR = realpath(dirname( __FILE__)); 
    9 require_once($SC_GRAPHPIE_DIR . "/config.php"); 
    10 require_once($SC_GRAPHPIE_DIR . "/lib.php");     
    11 */ 
    12 require_once(realpath(dirname( __FILE__)) . "/config.php"); 
    13 require_once(realpath(dirname( __FILE__)) . "/lib.php");     
    14  
    15 // SC_Graph共通クラス 
     7 
     8/** TTFフォントファイル */ 
     9define("FONT_PATH", DATA_PATH . "fonts/wlmaru20044.ttf"); 
     10 
     11/** フォントサイズ */ 
     12define("FONT_SIZE", 8); 
     13 
     14/** タイトルフォントサイズ */ 
     15define("TITLE_FONT_SIZE", 11); 
     16 
     17/** 背景幅 */ 
     18define("BG_WIDTH", 720); 
     19 
     20/** 背景高さ */ 
     21define("BG_HEIGHT", 400); 
     22 
     23/** 行間 */ 
     24define("LINE_PAD", 5); 
     25 
     26/** フォント補正値(実際の描画幅/フォントサイズ) */ 
     27define("TEXT_RATE", 0.75); 
     28 
     29// ----------------------------------------------------------------------------- 
     30// 円グラフ 
     31// ----------------------------------------------------------------------------- 
     32/** 円グラフ位置 */ 
     33define("PIE_LEFT", 200); 
     34 
     35/** 円グラフ位置 */ 
     36define("PIE_TOP", 150); 
     37 
     38/** 円グラフ幅 */ 
     39define("PIE_WIDTH", 230); 
     40 
     41/** 円グラフ高さ */ 
     42define("PIE_HEIGHT", 100); 
     43 
     44/** 円グラフ太さ */ 
     45define("PIE_THICK", 30); 
     46 
     47/** 円グラフのラベル位置を上にあげる */ 
     48define("PIE_LABEL_UP", 20); 
     49 
     50/** 値が大きいほど影が長くなる */ 
     51define("PIE_SHADE_IMPACT", 0.1); 
     52 
     53// ----------------------------------------------------------------------------- 
     54// 折れ線グラフ 
     55// ----------------------------------------------------------------------------- 
     56/** Y軸の目盛り数 */ 
     57define("LINE_Y_SCALE", 10); 
     58 
     59/** X軸の目盛り数 */ 
     60define("LINE_X_SCALE", 10); 
     61 
     62/** 線グラフ位置 */ 
     63define("LINE_LEFT", 60); 
     64 
     65/** 線グラフ位置 */ 
     66define("LINE_TOP", 50); 
     67 
     68/** 線グラフ背景のサイズ */ 
     69define("LINE_AREA_WIDTH", 600); 
     70 
     71/** 線グラフ背景のサイズ */ 
     72define("LINE_AREA_HEIGHT", 300); 
     73 
     74/** 線グラフマークのサイズ */ 
     75define("LINE_MARK_SIZE", 6); 
     76 
     77/** 目盛り幅 */ 
     78define("LINE_SCALE_SIZE", 6); 
     79 
     80/** X軸のラベルの表示制限数 */ 
     81define("LINE_XLABEL_MAX", 30); 
     82 
     83/** X軸のタイトルと軸の間隔 */ 
     84define("LINE_XTITLE_PAD", -5); 
     85 
     86/** Y軸のタイトルと軸の間隔 */ 
     87define("LINE_YTITLE_PAD", 15); 
     88 
     89// ----------------------------------------------------------------------------- 
     90//  棒グラフ 
     91// ----------------------------------------------------------------------------- 
     92/** グラフと目盛りの間隔 */ 
     93define("BAR_PAD", 6); 
     94 
     95// ----------------------------------------------------------------------------- 
     96//  タイトルラベル 
     97// ----------------------------------------------------------------------------- 
     98/** 背景枠との上幅 */ 
     99define("TITLE_TOP", 10); 
     100 
     101// ----------------------------------------------------------------------------- 
     102//  凡例 
     103// ----------------------------------------------------------------------------- 
     104/** 背景枠との上幅 */ 
     105define("LEGEND_TOP", 10); 
     106 
     107/** 背景枠との右幅 */ 
     108define("LEGEND_RIGHT", 10); 
     109 
     110/** 
     111 * SC_Graph共通クラス. 
     112 * 
     113 * @package Graph 
     114 * @author LOCKON CO.,LTD. 
     115 * @version $Id$ 
     116 */ 
    16117class 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  
     118 
     119    // {{{ properties 
     120 
     121    var $arrRGB; 
     122    var $arrColor; 
     123    var $arrDarkColor; 
     124    var $image; 
     125    var $left; 
     126    var $top; 
     127    var $shade_color; 
     128    var $flame_color; 
     129    var $shade_on; 
     130    var $text_color; 
     131    var $labelbg_color; 
     132    var $bgw; 
     133    var $bgh; 
     134    var $clabelbg_color; 
     135    var $title_color; 
     136    var $text_top; 
     137    var $mark_color; 
     138    var $arrLegend; 
     139 
     140    /** グラフ背景 */ 
     141    var $ARR_GRAPH_RGB; 
     142 
     143    /** 背景色 */ 
     144    var $ARR_BG_COLOR; 
     145 
     146    /** 影の色 */ 
     147    var $ARR_SHADE_COLOR; 
     148 
     149    /** 縁の色 */ 
     150    var $ARR_FLAME_COLOR; 
     151 
     152    /** 文字色 */ 
     153    var $ARR_TEXT_COLOR; 
     154 
     155    /** ラベル背景 */ 
     156    var $ARR_LABELBG_COLOR; 
     157 
     158    /** 凡例背景 */ 
     159    var $ARR_LEGENDBG_COLOR; 
     160 
     161    /** タイトル文字色 */ 
     162    var $ARR_TITLE_COLOR; 
     163 
     164    /** グリッド線色 */ 
     165    var $ARR_GRID_COLOR; 
     166 
     167    // コンストラクタ 
     168    function SC_GraphBase($bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left, $top) { 
     169        $this->init(); 
     170        // 画像作成 
     171        $this->bgw = $bgw; 
     172        $this->bgh = $bgh; 
     173        $this->image = imagecreatetruecolor($bgw, $bgh); 
     174        // アンチエイリアス有効 
     175        if (function_exists("imageantialias")) imageantialias($this->image, true); 
     176        // 背景色をセット 
     177        imagefill($this->image, 0, 0, $this->lfGetImageColor($this->image, $this->ARR_BG_COLOR)); 
     178 
     179        // 使用色の生成 
     180        $this->setColorList($this->ARR_GRAPH_RGB); 
     181        // グラフ描画位置の設定 
     182        $this->left = $left; 
     183        $this->top = $top; 
     184        $this->shade_color = $this->lfGetImageColor($this->image, $this->ARR_SHADE_COLOR); 
     185        $this->flame_color = $this->lfGetImageColor($this->image, $this->ARR_FLAME_COLOR); 
     186        $this->text_color = $this->lfGetImageColor($this->image, $this->ARR_TEXT_COLOR); 
     187        $this->labelbg_color = $this->lfGetImageColor($this->image, $this->ARR_LABELBG_COLOR); 
     188        $this->clabelbg_color = $this->lfGetImageColor($this->image, $this->ARR_LEGENDBG_COLOR); 
     189        $this->title_color = $this->lfGetImageColor($this->image, $this->ARR_TITLE_COLOR); 
     190        $this->grid_color = $this->lfGetImageColor($this->image, $this->ARR_GRID_COLOR); 
     191 
     192        // 影あり 
     193        $this->shade_on = true; 
     194    } 
     195 
     196    // リサンプル(画像を滑らかに縮小する) 
     197    function resampled() { 
     198        $new_width = $this->bgw * 0.8; 
     199        $new_height = $this->bgh * 0.8; 
     200        $tmp_image = imagecreatetruecolor($new_width, $new_height); 
     201        if(imagecopyresampled($tmp_image, $this->image, 0, 0, 0, 0, $new_width, $new_height, $this->bgw, $this->bgh)) { 
     202            $this->image = $tmp_image; 
     203        } 
     204    } 
     205 
     206 
     207    // オブジェクトカラーの設定 
     208    function setColorList($arrRGB) { 
     209        $this->arrRGB = $arrRGB; 
     210        $count = count($this->arrRGB); 
     211        // 通常色の設定 
     212        for($i = 0; $i < $count; $i++) { 
     213            $this->arrColor[$i] = $this->lfGetImageColor($this->image, $this->arrRGB[$i]); 
     214        } 
     215        // 暗色の設定 
     216        for($i = 0; $i < $count; $i++) { 
     217            $this->arrDarkColor[$i] = $this->lfGetImageDarkColor($this->image, $this->arrRGB[$i]); 
     218        } 
     219    } 
     220 
     221    // 影のありなし 
     222    function setShadeOn($shade_on) { 
     223        $this->shade_on = $shade_on; 
     224    } 
     225 
     226    // 画像を出力する 
     227    function outputGraph($header = true, $filename = "") { 
     228        if($header) { 
     229            header('Content-type: image/png'); 
     230        } 
     231 
     232        if ($filename != "") { 
     233            imagepng($this->image, $filename); 
     234        }else{ 
     235            imagepng($this->image); 
     236        } 
     237 
     238        imagedestroy($this->image); 
     239    } 
     240 
     241    // 描画時のテキスト幅を求める 
     242    function getTextWidth($text, $font_size) { 
     243        $text_len = strlen($text); 
     244        $ret = $font_size * $text_len * TEXT_RATE; 
     245        /* 
     246            ※正確な値が取得できなかったので廃止 
     247            // テキスト幅の取得 
     248            $arrPos = imagettfbbox($font_size, 0, FONT_PATH, $text); 
     249            $ret = $arrPos[2] - $arrPos[0]; 
     250        */ 
     251        return $ret; 
     252    } 
     253 
     254    // テキストを出力する 
     255    function setText($font_size, $left, $top, $text, $color = NULL, $angle = 0, $labelbg = false) { 
     256        // 時計回りに角度を変更 
     257        $angle = -$angle; 
     258        // ラベル背景 
     259        if($labelbg) { 
     260            $text_width = $this->getTextWidth($text, $font_size); 
     261            imagefilledrectangle($this->image, $left - 2, $top - 2, $left + $text_width + 2, $top + $font_size + 2, $this->labelbg_color); 
     262        } 
     263        //$text = mb_convert_encoding($text, "UTF-8", CHAR_CODE); 
     264        $text = mb_convert_encoding($text, CHAR_CODE); 
     265        if($color != NULL) { 
     266            ImageTTFText($this->image, $font_size, $angle, $left, $top + $font_size, $color, FONT_PATH, $text); 
     267        } else { 
     268            ImageTTFText($this->image, $font_size, $angle, $left, $top + $font_size, $this->text_color, FONT_PATH, $text); 
     269        } 
     270    } 
     271 
     272    // タイトルを出力する 
     273    function drawTitle($text, $font_size = TITLE_FONT_SIZE) { 
     274        // 出力位置の算出 
     275        $text_width = $this->getTextWidth($text, $font_size); 
     276        $left = ($this->bgw - $text_width) / 2; 
     277        $top = TITLE_TOP; 
     278        $this->setText($font_size, $left, $top, $text, $this->title_color); 
     279    } 
     280 
     281    // ログを出力する 
     282    function debugPrint($text) { 
     283        $text = mb_convert_encoding($text, "UTF-8", CHAR_CODE); 
     284        if(!isset($this->text_top)) { 
     285            $this->text_top = FONT_SIZE + LINE_PAD; 
     286        } 
     287        // テキスト描画 
     288        ImageTTFText($this->image, FONT_SIZE, 0, LINE_PAD, $this->text_top, $this->text_color, FONT_PATH, $text); 
     289        $this->text_top += FONT_SIZE + LINE_PAD; 
     290    } 
     291 
     292    // カラーラベルを描画 
     293    function drawLegend($legend_max = "", $clabelbg = true) { 
     294        // 凡例が登録されていなければ中止 
     295        if(count($this->arrLegend) <= 0) { 
     296            return; 
     297        } 
     298 
     299        if($legend_max != "") { 
     300            $label_max = $legend_max; 
     301        } else { 
     302            $label_max = count($this->arrLegend); 
     303        } 
     304 
     305        $height_max = 0; 
     306        $text_max = 0; 
     307        $width_max = 0; 
     308 
     309        // 一番文字数が多いものを取得 
     310        for($i = 0; $i < $label_max; $i++) { 
     311            $text_len = strlen($this->arrLegend[$i]); 
     312            if($text_max < $text_len) { 
     313                $text_max = $text_len; 
     314            } 
     315            $height_max += FONT_SIZE + LINE_PAD; 
     316        } 
     317        $width_max = FONT_SIZE * $text_max * TEXT_RATE; 
     318 
     319        //  カラーアイコンと文字間を含めた幅 
     320        $width_max += FONT_SIZE + (LINE_PAD * 2); 
     321        $left = $this->bgw - $width_max - LEGEND_RIGHT; 
     322        $top = LEGEND_TOP; 
     323        // カラーラベル背景の描画 
     324        if($clabelbg) { 
     325            $this->drawClabelBG($left - LINE_PAD, $top, $left + $width_max, $top + $height_max + LINE_PAD); 
     326        } 
     327        $top += LINE_PAD; 
     328 
     329        // 色数の取得 
     330        $c_max = count($this->arrColor); 
     331        for($i = 0; $i < $label_max; $i++) { 
     332            // カラーアイコンの表示 
     333            imagerectangle($this->image, $left, $top, $left + FONT_SIZE, $top + FONT_SIZE, $this->flame_color); 
     334            imagefilledrectangle($this->image, $left + 1, $top + 1, $left + FONT_SIZE - 1, $top + FONT_SIZE - 1, $this->arrColor[($i % $c_max)]); 
     335            // ラベルの表示 
     336            $this->setText(FONT_SIZE, $left + FONT_SIZE + LINE_PAD, $top, $this->arrLegend[$i]); 
     337            $top += FONT_SIZE + LINE_PAD; 
     338        } 
     339    } 
     340 
     341    // カラーラベル背景の描画 
     342    function drawClabelBG($left, $top, $right, $bottom) { 
     343        // 影の描画 
     344        if($this->shade_on) { 
     345            imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom + 2, $this->shade_color); 
     346        } 
     347        // カラーラベル背景の描画 
     348        imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->clabelbg_color); 
     349        imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color); 
     350    } 
     351 
     352    // 凡例をセットする 
     353    function setLegend($arrLegend) { 
     354        $this->arrLegend = array_values((array)$arrLegend); 
     355    } 
     356 
     357    // }}} 
     358    // {{{ protected functions 
     359 
     360    /** 
     361     * クラスの初期化を行う. 
     362     * 
     363     * 表示色をメンバ変数にセットする. 
     364     * 
     365     * @access protected 
     366     * @return void 
     367     */ 
     368    function init() { 
     369        // 凡例背景 
     370        $this->ARR_LEGENDBG_COLOR = array(245,245,245); 
     371        // ラベル背景 
     372        $this->ARR_LABELBG_COLOR = array(255,255,255); 
     373        // グラフカラー 
     374        $this->ARR_GRAPH_RGB = array( 
     375                               array(200,50,50), 
     376                               array(50,50,200), 
     377                               array(50,200,50), 
     378                               array(255,255,255), 
     379                               array(244,200,200), 
     380                               array(200,200,255), 
     381                               array(50,200,50), 
     382                               array(255,255,255), 
     383                               array(244,244,244), 
     384                               ); 
     385        // 影の色 
     386        $this->ARR_SHADE_COLOR = array(100,100,100); 
     387        // 縁の色 
     388        $this->ARR_FLAME_COLOR = array(0, 0, 0); 
     389        // 文字色 
     390        $this->ARR_TEXT_COLOR = array(0, 0, 0); 
     391        // 背景カラー 
     392        $this->ARR_BG_COLOR = array(255,255,255); 
     393        // タイトル文字色 
     394        $this->ARR_TITLE_COLOR = array(0, 0, 0); 
     395        // グリッド線色 
     396        $this->ARR_GRID_COLOR = array(200, 200, 200); 
     397        // マークの色 
     398        $this->ARR_MARK_COLOR = array(130, 130, 255); 
     399    } 
     400 
     401    /** 
     402     * 円の中心点と直径から弧の終端座標を算出する. 
     403     * 
     404     * @param integer $cx 中心点X座標 
     405     * @param integer $cy 中心点Y座標 
     406     * @param integer $r 半径 
     407     * @param integer $e 角度 
     408     * @return array 円の中心点と直径から弧の終端座標の配列 
     409     */ 
     410    function lfGetArcPos($cx, $cy, $cw, $ch, $e) { 
     411        // 三角関数用の角度を求める 
     412        $s = 90 - $e; 
     413        $r = $cw / 2; 
     414        // 位置を求める 
     415        $x = $cx + ($r * cos(deg2rad($s))); 
     416        $y = $cy - (($r * sin(deg2rad($s))) * ($ch / $cw)); 
     417        return array(round($x), round($y)); 
     418    } 
     419 
     420    /** 画像にテキストを描画する */ 
     421    function lfImageText($dst_image, $text, $font_size, $left, $top, $font, $arrRGB) { 
     422        $color = ImageColorAllocate($dst_image, $arrRGB[0], $arrRGB[1], $arrRGB[2]); 
     423        $text = mb_convert_encoding($text, "UTF-8", CHAR_CODE); 
     424        // 表示角度 
     425        $angle = 0; 
     426        // テキスト描画 
     427        ImageTTFText($dst_image, $font_size, $angle, $left, $top, $color, $font, $text); 
     428    } 
     429 
     430    /** 表示色の取得 */ 
     431    function lfGetImageColor($image, $array) { 
     432        if(count($array) != 3) { 
     433            return NULL; 
     434        } 
     435        $ret = imagecolorallocate($image, $array[0], $array[1], $array[2]); 
     436        return $ret; 
     437    } 
     438 
     439    /** 影用表示色の取得 */ 
     440    function lfGetImageDarkColor($image, $array) { 
     441        if(count($array) != 3) { 
     442            return NULL; 
     443        } 
     444        $i = 0; 
     445        foreach($array as $val) { 
     446            $dark[$i] = $val - 45; 
     447            if($dark[$i] < 0) { 
     448                $dark[$i] = 0; 
     449            } 
     450            $i++; 
     451        } 
     452        $ret = imagecolorallocate($image, $dark[0], $dark[1], $dark[2]); 
     453        return $ret; 
     454    } 
    235455} 
    236  
    237456?> 
Note: See TracChangeset for help on using the changeset viewer.