- Timestamp:
- 2007/09/04 20:24:51 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/graph/SC_GraphBar.php
r15597 r15599 6 6 */ 7 7 $SC_GRAPHBAR_DIR = realpath(dirname( __FILE__)); 8 require_once($SC_GRAPHBAR_DIR . "/SC_GraphLine.php"); 8 require_once($SC_GRAPHBAR_DIR . "/SC_GraphLine.php"); 9 9 10 10 // 棒グラフ生成クラス 11 11 class SC_GraphBar extends SC_GraphLine{ 12 12 // コンストラクタ 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 82 82 } 83 83 ?>
Note: See TracChangeset
for help on using the changeset viewer.
