Exemplo n.º 1
0
 function setLegend($legend, $align = NULL)
 {
     if (!isset($this->legend)) {
         $this->legend = array();
     }
     $this->legend = array_merge($this->legend, $legend);
     $spch = $this->font_legend * 4;
     #spazio per i caratteri della legenda
     for ($i = 0; $i < count($this->legend); $i++) {
         if (strlen($this->legend[$i]) > $this->LegStrLen) {
             $this->legend[$i] = substr($this->legend[$i], 0, $this->LegStrLen) . "...";
         }
         $tmpsp = graidle::stringlen($this->legend[$i]) * $this->font_legend;
         if ($spch < $tmpsp) {
             $spch = $tmpsp;
         }
     }
     if (isset($this->w)) {
         $this->nrow = ceil(($spch + $this->dim_quad + $this->spacing) * count($this->legend) / ($this->w - $this->s - $this->d));
     } else {
         $this->nrow = count($this->legend);
     }
     $this->spacerow = ceil($this->nrow * ($this->dim_quad + $this->spacing));
     $this->spch = $spch;
     $this->LegendAlign = strtolower($align);
     switch ($this->LegendAlign) {
         case "left":
             $this->s += $this->spacing + $this->dim_quad + $this->spch;
             break;
         case "top":
             $this->a += $this->spacerow;
             break;
         case "bottom":
             $this->b += $this->nrow * ($this->dim_quad + $this->spacing);
             break;
             break;
         default:
             $this->LegendAlign = "right";
             $this->d += $this->spacing + $this->dim_quad + $this->spch;
             break;
     }
 }
Exemplo n.º 2
0
 function drawHorizHisto()
 {
     for ($m = $t = 0; $t < count($this->value); $t++) {
         if ($this->type[$t] == 'hb') {
             if (isset($this->ExtLeg) && ($this->ExtLeg == 2 || $this->ExtLeg == 1)) {
                 for ($sum = $s = 0; $s < count($this->value[$t]); $s++) {
                     $sum += abs($this->value[$t][$s]);
                 }
             }
             $cc = $this->color[$t];
             list($name, $red, $green, $blue) = explode(',', $cc);
             $cc = imagecolorallocatealpha($this->im, $red, $green, $blue, 25);
             $cb = imagecolorallocatealpha($this->im, round($red / 2), round($green / 2), round($blue / 2), 50);
             $strExtVal = NULL;
             for ($y = $this->a + $this->larg / 2, $valuelen = 2, $i = 0; $i < count($this->value[$t]); $i++, $y += $this->ld, $valuelen = 2) {
                 $y2 = $y + $this->larg * $m;
                 $y1 = $y2 + $this->larg;
                 $x2 = $this->s + abs($this->mnvs * $this->mul);
                 $x1 = $x2 + $this->value[$t][$i] * $this->mul;
                 if (isset($this->ExtLeg)) {
                     switch ($this->ExtLeg) {
                         case 0:
                             $strExtVal = $this->value[$t][$i];
                             break;
                         case 1:
                             $strExtVal = round($this->value[$t][$i] / $sum * 100, 1) . "% ";
                             break;
                         case 2:
                             $strExtVal = $this->value[$t][$i] . " (" . round($this->value[$t][$i] / $sum * 100, 1) . "%)";
                             break;
                     }
                 }
                 if ($this->mnvs <= 0) {
                     if ($this->value[$t][$i] > 0) {
                         imagefilledrectangle($this->im, $x1, $y1, $x2, $y2, $cc);
                         $valuelen = -(graidle::stringlen($strExtVal) * $this->font_small);
                     } else {
                         imagefilledrectangle($this->im, $x1, $y2, $x2, $y1, $cc);
                     }
                     imagerectangle($this->im, $x1, $y1, $x2, $y2, $cb);
                     if (isset($this->ExtLeg)) {
                         if (abs($valuelen) < $x1 - $x2) {
                             imagettftext($this->im, $this->font_small, 0, $x1 + $valuelen, $y2 + $this->larg / 2 + $this->font_small / 2, $cb, $this->font, $strExtVal);
                         } else {
                             imagettftext($this->im, $this->font_small, 0, $x1 + $this->font_small / 2, $y2 + $this->larg / 2 + $this->font_small / 2, $cb, $this->font, $strExtVal);
                         }
                     }
                 } else {
                     if ($this->value[$t][$i] > $this->mnvs) {
                         $x1 = $this->s;
                         $x2 = $this->value[$t][$i] * $this->mul;
                         $valuelen = -(graidle::stringlen($strExtVal) * $this->font_small);
                         imagefilledrectangle($this->im, $x1, $y2, $x2, $y1, $cc);
                         imagerectangle($this->im, $x1, $y2, $x2, $y1, $cb);
                         if (isset($this->ExtLeg)) {
                             imagettftext($this->im, $this->font_small, 0, $x2 + $valuelen, $y2 + $this->larg / 2 + $this->font_small / 2, $cb, $this->font, $strExtVal);
                         }
                     }
                 }
                 if (isset($this->multicolor) && $this->multicolor == 1) {
                     $cc = next($this->color);
                     list($name, $red, $green, $blue) = explode(',', $cc);
                     $cc = imagecolorallocatealpha($this->im, $red, $green, $blue, 25);
                     $cb = imagecolorallocatealpha($this->im, round($red / 2), round($green / 2), round($blue / 2), 50);
                 }
             }
         }
         $m++;
     }
 }