Ver Mensaje Individual
  #9 (permalink)  
Antiguo 21/10/2005, 07:24
willyneverdie
 
Fecha de Ingreso: octubre-2005
Mensajes: 6
Antigüedad: 18 años, 6 meses
Puntos: 0
continuacion del codigo de arriba


// Método drawGrid – dibuja la cuadrícula sobre la imagen
//su parámetro puede ser la distancia entre las líneas consecutivas
function drawGrid($size = 20) {
$y = $size*round($this->_y_min/$size) - $size;
while($y < ($this->_y_max + $size)) {
//calculamos los valores consecutivos de y
$y0 = $this->translateCoordY($y);
//dibujamos las líneas horizontales
imageline($this->image, 0, $y0, $this->width, $y0,$this->translateColor($this->grid_color));
$y += $size;}}
// Método setValue – dibuja un rectángulo con base en los parámetros recibidos
// los parámetros son los valores x y y
function setValue($x, $y) {
//definimos todas las coordenadas del rectángulo de ancho de bar_w
$p = Array(($x-$this->bar_w/2), $y,($x+$this->bar_w/2), $y,($x+$this->bar_w/2), 0,($x-$this ->bar_w/2), 0);
//Las convertimos a coordenadas de la imagen
$r = $this->translatePoly($p);
//dibujamos el rectángulo
imagefilledpolygon($this->image, $r, sizeof($r)/2,$this->translateColor($this->bar_color));}
// Método calcRange – define el espacio para la gráfica
// su parámetro es la tabla de valores
function calcRange($series) {
//comenzamos en el inicio de las coordenadas polares
$this->_x_min = 0; $this->_y_min = 0;
$this->_x_max = 1; $this->_y_max = 1;
foreach($series as $x=>$y) {
//cambiamos el rango dependiendo del valor
if($x >= $this->_x_max) $this->_x_max = $x;
if($x < $this->_x_min) $this->_x_min = $x;
if($y >= $this->_y_max) $this->_y_max = $y;
if($y < $this->_y_min) $this->_y_min = $y;}
//definimos el ancho y la altura del diagrama
$this->_range_w = $this->_x_max-$this->_x_min;
$this->_range_h = $this->_y_max-$this->_y_min;}

// Método translatePoly – proyecta los puntos del espacio del diagrama
// al area de la imagen su parámetro es la tabla con los puntos x, y
// consecutivos
function translatePoly($p) {
$r = Array();
for($i=0; $i<sizeof($p); $i+=2) {
//convertimos los puntos consecutivamente
$r[] = $this->translateCoordX($p[$i]);
$r[] = $this->translateCoordY($p[$i+1]);}
return $r;}
// Métodos translateCoordX y translateCoordY – transforman las coordenadas
// del diagrama su parámetro es el valor x y y correspondientemente
// el método devuelve el valor de la coordenada para el área de la imagen
function translateCoordX($x) {
return round($this->margin_x+($this->width-2*$this->margin_x)*
($x-$this->_x_min)/$this->_range_w);}
function translateCoordY($y) {
return round($this->margin_y-($this->height-2*$this->margin_y)*
($y-$this->_y_max)/$this->_range_h);}
// Método translateColor – permite obtener el identificador del color
// su parámetro es la tabla de colores RGB
// el método devuelve el identificador del color
function translateColor($rgb = Array(255, 255, 255)) {
return imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]);}}
?>