source: branches/dev/html/admin/total/class/SC_GraphPie.php @ 8

Revision 8, 5.3 KB checked in by root, 17 years ago (diff)

new import

Line 
1<?php
2/*
3 * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7$SC_GRAPHPIE_DIR = realpath(dirname( __FILE__));
8require_once($SC_GRAPHPIE_DIR . "/SC_GraphBase.php");   
9
10// ±ß¥°¥é¥ÕÀ¸À®¥¯¥é¥¹
11class SC_GraphPie extends SC_GraphBase{
12    var $cw;
13    var $ch;
14    var $cz;
15    var $cx;
16    var $cy;
17    var $arrLabel;
18    var $arrData;
19   
20    // ¥³¥ó¥¹¥È¥é¥¯¥¿
21    function SC_GraphPie($bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = PIE_LEFT, $top = PIE_TOP) {
22        parent::SC_GraphBase($bgw, $bgh, $left, $top);
23        // ¥µ¥¤¥ºÀßÄê
24        $this->setSize(PIE_WIDTH, PIE_HEIGHT, PIE_THICK);
25        // °ÌÃÖÀßÄê
26        $this->setPosition($this->left + ($this->cw / 2), $this->top + ($this->ch / 2));
27    }
28   
29    // ¥Ç¡¼¥¿¤ò360¡ëÃͤËÊÑ´¹¤¹¤ë
30    function getCircleData($array) {
31        if(!is_array($array)) {
32            return;
33        }
34        $arrRet = array();
35        foreach($array as $val) {
36            $total += $val;         
37        }
38        if($total <= 0) {
39            return;
40        }       
41        $rate = 360 / $total;
42        // ¥é¥Ù¥ëɽ¼¨ÍÑ
43        $p_rate = 100 / $total;
44        $cnt = 0;
45        foreach($array as $val) {
46            $ret = round($val * $rate);
47            $new_total+= $ret;
48            $arrRet[] = $ret;
49            // ¥Ñ¡¼¥»¥ó¥Èɽ¼¨ÍÑ
50            $this->arrLabel[] = round($val * $p_rate) . " %";
51            $cnt++;
52        }
53        // ¹ç·×¤¬360¤Ë¤Ê¤ë¤è¤¦¤ËÊäÀµ¤·¤Æ¤ª¤¯
54        $arrRet[0] -= $new_total - 360;
55        return $arrRet;
56    }   
57       
58    // ±ß¤Î°ÌÃÖÀßÄê¤ò¹Ô¤¦
59    function setPosition($cx, $cy) {
60        $this->cx = $cx;
61        $this->cy = $cy;
62    }
63       
64    // ±ß¤Î¥µ¥¤¥ºÀßÄê¤ò¹Ô¤¦
65    function setSize($cw, $ch, $cz = 0) {
66        $this->cw = $cw;
67        $this->ch = $ch;
68        $this->cz = $cz;
69    }
70   
71    // ±Æ¤ÎÉÁ²è
72    function drawShade() {
73        $move = 1;
74        for($i = ($this->cy + $this->cz); $i <= ($this->cy + $this->cz + ($this->cz * PIE_SHADE_IMPACT)); $i++) {
75            imagefilledarc($this->image, $this->cx + $move, $i, $this->cw, $this->ch, 0, 360, $this->shade_color, IMG_ARC_PIE);
76            $move += 0.5;
77        }
78    }
79   
80    // ¥Ç¡¼¥¿¤ò¥»¥Ã¥È¤¹¤ë
81    function setData($arrData) {
82        $this->arrData = array_values($arrData);
83    }
84   
85    // ±ß¥°¥é¥Õ¤òÉÁ²è¤¹¤ë
86    function drawGraph() {
87        $x = $this->cx;
88        $y = $this->cy;
89        $z = $this->cz;
90        $h = $this->ch;
91        $w = $this->cw;
92       
93        // ¥Ç¡¼¥¿¤Î³ÑÅÙ¤ò¼èÆÀ¤¹¤ë
94        $arrRad = $this->getCircleData($this->arrData);
95        $rd_max = count($arrRad);
96       
97        // ¥Ç¡¼¥¿¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç
98        if($rd_max <= 0) {
99            return;
100        }
101       
102        // ±Æ¤ÎÉÁ²è
103        if($this->shade_on) {
104            $this->drawShade();
105        }
106           
107        // ¿§¿ô¤Î¼èÆÀ
108        $c_max = count($this->arrColor);
109        $dc_max = count($this->arrDarkColor);
110       
111        // ¦Ì̤ÎÉÁ²è       
112        for ($i = ($y + $z - 1); $i >= $y; $i--) {
113            $start = 0;
114            for($j = 0; $j < $rd_max; $j++) {
115                // ³ÑÅÙ¤¬0Åٰʾå¤Î¾ì¹ç¤Î¤ß¦Ì̤òÉÁ²è¤¹¤ë¡£
116                if($arrRad[$j] > 0) {
117                    $end = $start + $arrRad[$j];
118                    if($start == 0 && $end == 360) {
119                        // -90¢·270¤Ç»ØÄꤹ¤ë¤È±ß¤¬ÉÁ²è¤Ç¤­¤Ê¤¤¤Î¤Ç0¢·360¤Ë»ØÄê
120                        imagearc($this->image, $x, $i, $w, $h, 0, 360, $this->arrDarkColor[($j % $dc_max)]);
121                    } else {
122                        // -90¡ë¤Ï12»þ¤Î°ÌÃÖ¤«¤é³«»Ï¤¹¤ë¤è¤¦¤ËÊäÀµ¤·¤Æ¤¤¤ë
123                        imagearc($this->image, $x, $i, $w, $h, $start - 90, $end - 90, $this->arrDarkColor[($j % $dc_max)]);   
124                    }           
125                    $start = $end;
126                }
127            }
128        }
129        // ÄìÌ̤ÎÉÁ²è
130        imagearc($this->image, $x, $y + $z, $w, $h, 0, 180 , $this->flame_color);
131
132        // ¾åÌ̤ÎÉÁ²è
133        $start = 0;
134        for($i = 0; $i < $rd_max; $i++) {
135            $end = $start + $arrRad[$i];
136            if($start == 0 && $end == 360) {
137                // -90¢·270¤Ç»ØÄꤹ¤ë¤È±ß¤¬ÉÁ²è¤Ç¤­¤Ê¤¤¤Î¤Ç0¢·360¤Ë»ØÄê
138                imagefilledarc($this->image, $x, $y, $w, $h, 0, 360, $this->arrColor[($i % $c_max)], IMG_ARC_PIE);         
139            } else {
140                // -90¡ë¤Ï12»þ¤Î°ÌÃÖ¤«¤é³«»Ï¤¹¤ë¤è¤¦¤ËÊäÀµ¤·¤Æ¤¤¤ë¡£       
141                imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->arrColor[($i % $c_max)], IMG_ARC_PIE);
142            }
143            $start = $end;
144        }
145
146        // ¾åÌ̤αï¼è¤ê
147        $start = 0;
148        for($i = 0; $i < $rd_max; $i++) {
149            $end = $start + $arrRad[$i];
150            if($start == 0 && $end == 360) {
151                // -90¢·270¤Ç»ØÄꤹ¤ë¤È±ß¤¬ÉÁ²è¤Ç¤­¤Ê¤¤¤Î¤Ç0¢·360¤Ë»ØÄê
152                imagearc($this->image, $x, $y, $w, $h, 0, 360 , $this->flame_color);
153            }
154            // -90¡ë¤Ï12»þ¤Î°ÌÃÖ¤«¤é³«»Ï¤¹¤ë¤è¤¦¤ËÊäÀµ¤·¤Æ¤¤¤ë¡£
155            imagefilledarc($this->image, $x, $y, $w, $h, $start - 90, $end - 90, $this->flame_color, IMG_ARC_EDGED|IMG_ARC_NOFILL);
156            $start = $end;
157        }
158
159        // ¦Ì̤αï¼è¤ê
160        imageline($this->image, $x + ($w / 2), $y, $x + ($w / 2), $y + $z, $this->flame_color);
161        imageline($this->image, $x - ($w / 2), $y, $x - ($w / 2), $y + $z, $this->flame_color);
162        $start = 0;
163        for($i = 0; $i < $rd_max; $i++) {
164            $end = $start + $arrRad[$i];
165            // Á°Ì̤Τß
166            if($end > 90 && $end < 270) {
167                list($ax, $ay) = lfGetArcPos($x, $y, $w, $h, $end);
168                // ¥é¥¤¥ó¤Î¤º¤ì¤òÊäÀµ¤¹¤ë
169                if($end > 180) {
170                    $ax = $ax + 1;
171                }
172                imageline($this->image, $ax, $ay, $ax, $ay + $z, $this->flame_color);
173            }
174            $start = $end; 
175        }
176               
177        // ¥é¥Ù¥ë¤ÎÉÁ²è
178        $this->drawLabel($arrRad);
179        // ËÞÎã¤ÎÉÁ²è
180        $this->drawLegend(count($this->arrData));           
181    }
182   
183    // ±ß¥°¥é¥Õ¤Î¥é¥Ù¥ë¤òÉÁ²è¤¹¤ë
184    function drawLabel($arrRad) {
185        $rd_max = count($arrRad);
186        $start = 0;
187        for($i = 0; $i < $rd_max; $i++) {
188            $center = $start + ($arrRad[$i] / 2);
189            $end = $start + $arrRad[$i];
190            list($sx, $sy) = lfGetArcPos($this->cx, $this->cy, ($this->cw / 1.5), ($this->ch / 1.5), $center);
191            list($ex, $ey) = lfGetArcPos($this->cx, $this->cy, ($this->cw * 1.5), ($this->ch * 1.5), $center);
192            // »Ø¼¨Àþ¤ÎÉÁ²è
193            imageline($this->image, $sx, $sy, $ex + 2, $ey - PIE_LABEL_UP, $this->flame_color);
194            $this->setText(FONT_SIZE, $ex - 10, $ey - PIE_LABEL_UP - FONT_SIZE, $this->arrLabel[$i], NULL, 0, true);
195            $start = $end;
196        }
197    }   
198}
199
200?>
Note: See TracBrowser for help on using the repository browser.