[8] | 1 | <?php |
---|
| 2 | /* |
---|
[17] | 3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
[8] | 4 | * |
---|
| 5 | * http://www.lockon.co.jp/ |
---|
| 6 | */ |
---|
| 7 | /* |
---|
| 8 | $SC_GRAPHPIE_DIR = realpath(dirname( __FILE__)); |
---|
| 9 | require_once($SC_GRAPHPIE_DIR . "/config.php"); |
---|
| 10 | require_once($SC_GRAPHPIE_DIR . "/lib.php"); |
---|
| 11 | */ |
---|
| 12 | require_once(realpath(dirname( __FILE__)) . "/config.php"); |
---|
| 13 | require_once(realpath(dirname( __FILE__)) . "/lib.php"); |
---|
| 14 | |
---|
| 15 | // SC_Graph¶¦ÄÌ¥¯¥é¥¹ |
---|
| 16 | class SC_GraphBase { |
---|
| 17 | var $arrRGB; |
---|
| 18 | var $arrColor; |
---|
| 19 | var $arrDarkColor; |
---|
| 20 | var $image; |
---|
| 21 | var $left; |
---|
| 22 | var $top; |
---|
| 23 | var $shade_color; |
---|
| 24 | var $flame_color; |
---|
| 25 | var $shade_on; |
---|
| 26 | var $text_color; |
---|
| 27 | var $labelbg_color; |
---|
| 28 | var $bgw; |
---|
| 29 | var $bgh; |
---|
| 30 | var $clabelbg_color; |
---|
| 31 | var $title_color; |
---|
| 32 | var $text_top; |
---|
| 33 | var $mark_color; |
---|
| 34 | var $arrLegend; |
---|
| 35 | |
---|
| 36 | // ¥³¥ó¥¹¥È¥é¥¯¥¿ |
---|
| 37 | function SC_GraphBase($bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left, $top) { |
---|
| 38 | global $ARR_GRAPH_RGB; |
---|
| 39 | global $ARR_BG_COLOR; |
---|
| 40 | global $ARR_SHADE_COLOR; |
---|
| 41 | global $ARR_FLAME_COLOR; |
---|
| 42 | global $ARR_TEXT_COLOR; |
---|
| 43 | global $ARR_LABELBG_COLOR; |
---|
| 44 | global $ARR_LEGENDBG_COLOR; |
---|
| 45 | global $ARR_TITLE_COLOR; |
---|
| 46 | global $ARR_GRID_COLOR; |
---|
| 47 | |
---|
| 48 | // ²èÁüºîÀ® |
---|
| 49 | $this->bgw = $bgw; |
---|
| 50 | $this->bgh = $bgh; |
---|
| 51 | $this->image = imagecreatetruecolor($bgw, $bgh); |
---|
| 52 | // ¥¢¥ó¥Á¥¨¥¤¥ê¥¢¥¹Í¸ú |
---|
| 53 | if (function_exists("imageantialias")) imageantialias($this->image, true); |
---|
| 54 | // ÇØ·Ê¿§¤ò¥»¥Ã¥È |
---|
| 55 | imagefill($this->image, 0, 0, lfGetImageColor($this->image, $ARR_BG_COLOR)); |
---|
| 56 | |
---|
| 57 | // »ÈÍÑ¿§¤ÎÀ¸À® |
---|
| 58 | $this->setColorList($ARR_GRAPH_RGB); |
---|
| 59 | // ¥°¥é¥ÕÉÁ²è°ÌÃÖ¤ÎÀßÄê |
---|
| 60 | $this->left = $left; |
---|
| 61 | $this->top = $top; |
---|
| 62 | $this->shade_color = lfGetImageColor($this->image, $ARR_SHADE_COLOR); |
---|
| 63 | $this->flame_color = lfGetImageColor($this->image, $ARR_FLAME_COLOR); |
---|
| 64 | $this->text_color = lfGetImageColor($this->image, $ARR_TEXT_COLOR); |
---|
| 65 | $this->labelbg_color = lfGetImageColor($this->image, $ARR_LABELBG_COLOR); |
---|
| 66 | $this->clabelbg_color = lfGetImageColor($this->image, $ARR_LEGENDBG_COLOR); |
---|
| 67 | $this->title_color = lfGetImageColor($this->image, $ARR_TITLE_COLOR); |
---|
| 68 | $this->grid_color = lfGetImageColor($this->image, $ARR_GRID_COLOR); |
---|
| 69 | |
---|
| 70 | // ±Æ¤¢¤ê |
---|
| 71 | $this->shade_on = true; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | // ¥ª¥Ö¥¸¥§¥¯¥È¥«¥é¡¼¤ÎÀßÄê |
---|
| 75 | function setColorList($arrRGB) { |
---|
| 76 | $this->arrRGB = $arrRGB; |
---|
| 77 | $count = count($this->arrRGB); |
---|
| 78 | // Ä̾￧¤ÎÀßÄê |
---|
| 79 | for($i = 0; $i < $count; $i++) { |
---|
| 80 | $this->arrColor[$i] = lfGetImageColor($this->image, $this->arrRGB[$i]); |
---|
| 81 | } |
---|
| 82 | // °Å¿§¤ÎÀßÄê |
---|
| 83 | for($i = 0; $i < $count; $i++) { |
---|
| 84 | $this->arrDarkColor[$i] = lfGetImageDarkColor($this->image, $this->arrRGB[$i]); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | // ±Æ¤Î¤¢¤ê¤Ê¤· |
---|
| 89 | function setShadeOn($shade_on) { |
---|
| 90 | $this->shade_on = $shade_on; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | // ²èÁü¤ò½ÐÎϤ¹¤ë |
---|
| 94 | function outputGraph($header = true, $filename = "") { |
---|
| 95 | if($header) { |
---|
| 96 | header('Content-type: image/png'); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | if ($filename != "") { |
---|
| 100 | imagepng($this->image, $filename); |
---|
| 101 | }else{ |
---|
| 102 | imagepng($this->image); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | imagedestroy($this->image); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | // ÉÁ²è»þ¤Î¥Æ¥¥¹¥ÈÉý¤òµá¤á¤ë |
---|
| 109 | function getTextWidth($text, $font_size) { |
---|
| 110 | $text_len = strlen($text); |
---|
| 111 | $ret = $font_size * $text_len * TEXT_RATE; |
---|
| 112 | /* |
---|
| 113 | ¢¨Àµ³Î¤ÊÃͤ¬¼èÆÀ¤Ç¤¤Ê¤«¤Ã¤¿¤Î¤ÇÇÑ»ß |
---|
| 114 | // ¥Æ¥¥¹¥ÈÉý¤Î¼èÆÀ |
---|
| 115 | $arrPos = imagettfbbox($font_size, 0, FONT_PATH, $text); |
---|
| 116 | $ret = $arrPos[2] - $arrPos[0]; |
---|
| 117 | */ |
---|
| 118 | return $ret; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // ¥Æ¥¥¹¥È¤ò½ÐÎϤ¹¤ë |
---|
| 122 | function setText($font_size, $left, $top, $text, $color = NULL, $angle = 0, $labelbg = false) { |
---|
| 123 | // »þ·×²ó¤ê¤Ë³ÑÅÙ¤òÊѹ¹ |
---|
| 124 | $angle = -$angle; |
---|
| 125 | // ¥é¥Ù¥ëÇØ·Ê |
---|
| 126 | if($labelbg) { |
---|
| 127 | $text_width = $this->getTextWidth($text, $font_size); |
---|
| 128 | imagefilledrectangle($this->image, $left - 2, $top - 2, $left + $text_width + 2, $top + $font_size + 2, $this->labelbg_color); |
---|
| 129 | } |
---|
| 130 | //$text = mb_convert_encoding($text, "UTF-8", CHAR_CODE); |
---|
| 131 | $text = mb_convert_encoding($text, CHAR_CODE); |
---|
| 132 | if($color != NULL) { |
---|
| 133 | ImageTTFText($this->image, $font_size, $angle, $left, $top + $font_size, $color, FONT_PATH, $text); |
---|
| 134 | } else { |
---|
| 135 | ImageTTFText($this->image, $font_size, $angle, $left, $top + $font_size, $this->text_color, FONT_PATH, $text); |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | // ¥¿¥¤¥È¥ë¤ò½ÐÎϤ¹¤ë |
---|
| 140 | function drawTitle($text, $font_size = TITLE_FONT_SIZE) { |
---|
| 141 | // ½ÐÎÏ°ÌÃ֤λ»½Ð |
---|
| 142 | $text_width = $this->getTextWidth($text, $font_size); |
---|
| 143 | $left = ($this->bgw - $text_width) / 2; |
---|
| 144 | $top = TITLE_TOP; |
---|
| 145 | $this->setText($font_size, $left, $top, $text, $this->title_color); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | // ¥í¥°¤ò½ÐÎϤ¹¤ë |
---|
| 149 | function debugPrint($text) { |
---|
| 150 | $text = mb_convert_encoding($text, "UTF-8", CHAR_CODE); |
---|
| 151 | if(!isset($this->text_top)) { |
---|
| 152 | $this->text_top = FONT_SIZE + LINE_PAD; |
---|
| 153 | } |
---|
| 154 | // ¥Æ¥¥¹¥ÈÉÁ²è |
---|
| 155 | ImageTTFText($this->image, FONT_SIZE, 0, LINE_PAD, $this->text_top, $this->text_color, FONT_PATH, $text); |
---|
| 156 | $this->text_top += FONT_SIZE + LINE_PAD; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | // ¥«¥é¡¼¥é¥Ù¥ë¤òÉÁ²è |
---|
| 160 | function drawLegend($legend_max = "", $clabelbg = true) { |
---|
| 161 | // ËÞÎ㤬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤ÐÃæ»ß |
---|
| 162 | if(count($this->arrLegend) <= 0) { |
---|
| 163 | return; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | if($legend_max != "") { |
---|
| 167 | $label_max = $legend_max; |
---|
| 168 | } else { |
---|
| 169 | $label_max = count($this->arrLegend); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | $height_max = 0; |
---|
| 173 | $text_max = 0; |
---|
| 174 | $width_max = 0; |
---|
| 175 | |
---|
| 176 | // °ìÈÖʸ»ú¿ô¤¬Â¿¤¤¤â¤Î¤ò¼èÆÀ |
---|
| 177 | for($i = 0; $i < $label_max; $i++) { |
---|
| 178 | $text_len = strlen($this->arrLegend[$i]); |
---|
| 179 | if($text_max < $text_len) { |
---|
| 180 | $text_max = $text_len; |
---|
| 181 | } |
---|
| 182 | $height_max += FONT_SIZE + LINE_PAD; |
---|
| 183 | } |
---|
| 184 | $width_max = FONT_SIZE * $text_max * TEXT_RATE; |
---|
| 185 | |
---|
| 186 | // ¥«¥é¡¼¥¢¥¤¥³¥ó¤Èʸ»ú´Ö¤ò´Þ¤á¤¿Éý |
---|
| 187 | $width_max += FONT_SIZE + (LINE_PAD * 2); |
---|
| 188 | $left = $this->bgw - $width_max - LEGEND_RIGHT; |
---|
| 189 | $top = LEGEND_TOP; |
---|
| 190 | // ¥«¥é¡¼¥é¥Ù¥ëÇطʤÎÉÁ²è |
---|
| 191 | if($clabelbg) { |
---|
| 192 | $this->drawClabelBG($left - LINE_PAD, $top, $left + $width_max, $top + $height_max + LINE_PAD); |
---|
| 193 | } |
---|
| 194 | $top += LINE_PAD; |
---|
| 195 | |
---|
| 196 | // ¿§¿ô¤Î¼èÆÀ |
---|
| 197 | $c_max = count($this->arrColor); |
---|
| 198 | for($i = 0; $i < $label_max; $i++) { |
---|
| 199 | // ¥«¥é¡¼¥¢¥¤¥³¥ó¤Îɽ¼¨ |
---|
| 200 | imagerectangle($this->image, $left, $top, $left + FONT_SIZE, $top + FONT_SIZE, $this->flame_color); |
---|
| 201 | imagefilledrectangle($this->image, $left + 1, $top + 1, $left + FONT_SIZE - 1, $top + FONT_SIZE - 1, $this->arrColor[($i % $c_max)]); |
---|
| 202 | // ¥é¥Ù¥ë¤Îɽ¼¨ |
---|
| 203 | $this->setText(FONT_SIZE, $left + FONT_SIZE + LINE_PAD, $top, $this->arrLegend[$i]); |
---|
| 204 | $top += FONT_SIZE + LINE_PAD; |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | // ¥«¥é¡¼¥é¥Ù¥ëÇطʤÎÉÁ²è |
---|
| 209 | function drawClabelBG($left, $top, $right, $bottom) { |
---|
| 210 | // ±Æ¤ÎÉÁ²è |
---|
| 211 | if($this->shade_on) { |
---|
| 212 | imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom + 2, $this->shade_color); |
---|
| 213 | } |
---|
| 214 | // ¥«¥é¡¼¥é¥Ù¥ëÇطʤÎÉÁ²è |
---|
| 215 | imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->clabelbg_color); |
---|
| 216 | imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color); |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | // ËÞÎã¤ò¥»¥Ã¥È¤¹¤ë |
---|
| 220 | function setLegend($arrLegend) { |
---|
| 221 | $this->arrLegend = array_values((array)$arrLegend); |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | ?> |
---|