source: temp/trunk/html/admin/total/class/SC_GraphPie.php @ 1328

Revision 1328, 5.2 KB checked in by naka, 20 years ago (diff)

* empty log message *

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