Changeset 22585


Ignore:
Timestamp:
2013/02/27 00:01:06 (11 years ago)
Author:
Seasoft
Message:

#2163 (円グラフ 角度0°の値があると不適切な塗りつぶしが行なわれる)
#2044 (無駄な処理を改善する for 2.12.4)

  • 2つのループの統合

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)

  • for -> foreach
  • 既存の軽微な不具合について記載
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/graph/SC_Graph_Pie.php

    r22567 r22585  
    117117        // データの角度を取得する 
    118118        $arrRad = $this->getCircleData($this->arrData); 
    119         $rd_max = count($arrRad); 
    120119 
    121120        // データが存在しない場合 
    122         if ($rd_max <= 0) { 
     121        if (empty($arrRad)) { 
    123122            return; 
    124123        } 
     
    136135        for ($i = ($y + $z - 1); $i >= $y; $i--) { 
    137136            $start = 0; 
    138             for ($j = 0; $j < $rd_max; $j++) { 
     137            foreach ($arrRad as $rad) { 
    139138                // 角度が0度以上の場合のみ側面を描画する。 
    140                 if ($arrRad[$j] > 0) { 
    141                     $end = $start + $arrRad[$j]; 
     139                if ($rad > 0) { 
     140                    $end = $start + $rad; 
    142141                    if ($start == 0 && $end == 360) { 
    143142                        // -90~270で指定すると円が描画できないので0~360に指定 
     
    156155        // 上面の描画 
    157156        $start = 0; 
    158         for ($i = 0; $i < $rd_max; $i++) { 
    159             $end = $start + $arrRad[$i]; 
    160             if ($start == 0 && $end == 360) { 
    161                 // -90~270で指定すると円が描画できないので0~360に指定 
    162                 imagefilledarc($this->image, $x, $y, $w, $h, 0, 360, $this->arrColor[($i % $c_max)], IMG_ARC_PIE); 
    163             } else { 
    164                 // -90°は12時の位置から開始するように補正している。 
    165                 imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->arrColor[($i % $c_max)], IMG_ARC_PIE); 
     157        foreach ($arrRad as $key => $rad) { 
     158            $end = $start + $rad; 
     159            // 開始・終了が同一値だと、(imagefilledarc 関数における) 0°から360°として動作するようなので、スキップする。 
     160            // XXX 値ラベルは別ロジックなので、実質問題を生じないと考えている。 
     161            if ($start == $end) { 
     162                continue 1; 
    166163            } 
    167             $start = $end; 
    168         } 
    169  
    170         // 上面の縁取り 
    171         $start = 0; 
    172         for ($i = 0; $i < $rd_max; $i++) { 
    173             $end = $start + $arrRad[$i]; 
    174             if ($start == 0 && $end == 360) { 
    175                 // -90~270で指定すると円が描画できないので0~360に指定 
    176                 imagearc($this->image, $x, $y, $w, $h, 0, 360 , $this->flame_color); 
    177             } 
    178             // -90°は12時の位置から開始するように補正している。 
     164            // -90°は12時の位置から開始するように補正するもの。 
     165            // 塗りつぶし 
     166            imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->arrColor[($key % $c_max)], $style); 
     167            // FIXME 360°描画の場合、(imagefilledarc 関数における) 0°から360°として動作する。本来-90°から360°として動作すべき。 
     168            //       なお、360°と0°の組み合わせを考慮すると線が無いのも問題があるので、この処理をスキップする対応は不適当である。 
     169            // 縁取り線 
    179170            imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->flame_color, IMG_ARC_EDGED|IMG_ARC_NOFILL); 
    180171            $start = $end; 
     
    185176        imageline($this->image, $x - ($w / 2), $y, $x - ($w / 2), $y + $z, $this->flame_color); 
    186177        $start = 0; 
    187         for ($i = 0; $i < $rd_max; $i++) { 
    188             $end = $start + $arrRad[$i]; 
     178        foreach ($arrRad as $rad) { 
     179            $end = $start + $rad; 
    189180            // 前面のみ 
    190181            if ($end > 90 && $end < 270) { 
     
    208199    function drawLabel($arrRad) 
    209200    { 
    210         $rd_max = count($arrRad); 
    211201        $start = 0; 
    212         for ($i = 0; $i < $rd_max; $i++) { 
    213             $center = $start + ($arrRad[$i] / 2); 
    214             $end = $start + $arrRad[$i]; 
     202        foreach ($arrRad as $key => $rad) { 
     203            $center = $start + ($rad / 2); 
     204            $end = $start + $rad; 
    215205            list($sx, $sy) = $this->lfGetArcPos($this->cx, $this->cy, ($this->cw / 1.5), ($this->ch / 1.5), $center); 
    216206            list($ex, $ey) = $this->lfGetArcPos($this->cx, $this->cy, ($this->cw * 1.5), ($this->ch * 1.5), $center); 
    217207            // 指示線の描画 
    218208            imageline($this->image, $sx, $sy, $ex + 2, $ey - PIE_LABEL_UP, $this->flame_color); 
    219             $this->setText(FONT_SIZE, $ex - 10, $ey - PIE_LABEL_UP - FONT_SIZE, $this->arrLabel[$i], NULL, 0, true); 
     209            $this->setText(FONT_SIZE, $ex - 10, $ey - PIE_LABEL_UP - FONT_SIZE, $this->arrLabel[$key], NULL, 0, true); 
    220210            $start = $end; 
    221211        } 
Note: See TracChangeset for help on using the changeset viewer.