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

tab -> space

Location:
branches/feature-module-update/data/class/graph
Files:
3 edited

Legend:

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

    r15597 r15599  
    66 */ 
    77$SC_GRAPHBAR_DIR = realpath(dirname( __FILE__)); 
    8 require_once($SC_GRAPHBAR_DIR . "/SC_GraphLine.php");    
     8require_once($SC_GRAPHBAR_DIR . "/SC_GraphLine.php"); 
    99 
    1010// 棒グラフ生成クラス 
    1111class SC_GraphBar extends SC_GraphLine{ 
    1212    // コンストラクタ 
    13     function SC_GraphLine( 
    14         $bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = LINE_LEFT, $top = LINE_TOP, 
    15         $area_width = LINE_AREA_WIDTH, $area_height = LINE_AREA_HEIGHT) { 
    16         parent::SC_GraphLine($bgw, $bgh, $left, $top, $area_width, $area_height);    
    17     } 
    18      
    19     // グラフの描画 
    20     function drawGraph() { 
    21         $this->drawYLine(); 
    22         $this->drawXLine(true); 
    23          
    24         // 棒グラフの描画 
    25         for($i = 0; $i < $this->line_max; $i++) { 
    26             $this->drawBar($i); 
    27         } 
    28          
    29         // ラベルの描画 
    30         for($i = 0; $i < $this->line_max; $i++) { 
    31             $this->drawLabel($i); 
    32         } 
    33          
    34         // 凡例の描画 
    35         $this->drawLegend();     
    36     } 
    37      
    38     // 棒グラフの描画 
    39     function drawBar($line_no) { 
    40         $arrPointList = $this->arrPointList[$line_no]; 
    41         // データ数を数える 
    42         $count = count($arrPointList); 
    43         // 半目盛りの幅を求める 
    44         $half_scale = intval($this->area_width / ($count + 1) / 2); 
    45         // 目盛りの幅を求める 
    46         $scale_width = intval($this->area_width / ($count + 1)); 
    47         // 棒グラフのサイズを求める 
    48         $bar_width = intval(($scale_width - (BAR_PAD * 2)) / $this->line_max); 
    49         // 色数の取得 
    50         $c_max = count($this->arrColor); 
    51         for($i = 0; $i < $count; $i++) { 
    52             $left = $arrPointList[$i][0] - $half_scale + BAR_PAD + ($bar_width * $line_no); 
    53             $top = $arrPointList[$i][1]; 
    54             $right = $left + $bar_width; 
    55             $bottom = $this->top + $this->area_height; 
    56              
    57             // 影の描画 
    58             if($this->shade_on) { 
    59                 imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom, $this->shade_color); 
    60             } 
    61             //imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[($i % $c_max)]); 
    62             imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[$line_no]);             
    63             imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color);                  
    64         } 
    65     } 
    66      
    67     // ラベルを描画する 
    68     function drawLabel($line_no) { 
    69         $arrData = $this->arrDataList[$line_no]; 
    70         $arrPointList = $this->arrPointList[$line_no]; 
    71         $count = count($arrPointList); 
    72         for($i = 0; $i < $count; $i++) { 
    73             $x = $arrPointList[$i][0]; 
    74             $y = $arrPointList[$i][1]; 
    75             $text_width = $this->getTextWidth(number_format($arrData[$i]), FONT_SIZE); 
    76             $y_pos = $y - FONT_SIZE - 5; 
    77             $x_pos = $x - $text_width / 2; 
    78             $this->setText(FONT_SIZE, $x_pos, $y_pos, number_format($arrData[$i])); 
    79         } 
    80     } 
    81      
     13    function SC_GraphLine( 
     14        $bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = LINE_LEFT, $top = LINE_TOP, 
     15        $area_width = LINE_AREA_WIDTH, $area_height = LINE_AREA_HEIGHT) { 
     16        parent::SC_GraphLine($bgw, $bgh, $left, $top, $area_width, $area_height); 
     17    } 
     18 
     19    // グラフの描画 
     20    function drawGraph() { 
     21        $this->drawYLine(); 
     22        $this->drawXLine(true); 
     23 
     24        // 棒グラフの描画 
     25        for($i = 0; $i < $this->line_max; $i++) { 
     26            $this->drawBar($i); 
     27        } 
     28 
     29        // ラベルの描画 
     30        for($i = 0; $i < $this->line_max; $i++) { 
     31            $this->drawLabel($i); 
     32        } 
     33 
     34        // 凡例の描画 
     35        $this->drawLegend(); 
     36    } 
     37 
     38    // 棒グラフの描画 
     39    function drawBar($line_no) { 
     40        $arrPointList = $this->arrPointList[$line_no]; 
     41        // データ数を数える 
     42        $count = count($arrPointList); 
     43        // 半目盛りの幅を求める 
     44        $half_scale = intval($this->area_width / ($count + 1) / 2); 
     45        // 目盛りの幅を求める 
     46        $scale_width = intval($this->area_width / ($count + 1)); 
     47        // 棒グラフのサイズを求める 
     48        $bar_width = intval(($scale_width - (BAR_PAD * 2)) / $this->line_max); 
     49        // 色数の取得 
     50        $c_max = count($this->arrColor); 
     51        for($i = 0; $i < $count; $i++) { 
     52            $left = $arrPointList[$i][0] - $half_scale + BAR_PAD + ($bar_width * $line_no); 
     53            $top = $arrPointList[$i][1]; 
     54            $right = $left + $bar_width; 
     55            $bottom = $this->top + $this->area_height; 
     56 
     57            // 影の描画 
     58            if($this->shade_on) { 
     59                imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom, $this->shade_color); 
     60            } 
     61            //imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[($i % $c_max)]); 
     62            imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[$line_no]); 
     63            imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color); 
     64        } 
     65    } 
     66 
     67    // ラベルを描画する 
     68    function drawLabel($line_no) { 
     69        $arrData = $this->arrDataList[$line_no]; 
     70        $arrPointList = $this->arrPointList[$line_no]; 
     71        $count = count($arrPointList); 
     72        for($i = 0; $i < $count; $i++) { 
     73            $x = $arrPointList[$i][0]; 
     74            $y = $arrPointList[$i][1]; 
     75            $text_width = $this->getTextWidth(number_format($arrData[$i]), FONT_SIZE); 
     76            $y_pos = $y - FONT_SIZE - 5; 
     77            $x_pos = $x - $text_width / 2; 
     78            $this->setText(FONT_SIZE, $x_pos, $y_pos, number_format($arrData[$i])); 
     79        } 
     80    } 
     81 
    8282} 
    8383?> 
  • branches/feature-module-update/data/class/graph/SC_GraphLine.php

    r15597 r15599  
    66 */ 
    77$SC_GRAPHLINE_DIR = realpath(dirname( __FILE__)); 
    8 require_once($SC_GRAPHLINE_DIR . "/SC_GraphBase.php");   
     8require_once($SC_GRAPHLINE_DIR . "/SC_GraphBase.php"); 
    99 
    1010// 折れ線グラフ生成クラス 
    1111class SC_GraphLine extends SC_GraphBase{ 
    12     var $area_width; 
    13     var $area_height; 
    14     var $ygrid_on; 
    15     var $graph_max;     // グラフのエリア最大値(Y軸頂点の値) 
    16     var $arrXLabel;  
    17     var $XLabelAngle;   // X軸ラベル角度   
    18     var $XTitle;        // X軸タイトル 
    19     var $YTitle;        // Y軸タイトル 
    20     var $arrDataList;   // グラフデータを格納 
    21     var $arrPointList;  // 折れ線座標を格納 
    22     var $line_max;      // 複数の描画の場合に加算していく 
    23      
    24     var $x_margin; 
    25     var $y_margin; 
    26              
     12    var $area_width; 
     13    var $area_height; 
     14    var $ygrid_on; 
     15    var $graph_max;     // グラフのエリア最大値(Y軸頂点の値) 
     16    var $arrXLabel; 
     17    var $XLabelAngle;   // X軸ラベル角度 
     18    var $XTitle;        // X軸タイトル 
     19    var $YTitle;        // Y軸タイトル 
     20    var $arrDataList;   // グラフデータを格納 
     21    var $arrPointList;  // 折れ線座標を格納 
     22    var $line_max;      // 複数の描画の場合に加算していく 
     23 
     24    var $x_margin; 
     25    var $y_margin; 
     26 
    2727    // コンストラクタ 
    28     function SC_GraphLine( 
    29         $bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = LINE_LEFT, $top = LINE_TOP, 
    30         $area_width = LINE_AREA_WIDTH, $area_height = LINE_AREA_HEIGHT) { 
    31         parent::SC_GraphBase($bgw, $bgh, $left, $top);   
    32         $this->area_width = $area_width; 
    33         $this->area_height = $area_height; 
    34         $this->ygrid_on = true; 
    35         $this->line_max = 0; 
    36         $this->graph_max = 0; 
    37         $this->XLabelAngle = 0; 
    38         $this->x_margin = 0; 
    39         $this->y_margin = 0; 
    40     } 
    41      
    42     // X軸ラベルの角度セット 
    43     function setXLabelAngle($Angle) { 
    44         $this->XLabelAngle = $Angle; 
    45     } 
    46      
    47     // Y軸タイトル 
    48     function drawYTitle() { 
    49         // Y軸にタイトルを入れる 
    50         if($this->YTitle != "") { 
    51             $text_width = $this->getTextWidth($this->YTitle, FONT_SIZE); 
    52             $x_pos = $this->left - ($text_width / 2); 
    53             $y_pos = $this->top - FONT_SIZE - LINE_YTITLE_PAD;       
    54             $this->setText(FONT_SIZE, $x_pos, $y_pos, $this->YTitle); 
    55         } 
    56     } 
    57      
    58     // X軸タイトル 
    59     function drawXTitle() { 
    60         // Y軸にタイトルを入れる 
    61         if($this->XTitle != "") { 
    62             $text_width = $this->getTextWidth($this->XTitle, FONT_SIZE); 
    63             $x_pos = $this->left + $this->area_width - ($text_width / 2) + 30; 
    64             $y_pos = $this->top + $this->area_height + LINE_XTITLE_PAD; 
    65             $this->setText(FONT_SIZE, $x_pos, $y_pos, $this->XTitle); 
    66         } 
    67     } 
    68      
    69     // Y軸の描画 
    70     function drawYLine() { 
    71         imageline($this->image, $this->left, $this->top, $this->left, $this->top + $this->area_height, $this->flame_color); 
    72         // 目盛り幅を求める(中間点は自動) 
    73         $size = $this->area_height / (LINE_Y_SCALE * 2); 
    74         // 上から目盛りを入れていく 
    75         $pos = 0; 
    76         for($i = 0; $i < (LINE_Y_SCALE * 2); $i++) { 
    77             // 目盛り幅 
    78             if(($i % 2) == 0) { 
    79                 $sw = LINE_SCALE_SIZE; 
    80                 if($this->ygrid_on) { 
    81                     imageline($this->image, $this->left, $this->top + $pos, $this->left + $this->area_width, $this->top + $pos, $this->grid_color); 
    82                 } 
    83             } else { 
    84                 $sw = LINE_SCALE_SIZE / 2; 
    85             } 
    86             imageline($this->image, $this->left, $this->top + $pos, $this->left + $sw, $this->top + $pos, $this->flame_color); 
    87             $pos += $size; 
    88         } 
    89         // Y軸に目盛り値を入れる 
    90         $this->setYScale(); 
    91         $this->drawYTitle();     
    92     } 
    93      
    94     // X軸の描画 
    95     function drawXLine($bar = false) { 
    96         imageline($this->image, $this->left, $this->top + $this->area_height, $this->left + $this->area_width, $this->top + $this->area_height, $this->flame_color); 
    97         $arrPointList = $this->arrPointList[0]; 
    98         $count = count($arrPointList); 
    99          
    100         // 棒グラフの場合は半目盛りずらす 
    101         if($bar) { 
    102             $half_scale = intval($this->area_width / ($count + 1) / 2); 
    103         } else { 
    104             $half_scale = 0; 
    105         } 
    106          
    107         // ラベルの表示インターバルを算出 
    108         $interval = ceil($count / LINE_XLABEL_MAX); // 切り上げ              
    109         for($i = 0; $i < $count; $i++) { 
    110             // X軸に目盛りを入れる 
    111             $x = $arrPointList[$i][0]; 
    112             $pos = $this->top + $this->area_height; 
    113             imageline($this->image, $x - $half_scale, $pos, $x - $half_scale, $pos - LINE_SCALE_SIZE,  $this->flame_color);          
    114             // ラベルを入れる 
    115             if(($i % $interval) == 0) { 
    116                 $text_width = $this->getTextWidth($this->arrXLabel[$i], FONT_SIZE); 
    117                 $x_pos = $x; 
    118                  
    119                 if ($bar) $bar_margin = -15; 
    120  
    121                 $this->setText(FONT_SIZE, $x_pos + $this->x_margin + $bar_margin, $pos + FONT_SIZE + $this->y_margin, $this->arrXLabel[$i], NULL, $this->XLabelAngle); 
    122             } 
    123         } 
    124          
    125         // 棒グラフの場合は最後の目盛りを一つ追加する 
    126         if($bar) { 
    127             imageline($this->image, $x + $half_scale, $pos, $x + $half_scale, $pos - LINE_SCALE_SIZE,  $this->flame_color);  
    128         } 
    129          
    130         $this->drawXTitle(); 
    131     } 
    132          
    133     // グリッド表示 
    134     function setYGridOn($ygrid_on) { 
    135         $this->ygrid_on = $ygrid_on; 
    136     } 
    137      
    138     // ポイントの描画 
    139     function setMark($line_no, $left, $top, $size = LINE_MARK_SIZE) { 
    140         // 偶数に変換しておく 
    141         $size += $size % 2; 
    142         $array = array( 
    143             $left, $top - ($size / 2), 
    144             $left + ($size / 2), $top, 
    145             $left, $top + ($size / 2), 
    146             $left - ($size / 2), $top, 
    147         );       
    148         imagefilledpolygon($this->image, $array, 4, $this->arrColor[$line_no]); 
    149         imagepolygon($this->image, $array, 4, $this->flame_color); 
    150         imagesetpixel ($this->image, $left, $top + ($size / 2), $this->flame_color); 
    151     }    
    152      
    153     // Y軸目盛りに値を入れる 
    154     function setYScale() { 
    155         // 1目盛りの値 
    156         $number = intval($this->graph_max / LINE_Y_SCALE);               
    157         // 目盛り幅を求める 
    158         $size = $this->area_height / LINE_Y_SCALE; 
    159         $pos = 0; 
    160         for($i = 0; $i <= LINE_Y_SCALE; $i++) { 
    161             $snumber = $number * (LINE_Y_SCALE - $i); 
    162             $disp_number = number_format($snumber); 
    163             $num_width = $this->getTextWidth($disp_number, FONT_SIZE); 
    164             $this->setText(FONT_SIZE, $this->left - $num_width - 2, $this->top + $pos - (FONT_SIZE / 2), $disp_number); 
    165             $pos += $size; 
    166         } 
    167     } 
    168      
    169     //  
    170     function setMax($arrData) { 
    171         // データの最大値を取得する。 
    172         $data_max = max($arrData); 
    173         // 10の何倍かを取得 
    174         $figure = strlen($data_max) - 1; 
    175         // 次の桁を計算する 
    176         $tenval = pow(10, $figure); 
    177         // グラフ上での最大値を求める 
    178         $this->graph_max = $tenval * (intval($data_max / $tenval) + 1); 
    179         // 最大値が10未満の場合の対応 
    180         if($this->graph_max < 10) { 
    181             $this->graph_max = 10; 
    182         }    
    183     } 
    184      
    185     // グラフの描画 
    186     function drawGraph() { 
    187         // グラフ背景を描画 
    188         $this->drawYLine(); 
    189         $this->drawXLine(); 
    190          
    191         // 折れ線グラフ描画 
    192         for($i = 0; $i < $this->line_max; $i++) { 
    193             $this->drawLine($i); 
    194         } 
    195          
    196         // マークを描画 
    197         for($i = 0; $i < $this->line_max; $i++) { 
    198             $this->drawMark($i); 
    199         } 
    200          
    201         // ラベルを描画 
    202         for($i = 0; $i < $this->line_max; $i++) { 
    203             $this->drawLabel($i);        
    204         } 
    205  
    206         // 凡例の描画 
    207         $this->drawLegend();     
    208     } 
    209      
    210     // ラインを描画する 
    211     function drawLine($line_no) { 
    212         $arrPointList = $this->arrPointList[$line_no]; 
    213          
    214         $count = count($arrPointList); 
    215         for($i = 0; $i < $count; $i++) { 
    216             $x = $arrPointList[$i][0]; 
    217             $y = $arrPointList[$i][1]; 
    218             if(isset($arrPointList[$i + 1])) { 
    219                 $next_x = $arrPointList[$i + 1][0]; 
    220                 $next_y = $arrPointList[$i + 1][1]; 
    221                 imageline($this->image, $x, $y, $next_x, $next_y, $this->arrColor[$line_no]); 
    222             } 
    223         } 
    224     } 
    225      
    226     // マークを描画する 
    227     function drawMark($line_no) { 
    228         $arrPointList = $this->arrPointList[$line_no]; 
    229         $count = count($arrPointList); 
    230         for($i = 0; $i < $count; $i++) { 
    231             $x = $arrPointList[$i][0]; 
    232             $y = $arrPointList[$i][1];           
    233             $this->setMark($line_no, $x, $y); 
    234         } 
    235     } 
    236      
    237     // ラベルを描画する 
    238     function drawLabel($line_no) { 
    239         $arrData = $this->arrDataList[$line_no]; 
    240         $arrPointList = $this->arrPointList[$line_no]; 
    241         $count = count($arrPointList); 
    242         for($i = 0; $i < $count; $i++) { 
    243             $x = $arrPointList[$i][0]; 
    244             $y = $arrPointList[$i][1]; 
    245             $text_width = $this->getTextWidth(number_format($arrData[$i]), FONT_SIZE); 
    246             $y_pos = $y - FONT_SIZE - 5; 
    247             $x_pos = $x - $text_width / 2; 
    248             $this->setText(FONT_SIZE, $x_pos, $y_pos, number_format($arrData[$i])); 
    249         } 
    250     } 
    251      
    252     // データをセットする 
    253     function setData($arrData) { 
    254         $this->arrDataList[$this->line_max] = array_values((array)$arrData); 
    255         $this->setMax($this->arrDataList[$this->line_max]); 
    256         // 値の描画変換率 
    257         $rate = $this->area_height / $this->graph_max; 
    258         // 描画率を計算 
    259         $count = count($this->arrDataList[$this->line_max]); 
    260         $scale_width = $this->area_width / ($count + 1);         
    261         $this->arrPointList[$this->line_max] = array(); 
    262         for($i = 0; $i < $count; $i++) { 
    263             // X座標を求める 
    264             $x = intval($this->left + ($scale_width * ($i + 1))); 
    265             // Y座標を求める 
    266             $y = intval($this->top + $this->area_height - ($this->arrDataList[$this->line_max][$i] * $rate)); 
    267             // XY座標を保存する 
    268             $this->arrPointList[$this->line_max][] = array($x, $y); 
    269         } 
    270         $this->line_max++; 
    271     } 
    272      
    273     // X軸ラベルをセットする 
    274     function setXLabel($arrXLabel) { 
    275         $this->arrXLabel = array_values((array)$arrXLabel); 
    276     } 
    277      
    278     // X軸タイトルをセットする 
    279     function setXTitle($title) { 
    280         $this->XTitle = $title; 
    281     } 
    282      
    283     // Y軸タイトルをセットする 
    284     function setYTitle($title) { 
    285         $this->YTitle = $title; 
    286     }    
     28    function SC_GraphLine( 
     29        $bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = LINE_LEFT, $top = LINE_TOP, 
     30        $area_width = LINE_AREA_WIDTH, $area_height = LINE_AREA_HEIGHT) { 
     31        parent::SC_GraphBase($bgw, $bgh, $left, $top); 
     32        $this->area_width = $area_width; 
     33        $this->area_height = $area_height; 
     34        $this->ygrid_on = true; 
     35        $this->line_max = 0; 
     36        $this->graph_max = 0; 
     37        $this->XLabelAngle = 0; 
     38        $this->x_margin = 0; 
     39        $this->y_margin = 0; 
     40    } 
     41 
     42    // X軸ラベルの角度セット 
     43    function setXLabelAngle($Angle) { 
     44        $this->XLabelAngle = $Angle; 
     45    } 
     46 
     47    // Y軸タイトル 
     48    function drawYTitle() { 
     49        // Y軸にタイトルを入れる 
     50        if($this->YTitle != "") { 
     51            $text_width = $this->getTextWidth($this->YTitle, FONT_SIZE); 
     52            $x_pos = $this->left - ($text_width / 2); 
     53            $y_pos = $this->top - FONT_SIZE - LINE_YTITLE_PAD; 
     54            $this->setText(FONT_SIZE, $x_pos, $y_pos, $this->YTitle); 
     55        } 
     56    } 
     57 
     58    // X軸タイトル 
     59    function drawXTitle() { 
     60        // Y軸にタイトルを入れる 
     61        if($this->XTitle != "") { 
     62            $text_width = $this->getTextWidth($this->XTitle, FONT_SIZE); 
     63            $x_pos = $this->left + $this->area_width - ($text_width / 2) + 30; 
     64            $y_pos = $this->top + $this->area_height + LINE_XTITLE_PAD; 
     65            $this->setText(FONT_SIZE, $x_pos, $y_pos, $this->XTitle); 
     66        } 
     67    } 
     68 
     69    // Y軸の描画 
     70    function drawYLine() { 
     71        imageline($this->image, $this->left, $this->top, $this->left, $this->top + $this->area_height, $this->flame_color); 
     72        // 目盛り幅を求める(中間点は自動) 
     73        $size = $this->area_height / (LINE_Y_SCALE * 2); 
     74        // 上から目盛りを入れていく 
     75        $pos = 0; 
     76        for($i = 0; $i < (LINE_Y_SCALE * 2); $i++) { 
     77            // 目盛り幅 
     78            if(($i % 2) == 0) { 
     79                $sw = LINE_SCALE_SIZE; 
     80                if($this->ygrid_on) { 
     81                    imageline($this->image, $this->left, $this->top + $pos, $this->left + $this->area_width, $this->top + $pos, $this->grid_color); 
     82                } 
     83            } else { 
     84                $sw = LINE_SCALE_SIZE / 2; 
     85            } 
     86            imageline($this->image, $this->left, $this->top + $pos, $this->left + $sw, $this->top + $pos, $this->flame_color); 
     87            $pos += $size; 
     88        } 
     89        // Y軸に目盛り値を入れる 
     90        $this->setYScale(); 
     91        $this->drawYTitle(); 
     92    } 
     93 
     94    // X軸の描画 
     95    function drawXLine($bar = false) { 
     96        imageline($this->image, $this->left, $this->top + $this->area_height, $this->left + $this->area_width, $this->top + $this->area_height, $this->flame_color); 
     97        $arrPointList = $this->arrPointList[0]; 
     98        $count = count($arrPointList); 
     99 
     100        // 棒グラフの場合は半目盛りずらす 
     101        if($bar) { 
     102            $half_scale = intval($this->area_width / ($count + 1) / 2); 
     103        } else { 
     104            $half_scale = 0; 
     105        } 
     106 
     107        // ラベルの表示インターバルを算出 
     108        $interval = ceil($count / LINE_XLABEL_MAX); // 切り上げ 
     109        for($i = 0; $i < $count; $i++) { 
     110            // X軸に目盛りを入れる 
     111            $x = $arrPointList[$i][0]; 
     112            $pos = $this->top + $this->area_height; 
     113            imageline($this->image, $x - $half_scale, $pos, $x - $half_scale, $pos - LINE_SCALE_SIZE,  $this->flame_color); 
     114            // ラベルを入れる 
     115            if(($i % $interval) == 0) { 
     116                $text_width = $this->getTextWidth($this->arrXLabel[$i], FONT_SIZE); 
     117                $x_pos = $x; 
     118 
     119                if ($bar) $bar_margin = -15; 
     120 
     121                $this->setText(FONT_SIZE, $x_pos + $this->x_margin + $bar_margin, $pos + FONT_SIZE + $this->y_margin, $this->arrXLabel[$i], NULL, $this->XLabelAngle); 
     122            } 
     123        } 
     124 
     125        // 棒グラフの場合は最後の目盛りを一つ追加する 
     126        if($bar) { 
     127            imageline($this->image, $x + $half_scale, $pos, $x + $half_scale, $pos - LINE_SCALE_SIZE,  $this->flame_color); 
     128        } 
     129 
     130        $this->drawXTitle(); 
     131    } 
     132 
     133    // グリッド表示 
     134    function setYGridOn($ygrid_on) { 
     135        $this->ygrid_on = $ygrid_on; 
     136    } 
     137 
     138    // ポイントの描画 
     139    function setMark($line_no, $left, $top, $size = LINE_MARK_SIZE) { 
     140        // 偶数に変換しておく 
     141        $size += $size % 2; 
     142        $array = array( 
     143            $left, $top - ($size / 2), 
     144            $left + ($size / 2), $top, 
     145            $left, $top + ($size / 2), 
     146            $left - ($size / 2), $top, 
     147        ); 
     148        imagefilledpolygon($this->image, $array, 4, $this->arrColor[$line_no]); 
     149        imagepolygon($this->image, $array, 4, $this->flame_color); 
     150        imagesetpixel ($this->image, $left, $top + ($size / 2), $this->flame_color); 
     151    } 
     152 
     153    // Y軸目盛りに値を入れる 
     154    function setYScale() { 
     155        // 1目盛りの値 
     156        $number = intval($this->graph_max / LINE_Y_SCALE); 
     157        // 目盛り幅を求める 
     158        $size = $this->area_height / LINE_Y_SCALE; 
     159        $pos = 0; 
     160        for($i = 0; $i <= LINE_Y_SCALE; $i++) { 
     161            $snumber = $number * (LINE_Y_SCALE - $i); 
     162            $disp_number = number_format($snumber); 
     163            $num_width = $this->getTextWidth($disp_number, FONT_SIZE); 
     164            $this->setText(FONT_SIZE, $this->left - $num_width - 2, $this->top + $pos - (FONT_SIZE / 2), $disp_number); 
     165            $pos += $size; 
     166        } 
     167    } 
     168 
     169    // 
     170    function setMax($arrData) { 
     171        // データの最大値を取得する。 
     172        $data_max = max($arrData); 
     173        // 10の何倍かを取得 
     174        $figure = strlen($data_max) - 1; 
     175        // 次の桁を計算する 
     176        $tenval = pow(10, $figure); 
     177        // グラフ上での最大値を求める 
     178        $this->graph_max = $tenval * (intval($data_max / $tenval) + 1); 
     179        // 最大値が10未満の場合の対応 
     180        if($this->graph_max < 10) { 
     181            $this->graph_max = 10; 
     182        } 
     183    } 
     184 
     185    // グラフの描画 
     186    function drawGraph() { 
     187        // グラフ背景を描画 
     188        $this->drawYLine(); 
     189        $this->drawXLine(); 
     190 
     191        // 折れ線グラフ描画 
     192        for($i = 0; $i < $this->line_max; $i++) { 
     193            $this->drawLine($i); 
     194        } 
     195 
     196        // マークを描画 
     197        for($i = 0; $i < $this->line_max; $i++) { 
     198            $this->drawMark($i); 
     199        } 
     200 
     201        // ラベルを描画 
     202        for($i = 0; $i < $this->line_max; $i++) { 
     203            $this->drawLabel($i); 
     204        } 
     205 
     206        // 凡例の描画 
     207        $this->drawLegend(); 
     208    } 
     209 
     210    // ラインを描画する 
     211    function drawLine($line_no) { 
     212        $arrPointList = $this->arrPointList[$line_no]; 
     213 
     214        $count = count($arrPointList); 
     215        for($i = 0; $i < $count; $i++) { 
     216            $x = $arrPointList[$i][0]; 
     217            $y = $arrPointList[$i][1]; 
     218            if(isset($arrPointList[$i + 1])) { 
     219                $next_x = $arrPointList[$i + 1][0]; 
     220                $next_y = $arrPointList[$i + 1][1]; 
     221                imageline($this->image, $x, $y, $next_x, $next_y, $this->arrColor[$line_no]); 
     222            } 
     223        } 
     224    } 
     225 
     226    // マークを描画する 
     227    function drawMark($line_no) { 
     228        $arrPointList = $this->arrPointList[$line_no]; 
     229        $count = count($arrPointList); 
     230        for($i = 0; $i < $count; $i++) { 
     231            $x = $arrPointList[$i][0]; 
     232            $y = $arrPointList[$i][1]; 
     233            $this->setMark($line_no, $x, $y); 
     234        } 
     235    } 
     236 
     237    // ラベルを描画する 
     238    function drawLabel($line_no) { 
     239        $arrData = $this->arrDataList[$line_no]; 
     240        $arrPointList = $this->arrPointList[$line_no]; 
     241        $count = count($arrPointList); 
     242        for($i = 0; $i < $count; $i++) { 
     243            $x = $arrPointList[$i][0]; 
     244            $y = $arrPointList[$i][1]; 
     245            $text_width = $this->getTextWidth(number_format($arrData[$i]), FONT_SIZE); 
     246            $y_pos = $y - FONT_SIZE - 5; 
     247            $x_pos = $x - $text_width / 2; 
     248            $this->setText(FONT_SIZE, $x_pos, $y_pos, number_format($arrData[$i])); 
     249        } 
     250    } 
     251 
     252    // データをセットする 
     253    function setData($arrData) { 
     254        $this->arrDataList[$this->line_max] = array_values((array)$arrData); 
     255        $this->setMax($this->arrDataList[$this->line_max]); 
     256        // 値の描画変換率 
     257        $rate = $this->area_height / $this->graph_max; 
     258        // 描画率を計算 
     259        $count = count($this->arrDataList[$this->line_max]); 
     260        $scale_width = $this->area_width / ($count + 1); 
     261        $this->arrPointList[$this->line_max] = array(); 
     262        for($i = 0; $i < $count; $i++) { 
     263            // X座標を求める 
     264            $x = intval($this->left + ($scale_width * ($i + 1))); 
     265            // Y座標を求める 
     266            $y = intval($this->top + $this->area_height - ($this->arrDataList[$this->line_max][$i] * $rate)); 
     267            // XY座標を保存する 
     268            $this->arrPointList[$this->line_max][] = array($x, $y); 
     269        } 
     270        $this->line_max++; 
     271    } 
     272 
     273    // X軸ラベルをセットする 
     274    function setXLabel($arrXLabel) { 
     275        $this->arrXLabel = array_values((array)$arrXLabel); 
     276    } 
     277 
     278    // X軸タイトルをセットする 
     279    function setXTitle($title) { 
     280        $this->XTitle = $title; 
     281    } 
     282 
     283    // Y軸タイトルをセットする 
     284    function setYTitle($title) { 
     285        $this->YTitle = $title; 
     286    } 
    287287} 
    288288?> 
  • branches/feature-module-update/data/class/graph/SC_GraphPie.php

    r15597 r15599  
    66 */ 
    77$SC_GRAPHPIE_DIR = realpath(dirname( __FILE__)); 
    8 require_once($SC_GRAPHPIE_DIR . "/SC_GraphBase.php");    
     8require_once($SC_GRAPHPIE_DIR . "/SC_GraphBase.php"); 
    99 
    1010// 円グラフ生成クラス 
    1111class SC_GraphPie extends SC_GraphBase{ 
    12     var $cw; 
    13     var $ch; 
    14     var $cz; 
    15     var $cx; 
    16     var $cy; 
    17     var $arrLabel; 
    18     var $arrData; 
    19      
     12    var $cw; 
     13    var $ch; 
     14    var $cz; 
     15    var $cx; 
     16    var $cy; 
     17    var $arrLabel; 
     18    var $arrData; 
     19 
    2020    // コンストラクタ 
    21     function SC_GraphPie($bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = PIE_LEFT, $top = PIE_TOP) { 
    22         parent::SC_GraphBase($bgw, $bgh, $left, $top); 
    23         // サイズ設定 
    24         $this->setSize(PIE_WIDTH, PIE_HEIGHT, PIE_THICK); 
    25         // 位置設定 
    26         $this->setPosition($this->left + ($this->cw / 2), $this->top + ($this->ch / 2)); 
     21    function SC_GraphPie($bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = PIE_LEFT, $top = PIE_TOP) { 
     22        parent::SC_GraphBase($bgw, $bgh, $left, $top); 
     23        // サイズ設定 
     24        $this->setSize(PIE_WIDTH, PIE_HEIGHT, PIE_THICK); 
     25        // 位置設定 
     26        $this->setPosition($this->left + ($this->cw / 2), $this->top + ($this->ch / 2)); 
    2727    } 
    28      
    29     // データを360°値に変換する 
    30     function getCircleData($array) { 
    31         if(!is_array($array)) { 
    32             return; 
    33         } 
    34         $arrRet = array(); 
    35         foreach($array as $val) { 
    36             $total += $val;          
    37         } 
    38         if($total <= 0) { 
    39             return; 
    40         }        
    41         $rate = 360 / $total; 
    42         // ラベル表示用 
    43         $p_rate = 100 / $total; 
    44         $cnt = 0; 
    45         foreach($array as $val) { 
    46             $ret = round($val * $rate); 
    47             $new_total+= $ret; 
    48             $arrRet[] = $ret; 
    49             // パーセント表示用 
    50             $this->arrLabel[] = round($val * $p_rate) . " %"; 
    51             $cnt++; 
    52         } 
    53         // 合計が360になるように補正しておく 
    54         $arrRet[0] -= $new_total - 360; 
    55         return $arrRet; 
    56     }    
    57          
    58     // 円の位置設定を行う 
    59     function setPosition($cx, $cy) { 
    60         $this->cx = $cx; 
    61         $this->cy = $cy; 
    62     } 
    63          
    64     // 円のサイズ設定を行う 
    65     function setSize($cw, $ch, $cz = 0) { 
    66         $this->cw = $cw; 
    67         $this->ch = $ch; 
    68         $this->cz = $cz; 
    69     } 
    70      
    71     // 影の描画 
    72     function drawShade() { 
    73         $move = 1; 
    74         for($i = ($this->cy + $this->cz); $i <= ($this->cy + $this->cz + ($this->cz * PIE_SHADE_IMPACT)); $i++) { 
    75             imagefilledarc($this->image, $this->cx + $move, $i, $this->cw, $this->ch, 0, 360, $this->shade_color, IMG_ARC_PIE); 
    76             $move += 0.5; 
    77         } 
    78     } 
    79      
    80     // データをセットする 
    81     function setData($arrData) { 
    82         $this->arrData = array_values($arrData); 
    83     } 
    84      
    85     // 円グラフを描画する 
    86     function drawGraph() { 
    87         $x = $this->cx; 
    88         $y = $this->cy; 
    89         $z = $this->cz; 
    90         $h = $this->ch; 
    91         $w = $this->cw; 
    92          
    93         // データの角度を取得する 
    94         $arrRad = $this->getCircleData($this->arrData); 
    95         $rd_max = count($arrRad); 
    96          
    97         // データが存在しない場合 
    98         if($rd_max <= 0) { 
    99             return; 
    100         } 
    101          
    102         // 影の描画 
    103         if($this->shade_on) { 
    104             $this->drawShade(); 
    105         } 
    106              
    107         // 色数の取得 
    108         $c_max = count($this->arrColor); 
    109         $dc_max = count($this->arrDarkColor); 
    110          
    111         // 側面の描画         
    112         for ($i = ($y + $z - 1); $i >= $y; $i--) { 
    113             $start = 0; 
    114             for($j = 0; $j < $rd_max; $j++) { 
    115                 // 角度が0度以上の場合のみ側面を描画する。 
    116                 if($arrRad[$j] > 0) { 
    117                     $end = $start + $arrRad[$j]; 
    118                     if($start == 0 && $end == 360) { 
    119                         // -90~270で指定すると円が描画できないので0~360に指定 
    120                         imagearc($this->image, $x, $i, $w, $h, 0, 360, $this->arrDarkColor[($j % $dc_max)]); 
    121                     } else { 
    122                         // -90°は12時の位置から開始するように補正している 
    123                         imagearc($this->image, $x, $i, $w, $h, $start - 90, $end - 90, $this->arrDarkColor[($j % $dc_max)]);     
    124                     }            
    125                     $start = $end; 
    126                 } 
    127             } 
    128         } 
    129         // 底面の描画 
    130         imagearc($this->image, $x, $y + $z, $w, $h, 0, 180 , $this->flame_color); 
    13128 
    132         // 上面の描画 
    133         $start = 0; 
    134         for($i = 0; $i < $rd_max; $i++) { 
    135             $end = $start + $arrRad[$i]; 
    136             if($start == 0 && $end == 360) { 
    137                 // -90~270で指定すると円が描画できないので0~360に指定 
    138                 imagefilledarc($this->image, $x, $y, $w, $h, 0, 360, $this->arrColor[($i % $c_max)], IMG_ARC_PIE);           
    139             } else { 
    140                 // -90°は12時の位置から開始するように補正している。       
    141                 imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->arrColor[($i % $c_max)], IMG_ARC_PIE); 
    142             } 
    143             $start = $end; 
    144         } 
     29    // データを360°値に変換する 
     30    function getCircleData($array) { 
     31        if(!is_array($array)) { 
     32            return; 
     33        } 
     34        $arrRet = array(); 
     35        foreach($array as $val) { 
     36            $total += $val; 
     37        } 
     38        if($total <= 0) { 
     39            return; 
     40        } 
     41        $rate = 360 / $total; 
     42        // ラベル表示用 
     43        $p_rate = 100 / $total; 
     44        $cnt = 0; 
     45        foreach($array as $val) { 
     46            $ret = round($val * $rate); 
     47            $new_total+= $ret; 
     48            $arrRet[] = $ret; 
     49            // パーセント表示用 
     50            $this->arrLabel[] = round($val * $p_rate) . " %"; 
     51            $cnt++; 
     52        } 
     53        // 合計が360になるように補正しておく 
     54        $arrRet[0] -= $new_total - 360; 
     55        return $arrRet; 
     56    } 
    14557 
    146         // 上面の縁取り 
    147         $start = 0; 
    148         for($i = 0; $i < $rd_max; $i++) { 
    149             $end = $start + $arrRad[$i]; 
    150             if($start == 0 && $end == 360) { 
    151                 // -90~270で指定すると円が描画できないので0~360に指定 
    152                 imagearc($this->image, $x, $y, $w, $h, 0, 360 , $this->flame_color); 
    153             } 
    154             // -90°は12時の位置から開始するように補正している。 
    155             imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->flame_color, IMG_ARC_EDGED|IMG_ARC_NOFILL); 
    156             $start = $end; 
    157         } 
     58    // 円の位置設定を行う 
     59    function setPosition($cx, $cy) { 
     60        $this->cx = $cx; 
     61        $this->cy = $cy; 
     62    } 
    15863 
    159         // 側面の縁取り 
    160         imageline($this->image, $x + ($w / 2), $y, $x + ($w / 2), $y + $z, $this->flame_color); 
    161         imageline($this->image, $x - ($w / 2), $y, $x - ($w / 2), $y + $z, $this->flame_color); 
    162         $start = 0; 
    163         for($i = 0; $i < $rd_max; $i++) { 
    164             $end = $start + $arrRad[$i]; 
    165             // 前面のみ 
    166             if($end > 90 && $end < 270) { 
    167                 list($ax, $ay) = lfGetArcPos($x, $y, $w, $h, $end); 
    168                 // ラインのずれを補正する 
    169                 if($end > 180) { 
    170                     $ax = $ax + 1; 
    171                 } 
    172                 imageline($this->image, $ax, $ay, $ax, $ay + $z, $this->flame_color); 
    173             } 
    174             $start = $end;   
    175         } 
    176                  
    177         // ラベルの描画 
    178         $this->drawLabel($arrRad); 
    179         // 凡例の描画 
    180         $this->drawLegend(count($this->arrData));            
    181     } 
    182      
    183     // 円グラフのラベルを描画する 
    184     function drawLabel($arrRad) { 
    185         $rd_max = count($arrRad); 
    186         $start = 0; 
    187         for($i = 0; $i < $rd_max; $i++) { 
    188             $center = $start + ($arrRad[$i] / 2); 
    189             $end = $start + $arrRad[$i]; 
    190             list($sx, $sy) = lfGetArcPos($this->cx, $this->cy, ($this->cw / 1.5), ($this->ch / 1.5), $center); 
    191             list($ex, $ey) = lfGetArcPos($this->cx, $this->cy, ($this->cw * 1.5), ($this->ch * 1.5), $center); 
    192             // 指示線の描画 
    193             imageline($this->image, $sx, $sy, $ex + 2, $ey - PIE_LABEL_UP, $this->flame_color); 
    194             $this->setText(FONT_SIZE, $ex - 10, $ey - PIE_LABEL_UP - FONT_SIZE, $this->arrLabel[$i], NULL, 0, true); 
    195             $start = $end; 
    196         } 
    197     }    
     64    // 円のサイズ設定を行う 
     65    function setSize($cw, $ch, $cz = 0) { 
     66        $this->cw = $cw; 
     67        $this->ch = $ch; 
     68        $this->cz = $cz; 
     69    } 
     70 
     71    // 影の描画 
     72    function drawShade() { 
     73        $move = 1; 
     74        for($i = ($this->cy + $this->cz); $i <= ($this->cy + $this->cz + ($this->cz * PIE_SHADE_IMPACT)); $i++) { 
     75            imagefilledarc($this->image, $this->cx + $move, $i, $this->cw, $this->ch, 0, 360, $this->shade_color, IMG_ARC_PIE); 
     76            $move += 0.5; 
     77        } 
     78    } 
     79 
     80    // データをセットする 
     81    function setData($arrData) { 
     82        $this->arrData = array_values($arrData); 
     83    } 
     84 
     85    // 円グラフを描画する 
     86    function drawGraph() { 
     87        $x = $this->cx; 
     88        $y = $this->cy; 
     89        $z = $this->cz; 
     90        $h = $this->ch; 
     91        $w = $this->cw; 
     92 
     93        // データの角度を取得する 
     94        $arrRad = $this->getCircleData($this->arrData); 
     95        $rd_max = count($arrRad); 
     96 
     97        // データが存在しない場合 
     98        if($rd_max <= 0) { 
     99            return; 
     100        } 
     101 
     102        // 影の描画 
     103        if($this->shade_on) { 
     104            $this->drawShade(); 
     105        } 
     106 
     107        // 色数の取得 
     108        $c_max = count($this->arrColor); 
     109        $dc_max = count($this->arrDarkColor); 
     110 
     111        // 側面の描画 
     112        for ($i = ($y + $z - 1); $i >= $y; $i--) { 
     113            $start = 0; 
     114            for($j = 0; $j < $rd_max; $j++) { 
     115                // 角度が0度以上の場合のみ側面を描画する。 
     116                if($arrRad[$j] > 0) { 
     117                    $end = $start + $arrRad[$j]; 
     118                    if($start == 0 && $end == 360) { 
     119                        // -90~270で指定すると円が描画できないので0~360に指定 
     120                        imagearc($this->image, $x, $i, $w, $h, 0, 360, $this->arrDarkColor[($j % $dc_max)]); 
     121                    } else { 
     122                        // -90°は12時の位置から開始するように補正している 
     123                        imagearc($this->image, $x, $i, $w, $h, $start - 90, $end - 90, $this->arrDarkColor[($j % $dc_max)]); 
     124                    } 
     125                    $start = $end; 
     126                } 
     127            } 
     128        } 
     129        // 底面の描画 
     130        imagearc($this->image, $x, $y + $z, $w, $h, 0, 180 , $this->flame_color); 
     131 
     132        // 上面の描画 
     133        $start = 0; 
     134        for($i = 0; $i < $rd_max; $i++) { 
     135            $end = $start + $arrRad[$i]; 
     136            if($start == 0 && $end == 360) { 
     137                // -90~270で指定すると円が描画できないので0~360に指定 
     138                imagefilledarc($this->image, $x, $y, $w, $h, 0, 360, $this->arrColor[($i % $c_max)], IMG_ARC_PIE); 
     139            } else { 
     140                // -90°は12時の位置から開始するように補正している。 
     141                imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->arrColor[($i % $c_max)], IMG_ARC_PIE); 
     142            } 
     143            $start = $end; 
     144        } 
     145 
     146        // 上面の縁取り 
     147        $start = 0; 
     148        for($i = 0; $i < $rd_max; $i++) { 
     149            $end = $start + $arrRad[$i]; 
     150            if($start == 0 && $end == 360) { 
     151                // -90~270で指定すると円が描画できないので0~360に指定 
     152                imagearc($this->image, $x, $y, $w, $h, 0, 360 , $this->flame_color); 
     153            } 
     154            // -90°は12時の位置から開始するように補正している。 
     155            imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->flame_color, IMG_ARC_EDGED|IMG_ARC_NOFILL); 
     156            $start = $end; 
     157        } 
     158 
     159        // 側面の縁取り 
     160        imageline($this->image, $x + ($w / 2), $y, $x + ($w / 2), $y + $z, $this->flame_color); 
     161        imageline($this->image, $x - ($w / 2), $y, $x - ($w / 2), $y + $z, $this->flame_color); 
     162        $start = 0; 
     163        for($i = 0; $i < $rd_max; $i++) { 
     164            $end = $start + $arrRad[$i]; 
     165            // 前面のみ 
     166            if($end > 90 && $end < 270) { 
     167                list($ax, $ay) = lfGetArcPos($x, $y, $w, $h, $end); 
     168                // ラインのずれを補正する 
     169                if($end > 180) { 
     170                    $ax = $ax + 1; 
     171                } 
     172                imageline($this->image, $ax, $ay, $ax, $ay + $z, $this->flame_color); 
     173            } 
     174            $start = $end; 
     175        } 
     176 
     177        // ラベルの描画 
     178        $this->drawLabel($arrRad); 
     179        // 凡例の描画 
     180        $this->drawLegend(count($this->arrData)); 
     181    } 
     182 
     183    // 円グラフのラベルを描画する 
     184    function drawLabel($arrRad) { 
     185        $rd_max = count($arrRad); 
     186        $start = 0; 
     187        for($i = 0; $i < $rd_max; $i++) { 
     188            $center = $start + ($arrRad[$i] / 2); 
     189            $end = $start + $arrRad[$i]; 
     190            list($sx, $sy) = lfGetArcPos($this->cx, $this->cy, ($this->cw / 1.5), ($this->ch / 1.5), $center); 
     191            list($ex, $ey) = lfGetArcPos($this->cx, $this->cy, ($this->cw * 1.5), ($this->ch * 1.5), $center); 
     192            // 指示線の描画 
     193            imageline($this->image, $sx, $sy, $ex + 2, $ey - PIE_LABEL_UP, $this->flame_color); 
     194            $this->setText(FONT_SIZE, $ex - 10, $ey - PIE_LABEL_UP - FONT_SIZE, $this->arrLabel[$i], NULL, 0, true); 
     195            $start = $end; 
     196        } 
     197    } 
    198198} 
    199  
    200199?> 
Note: See TracChangeset for help on using the changeset viewer.