home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 October / CMCD1004.ISO / Software / Shareware / Programare / cnstats / graph / 3d.php next >
Encoding:
PHP Script  |  2004-06-21  |  5.0 KB  |  181 lines

  1. <?
  2. session_start();
  3. session_register("DATA");
  4. $DATA=$HTTP_SESSION_VARS["DATA"];
  5.  
  6. include "../_funct.php";
  7.  
  8. function imagebar($im,$x,$y,$w,$h,$dx,$dy,$c1,$c2,$c3) {
  9.  
  10.     imagefilledpolygon($im,
  11.         Array(
  12.             $x, $y-$h,
  13.             $x+$w, $y-$h,
  14.             $x+$w+$dx, $y-$h-$dy,
  15.             $x+$dx, $y-$dy-$h
  16.         ), 4, $c1);
  17.  
  18.     imagefilledpolygon($im,
  19.         Array(
  20.             $x+$w, $y-$h,
  21.             $x+$w, $y,
  22.             $x+$w+$dx, $y-$dy,
  23.             $x+$w+$dx, $y-$dy-$h
  24.         ), 4, $c3);
  25.  
  26.     imagefilledrectangle($im, $x, $y-$h, $x+$w, $y, $c2);
  27.     }
  28.  
  29. $GDVERSION=gdVersion();
  30. if ($HTTP_GET_VARS["antialias"]==0) $GDVERSION=1;
  31.  
  32. // ╨ατ≡σ°σφΦσ
  33. $W=$IMGW;
  34. $H=$IMGH;
  35.  
  36. // ╧±σΓΣεπδ≤ßΦφα
  37. $DX=30;
  38. $DY=20;
  39.  
  40. // ╬≥±≥≤∩√
  41. $MB=20; // bottom
  42. $ML=8; // left
  43. $M=5; // ε±≥αδⁿφ√σ
  44.  
  45. // ╪Φ≡Φφα εΣφεπε ±Φ∞Γεδα
  46. $LW=imagefontwidth(2);
  47.  
  48. // ┼±δΦ Γσ≡±Φ  GD ßεδⁿ°σ ≈σ∞ 2.0, ≥ε Γ±σ Γ ΣΓα ≡ατα ßεδⁿ°σ (Σδ  ±πδαµΦΓαφΦ )
  49. if ($GDVERSION>=2) {
  50.     $W*=2;$H*=2;
  51.     $DX*=2;$DY*=2;
  52.     $LW*=2;$MB*=2;$M*=2;$ML*=2;
  53.     }
  54.  
  55. // ╩εδΦ≈σ±≥Γε ²δσ∞σφ≥εΓ
  56. $count=count($DATA[0]);
  57. if (count($DATA[1])>$count) $count=count($DATA[1]);
  58. if (count($DATA[2])>$count) $count=count($DATA[2]);
  59.  
  60. if ($count==0) $count=1;
  61.  
  62. // ╤πδαµΦΓασ∞ π≡α⌠ΦΩΦ ##########################################################
  63. if ($HTTP_GET_VARS["s"]==1) {
  64.     for ($i=2;$i<$count-2;$i++) {
  65.         for ($j=0;$j<$count;$j++) {
  66.             $DATA[$j][$i]=($DATA[$j][$i-1]+$DATA[$j][$i-2]+$DATA[$j][$i]+$DATA[$j][$i+1]+$DATA[$j][$i+2])/5;
  67.             }
  68.         }
  69.     }
  70.  
  71. // ╠αΩ±Φ∞αδⁿφεσ τφα≈σφΦσ
  72. $max=0;
  73. for ($i=0;$i<$count;$i++) {
  74.     $max=$max<$DATA[0][$i]?$DATA[0][$i]:$max;
  75.     $max=$max<$DATA[1][$i]?$DATA[1][$i]:$max;
  76.     $max=$max<$DATA[2][$i]?$DATA[2][$i]:$max;
  77.     }
  78.  
  79. include "shared.php";
  80.  
  81. $county=10;
  82. $max=$nmax;
  83.  
  84. // ╧εΣ≡αΓφ σ∞ δσΓ≤■ π≡αφΦ÷≤
  85. $text_width=strlen(cNumber($max))*$LW;
  86. $ML+=$text_width;
  87.  
  88. // ┬√ΓεΣ ⌠εφα π≡α⌠ΦΩα
  89. imageline($im, $ML, $M+$DY, $ML, $H-$MB, $c);
  90. imageline($im, $ML, $M+$DY, $ML+$DX, $M, $c);
  91. imageline($im, $ML, $H-$MB, $ML+$DX, $H-$MB-$DY, $c);
  92. imageline($im, $ML, $H-$MB, $W-$M-$DX, $H-$MB, $c);
  93. imageline($im, $W-$M-$DX, $H-$MB, $W-$M, $H-$MB-$DY, $c);
  94.  
  95. imagefilledrectangle($im, $ML+$DX, $M, $W-$M, $H-$MB-$DY, $bg[1]);
  96. imagerectangle($im, $ML+$DX, $M, $W-$M, $H-$MB-$DY, $c);
  97.  
  98. imagefill($im, $ML+1, $H/2, $bg[2]);
  99.  
  100. // ┬√ΓεΣ φσΦτ∞σφ σ∞εΘ ±σ≥ΩΦ
  101. for ($i=1;$i<3;$i++) {
  102.     imageline($im, $ML+$i*intval($DX/3), $M+$DY-$i*intval($DY/3), $ML+$i*intval($DX/3), $H-$MB-$i*intval($DY/3), $c);
  103.     imageline($im, $ML+$i*intval($DX/3), $H-$MB-$i*intval($DY/3), $W-$M-$DX+$i*intval($DX/3), $H-$MB-$i*intval($DY/3), $c);
  104.     }
  105.  
  106. // ╨σαδⁿφ√σ ≡ατ∞σ≡√ π≡α⌠ΦΩα
  107. $RW=$W-$ML-$M-$DX;
  108. $RH=$H-$MB-$M-$DY;
  109.  
  110. // ╩εε≡ΣΦφα≥√ φ≤δ 
  111. $X0=$ML+$DX;
  112. $Y0=$H-$MB-$DY;
  113.  
  114. // ┬√ΓεΣ Φτ∞σφ σ∞εΘ ±σ≥ΩΦ
  115. for ($i=0;$i<$count;$i++) {
  116.     imageline($im,$X0+$i*($RW/$count),$Y0,$X0+$i*($RW/$count)-$DX,$Y0+$DY,$c);
  117.     imageline($im,$X0+$i*($RW/$count),$Y0,$X0+$i*($RW/$count),$Y0-$RH,$c);
  118.     }
  119.  
  120. $step=$RH/$county;
  121. for ($i=0;$i<=$county;$i++) {
  122.     imageline($im,$X0,$Y0-$step*$i,$X0+$RW,$Y0-$step*$i,$c);
  123.     imageline($im,$X0,$Y0-$step*$i,$X0-$DX,$Y0-$step*$i+$DY,$c);
  124.     imageline($im,$X0-$DX,$Y0-$step*$i+$DY,$X0-$DX-($ML-$text_width)/4,$Y0-$step*$i+$DY,$text);
  125.     }
  126.  
  127. // ┬√ΓεΣ ßα≡εΓ
  128. for ($i=0;$i<$count;$i++) 
  129.     imagebar($im, $X0+$i*($RW/$count)+4-1*intval($DX/3), $Y0+1*intval($DY/3), intval($RW/$count)-4, $RH/$max*$DATA[0][$i], intval($DX/3)-5, intval($DY/3)-3, $bar[0][0], $bar[0][1], $bar[0][2]);
  130.  
  131. for ($i=0;$i<$count;$i++) 
  132.     imagebar($im, $X0+$i*($RW/$count)+4-2*intval($DX/3), $Y0+2*intval($DY/3), intval($RW/$count)-4, $RH/$max*$DATA[1][$i], intval($DX/3)-5, intval($DY/3)-3, $bar[1][0], $bar[1][1], $bar[1][2]);
  133.  
  134. for ($i=0;$i<$count;$i++) 
  135.     imagebar($im, $X0+$i*($RW/$count)+4-3*intval($DX/3), $Y0+3*intval($DY/3), intval($RW/$count)-4, $RH/$max*$DATA[2][$i], intval($DX/3)-5, intval($DY/3)-3, $bar[2][0], $bar[2][1], $bar[2][2]);
  136.  
  137. // ╙∞σφⁿ°σφΦσ Φ ∩σ≡σ±≈σ≥ Ωε≡≡ΣΦφα≥
  138. $ML-=$text_width;
  139. if ($GDVERSION>=2) {                                                                                        
  140.     $im1=imagecreatetruecolor($W/2,$H/2);
  141.     imagecopyresampled($im1,$im,0,0,0,0,$W/2,$H/2,$W,$H);                                                   
  142.     imagedestroy($im);
  143.     $im=$im1;                                                                                               
  144.  
  145.     $W/=2;$H/=2;
  146.     $DX/=2;$DY/=2;
  147.     $LW/=2;$MB/=2;$M/=2;$ML/=2;
  148.     $X0/=2;$Y0/=2;$step/=2;
  149.     $RW/=2;$RH/=2;
  150.     }
  151.  
  152. $text=imagecolorallocate($im,136,197,145);
  153.  
  154. // ┬√ΓεΣ ∩εΣ∩Φ±σΘ ∩ε ε±Φ Y
  155. for ($i=1;$i<=$county;$i++) {
  156.     $str=cNumber(($max/$county)*$i);
  157.     imagestring($im,2, $X0-$DX-strlen($str)*$LW-$ML/4-2,$Y0+$DY-$step*$i-imagefontheight(2)/2,$str,$text);
  158.     }
  159.  
  160. // ┬√ΓεΣ ∩εΣ∩Φ±σΘ ∩ε ε±Φ X
  161. $prev=100000;
  162. $twidth=$LW*strlen($DATA["x"][0])+6;
  163. $i=$X0+$RW-$DX;
  164.  
  165. while ($i>$X0-$DX) {
  166.     if ($prev-$twidth>$i) {
  167.         $drawx=$i+1-($RW/$count)/2;
  168.         if ($drawx>$X0-$DX) {
  169.             $str=$DATA["x"][intval(($i-$X0+$DX)/($RW/$count))-1];
  170.             imageline($im,$drawx,$Y0+$DY,$i+1-($RW/$count)/2,$Y0+$DY+5,$text);
  171.             imagestring($im,2, $drawx+1-(strlen($str)*$LW)/2 ,$Y0+$DY+7,$str,$text);
  172.             }
  173.         $prev=$i;
  174.         }
  175.     $i-=$RW/$count;
  176.     }
  177.  
  178. header("Content-Type: image/png");
  179. imagepng($im);
  180. imagedestroy($im);
  181. ?>