חבר בקהילה
מיני פרופיל
תאריך הצטרפות: Oct 2005
הודעות: 342
קלאס גראף עוגה למערכות סקרים\סטסטיקות
סיימתי את זה לפני כמה שעות
הקוד:
PHP קוד:
<?
#class by Yonatan Rab - yonatan.rab@gmail.com - 72329528
#all rights reseved
class graph
{
var $Graph ;
var $Image ;
var $Angels ;
var $SliceCount ;
var $Slice ;
var $Colors ;
function graph ( $width , $height )
{
$this -> Graph [ "title" ]= $title ;
$this -> Graph [ "width" ]= $width ;
$this -> Graph [ "height" ]= $height ;
header ( "Content-type: image/png" );
$this -> Image = @ imagecreate ( $width , $height ) or die( "Cannot Initialize new GD image" );
}
function makeTitle ( $title , $font ) {
$width = imagefontwidth ( $font );
$height = imagefontheight ( $font );
imagefilledpolygon ( $this -> Image ,
array (
65 , 6 ,
65 , ( 6 + $height ),
( 65 +( $width * strlen ( $title ))+ 4 ), ( 6 + $height ),
( 65 +( $width * strlen ( $title ))+ 4 ), 6
),
4 ,
$this -> Colors [ "white" ]);
imagepolygon ( $this -> Image ,
array (
65 , 6 ,
65 , ( 6 + $height ),
( 65 +( $width * strlen ( $title ))+ 4 ), ( 6 + $height ),
( 65 +( $width * strlen ( $title ))+ 4 ), 6
),
4 ,
$this -> Colors [ "black" ]);
imagestring ( $this -> Image , $font , 68 , 6 , $title , $this -> Colors [ "black" ]);
}
function addVote ( $num , $vote , $r , $g , $b )
{
$this -> Angels [ $num ]= $vote ;
$this -> Colors [ $num ]= imagecolorallocate ( $this -> Image , $r , $g , $b );
}
function graphBG ( $r , $g , $b )
{
$this -> Colors [ 0 ]= imagecolorallocate ( $this -> Image , $r , $g , $b );
$this -> Colors [ "black" ] = imagecolorallocate ( $this -> Image , 0 , 0 , 0 );
$this -> Colors [ "white" ] = imagecolorallocate ( $this -> Image , 255 , 255 , 255 );
}
function makeAngels ()
{
$this -> SliceCount = count ( $this -> Angels );
$ar_num_count = 0 ;
for ( $i = 1 ; $i <= $this -> SliceCount ; $i ++) {
$ar_num_count = $ar_num_count + $this -> Angels [ $i ];
}
$this -> Slice = 360 / $ar_num_count ;
$count = 0 ;
}
function makeDeatils ()
{
$x = 10 ;
$y = 10 ;
$z = 0 ;
for ( $i = 1 ; $i <= $this -> SliceCount ; $i ++) {
$ar_num_count = $ar_num_count + $this -> Angels [ $i ];
}
//÷åôñà âãåìä
imagefilledpolygon ( $this -> Image ,
array (
6 , 6 ,
5 , ( 9 +( 15 * $this -> SliceCount )),
61 , ( 9 +( 15 * $this -> SliceCount )),
61 , 6
),
4 ,
$this -> Colors [ "white" ]);
imagepolygon ( $this -> Image ,
array (
6 , 6 ,
6 , ( 9 +( 15 * $this -> SliceCount )),
61 , ( 9 +( 15 * $this -> SliceCount )),
61 , 6
),
4 ,
$this -> Colors [ "black" ]);
//÷åôñàåú ÷èðåú
for ( $i = 1 ; $i <= $this -> SliceCount ; $i ++)
{
imagefilledpolygon ( $this -> Image ,
array (
$x , $y + $z ,
$x , ( $y + 10 + $z ),
( $x + 10 ), ( $y + 10 + $z ),
( $x + 10 ), $y + $z
),
4 ,
$this -> Colors [ $i ]);
imagepolygon ( $this -> Image ,
array (
$x , $y + $z ,
$x , ( $y + 10 + $z ),
( $x + 10 ), ( $y + 10 + $z ),
( $x + 10 ), $y + $z
),
4 ,
$this -> Colors [ "black" ]);
$num = $this -> Angels [ $i ]* 100 / $ar_num_count ;
imagestring ( $this -> Image , 2 , ( $x + 14 ), ( $y + $z - 1 ), round ( $num , 2 ). "%" , $this -> Colors [ "black" ]);
$y += 10 ;
$z += 5 ;
}
}
function drawAngels ()
{
$c = 0 ;
for ( $i = 1 ; $i <= $this -> SliceCount ; $i ++) {
$x = $this -> Slice * $this -> Angels [ $i ]+ $c ;
imagefilledarc ( $this -> Image , $this -> Graph [ "width" ]/ 2 , $this -> Graph [ "height" ]/ 2 , $this -> Graph [ "width" ]* 0.8 , $this -> Graph [ "height" ]* 0.8 , $c , $x , $this -> Colors [ $i ], IMG_ARC_PIE );
$c = $x ;
}
imageellipse ( $this -> Image , $this -> Graph [ "width" ]/ 2 , $this -> Graph [ "height" ]/ 2 , $this -> Graph [ "width" ]* 0.8 , $this -> Graph [ "height" ]* 0.8 , $this -> Colors [ "black" ]);
}
function finish ()
{
imagepng ( $this -> Image );
imagedestroy ( $this -> Image );
}
}
$bla =new graph ( 400 , 400 );
$bla -> graphBG ( 255 , 255 , 200 );
$bla -> makeTitle ( "What do you say about the site?" , 2 );
$bla -> addVote ( 1 , 23 , 255 , 0 , 0 );
$bla -> addVote ( 2 , 24 , 0 , 0 , 255 );
$bla -> addVote ( 3 , 25 , 0 , 255 , 0 );
$bla -> addVote ( 4 , 26 , 255 , 0 , 255 );
$bla -> addVote ( 5 , 155 , 150 , 150 , 150 );
$bla -> makeAngels ();
$bla -> drawAngels ();
$bla -> makeDeatils ();
$bla -> finish ();
?>
אם מישהו רוצה לראות את זה
www.yonatan.co.il/graph.php
קצת הסברים
PHP קוד:
<?
$bla =new graph ( 400 , 400 );
//יוצר גראף חדש בגודל 400 על 400
$bla -> graphBG ( 255 , 255 , 200 );
//קובע את צבע הרקע של הגראף
$bla -> makeTitle ( "What do you say about the site?" , 2 );
//כותרת לגראף - לא חובה
$bla -> addVote ( 1 , 23 , 255 , 0 , 0 );
//מוסיף הצבעה חדשה
//1=מספר התוצאה
//23=מספר התשובות
//255, 0, 0= צבע
$bla -> addVote ( 2 , 24 , 0 , 0 , 255 );
$bla -> addVote ( 3 , 25 , 0 , 255 , 0 );
$bla -> addVote ( 4 , 26 , 255 , 0 , 255 );
$bla -> addVote ( 5 , 155 , 150 , 150 , 150 );
$bla -> makeAngels ();
//מחשב זוויות וכ'ו...
$bla -> drawAngels ();
//מצייר את הגראף
$bla -> makeDeatils ();
//יוצר את הריבוע הקטן עם הפרטים - לא חובה
$bla -> finish ();
//מסיים את הגראף
?>
אשמח לשמוע ביקורות, איך הייתי יכול לשפר מה לא טוב וכ'ו...