Changeset 11730 for branches/comu/html/admin/total/class/SC_GraphLine.php
- Timestamp:
- 2007/03/11 06:27:25 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/comu/html/admin/total/class/SC_GraphLine.php
r11729 r11730 8 8 require_once($SC_GRAPHLINE_DIR . "/SC_GraphBase.php"); 9 9 10 // 折れ線グラフ生成クラス10 // ÀÞ¤ìÀþ¥°¥é¥ÕÀ¸À®¥¯¥é¥¹ 11 11 class SC_GraphLine extends SC_GraphBase{ 12 12 var $area_width; 13 13 var $area_height; 14 14 var $ygrid_on; 15 var $graph_max; // グラフのエリア最大値(Y軸頂点の値)15 var $graph_max; // ¥°¥é¥Õ¤Î¥¨¥ê¥¢ºÇÂçÃÍ(Y¼´ÄºÅÀ¤ÎÃÍ) 16 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; // 複数の描画の場合に加算していく17 var $XLabelAngle; // X¼´¥é¥Ù¥ë³ÑÅÙ 18 var $XTitle; // X¼´¥¿¥¤¥È¥ë 19 var $YTitle; // Y¼´¥¿¥¤¥È¥ë 20 var $arrDataList; // ¥°¥é¥Õ¥Ç¡¼¥¿¤ò³ÊǼ 21 var $arrPointList; // ÀÞ¤ìÀþºÂɸ¤ò³ÊǼ 22 var $line_max; // Ê£¿ô¤ÎÉÁ²è¤Î¾ì¹ç¤Ë²Ã»»¤·¤Æ¤¤¤¯ 23 23 24 24 var $x_margin; 25 25 var $y_margin; 26 26 27 // コンストラクタ27 // ¥³¥ó¥¹¥È¥é¥¯¥¿ 28 28 function SC_GraphLine( 29 29 $bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = LINE_LEFT, $top = LINE_TOP, … … 40 40 } 41 41 42 // X 軸ラベルの角度セット42 // X¼´¥é¥Ù¥ë¤Î³ÑÅÙ¥»¥Ã¥È 43 43 function setXLabelAngle($Angle) { 44 44 $this->XLabelAngle = $Angle; 45 45 } 46 46 47 // Y 軸タイトル47 // Y¼´¥¿¥¤¥È¥ë 48 48 function drawYTitle() { 49 // Y 軸にタイトルを入れる49 // Y¼´¤Ë¥¿¥¤¥È¥ë¤òÆþ¤ì¤ë 50 50 if($this->YTitle != "") { 51 51 $text_width = $this->getTextWidth($this->YTitle, FONT_SIZE); … … 56 56 } 57 57 58 // X 軸タイトル58 // X¼´¥¿¥¤¥È¥ë 59 59 function drawXTitle() { 60 // Y 軸にタイトルを入れる60 // Y¼´¤Ë¥¿¥¤¥È¥ë¤òÆþ¤ì¤ë 61 61 if($this->XTitle != "") { 62 62 $text_width = $this->getTextWidth($this->XTitle, FONT_SIZE); … … 67 67 } 68 68 69 // Y 軸の描画69 // Y¼´¤ÎÉÁ²è 70 70 function drawYLine() { 71 71 imageline($this->image, $this->left, $this->top, $this->left, $this->top + $this->area_height, $this->flame_color); 72 // 目盛り幅を求める(中間点は自動)72 // ÌÜÀ¹¤êÉý¤òµá¤á¤ë(Ãæ´ÖÅÀ¤Ï¼«Æ°) 73 73 $size = $this->area_height / (LINE_Y_SCALE * 2); 74 // 上から目盛りを入れていく74 // ¾å¤«¤éÌÜÀ¹¤ê¤òÆþ¤ì¤Æ¤¤¤¯ 75 75 $pos = 0; 76 76 for($i = 0; $i < (LINE_Y_SCALE * 2); $i++) { 77 // 目盛り幅77 // ÌÜÀ¹¤êÉý 78 78 if(($i % 2) == 0) { 79 79 $sw = LINE_SCALE_SIZE; … … 87 87 $pos += $size; 88 88 } 89 // Y 軸に目盛り値を入れる89 // Y¼´¤ËÌÜÀ¹¤êÃͤòÆþ¤ì¤ë 90 90 $this->setYScale(); 91 91 $this->drawYTitle(); 92 92 } 93 93 94 // X 軸の描画94 // X¼´¤ÎÉÁ²è 95 95 function drawXLine($bar = false) { 96 96 imageline($this->image, $this->left, $this->top + $this->area_height, $this->left + $this->area_width, $this->top + $this->area_height, $this->flame_color); … … 98 98 $count = count($arrPointList); 99 99 100 // 棒グラフの場合は半目盛りずらす100 // ËÀ¥°¥é¥Õ¤Î¾ì¹ç¤ÏȾÌÜÀ¹¤ê¤º¤é¤¹ 101 101 if($bar) { 102 102 $half_scale = intval($this->area_width / ($count + 1) / 2); … … 105 105 } 106 106 107 // ラベルの表示インターバルを算出108 $interval = ceil($count / LINE_XLABEL_MAX); // 切り上げ109 for($i = 0; $i < $count; $i++) { 110 // X 軸に目盛りを入れる107 // ¥é¥Ù¥ë¤Îɽ¼¨¥¤¥ó¥¿¡¼¥Ð¥ë¤ò»»½Ð 108 $interval = ceil($count / LINE_XLABEL_MAX); // ÀÚ¤ê¾å¤² 109 for($i = 0; $i < $count; $i++) { 110 // X¼´¤ËÌÜÀ¹¤ê¤òÆþ¤ì¤ë 111 111 $x = $arrPointList[$i][0]; 112 112 $pos = $this->top + $this->area_height; 113 113 imageline($this->image, $x - $half_scale, $pos, $x - $half_scale, $pos - LINE_SCALE_SIZE, $this->flame_color); 114 // ラベルを入れる114 // ¥é¥Ù¥ë¤òÆþ¤ì¤ë 115 115 if(($i % $interval) == 0) { 116 116 $text_width = $this->getTextWidth($this->arrXLabel[$i], FONT_SIZE); … … 123 123 } 124 124 125 // 棒グラフの場合は最後の目盛りを一つ追加する125 // ËÀ¥°¥é¥Õ¤Î¾ì¹ç¤ÏºÇ¸å¤ÎÌÜÀ¹¤ê¤ò°ì¤ÄÄɲ乤ë 126 126 if($bar) { 127 127 imageline($this->image, $x + $half_scale, $pos, $x + $half_scale, $pos - LINE_SCALE_SIZE, $this->flame_color); … … 131 131 } 132 132 133 // グリッド表示133 // ¥°¥ê¥Ã¥Éɽ¼¨ 134 134 function setYGridOn($ygrid_on) { 135 135 $this->ygrid_on = $ygrid_on; 136 136 } 137 137 138 // ポイントの描画138 // ¥Ý¥¤¥ó¥È¤ÎÉÁ²è 139 139 function setMark($line_no, $left, $top, $size = LINE_MARK_SIZE) { 140 // 偶数に変換しておく140 // ¶ö¿ô¤ËÊÑ´¹¤·¤Æ¤ª¤¯ 141 141 $size += $size % 2; 142 142 $array = array( … … 151 151 } 152 152 153 // Y 軸目盛りに値を入れる153 // Y¼´ÌÜÀ¹¤ê¤ËÃͤòÆþ¤ì¤ë 154 154 function setYScale() { 155 // 1 目盛りの値155 // 1ÌÜÀ¹¤ê¤ÎÃÍ 156 156 $number = intval($this->graph_max / LINE_Y_SCALE); 157 // 目盛り幅を求める157 // ÌÜÀ¹¤êÉý¤òµá¤á¤ë 158 158 $size = $this->area_height / LINE_Y_SCALE; 159 159 $pos = 0; … … 169 169 // 170 170 function setMax($arrData) { 171 // データの最大値を取得する。171 // ¥Ç¡¼¥¿¤ÎºÇÂçÃͤò¼èÆÀ¤¹¤ë¡£ 172 172 $data_max = max($arrData); 173 // 10 の何倍かを取得173 // 10¤Î²¿Çܤ«¤ò¼èÆÀ 174 174 $figure = strlen($data_max) - 1; 175 // 次の桁を計算する175 // ¼¡¤Î·å¤ò·×»»¤¹¤ë 176 176 $tenval = pow(10, $figure); 177 // グラフ上での最大値を求める177 // ¥°¥é¥Õ¾å¤Ç¤ÎºÇÂçÃͤòµá¤á¤ë 178 178 $this->graph_max = $tenval * (intval($data_max / $tenval) + 1); 179 // 最大値が10未満の場合の対応179 // ºÇÂçÃͤ¬10̤Ëþ¤Î¾ì¹ç¤ÎÂбþ 180 180 if($this->graph_max < 10) { 181 181 $this->graph_max = 10; … … 183 183 } 184 184 185 // グラフの描画185 // ¥°¥é¥Õ¤ÎÉÁ²è 186 186 function drawGraph() { 187 // グラフ背景を描画187 // ¥°¥é¥ÕÇØ·Ê¤òÉÁ²è 188 188 $this->drawYLine(); 189 189 $this->drawXLine(); 190 190 191 // 折れ線グラフ描画191 // ÀÞ¤ìÀþ¥°¥é¥ÕÉÁ²è 192 192 for($i = 0; $i < $this->line_max; $i++) { 193 193 $this->drawLine($i); 194 194 } 195 195 196 // マークを描画196 // ¥Þ¡¼¥¯¤òÉÁ²è 197 197 for($i = 0; $i < $this->line_max; $i++) { 198 198 $this->drawMark($i); 199 199 } 200 200 201 // ラベルを描画201 // ¥é¥Ù¥ë¤òÉÁ²è 202 202 for($i = 0; $i < $this->line_max; $i++) { 203 203 $this->drawLabel($i); 204 204 } 205 205 206 // 凡例の描画206 // ËÞÎã¤ÎÉÁ²è 207 207 $this->drawLegend(); 208 208 } 209 209 210 // ラインを描画する210 // ¥é¥¤¥ó¤òÉÁ²è¤¹¤ë 211 211 function drawLine($line_no) { 212 212 $arrPointList = $this->arrPointList[$line_no]; … … 224 224 } 225 225 226 // マークを描画する226 // ¥Þ¡¼¥¯¤òÉÁ²è¤¹¤ë 227 227 function drawMark($line_no) { 228 228 $arrPointList = $this->arrPointList[$line_no]; … … 235 235 } 236 236 237 // ラベルを描画する237 // ¥é¥Ù¥ë¤òÉÁ²è¤¹¤ë 238 238 function drawLabel($line_no) { 239 239 $arrData = $this->arrDataList[$line_no]; … … 250 250 } 251 251 252 // データをセットする252 // ¥Ç¡¼¥¿¤ò¥»¥Ã¥È¤¹¤ë 253 253 function setData($arrData) { 254 254 $this->arrDataList[$this->line_max] = array_values((array)$arrData); 255 255 $this->setMax($this->arrDataList[$this->line_max]); 256 // 値の描画変換率256 // ÃͤÎÉÁ²èÊÑ´¹Î¨ 257 257 $rate = $this->area_height / $this->graph_max; 258 // 描画率を計算258 // ÉÁ²èΨ¤ò·×»» 259 259 $count = count($this->arrDataList[$this->line_max]); 260 260 $scale_width = $this->area_width / ($count + 1); 261 261 $this->arrPointList[$this->line_max] = array(); 262 262 for($i = 0; $i < $count; $i++) { 263 // X 座標を求める263 // XºÂɸ¤òµá¤á¤ë 264 264 $x = intval($this->left + ($scale_width * ($i + 1))); 265 // Y 座標を求める265 // YºÂɸ¤òµá¤á¤ë 266 266 $y = intval($this->top + $this->area_height - ($this->arrDataList[$this->line_max][$i] * $rate)); 267 // XY 座標を保存する267 // XYºÂɸ¤òÊݸ¤¹¤ë 268 268 $this->arrPointList[$this->line_max][] = array($x, $y); 269 269 } … … 271 271 } 272 272 273 // X 軸ラベルをセットする273 // X¼´¥é¥Ù¥ë¤ò¥»¥Ã¥È¤¹¤ë 274 274 function setXLabel($arrXLabel) { 275 275 $this->arrXLabel = array_values((array)$arrXLabel); 276 276 } 277 277 278 // X 軸タイトルをセットする278 // X¼´¥¿¥¤¥È¥ë¤ò¥»¥Ã¥È¤¹¤ë 279 279 function setXTitle($title) { 280 280 $this->XTitle = $title; 281 281 } 282 282 283 // Y 軸タイトルをセットする283 // Y¼´¥¿¥¤¥È¥ë¤ò¥»¥Ã¥È¤¹¤ë 284 284 function setYTitle($title) { 285 285 $this->YTitle = $title;
Note: See TracChangeset
for help on using the changeset viewer.
