- Timestamp:
- 2013/05/02 18:11:36 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/graph/SC_Graph_Pie.php
r22585 r22796 23 23 24 24 // 円グラフ生成クラス 25 class SC_Graph_Pie extends SC_Graph_Base_Ex 26 { 25 class SC_Graph_Pie extends SC_Graph_Base_Ex{ 27 26 var $cw; 28 27 var $ch; … … 34 33 35 34 // コンストラクタ 36 function __construct($bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = PIE_LEFT, $top = PIE_TOP) 37 { 35 function __construct($bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = PIE_LEFT, $top = PIE_TOP) { 38 36 parent::__construct($bgw, $bgh, $left, $top); 39 37 // サイズ設定 … … 44 42 45 43 // データを360°値に変換する 46 function getCircleData($array) 47 { 44 function getCircleData($array) { 48 45 $total = ''; 49 46 $new_total = ''; … … 76 73 77 74 // 円の位置設定を行う 78 function setPosition($cx, $cy) 79 { 75 function setPosition($cx, $cy) { 80 76 $this->cx = $cx; 81 77 $this->cy = $cy; … … 83 79 84 80 // 円のサイズ設定を行う 85 function setSize($cw, $ch, $cz = 0) 86 { 81 function setSize($cw, $ch, $cz = 0) { 87 82 $this->cw = $cw; 88 83 $this->ch = $ch; … … 91 86 92 87 // 影の描画 93 function drawShade() 94 { 88 function drawShade() { 95 89 $move = 1; 96 90 for ($i = ($this->cy + $this->cz); $i <= ($this->cy + $this->cz + ($this->cz * PIE_SHADE_IMPACT)); $i++) { … … 101 95 102 96 // データをセットする 103 function setData($arrData) 104 { 97 function setData($arrData) { 105 98 $this->arrData = array_values($arrData); 106 99 } 107 100 108 101 // 円グラフを描画する 109 function drawGraph() 110 { 102 function drawGraph() { 111 103 $x = $this->cx; 112 104 $y = $this->cy; … … 117 109 // データの角度を取得する 118 110 $arrRad = $this->getCircleData($this->arrData); 111 $rd_max = count($arrRad); 119 112 120 113 // データが存在しない場合 121 if ( empty($arrRad)) {114 if ($rd_max <= 0) { 122 115 return; 123 116 } … … 135 128 for ($i = ($y + $z - 1); $i >= $y; $i--) { 136 129 $start = 0; 137 for each ($arrRad as $rad) {130 for ($j = 0; $j < $rd_max; $j++) { 138 131 // 角度が0度以上の場合のみ側面を描画する。 139 if ($ rad> 0) {140 $end = $start + $ rad;132 if ($arrRad[$j] > 0) { 133 $end = $start + $arrRad[$j]; 141 134 if ($start == 0 && $end == 360) { 142 135 // -90~270で指定すると円が描画できないので0~360に指定 … … 155 148 // 上面の描画 156 149 $start = 0; 157 foreach ($arrRad as $key => $rad) { 158 $end = $start + $rad; 159 // 開始・終了が同一値だと、(imagefilledarc 関数における) 0°から360°として動作するようなので、スキップする。 160 // XXX 値ラベルは別ロジックなので、実質問題を生じないと考えている。 161 if ($start == $end) { 162 continue 1; 163 } 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 // 縁取り線 150 for ($i = 0; $i < $rd_max; $i++) { 151 $end = $start + $arrRad[$i]; 152 if ($start == 0 && $end == 360) { 153 // -90~270で指定すると円が描画できないので0~360に指定 154 imagefilledarc($this->image, $x, $y, $w, $h, 0, 360, $this->arrColor[($i % $c_max)], IMG_ARC_PIE); 155 } else { 156 // -90°は12時の位置から開始するように補正している。 157 imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->arrColor[($i % $c_max)], IMG_ARC_PIE); 158 } 159 $start = $end; 160 } 161 162 // 上面の縁取り 163 $start = 0; 164 for ($i = 0; $i < $rd_max; $i++) { 165 $end = $start + $arrRad[$i]; 166 if ($start == 0 && $end == 360) { 167 // -90~270で指定すると円が描画できないので0~360に指定 168 imagearc($this->image, $x, $y, $w, $h, 0, 360 , $this->flame_color); 169 } 170 // -90°は12時の位置から開始するように補正している。 170 171 imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->flame_color, IMG_ARC_EDGED|IMG_ARC_NOFILL); 171 172 $start = $end; … … 176 177 imageline($this->image, $x - ($w / 2), $y, $x - ($w / 2), $y + $z, $this->flame_color); 177 178 $start = 0; 178 for each ($arrRad as $rad) {179 $end = $start + $ rad;179 for ($i = 0; $i < $rd_max; $i++) { 180 $end = $start + $arrRad[$i]; 180 181 // 前面のみ 181 182 if ($end > 90 && $end < 270) { … … 197 198 198 199 // 円グラフのラベルを描画する 199 function drawLabel($arrRad) 200 {201 $start = 0; 202 for each ($arrRad as $key => $rad) {203 $center = $start + ($ rad/ 2);204 $end = $start + $ rad;200 function drawLabel($arrRad) { 201 $rd_max = count($arrRad); 202 $start = 0; 203 for ($i = 0; $i < $rd_max; $i++) { 204 $center = $start + ($arrRad[$i] / 2); 205 $end = $start + $arrRad[$i]; 205 206 list($sx, $sy) = $this->lfGetArcPos($this->cx, $this->cy, ($this->cw / 1.5), ($this->ch / 1.5), $center); 206 207 list($ex, $ey) = $this->lfGetArcPos($this->cx, $this->cy, ($this->cw * 1.5), ($this->ch * 1.5), $center); 207 208 // 指示線の描画 208 209 imageline($this->image, $sx, $sy, $ex + 2, $ey - PIE_LABEL_UP, $this->flame_color); 209 $this->setText(FONT_SIZE, $ex - 10, $ey - PIE_LABEL_UP - FONT_SIZE, $this->arrLabel[$ key], NULL, 0, true);210 $this->setText(FONT_SIZE, $ex - 10, $ey - PIE_LABEL_UP - FONT_SIZE, $this->arrLabel[$i], NULL, 0, true); 210 211 $start = $end; 211 212 }
Note: See TracChangeset
for help on using the changeset viewer.