예제 #1
0
 /**
  * Genera un gráfico con todas las combinaciones de gráficas entre todas las "x" y la "y", ej: f(x1,x2) = y
  * generará un gráfico con 6 gráficas (x1,y), (x1,x2), (x2,y), (x2,x1), (y,x1), (y,x2).
  * f(x1,x2,x3) = y generará 12 gráficas.
  * Las gráficas maximizaran el espacio de dibujo disponible, mostrarán la línea de tendencia, y la fórmula con ß0
  * ß1 y R2
  *
  * @param string $filename
  * @return string
  */
 public function generateDraw($filename = null)
 {
     $boxes = $this->independentVars->getNumRows() + $this->dependentVars->getNumRows();
     $drawSize = ($this->drawBoxSize + 1) * $boxes - 2;
     $image = imagecreatetruecolor($drawSize, $drawSize);
     $color = imagecolorallocate($image, 255, 255, 255);
     imagefilledrectangle($image, 0, 0, $drawSize, $drawSize, $color);
     $color = imagecolorallocate($image, 255, 0, 0);
     for ($a = 1; $a < $boxes; $a++) {
         $pos = ($this->drawBoxSize + 1) * $a - 1;
         imageline($image, 0, $pos, $drawSize, $pos, $color);
         imageline($image, $pos, 0, $pos, $drawSize, $color);
     }
     for ($a = 0; $a < $boxes; $a++) {
         if ($a == 0) {
             $text = isset($this->dependentTitle[0]) ? $this->dependentTitle[0] : 'Y';
         } else {
             $text = isset($this->independentTitles[$a - 1]) ? $this->independentTitles[$a - 1] : 'X' . $a;
         }
         $pos = $this->drawBoxSize * $a;
         $this->imageTextCentered($image, $color, 45, $this->fontSize, $this->fontName, $pos, $pos, $pos + $this->drawBoxSize, $pos + $this->drawBoxSize, $text);
     }
     $colorPoint = imagecolorallocate($image, 0, 0, 255);
     $colorLine = imagecolorallocate($image, 0, 255, 0);
     $colorFormula = imagecolorallocate($image, 64, 64, 64);
     for ($a = 0; $a < $boxes; $a++) {
         for ($b = 0; $b < $boxes; $b++) {
             if ($a == $b) {
                 continue;
             }
             if ($a == 0) {
                 $x = $this->dependentVars->getRow(1);
             } else {
                 $x = $this->independentVars->getRow($a);
             }
             if ($b == 0) {
                 $y = $this->dependentVars->getRow(1);
             } else {
                 $y = $this->independentVars->getRow($b);
             }
             $this->drawDotPlot($image, $colorPoint, $colorLine, $colorFormula, ($this->drawBoxSize + 1) * $a, ($this->drawBoxSize + 1) * $b, ($this->drawBoxSize + 1) * ($a + 1) - 2, ($this->drawBoxSize + 1) * ($b + 1) - 2, $x, $y);
         }
     }
     if (is_null($filename)) {
         $filename = 'test.png';
     }
     imagepng($image, $filename);
     return $filename;
 }