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

tab -> space

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.