Ejemplo n.º 1
0
 /**
  * @return Text
  */
 private function addTextToGraph($msg, $padding_left, $padding_top, $font_weight, $font_size, $img_width)
 {
     $text = new Text($msg, $padding_left, $padding_top);
     $text->SetFont($this->getFont(), $font_weight, $font_size);
     $text->SetColor($this->getMainColor());
     //word wrap
     $width = $text->GetWidth($this->jpgraph_instance->img) - $padding_left;
     $text->SetWordWrap(floor(strlen($msg) * ($this->img_width - 3 * $padding_left) / $width));
     $text->Stroke($this->jpgraph_instance->img);
     return $text;
 }
Ejemplo n.º 2
0
 function Create()
 {
     if ($this->ready) {
         return;
     }
     $this->graph = new CanvasGraph($this->width, $this->height, 'auto');
     $this->graph->SetMargin(5, 11, 6, 11);
     /*
         $this->graph->SetShadow();
         $this->graph->SetMarginColor( "teal");
         $this->graph->InitFrame(); 
     */
     $hpos = 15;
     $text = new Text("ADEI", $this->width / 2, $hpos);
     $text->SetFont(FF_ARIAL, FS_BOLD, 24);
     $text->Align('center', 'top');
     $text->Stroke($this->graph->img);
     $hpos += $text->GetTextHeight($this->graph->img) + 10;
     //    $msg = "Welcome to the Advanced Data Extraction Infrastructure! Please";
     $msg = preg_replace(array("/\n([^\n])/"), array(' \\1'), file_get_contents("docs/welcome.txt"));
     $text_width = $this->width - 50;
     if ($text_width < 100) {
         return;
     }
     $text = new Text($msg, $this->width / 2, $hpos);
     $text->SetFont(FF_ARIAL, FS_NORMAL, 18);
     $text->Align('center', 'top');
     $width = $text->GetWidth($this->graph->img);
     if ($width > $text_width) {
         $char_width = ceil($width / strlen($msg));
         $cpl = $text_width / $char_width;
         $wmsg = wordwrap($msg, $cpl, "\n", true);
         $text->Set($wmsg);
         $width = $text->GetWidth($this->graph->img);
         while ($width > $text_width && $cpl > 10) {
             $cpl -= $cpl / 10;
             $wmsg = wordwrap($msg, $cpl, "\n", true);
             $text->Set($wmsg);
             $width = $text->GetWidth($this->graph->img);
         }
     }
     $text->Stroke($this->graph->img);
     //    $text->ParagraphAlign('center');
     //    $text->SetBox( "white", "black","gray");
     /*
     //    $text->Align('left', 'top');
     //    $text->ParagraphAlign('left'); 
     //    $text->SetBox( "white", "black","gray"); 
         $width = $text->GetWidth($this->graph->img);
     */
     //    $text->Stroke( $this->graph->img);
 }
Ejemplo n.º 3
0
 function CreateMessage($header, $msg)
 {
     $this->graph = new CanvasGraph($this->width, $this->height, 'auto');
     $this->graph->SetMargin(5, 11, 6, 11);
     $this->graph->SetShadow();
     $this->graph->SetMarginColor("teal");
     $this->graph->InitFrame();
     $text_width = $this->width - 50;
     if ($text_width < 100) {
         return;
     }
     $text = new Text($msg, 25, 25);
     $text->SetFont(FF_ARIAL, FS_NORMAL, 24);
     //    $text->Align('left', 'top');
     //    $text->ParagraphAlign('left');
     //    $text->SetBox( "white", "black","gray");
     $width = $text->GetWidth($this->graph->img);
     if ($width > $text_width) {
         $char_width = ceil($width / strlen($msg));
         $cpl = $text_width / $char_width;
         /*
         	Does not taken into the account by GetWidth function
         	$text->SetWordWrap($cpl);
         */
         $wmsg = wordwrap($msg, $cpl, "\n", true);
         $text->Set($wmsg);
         $width = $text->GetWidth($this->graph->img);
         while ($width > $text_width && $cpl > 10) {
             $cpl -= $cpl / 10;
             $wmsg = wordwrap($msg, $cpl, "\n", true);
             $text->Set($wmsg);
             $width = $text->GetWidth($this->graph->img);
         }
     }
     $text->Stroke($this->graph->img);
 }
Ejemplo n.º 4
0
 function Stroke($aData, $aFile = '', $aOnlyDebug = false)
 {
     $topmargin = 10;
     $bottommargin = 10;
     $textmargin = 5;
     $txtmargin = 4;
     $this->iHeight *= $this->iModuleWidth;
     $spec = $this->iEncoder->Enc($aData);
     if ($aOnlyDebug) {
         return $spec->toString();
     }
     $this->AdjustSpec($spec);
     $data = '';
     if (is_array($aData)) {
         $n = count($aData);
         for ($i = 0; $i < $n; ++$i) {
             $data .= $aData[$i][1];
         }
     } elseif (is_string($aData)) {
         $data = $aData;
     }
     if (!$this->iFontSpecified) {
         if ($this->iModuleWidth > 1) {
             $this->iFontFam = FF_ARIAL;
             $this->iFontStyle = FS_BOLD;
             $this->iFontSize = 10;
         } else {
             $this->iFontFam = FF_ARIAL;
             $this->iFontStyle = FS_NORMAL;
             $this->iFontSize = 7;
         }
     }
     $s = '';
     $g = new CanvasGraph(0, 0);
     // Dummy graph context
     $g->img->SetImgFormat($this->iImgFormat);
     $w = round($spec->iModuleWidth);
     // Calculate total width
     $totwidth = $spec->iLeftMargin * $w;
     $n = count($spec->iBar[0]);
     for ($i = 0; $i < $n; ++$i) {
         $b = $spec->iBar[0][$i];
         $bn = strlen($b[3]);
         for ($j = 0; $j < $bn; ++$j) {
             $wb = substr($b[3], $j, 1) * $w;
             $totwidth += $wb;
         }
     }
     $totwidth += $spec->iRightMargin * $w;
     // Calculate total height
     $height = $this->iHeight * count($spec->iBar) + $topmargin + $bottommargin;
     $g->img->SetFont($this->iFontFam, $this->iFontStyle, $this->iFontSize);
     $th = $g->img->GetTextHeight($data) + $txtmargin;
     if ($spec->iStrokeDataBelow) {
         $height += $th;
     }
     $width = $totwidth;
     $g->img->SetFont(FF_FONT2);
     $tw = 2 * $textmargin + $g->img->GetTextWidth($s);
     if ($width < $tw) {
         $width = $tw;
     }
     $g = new CanvasGraph($width, $height);
     $g->img->SetImgFormat($this->iImgFormat);
     $g->SetMarginColor($this->iBkgColor);
     $g->SetColor($this->iBkgColor);
     if ($this->iShowFrame) {
         $g->InitFrame();
     } else {
         $g->frame_weight = 0;
         $g->InitFrame();
     }
     $g->img->SetLineWeight(1);
     $g->img->SetColor('black');
     $x = $w * $spec->iLeftMargin;
     $ystart = $topmargin;
     $inunder = false;
     $under_s = '';
     $startx = $x;
     for ($r = 0; $r < count($spec->iBar); ++$r) {
         $yend = $ystart + $this->iHeight - 1;
         $x = $startx;
         for ($i = 0; $i < $n; ++$i) {
             $b = $spec->iBar[$r][$i];
             $bn = strlen($b[3]);
             for ($j = 0; $j < $bn; ++$j) {
                 $wb = substr($b[3], $j, 1) * $w;
                 if (!($j % 2)) {
                     $g->img->SetColor($this->iColor);
                     $g->img->FilledRectangle($x, $ystart, $x + $wb - 1, $yend);
                 }
                 $x += $wb;
             }
         }
         $ystart += $this->iHeight;
     }
     // row
     $g->img->SetColor($this->iColor);
     if ($spec->iStrokeDataBelow) {
         // Center data underneath
         $y = $yend + $txtmargin;
         $bw = $totwidth - $spec->iLeftMargin * $w - $spec->iRightMargin * $w;
         $x = $spec->iLeftMargin * $w + floor($bw / 2);
         $g->img->SetTextAlign('center', 'top');
         $g->img->SetFont($this->iFontFam, $this->iFontStyle, $this->iFontSize);
         $g->img->StrokeText($x, $y, $data);
     }
     if (ADD_DEMOTXT) {
         $ystart = 0;
         $t = new Text(" DEMO ", $totwidth / 2, $ystart);
         if ($this->iModuleWidth > 1) {
             if ($this->iModuleWidth > 2) {
                 $t->SetFont(FF_ARIAL, FS_BOLD, 24);
                 $step = 120;
             } else {
                 $t->SetFont(FF_ARIAL, FS_BOLD, 16);
                 $step = 100;
             }
         } else {
             $t->SetFont(FF_ARIAL, FS_BOLD, 12);
             $step = 80;
         }
         $t->SetColor('red@0.5');
         $t->Align('center', 'top');
         $t->SetAngle(-15);
         $n = ceil($totwidth / $step);
         for ($y = $ystart; $y < $yend; $y += 50) {
             for ($i = 0; $i < $n; ++$i) {
                 $t->SetPos(-30 + $i * $step, $y);
                 $t->Stroke($g->img);
             }
         }
     }
     if ($this->iVertical) {
         $g->img->img = $this->Rotate($g->img->img, 90);
     }
     if ($this->iScale != 1) {
         $nwidth = round($width * $this->iScale);
         $nheight = round($height * $this->iScale);
         if ($this->iVertical) {
             $tmp = $height;
             $height = $width;
             $width = $tmp;
             $tmp = $nheight;
             $nheight = $nwidth;
             $nwidth = $tmp;
         }
         $img = @imagecreatetruecolor($nwidth, $nheight);
         if ($img) {
             imagealphablending($img, true);
             imagecopyresampled($img, $g->img->img, 0, 0, 0, 0, $nwidth, $nheight, $width, $height);
             $g->img->CreateImgCanvas($nwidth, $nheight);
             $g->img->img = $img;
         } else {
             return false;
         }
     }
     $g->Stroke($aFile);
     return true;
 }
Ejemplo n.º 5
0
 function _StrokeLegend(&$aImg, $x, $y, $scaling = 1, $aReturnWidth = false)
 {
     if (!$this->legend->iShow) {
         return;
     }
     $nlc = count($this->iLegColors);
     $nlw = count($this->iLegweights);
     $value = new Text();
     $value->SetAlign('center', 'bottom');
     $value->SetFont($this->legend->iLblFontFamily, $this->legend->iLblFontStyle, $this->legend->iLblFontSize * $scaling);
     $value->SetColor($this->legend->iLblFontColor);
     $xcenter = $x;
     $fmt = $this->legend->iFormatString . '-' . $this->legend->iFormatString;
     $tst = sprintf($fmt, $this->iRanges[0], $this->iRanges[1]);
     $value->Set($tst);
     $w = $value->GetWidth($aImg);
     $l = round(max($this->legend->iLength * $scaling, $w * 1.5));
     $r = $this->legend->iCircleRadius * $scaling;
     $len = 2 * $r + $this->scale->iMaxNum * $l;
     if ($aReturnWidth) {
         return $len;
     }
     $x -= round($len / 2);
     $x += $r;
     $y -= ($this->legend->iCircleRadius + 2) * $scaling + $this->legend->iBottomMargin * $scaling;
     if ($this->legend->iTxt != '') {
         $value->Set($this->legend->iTxt);
         $y -= $value->GetHeight($aImg);
     }
     $this->_ThickCircle($aImg, $x, $y, $r, $this->legend->iCircleWeight, $this->legend->iCircleColor);
     $xc = $x;
     $yc = $y;
     $value->SetAlign('center', 'bottom');
     $x += $r + 1;
     $txty = $y - round($this->iLegweights[($this->scale->iMaxNum - 1) % $nlw] * $scaling) - 4 * $scaling;
     if ($this->scale->iMaxNum >= count($this->iRanges)) {
         JpGraphError::RaiseL(22007);
     }
     $i = 0;
     $idx = 0;
     while ($i < $this->scale->iMaxNum) {
         $y1 = $y - round($this->iLegweights[$i % $nlw] * $scaling);
         $y2 = $y + round($this->iLegweights[$i % $nlw] * $scaling);
         $x2 = $x + $l;
         $aImg->SetColor($this->iLegColors[$i % $nlc]);
         $aImg->FilledRectangle($x, $y1, $x2, $y2);
         if ($this->iRangeStyle == RANGE_OVERLAPPING) {
             $lbl = sprintf($fmt, $this->iRanges[$idx], $this->iRanges[$idx + 1]);
         } else {
             $lbl = sprintf($fmt, $this->iRanges[$idx], $this->iRanges[$idx + 1]);
             ++$idx;
         }
         $value->Set($lbl);
         $value->Stroke($aImg, $x + $l / 2, $txty);
         $x = $x2;
         ++$i;
         ++$idx;
     }
     $value->SetFont($this->legend->iCircleFontFamily, $this->legend->iCircleFontStyle, $this->legend->iCircleFontSize * $scaling);
     $value->SetColor($this->legend->iCircleFontColor);
     $value->Set($this->legend->iZCircleTxt);
     $value->SetAlign('center', 'center');
     $value->ParagraphAlign('center');
     $value->Stroke($aImg, $xc, $yc);
     $value->SetFont($this->legend->iTxtFontFamily, $this->legend->iTxtFontStyle, $this->legend->iTxtFontSize * $scaling);
     $value->SetColor($this->legend->iTxtFontColor);
     $value->Set($this->legend->iTxt);
     $value->SetAlign('center', 'top');
     $value->SetParagraphAlign('center');
     $value->Stroke($aImg, $xcenter, $y2 + $this->legend->iTxtMargin * $scaling);
 }
Ejemplo n.º 6
0
 function StrokeAngleLabels($pos, $type)
 {
     if (!$this->show_angle_label) {
         return;
     }
     $x0 = round($this->img->left_margin + $this->img->plotwidth / 2) + 1;
     $d = max($this->img->plotwidth, $this->img->plotheight) * 1.42;
     $a = $this->angle_step;
     $t = new Text();
     $t->SetColor($this->angle_fontcolor);
     $t->SetFont($this->angle_fontfam, $this->angle_fontstyle, $this->angle_fontsize);
     $xright = $this->img->width - $this->img->right_margin;
     $ytop = $this->img->top_margin;
     $xleft = $this->img->left_margin;
     $ybottom = $this->img->height - $this->img->bottom_margin;
     $ha = 'left';
     $va = 'center';
     $w = $this->img->plotwidth / 2;
     $h = $this->img->plotheight / 2;
     $xt = $x0;
     $yt = $pos;
     $margin = 5;
     $tl = $this->angle_tick_len;
     // Outer len
     $tl2 = $this->angle_tick_len2;
     // Interior len
     $this->img->SetColor($this->angle_tick_color);
     $rot90 = $this->img->a == 90;
     if ($type == POLAR_360) {
         $ca1 = atan($h / $w) / M_PI * 180;
         $ca2 = 180 - $ca1;
         $ca3 = $ca1 + 180;
         $ca4 = 360 - $ca1;
         $end = 360;
         while ($a < $end) {
             $ca = cos($a / 180 * M_PI);
             $sa = sin($a / 180 * M_PI);
             $x = $d * $ca;
             $y = $d * $sa;
             $xt = 1000;
             $yt = 1000;
             if ($a <= $ca1 || $a >= $ca4) {
                 $yt = $pos - $w * $y / $x;
                 $xt = $xright + $margin;
                 if ($rot90) {
                     $ha = 'center';
                     $va = 'top';
                 } else {
                     $ha = 'left';
                     $va = 'center';
                 }
                 $x1 = $xright - $tl2;
                 $x2 = $xright + $tl;
                 $y1 = $y2 = $yt;
             } elseif ($a > $ca1 && $a < $ca2) {
                 $xt = $x0 + $h * $x / $y;
                 $yt = $ytop - $margin;
                 if ($rot90) {
                     $ha = 'left';
                     $va = 'center';
                 } else {
                     $ha = 'center';
                     $va = 'bottom';
                 }
                 $y1 = $ytop + $tl2;
                 $y2 = $ytop - $tl;
                 $x1 = $x2 = $xt;
             } elseif ($a >= $ca2 && $a <= $ca3) {
                 $yt = $pos + $w * $y / $x;
                 $xt = $xleft - $margin;
                 if ($rot90) {
                     $ha = 'center';
                     $va = 'bottom';
                 } else {
                     $ha = 'right';
                     $va = 'center';
                 }
                 $x1 = $xleft + $tl2;
                 $x2 = $xleft - $tl;
                 $y1 = $y2 = $yt;
             } else {
                 $xt = $x0 - $h * $x / $y;
                 $yt = $ybottom + $margin;
                 if ($rot90) {
                     $ha = 'right';
                     $va = 'center';
                 } else {
                     $ha = 'center';
                     $va = 'top';
                 }
                 $y1 = $ybottom - $tl2;
                 $y2 = $ybottom + $tl;
                 $x1 = $x2 = $xt;
             }
             if ($a != 0 && $a != 180) {
                 $t->Align($ha, $va);
                 if ($this->show_angle_mark) {
                     $a .= '°';
                 }
                 $t->Set($a);
                 $t->Stroke($this->img, $xt, $yt);
                 if ($this->show_angle_tick) {
                     $this->img->Line($x1, $y1, $x2, $y2);
                 }
             }
             $a += $this->angle_step;
         }
     } else {
         // POLAR_HALF
         $ca1 = atan($h / $w * 2) / M_PI * 180;
         $ca2 = 180 - $ca1;
         $end = 180;
         while ($a < $end) {
             $ca = cos($a / 180 * M_PI);
             $sa = sin($a / 180 * M_PI);
             $x = $d * $ca;
             $y = $d * $sa;
             if ($a <= $ca1) {
                 $yt = $pos - $w * $y / $x;
                 $xt = $xright + $margin;
                 if ($rot90) {
                     $ha = 'center';
                     $va = 'top';
                 } else {
                     $ha = 'left';
                     $va = 'center';
                 }
                 $x1 = $xright - $tl2;
                 $x2 = $xright + $tl;
                 $y1 = $y2 = $yt;
             } elseif ($a > $ca1 && $a < $ca2) {
                 $xt = $x0 + 2 * $h * $x / $y;
                 $yt = $ytop - $margin;
                 if ($rot90) {
                     $ha = 'left';
                     $va = 'center';
                 } else {
                     $ha = 'center';
                     $va = 'bottom';
                 }
                 $y1 = $ytop + $tl2;
                 $y2 = $ytop - $tl;
                 $x1 = $x2 = $xt;
             } elseif ($a >= $ca2) {
                 $yt = $pos + $w * $y / $x;
                 $xt = $xleft - $margin;
                 if ($rot90) {
                     $ha = 'center';
                     $va = 'bottom';
                 } else {
                     $ha = 'right';
                     $va = 'center';
                 }
                 $x1 = $xleft + $tl2;
                 $x2 = $xleft - $tl;
                 $y1 = $y2 = $yt;
             }
             $t->Align($ha, $va);
             if ($this->show_angle_mark) {
                 $a .= '°';
             }
             $t->Set($a);
             $t->Stroke($this->img, $xt, $yt);
             if ($this->show_angle_tick) {
                 $this->img->Line($x1, $y1, $x2, $y2);
             }
             $a += $this->angle_step;
         }
     }
 }
Ejemplo n.º 7
0
 function _StrokeLegend($aImg, $x, $y, $scaling = 1, $aReturnWidth = false)
 {
     if (!$this->legend->iShow) {
         return 0;
     }
     $nlc = count($this->iLegColors);
     $nlw = count($this->iLegweights);
     // Setup font for ranges
     $value = new Text();
     $value->SetAlign('center', 'bottom');
     $value->SetFont($this->legend->iLblFontFamily, $this->legend->iLblFontStyle, $this->legend->iLblFontSize * $scaling);
     $value->SetColor($this->legend->iLblFontColor);
     // Remember x-center
     $xcenter = $x;
     // Construct format string
     $fmt = $this->legend->iFormatString . '-' . $this->legend->iFormatString;
     // Make sure that the length of each range is enough to cover the
     // size of the labels
     $tst = sprintf($fmt, $this->iRanges[0], $this->iRanges[1]);
     $value->Set($tst);
     $w = $value->GetWidth($aImg);
     $l = round(max($this->legend->iLength * $scaling, $w * 1.5));
     $r = $this->legend->iCircleRadius * $scaling;
     $len = 2 * $r + $this->scale->iMaxNum * $l;
     // We are called just to find out the width
     if ($aReturnWidth) {
         return $len;
     }
     $x -= round($len / 2);
     $x += $r;
     // 4 pixels extra vertical margin since the circle sometimes is +/- 1 pixel of the
     // theorethical radius due to imperfection in the GD library
     //$y -= round(max($r,$scaling*$this->iLegweights[($this->scale->iMaxNum-1) % $nlw])+4*$scaling);
     $y -= ($this->legend->iCircleRadius + 2) * $scaling + $this->legend->iBottomMargin * $scaling;
     // Adjust for bottom text
     if ($this->legend->iTxt != '') {
         // Setup font for text
         $value->Set($this->legend->iTxt);
         $y -= $value->GetHeight($aImg);
     }
     // Stroke 0-circle
     $this->_ThickCircle($aImg, $x, $y, $r, $this->legend->iCircleWeight, $this->legend->iCircleColor);
     // Remember the center of the circe
     $xc = $x;
     $yc = $y;
     $value->SetAlign('center', 'bottom');
     $x += $r + 1;
     // Stroke all used ranges
     $txty = $y - round($this->iLegweights[($this->scale->iMaxNum - 1) % $nlw] * $scaling) - 4 * $scaling;
     if ($this->scale->iMaxNum >= count($this->iRanges)) {
         JpGraphError::RaiseL(22007);
         //('To few values for the range legend.');
     }
     $i = 0;
     $idx = 0;
     while ($i < $this->scale->iMaxNum) {
         $y1 = $y - round($this->iLegweights[$i % $nlw] * $scaling);
         $y2 = $y + round($this->iLegweights[$i % $nlw] * $scaling);
         $x2 = $x + $l;
         $aImg->SetColor($this->iLegColors[$i % $nlc]);
         $aImg->FilledRectangle($x, $y1, $x2, $y2);
         if ($this->iRangeStyle == RANGE_OVERLAPPING) {
             $lbl = sprintf($fmt, $this->iRanges[$idx], $this->iRanges[$idx + 1]);
         } else {
             $lbl = sprintf($fmt, $this->iRanges[$idx], $this->iRanges[$idx + 1]);
             ++$idx;
         }
         $value->Set($lbl);
         $value->Stroke($aImg, $x + $l / 2, $txty);
         $x = $x2;
         ++$i;
         ++$idx;
     }
     // Setup circle font
     $value->SetFont($this->legend->iCircleFontFamily, $this->legend->iCircleFontStyle, $this->legend->iCircleFontSize * $scaling);
     $value->SetColor($this->legend->iCircleFontColor);
     // Stroke 0-circle text
     $value->Set($this->legend->iZCircleTxt);
     $value->SetAlign('center', 'center');
     $value->ParagraphAlign('center');
     $value->Stroke($aImg, $xc, $yc);
     // Setup circle font
     $value->SetFont($this->legend->iTxtFontFamily, $this->legend->iTxtFontStyle, $this->legend->iTxtFontSize * $scaling);
     $value->SetColor($this->legend->iTxtFontColor);
     // Draw the text under the legend
     $value->Set($this->legend->iTxt);
     $value->SetAlign('center', 'top');
     $value->SetParagraphAlign('center');
     $value->Stroke($aImg, $xcenter, $y2 + $this->legend->iTxtMargin * $scaling);
 }
Ejemplo n.º 8
0
$txt = "The day was rapidly becoming more and\nmore strange.\n\nNot only had he managed to\nget by the first pass without so much as\na hint of questions but now when he\ncould feel that the second pass wouldn't\nlong be noone had yet seen him.";
$w = 950;
$h = 250;
$xm = 20;
$ym = 20;
$tw = 300;
$g = new CanvasGraph($w, $h);
$img = $g->img;
// Alignment for anchor points to use
$palign = array('left', 'center', 'right');
$n = count($palign);
$t = new Text($txt);
$y = $ym;
for ($i = 0; $i < $n; ++$i) {
    $x = $xm + $i * $tw;
    $t->SetColor('black');
    $t->SetAlign('left', 'top');
    $t->SetFont(FF_ARIAL, FS_NORMAL, 11);
    $t->SetBox();
    $t->SetParagraphAlign($palign[$i]);
    $t->Stroke($img, $x, $y);
    $img->SetColor('black');
    $img->SetFont(FF_FONT1, FS_BOLD);
    $img->SetTextAlign('center', 'top');
    $img->StrokeText($x + 140, $y + 160, '"' . $palign[$i] . '"' . ' pargraph align');
}
// .. and send back to browser
$g->Stroke();
?>

Ejemplo n.º 9
0
/**
 * Método que sirve de reemplazo al mecanismo de paloSantoGraph y paloSantoGraphLib
 * para generar gráficos a partir de una clase que devuelve datos.
 *
 * @param   string  $module     Módulo que contiene la clase fuente de datos
 * @param   string  $class      Clase a instanciar para obtener fuente de datos
 * @param   string  $function   Método a llamar en la clase para obtener datos
 * @param   array   $arrParameters  Lista de parámetros para la invocación 
 * @param   string  $functionCB 
 */
function displayGraph($G_MODULE, $G_CLASS, $G_FUNCTION, $G_PARAMETERS, $G_FUNCTIONCB = "")
{
    //------- PARAMETROS DEL GRAPH -------
    $G_TYPE = null;
    //tipo de grafica
    $G_TITLE = null;
    //titulo
    $G_COLOR = null;
    //colores
    $G_LABEL = array();
    //etiquetas
    $G_SIZE = array();
    //tamaño
    $G_MARGIN = array();
    //margen
    $G_LEYEND_NUM_COLUMN = 1;
    $G_LEYEND_POS = array(0.05, 0.5);
    //posicion de las leyendas
    $_MSJ_ERROR = null;
    //$_MSJ_ERROR   = "Sin mensaje ERROR";
    global $_MSJ_NOTHING;
    //$_MSJ_NOTHING = "Sin mensaje NOTHING";
    $G_YDATAS = array();
    $G_ARR_COLOR = array();
    $G_ARR_FILL_COLOR = array();
    $G_ARR_LEYEND = array();
    $G_ARR_STEP = array();
    $G_SHADOW = false;
    $G_LABEL_Y = null;
    //ESTATICOS
    $G_SCALE = "textlin";
    $G_WEIGHT = 1;
    if ($G_MODULE != '') {
        require_once "modules/{$G_MODULE}/libs/{$G_CLASS}.class.php";
        //lib del modulo
        require_once "modules/{$G_MODULE}/configs/default.conf.php";
        //archivo configuracion del modulo
        global $arrConfModule;
        $dsn = isset($arrConfModule["dsn_conn_database"]) ? $arrConfModule["dsn_conn_database"] : "";
    } else {
        require_once "libs/{$G_CLASS}.class.php";
        //lib del modulo
        require_once "configs/default.conf.php";
        //archivo configuracion del modulo
        global $arrConf;
        $dsn = isset($arrConf["dsn_conn_database"]) ? $arrConf["dsn_conn_database"] : "";
    }
    $oPaloClass = new $G_CLASS($dsn);
    $arrParam = $G_PARAMETERS;
    $result = call_user_func_array(array(&$oPaloClass, $G_FUNCTION), $arrParam);
    global $globalCB;
    $globalCB = NULL;
    if ($G_FUNCTIONCB != '') {
        $globalCB = array($oPaloClass, $G_FUNCTIONCB);
    }
    //------------------- CONTRUCCION DEL ARREGLO PARA X & Y -------------------
    global $xData;
    $xData = array();
    $yData = array();
    if (sizeof($result) != 0) {
        $isX_array = false;
        //usado en LINEPLOT, PLOT3D, BARPLOT, LINEPLOT_MULTIAXIS
        foreach ($result as $att => $arrXY) {
            //------------------ ATTRIBUTES ------------------
            if ($att == 'ATTRIBUTES') {
                foreach ($arrXY as $key => $values) {
                    //VARIABLES NECESARIAS
                    if ($key == 'LABEL_X') {
                        $G_LABEL[0] = $values;
                    } else {
                        if ($key == 'LABEL_Y') {
                            $G_LABEL[1] = $values;
                        } else {
                            if ($key == 'TITLE') {
                                $G_TITLE = $values;
                            } else {
                                if ($key == 'TYPE') {
                                    $G_TYPE = $values;
                                } else {
                                    if ($key == 'SIZE') {
                                        $G_SIZE = explode(',', $values);
                                    } else {
                                        if ($key == 'MARGIN') {
                                            $G_MARGIN = explode(',', $values);
                                        } else {
                                            if ($key == 'COLOR') {
                                                $G_COLOR = $values;
                                            } else {
                                                if ($key == 'POS_LEYEND') {
                                                    $G_LEYEND_POS = explode(',', $values);
                                                } else {
                                                    if ($key == 'NUM_COL_LEYEND') {
                                                        $G_LEYEND_NUM_COLUMN = $values;
                                                    } else {
                                                        if ($key == 'SHADOW') {
                                                            $G_SHADOW = $values;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if ($att == 'MESSAGES') {
                    foreach ($arrXY as $key => $values) {
                        if ($key == 'ERROR') {
                            $_MSJ_ERROR = $values;
                        } else {
                            if ($key == 'NOTHING_SHOW') {
                                $_MSJ_NOTHING = $values;
                            }
                        }
                    }
                } else {
                    if ($att == 'DATA') {
                        foreach ($arrXY as $DAT_N => $MODES) {
                            foreach ($MODES as $key => $values) {
                                /************************************************************/
                                if ($G_TYPE == 'lineplot' || $G_TYPE == 'barplot' || $G_TYPE == 'lineplot_multiaxis') {
                                    if ($key == 'VALUES') {
                                        $yData = array();
                                        foreach ($values as $x => $y) {
                                            if ($isX_array == false) {
                                                $xData[] = $x;
                                            }
                                            $yData[] = $y;
                                        }
                                        $isX_array = is_array($xData) ? true : false;
                                        $G_YDATAS[] = $yData;
                                    } else {
                                        if ($key == 'STYLE') {
                                            foreach ($values as $x => $y) {
                                                if ($x == 'COLOR') {
                                                    $G_ARR_COLOR[] = $y;
                                                } else {
                                                    if ($x == 'LEYEND') {
                                                        $G_ARR_LEYEND[] = $y;
                                                    } else {
                                                        if ($x == 'STYLE_STEP') {
                                                            $G_ARR_STEP[] = $y;
                                                        } else {
                                                            if ($x == 'FILL_COLOR') {
                                                                $G_ARR_FILL_COLOR[] = $y;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    if ($G_TYPE == 'plot3d' || $G_TYPE == 'plot3d2') {
                                        if ($key == 'VALUES') {
                                            foreach ($values as $x => $y) {
                                                $yData[] = $y;
                                            }
                                            $G_YDATAS[0] = $yData;
                                        } else {
                                            if ($key == 'STYLE') {
                                                foreach ($values as $x => $y) {
                                                    if ($x == 'COLOR') {
                                                        $G_ARR_COLOR[] = $y;
                                                    } else {
                                                        if ($x == 'LEYEND') {
                                                            $xData[] = $y;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        if ($G_TYPE == 'bar' || $G_TYPE == 'gauge') {
                                            if ($key == 'VALUES') {
                                                foreach ($values as $x => $y) {
                                                    $G_YDATAS[] = $y;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //*****************************************//
    //      ***** ***** ***** ***** *   *      //
    //      *     *   * *   * *   * *   *      //
    //      * *** ***** ***** ***** *****      //
    //      *   * * *   *   * *     *   *      //
    //      ***** *   * *   * *     *   *      //
    //*****************************************//
    // L I N E P L O T
    if (sizeof($G_YDATAS) >= 1) {
        // true no funciona porque cada cadena u otro valor que se retorne es valor "valido o verdadero"
        // y equivale a true, entonces para diferenciarlo verdaderamente se compara con 'true'
        $str = checkAttributes($G_TITLE, $G_TYPE, $G_LABEL_Y, $_MSJ_ERROR, $_MSJ_NOTHING);
        if ($str != 'true') {
            showError($str, $G_SIZE);
            return;
        }
        if ($G_TYPE == 'lineplot') {
            $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
            if ($G_SHADOW) {
                $graph->SetShadow();
            }
            $graph->SetScale($G_SCALE);
            $graph->SetMarginColor($G_COLOR);
            $graph->title->Set($G_TITLE);
            $graph->SetFrame(true, '#999999');
            $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
            $graph->img->SetAntiAliasing();
            $graph->xaxis->SetLabelFormatCallback("CallBack");
            $graph->xaxis->SetLabelAngle(90);
            $graph->xaxis->title->Set($G_LABEL[0]);
            $graph->yaxis->title->Set($G_LABEL[1]);
            $graph->xgrid->Show();
            $graph->legend->SetFillColor("#fafafa");
            $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
            $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
            $graph->legend->SetColor("#444444", "#999999");
            $arr_lineplot = array();
            foreach ($G_YDATAS as $num => $yDatas) {
                $lineplot = new LinePlot($yDatas);
                if ($G_ARR_STEP[$num] == true) {
                    $lineplot->SetStepStyle();
                }
                if ($G_ARR_FILL_COLOR[$num] == true) {
                    $lineplot->SetFillColor($G_ARR_COLOR[$num]);
                }
                $lineplot->SetColor($G_ARR_COLOR[$num]);
                $lineplot->SetWeight($G_WEIGHT);
                $lineplot->SetLegend($G_ARR_LEYEND[$num]);
                $arr_lineplot[] = $lineplot;
            }
            foreach ($arr_lineplot as $num => $yDatas) {
                $graph->Add($yDatas);
            }
            if (sizeof($xData) > 100) {
                $graph->xaxis->SetTextTickInterval((int) (sizeof($xData) / 10));
            }
            $graph->Stroke();
        } else {
            if ($G_TYPE == 'plot3d') {
                $graph = new PieGraph($G_SIZE[0], $G_SIZE[1], "auto");
                if ($G_SHADOW) {
                    $graph->SetShadow();
                }
                $dataMarginColor = isset($result["ATTRIBUTES"]["MARGIN_COLOR"]) ? $result["ATTRIBUTES"]["MARGIN_COLOR"] : "#999999";
                $dataSizePie = isset($result["ATTRIBUTES"]["SIZE_PIE"]) ? $result["ATTRIBUTES"]["SIZE_PIE"] : "80";
                $graph->SetMarginColor($G_COLOR);
                $graph->SetFrame(true, $dataMarginColor);
                $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                $graph->legend->SetFillColor("#fafafa");
                $graph->legend->SetColor("#444444", "#999999");
                $graph->legend->SetShadow('gray@0.6', 4);
                $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                $graph->title->Set($G_TITLE);
                $pieplot3d = new PiePlot3d($G_YDATAS[0]);
                $pieplot3d->SetSliceColors($G_ARR_COLOR);
                $pieplot3d->SetCenter(0.4);
                $pieplot3d->SetSize($dataSizePie);
                $pieplot3d->SetAngle(45);
                $pieplot3d->SetStartAngle(45);
                $pieplot3d->value->SetColor('black');
                //color a los porcentages
                $pieplot3d->SetEdge('black');
                //da color al contorno y separacion del pastel
                $pieplot3d->SetLegends($xData);
                $graph->Add($pieplot3d);
                $graph->Stroke();
            } else {
                if ($G_TYPE == 'plot3d2') {
                    if (!function_exists('displayGraph_draw_pie3d')) {
                        function displayGraph_draw_pie3d($canvasx, $ydata, $arrcolor)
                        {
                            $canvasy = $canvasx;
                            $escala = $canvasx / 320.0;
                            $iAnchoPastel = 256 * $escala;
                            $iAltoPastel = 155 * $escala;
                            $iPosCentroX = 141 * $escala;
                            $iPosCentroY = 91 * $escala;
                            $thumb = imagecreatetruecolor($canvasx * 284 / 320, $canvasy * 250 / 320);
                            $transparent = imagecolorallocatealpha($thumb, 200, 200, 200, 127);
                            imagefill($thumb, 0, 0, $transparent);
                            // Asignar colores de imagen
                            $imgcolor = array();
                            foreach ($arrcolor as $i => $sHtmlColor) {
                                $r = $g = $b = 0;
                                sscanf($sHtmlColor, "#%02x%02x%02x", $r, $g, $b);
                                $imgcolor[$i] = imagecolorallocate($thumb, $r, $g, $b);
                            }
                            $colorTexto = imagecolorallocate($thumb, 0, 0, 0);
                            // Mostrar el gráfico de pastel
                            if (!function_exists('displayGraph_pie')) {
                                function displayGraph_pie($thumb, $x, $y, $w, $h, $ydata, $G_ARR_COLOR, $colorTexto)
                                {
                                    $iTotal = array_sum($ydata);
                                    $iFraccion = 0;
                                    $etiquetas = array();
                                    for ($i = 0; $i < count($ydata); $i++) {
                                        if ($ydata[$i] >= $iTotal) {
                                            imagefilledellipse($thumb, $x, $y, $w, $h, $G_ARR_COLOR[$i]);
                                        } else {
                                            $degInicio = 360 - 45 - (int) (360.0 * ($iFraccion + $ydata[$i]) / $iTotal);
                                            $degFinal = 360 - 45 - (int) (360.0 * $iFraccion / $iTotal);
                                            imagefilledarc($thumb, $x, $y, $w, $h, $degInicio, $degFinal, $G_ARR_COLOR[$i], IMG_ARC_PIE);
                                        }
                                        $iFraccion += $ydata[$i];
                                        $degMitad = ($degInicio + $degFinal) / 2;
                                        $iPosTextoX = $x + 0.5 * ($w / 2.0) * cos(deg2rad($degMitad));
                                        $iPosTextoY = $y + 0.5 * ($h / 2.0) * sin(deg2rad($degMitad));
                                        $etiquetas[] = array($iPosTextoX, $iPosTextoY, sprintf('%.1f %%', 100.0 * $ydata[$i] / $iTotal));
                                    }
                                    /*
                                                            if (!is_null($colorTexto)) {
                                                                for ($i = 0; $i < count($ydata); $i++)
                                                                    imagestring($thumb, 5, $etiquetas[$i][0], $etiquetas[$i][1], $etiquetas[$i][2], $colorTexto);
                                                            }
                                    */
                                }
                            }
                            for ($i = (int) (60 * $escala); $i > 0; $i--) {
                                displayGraph_pie($thumb, $iPosCentroX, $iPosCentroY + $i, $iAnchoPastel, $iAltoPastel, $ydata, $imgcolor, NULL);
                            }
                            displayGraph_pie($thumb, $iPosCentroX, $iPosCentroY, $iAnchoPastel, $iAltoPastel, $ydata, $imgcolor, $colorTexto);
                            imagealphablending($thumb, true);
                            imagesavealpha($thumb, true);
                            $source2 = imagecreatefrompng("images/pie_alpha.png");
                            imagealphablending($source2, true);
                            imagecopyresampled($thumb, $source2, 0, 0, 0, 0, 290 * $escala, 294 * $escala, 290, 294);
                            header("Content-Type: image/png");
                            imagepng($thumb);
                        }
                    }
                    displayGraph_draw_pie3d($G_SIZE[0], $G_YDATAS[0], $G_ARR_COLOR);
                } else {
                    if ($G_TYPE == 'barplot') {
                        $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
                        if ($G_SHADOW) {
                            $graph->SetShadow();
                        }
                        $graph->SetScale($G_SCALE);
                        $graph->SetMarginColor($G_COLOR);
                        $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
                        $graph->title->Set($G_TITLE);
                        $graph->xaxis->title->Set($G_LABEL[0]);
                        $graph->xaxis->SetLabelFormatCallback("CallBack");
                        $graph->xaxis->SetLabelAngle(90);
                        //$graph->xaxis->SetTickLabels($xData);
                        $graph->yaxis->title->Set($G_LABEL[1]);
                        $graph->legend->SetFillColor("#fafafa");
                        $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                        $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                        $arr_barplot = array();
                        foreach ($G_YDATAS as $num => $yDatas) {
                            $barplot = new BarPlot($yDatas);
                            $barplot->SetFillColor($G_ARR_COLOR[$num]);
                            $barplot->SetLegend($G_ARR_LEYEND[$num]);
                            $arr_barplot[] = $barplot;
                        }
                        $gbarplot = new GroupBarPlot($arr_barplot);
                        $gbarplot->SetWidth(0.6);
                        $graph->Add($gbarplot);
                        $graph->Stroke();
                    } else {
                        if ($G_TYPE == 'lineplot_multiaxis') {
                            $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
                            if ($G_SHADOW) {
                                $graph->SetShadow();
                            }
                            $inc = sizeof($G_YDATAS);
                            $graph->SetScale($G_SCALE);
                            $graph->SetFrame(true, '#999999');
                            $graph->title->Set($G_TITLE);
                            $graph->img->SetAntiAliasing();
                            $graph->xaxis->SetLabelFormatCallback("CallBack");
                            $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
                            $graph->SetMarginColor($G_COLOR);
                            $graph->legend->SetFillColor("#fafafa");
                            $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                            $graph->xaxis->SetLabelAngle(90);
                            $graph->legend->SetColor("#444444", "#999999");
                            $graph->legend->SetShadow('gray@0.6', 4);
                            $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                            foreach ($G_YDATAS as $num => $yData) {
                                $lineplot = new LinePlot($yData);
                                $lineplot->SetWeight($G_WEIGHT);
                                $lineplot->SetLegend($G_ARR_LEYEND[$num]);
                                if ($G_ARR_STEP[$num] == true) {
                                    $lineplot->SetStepStyle();
                                }
                                if ($G_ARR_FILL_COLOR[$num] == true) {
                                    $lineplot->SetFillColor($G_ARR_COLOR[$num]);
                                }
                                if ($num == 0) {
                                    $lineplot->SetColor($G_ARR_COLOR[$num]);
                                    $graph->yaxis->SetColor($G_ARR_COLOR[$num]);
                                    $graph->Add($lineplot);
                                } else {
                                    $lineplot->SetColor($G_ARR_COLOR[$num]);
                                    $graph->SetYScale($num - 1, 'lin');
                                    $graph->ynaxis[$num - 1]->SetColor($G_ARR_COLOR[$num]);
                                    $graph->ynaxis[$num - 1]->SetPosAbsDelta($G_MARGIN[1] + 49 * ($num - 1));
                                    //mueve el eje Y
                                    $graph->AddY($num - 1, $lineplot);
                                }
                            }
                            if (sizeof($xData) > 100) {
                                //$graph->xaxis->SetTextLabelInterval( (int)(sizeof($xData)/8) );
                                $graph->xaxis->SetTextTickInterval((int) (sizeof($xData) / 10));
                                //$graph->xaxis->SetTextTickInterval( 9*(int)(log(sizeof($xData))-1) );
                            }
                            $graph->Stroke();
                        } else {
                            if ($G_TYPE == 'bar') {
                                $g = new CanvasGraph(91, 21, 'auto');
                                $g->SetMargin(0, 0, 0, 0);
                                $g->InitFrame();
                                $xmax = 20;
                                $ymax = 20;
                                $scale = new CanvasScale($g);
                                $scale->Set(0, $G_SIZE[0], 0, $G_SIZE[1]);
                                //DUBUJA LA BARRA
                                $alto = $G_SIZE[1];
                                $ancho = $G_SIZE[0];
                                $coor_x = 0;
                                $coor_y = 0;
                                $porcentage = $G_YDATAS[0];
                                $valor = 90 * (1 - $porcentage);
                                $g->img->Line($coor_x, $coor_y, $coor_x + $ancho, $coor_y);
                                $g->img->Line($coor_x, $coor_y, $coor_x, $coor_y + $alto);
                                $g->img->Line($coor_x + $ancho, $coor_y, $coor_x + $ancho, $coor_y + $alto);
                                $g->img->Line($coor_x, $coor_y + $alto, $coor_x + $ancho, $coor_y + $alto);
                                for ($i = 0; $i < $alto; $i++) {
                                    $g->img->SetColor(array(95 - 3 * $i, 138 - 3 * $i, 203 - 3 * $i));
                                    //para hacerlo 3D, degradacion
                                    $g->img->Line($coor_x, $coor_y + $i + 1, $coor_x + $ancho - $valor - 1, $coor_y + $i + 1);
                                }
                                $g->Stroke();
                            } else {
                                if ($G_TYPE == 'gauge') {
                                    if (!function_exists('displayGraph_draw_gauge')) {
                                        function displayGraph_draw_gauge($canvasx, $percent)
                                        {
                                            $escala = $canvasx / 320.0;
                                            $thumb = imagecreatetruecolor($canvasx * 284 / 320, $canvasx * 284 / 320);
                                            if ($percent > 100) {
                                                $percent = 100.0;
                                            }
                                            if ($percent < 0) {
                                                $percent = 0.0;
                                            }
                                            $angle = -135.0 + 270 * $percent / 100.0;
                                            // COLORES
                                            $blanco = imagecolorallocate($thumb, 255, 255, 255);
                                            $dred = imagecolorallocate($thumb, 180, 0, 0);
                                            $lred = imagecolorallocate($thumb, 100, 0, 0);
                                            $transparent = imagecolorallocatealpha($thumb, 200, 200, 200, 127);
                                            imagefill($thumb, 0, 0, $transparent);
                                            imagealphablending($thumb, true);
                                            imagesavealpha($thumb, true);
                                            $source = imagecreatefrompng("images/gauge_base.png");
                                            imagealphablending($source, true);
                                            imagecopyresampled($thumb, $source, 0, 0, 0, 0, 285 * $escala, 285 * $escala, 285, 285);
                                            $radius = 100 * $escala;
                                            $radius_min = 12 * $escala;
                                            $centrox = 142 * $escala;
                                            $centroy = 141 * $escala;
                                            $x1 = $centrox + sin(deg2rad($angle)) * $radius;
                                            // x coord farest
                                            $x2 = $centrox + sin(deg2rad($angle - 90)) * $radius_min;
                                            $x3 = $centrox + sin(deg2rad($angle + 90)) * $radius_min;
                                            $y1 = $centroy - cos(deg2rad($angle)) * $radius;
                                            $y2 = $centroy - cos(deg2rad($angle - 90)) * $radius_min;
                                            $y3 = $centroy - cos(deg2rad($angle + 90)) * $radius_min;
                                            $arrTriangle1 = array($centrox, $centroy, $x1, $y1, $x2, $y2);
                                            $arrTriangle2 = array($centrox, $centroy, $x1, $y1, $x3, $y3);
                                            imagefilledpolygon($thumb, $arrTriangle1, 3, $lred);
                                            imagefilledpolygon($thumb, $arrTriangle2, 3, $dred);
                                            $source2 = imagecreatefrompng("images/gauge_center.png");
                                            imagealphablending($source2, true);
                                            imagecopyresampled($thumb, $source2, 121 * $escala, 120 * $escala, 0, 0, 44 * $escala, 44 * $escala, 44, 44);
                                            header("Content-Type: image/png");
                                            imagepng($thumb);
                                        }
                                    }
                                    displayGraph_draw_gauge($G_SIZE[0], $G_YDATAS[0] * 100.0);
                                } else {
                                    if ($G_TYPE == 'bar2') {
                                        $alto = 20;
                                        $ancho = 90;
                                        $coor_x = 100;
                                        $coor_y = 10;
                                        $porcentage = 0.67;
                                        $valor = 90 * (1 - $porcentage);
                                        $g = new CanvasGraph($G_LEN_X, 40, 'auto');
                                        $g->SetMargin(1, 1, 31, 9);
                                        $g->SetMarginColor('#fafafa');
                                        $g->SetColor(array(250, 250, 250));
                                        $g->InitFrame();
                                        $xmax = 20;
                                        $ymax = 20;
                                        $scale = new CanvasScale($g);
                                        $scale->Set(0, $G_LEN_X, 0, $G_LEN_Y);
                                        //DUBUJA LA BARRA
                                        $g->img->Line($coor_x, $coor_y, $coor_x + $ancho, $coor_y);
                                        $g->img->Line($coor_x, $coor_y, $coor_x, $coor_y + $alto);
                                        $g->img->Line($coor_x + $ancho, $coor_y, $coor_x + $ancho, $coor_y + $alto);
                                        $g->img->Line($coor_x, $coor_y + $alto, $coor_x + $ancho, $coor_y + $alto);
                                        for ($i = 0; $i < $alto; $i++) {
                                            $g->img->SetColor(array(95 - 4 * $i, 138 - 4 * $i, 203 - 4 * $i));
                                            //para hacerlo 3D, degradacion
                                            $g->img->Line($coor_x, $coor_y + $i, $coor_x + $ancho - $valor - 1, $coor_y + $i);
                                        }
                                        //AGREGA LABEL 1
                                        $txt = "Uso de CPU";
                                        $t = new Text($txt, 10, 12);
                                        $t->font_style = FS_BOLD;
                                        $t->Stroke($g->img);
                                        //AGREGA LABEL 2
                                        $txt = "67.64% used of 2,200.00 MHz";
                                        $t = new Text($txt, 200, 12);
                                        $t->font_style = FS_BOLD;
                                        $t->Stroke($g->img);
                                        $g->Stroke();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        showError('nothing', $G_SIZE, $G_TITLE);
    }
}
Ejemplo n.º 10
0
 public function Draw($aTitle, $aStart, $aEnd, $n = 64, $aReverse = false, $addColorNames = false)
 {
     // Setup to draw colormap with names platoe colors
     $lmarg = ColorMapDriver::LMARG;
     // left margin
     $rmarg = ColorMapDriver::RMARG;
     // right margin
     $width = ColorMapDriver::WIDTH;
     // Overall image width
     // Module height
     $mh = ColorMapDriver::MODHEIGHT;
     // Step between each map
     $ymarg = $mh + ColorMapDriver::MAPMARG;
     if ($addColorNames) {
         $ymarg += 50;
     }
     // Start position
     $xs = $lmarg;
     $ys = ColorMapDriver::YSTART;
     // Setup a basic canvas graph
     $height = ($aEnd - $aStart + 1) * $ymarg + 50;
     $graph = new CanvasGraph($width, $height);
     $graph->img->SetColor('darkgray');
     $graph->img->Rectangle(0, 0, $width - 1, $height - 1);
     $t = new Text($aTitle, $width / 2, 5);
     $t->SetAlign('center', 'top');
     $t->SetFont(FF_ARIAL, FS_BOLD, 14);
     $t->Stroke($graph->img);
     // Instantiate a colormap
     $cm = new ColorMap();
     $cm->InitRGB($graph->img->rgb);
     for ($mapidx = $aStart; $mapidx <= $aEnd; ++$mapidx, $ys += $ymarg) {
         $cm->SetMap($mapidx, $aReverse);
         $n = $cm->SetNumColors($n);
         list($mapidx, $maparray) = $cm->GetCurrMap();
         $ncols = count($maparray);
         $colbuckets = $cm->GetBuckets();
         // The module width will depend on the actual number of colors
         $mw = round(($width - $lmarg - $rmarg) / $n);
         // Draw color map title (name)
         $t->Set('Basic colors: ' . $ncols . ',   Total colors: ' . $n);
         $t->SetAlign('center', 'bottom');
         $t->SetAngle(0);
         $t->SetFont(FF_TIMES, FS_NORMAL, 14);
         $t->Stroke($graph->img, $width / 2, $ys - 3);
         // Add the name/number of the map to the left
         $t->SetAlign('right', 'center');
         $t->Set('Map: ' . $mapidx);
         $t->SetFont(FF_ARIAL, FS_NORMAL, 14);
         $t->Stroke($graph->img, $xs - 20, round($ys + $mh / 2));
         // Setup text properties for the color names
         if ($addColorNames) {
             $t->SetAngle(30);
             $t->SetFont(FF_ARIAL, FS_NORMAL, 12);
             $t->SetAlign('right', 'top');
         }
         // Loop through all colors in the map
         $x = $xs;
         $y = $ys;
         $k = 0;
         for ($i = 0; $i < $n; ++$i) {
             $graph->img->SetColor($colbuckets[$i]);
             $graph->img->FilledRectangle($x, $y, $x + $mw, $y + $mh);
             // Mark all basic colors in the map with a bar and name
             if ($i % (($n - $ncols) / ($ncols - 1) + 1) == 0) {
                 $graph->img->SetColor('black');
                 $graph->img->FilledRectangle($x, $y + $mh + 4, $x + $mw - 1, $y + $mh + 6);
                 if ($addColorNames) {
                     $t->Set($maparray[$k++]);
                     $t->Stroke($graph->img, $x + $mw / 2, $y + $mh + 10);
                 }
             }
             $x += $mw;
         }
         // Draw a border around the map
         $graph->img->SetColor('black');
         $graph->img->Rectangle($xs, $ys, $xs + $mw * $n, $ys + $mh);
     }
     // Send back to client
     $graph->Stroke();
 }
Ejemplo n.º 11
0
 /**
  * Internal. Stroke labels
  * @param MatrixPlot $aMPlot
  * @param Image $aImg
  */
 function Stroke(MatrixPlot $aMPlot, Image $aImg)
 {
     $t = new Text();
     $t->SetColor($this->iColor);
     $t->SetFont($this->iFF, $this->iFS, $this->iFSize);
     $n = count($this->iLabels);
     $rows = count($aMPlot->iData);
     $cols = count($aMPlot->iData[0]);
     list($modwidth, $modheight) = $aMPlot->GetModSizes();
     $x = $this->iStartX;
     $y = $this->iStartY;
     if (!empty($this->csimtargets) || is_array($this->csimtargets) && count($this->csimtargets) == 0) {
         $csn = count($this->csimtargets);
         if ($csn != $n) {
             JpGraphError::RaiseL(29210, $csn, $n);
             // CSIM Target for matrix labels must be the same length as the labels
         }
     }
     $csim = '';
     switch ($this->iSide) {
         case 'top':
         case 'bottom':
             $t->SetAngle($this->iAngle);
             $x += round($modwidth / 2);
             if ($this->iSide == 'top') {
                 $y -= $this->iMargin;
                 $t->SetAlign('center', 'bottom');
             } else {
                 $y += $this->iMargin + $rows * $modheight;
                 if ($this->iAngle > 0 && $this->iAngle < 90) {
                     $t->SetAlign('right', 'top');
                 } else {
                     $t->SetAlign('center', 'top');
                 }
             }
             for ($i = 0; $i < $n && $i < $cols; ++$i, $x += $modwidth) {
                 $t->Set($this->iLabels[$i]);
                 if (!empty($this->csimtargets)) {
                     if (!empty($this->csimalts[$i]) && !empty($this->csimwintargets[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], $this->csimalts[$i], $this->csimwintargets[$i]);
                     } elseif (!empty($this->csimalts[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], $this->csimalts[$i]);
                     } elseif (!empty($this->csimwintargets[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], '', $this->csimwintargets[$i]);
                     } else {
                         $t->SetCSIMTarget($this->csimtargets[$i]);
                     }
                 }
                 $t->Stroke($aImg, $x, $y);
                 $csim .= $t->GetCSIMareas();
             }
             break;
         case 'left':
         case 'right':
             $t->SetAngle($this->iAngle);
             $y += round($modheight / 2);
             if ($this->iSide == 'left') {
                 $x -= $this->iMargin + 1;
                 $t->SetAlign('right', 'center');
             } else {
                 $x += $this->iMargin + $cols * $modwidth;
                 $t->SetAlign('left', 'center');
             }
             for ($i = 0; $i < $n && $i < $rows; ++$i, $y += $modheight) {
                 $t->Set($this->iLabels[$i]);
                 if (!empty($this->csimtargets)) {
                     if (!empty($this->csimalts[$i]) && !empty($this->csimwintargets[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], $this->csimalts[$i], $this->csimwintargets[$i]);
                     } elseif (!empty($this->csimalts[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], $this->csimalts[$i]);
                     } elseif (!empty($this->csimwintargets[$i])) {
                         $t->SetCSIMTarget($this->csimtargets[$i], '', $this->csimwintargets[$i]);
                     } else {
                         $t->SetCSIMTarget($this->csimtargets[$i]);
                     }
                 }
                 $t->Stroke($aImg, $x, $y);
                 $csim .= $t->GetCSIMareas();
             }
             break;
     }
     $this->csimareas = $csim;
 }
Ejemplo n.º 12
0
 function Stroke(&$img, $aVal, $x, $y)
 {
     if ($this->show) {
         if ($this->negformat == "") {
             $this->negformat = $this->format;
         }
         if ($this->negcolor == "") {
             $this->negcolor = $this->color;
         }
         if ($aVal === NULL || is_string($aVal) && ($aVal == "" || $aVal == "-" || $aVal == "x")) {
             return;
         }
         if (is_numeric($aVal) && $aVal == 0 && $this->iHideZero) {
             return;
         }
         if ($this->iFormCallback != '') {
             $f = $this->iFormCallback;
             $sval = call_user_func($f, $aVal);
         } elseif (is_numeric($aVal)) {
             if ($aVal >= 0) {
                 $sval = sprintf($this->format, $aVal);
             } else {
                 $sval = sprintf($this->negformat, $aVal);
             }
         } else {
             $sval = $aVal;
         }
         $y = $y - sign($aVal) * $this->margin;
         $txt = new Text($sval, $x, $y);
         $txt->SetFont($this->ff, $this->fs, $this->fsize);
         if ($this->valign == "") {
             if ($aVal >= 0) {
                 $valign = "bottom";
             } else {
                 $valign = "top";
             }
         } else {
             $valign = $this->valign;
         }
         $txt->Align($this->halign, $valign);
         $txt->SetOrientation($this->angle);
         if ($aVal > 0) {
             $txt->SetColor($this->color);
         } else {
             $txt->SetColor($this->negcolor);
         }
         $txt->Stroke($img);
     }
 }
Ejemplo n.º 13
0
 /**
  * Stroke all stored labels to the plot
  *
  * @return void
  */
 function StrokeLabels()
 {
     $t = new Text();
     $t->SetColor($this->labelColor);
     $t->SetFont($this->labelFF, $this->labelFS, $this->labelFSize);
     $t->SetAlign('center', 'center');
     foreach ($this->labels as $cont_idx => $pos) {
         // FIXME:
         //if( $cont_idx >= 10 ) return;
         foreach ($pos as $idx => $coord) {
             $t->Set(sprintf("%.1f", $coord[2]));
             if ($this->angledLabels) {
                 $t->SetAngle($coord[3]);
             }
             //$t->SetBox2('lightyellow:1.9');
             $t->Stroke($this->img, $coord[0], $coord[1]);
         }
     }
 }
Ejemplo n.º 14
0
 function SetDatapoints($datapoints)
 {
     $ny = count($datapoints);
     $nx = count($datapoints[0]);
     $t = new Text();
     $t->SetFont(FF_ARIAL, FS_NORMAL, 8);
     for ($x = 0; $x < $nx; ++$x) {
         for ($y = 0; $y < $ny; ++$y) {
             list($x1, $y1) = $this->scale->Translate($x, $y);
             if ($datapoints[$y][$x] > 0) {
                 $t->SetColor('blue');
             } else {
                 $t->SetColor('black');
             }
             $t->SetFont(FF_ARIAL, FS_BOLD, 8);
             $t->Set($datapoints[$y][$x]);
             $t->Stroke($this->g->img, $x1, $y1);
             $t->SetColor('gray');
             $t->SetFont(FF_ARIAL, FS_NORMAL, 8);
             $t->Set("({$y},{$x})");
             $t->Stroke($this->g->img, $x1 + 10, $y1);
         }
     }
 }
Ejemplo n.º 15
0
 function Raise($aMsg, $aHalt = true)
 {
     $img_iconerror = 'iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAAAaV' . 'BMVEX//////2Xy8mLl5V/Z2VvMzFi/v1WyslKlpU+ZmUyMjEh/' . 'f0VyckJlZT9YWDxMTDjAwMDy8sLl5bnY2K/MzKW/v5yyspKlpY' . 'iYmH+MjHY/PzV/f2xycmJlZVlZWU9MTEXY2Ms/PzwyMjLFTjea' . 'AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACx' . 'IAAAsSAdLdfvwAAAAHdElNRQfTBgISOCqusfs5AAABLUlEQVR4' . '2tWV3XKCMBBGWfkranCIVClKLd/7P2Q3QsgCxjDTq+6FE2cPH+' . 'xJ0Ogn2lQbsT+Wrs+buAZAV4W5T6Bs0YXBBwpKgEuIu+JERAX6' . 'wM2rHjmDdEITmsQEEmWADgZm6rAjhXsoMGY9B/NZBwJzBvn+e3' . 'wHntCAJdGu9SviwIwoZVDxPB9+Rc0TSEbQr0j3SA1gwdSn6Db0' . '6Tm1KfV6yzWGQO7zdpvyKLKBDmRFjzeB3LYgK7r6A/noDAfjtS' . 'IXaIzbJSv6WgUebTMV4EoRB8a2mQiQjgtF91HdKDKZ1gtFtQjk' . 'YcWaR5OKOhkYt+ZsTFdJRfPAApOpQYJTNHvCRSJR6SJngQadfc' . 'vd69OLMddVOPCGVnmrFD8bVYd3JXfxXPtLR/+mtv59/ALWiiMx' . 'qL72fwAAAABJRU5ErkJggg==';
     if (function_exists("imagetypes")) {
         $supported = imagetypes();
     } else {
         $supported = 0;
     }
     if (!function_exists('imagecreatefromstring')) {
         $supported = 0;
     }
     if (ob_get_length() || headers_sent() || !($supported & IMG_PNG)) {
         die($this->iTitle . ' ' . $aMsg);
     }
     $aMsg = wordwrap($aMsg, 55);
     $lines = substr_count($aMsg, "\n");
     $erricon = Image::CreateFromString(base64_decode($img_iconerror));
     $w = 400;
     $h = 100 + 15 * max(0, $lines - 3);
     $img = new Image($w, $h);
     $img->SetColor("gray");
     $img->FilledRectangle(5, 5, $w - 1, $h - 1, 10);
     $img->SetColor("gray:0.7");
     $img->FilledRectangle(5, 5, $w - 3, $h - 3, 10);
     $img->SetColor("lightblue");
     $img->FilledRectangle(1, 1, $w - 5, $h - 5);
     $img->CopyCanvasH($img->img, $erricon, 5, 30, 0, 0, 40, 40);
     $img->SetColor("black");
     $img->Rectangle(1, 1, $w - 5, $h - 5);
     $img->Rectangle(0, 0, $w - 4, $h - 4);
     $img->SetColor("darkred");
     for ($y = 3; $y < 18; $y += 2) {
         $img->Line(1, $y, $w - 6, $y);
     }
     $img->SetColor("white");
     $img->Line(2, 2, 2, $h - 5);
     $img->Line(2, 2, $w - 6, 2);
     $img->SetColor("darkgray");
     $img->Line(2, $h - 6, $w - 5, $h - 6);
     $img->Line(3, $h - 7, $w - 5, $h - 7);
     $m = floor($w / 2 - 5);
     $l = 100;
     $img->SetColor("lightgray:1.3");
     $img->FilledRectangle($m - $l, 2, $m + $l, 16);
     $img->SetColor("darkred");
     $img->SetFont(FF_FONT2, FS_BOLD);
     $img->StrokeText($m - 50, 15, $this->iTitle);
     $img->SetColor("black");
     $img->SetFont(FF_FONT1, FS_NORMAL);
     $txt = new Text($aMsg, 52, 25);
     $txt->Align("left", "top");
     $txt->Stroke($img);
     if ($this->iDest) {
         $img->Stream($this->iDest);
     } else {
         $img->Headers();
         $img->Stream();
     }
     if ($aHalt) {
         die;
     }
 }
Ejemplo n.º 16
0
<?php

// content="text/plain; charset=utf-8"
// $Id: canvasex01.php,v 1.3 2002/10/23 08:17:23 aditus Exp $
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_canvas.php';
// Setup a basic canvas we can work
$g = new CanvasGraph(400, 300, 'auto');
$g->SetMargin(5, 11, 6, 11);
$g->SetShadow();
$g->SetMarginColor("teal");
// We need to stroke the plotarea and margin before we add the
// text since we otherwise would overwrite the text.
$g->InitFrame();
// Draw a text box in the middle
$txt = "This\nis\na TEXT!!!";
$t = new Text($txt, 200, 10);
$t->SetFont(FF_ARIAL, FS_BOLD, 40);
// How should the text box interpret the coordinates?
$t->Align('center', 'top');
// How should the paragraph be aligned?
$t->ParagraphAlign('center');
// Add a box around the text, white fill, black border and gray shadow
$t->SetBox("white", "black", "gray");
// Stroke the text
$t->Stroke($g->img);
// Stroke the graph
$g->Stroke();
?>

Ejemplo n.º 17
0
 function Stroke($img, $aVal, $x, $y)
 {
     if ($this->show) {
         if ($this->negformat == "") {
             $this->negformat = $this->format;
         }
         if ($this->negcolor == "") {
             $this->negcolor = $this->color;
         }
         if ($aVal == NULL || is_string($aVal) && ($aVal == "" || $aVal == "-" || $aVal == "x")) {
             return;
         }
         if ($aVal >= 0) {
             $sval = sprintf($this->format, $aVal);
         } else {
             $sval = sprintf($this->negformat, $aVal);
         }
         $txt = new Text($sval, $x, $y - sign($aVal) * $this->margin);
         $txt->SetFont($this->ff, $this->fs, $this->fsize);
         if ($this->valign == "") {
             if ($aVal >= 0) {
                 $valign = "bottom";
             } else {
                 $valign = "top";
             }
         } else {
             $valign = $this->valign;
         }
         $txt->Align($this->halign, $valign);
         $txt->SetOrientation($this->angle);
         if ($aVal > 0) {
             $txt->SetColor($this->color);
         } else {
             $txt->SetColor($this->negcolor);
         }
         $txt->Stroke($img);
     }
 }
Ejemplo n.º 18
0
 function Raise($aMsg, $aHalt = true)
 {
     $img_iconerror = 'iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAAAaV' . 'BMVEX//////2Xy8mLl5V/Z2VvMzFi/v1WyslKlpU+ZmUyMjEh/' . 'f0VyckJlZT9YWDxMTDjAwMDy8sLl5bnY2K/MzKW/v5yyspKlpY' . 'iYmH+MjHY/PzV/f2xycmJlZVlZWU9MTEXY2Ms/PzwyMjLFTjea' . 'AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACx' . 'IAAAsSAdLdfvwAAAAHdElNRQfTBgISOCqusfs5AAABLUlEQVR4' . '2tWV3XKCMBBGWfkranCIVClKLd/7P2Q3QsgCxjDTq+6FE2cPH+' . 'xJ0Ogn2lQbsT+Wrs+buAZAV4W5T6Bs0YXBBwpKgEuIu+JERAX6' . 'wM2rHjmDdEITmsQEEmWADgZm6rAjhXsoMGY9B/NZBwJzBvn+e3' . 'wHntCAJdGu9SviwIwoZVDxPB9+Rc0TSEbQr0j3SA1gwdSn6Db0' . '6Tm1KfV6yzWGQO7zdpvyKLKBDmRFjzeB3LYgK7r6A/noDAfjtS' . 'IXaIzbJSv6WgUebTMV4EoRB8a2mQiQjgtF91HdKDKZ1gtFtQjk' . 'YcWaR5OKOhkYt+ZsTFdJRfPAApOpQYJTNHvCRSJR6SJngQadfc' . 'vd69OLMddVOPCGVnmrFD8bVYd3JXfxXPtLR/+mtv59/ALWiiMx' . 'qL72fwAAAABJRU5ErkJggg==';
     if (function_exists('imagetypes')) {
         $supported = imagetypes();
     } else {
         $supported = 0;
     }
     if (!function_exists('imagecreatefromstring')) {
         $supported = 0;
     }
     if (ob_get_length() || headers_sent() || !($supported & IMG_PNG)) {
         // Special case for headers already sent or that the installation doesn't support
         // the PNG format (which the error icon is encoded in).
         // Dont return an image since it can't be displayed
         echo $this->iTitle . ' ' . $aMsg . '\\n';
         return;
     }
     $aMsg = wordwrap($aMsg, 55);
     $lines = substr_count($aMsg, '\\n');
     // Create the error icon GD
     $erricon = imagecreatefromstring(base64_decode($img_iconerror));
     // Create an image that contains the error text.
     $w = 400;
     $h = 100 + 15 * max(0, $lines - 3);
     $img = new Image($w, $h);
     // Drop shadow
     $img->SetColor('gray');
     $img->FilledRectangle(5, 5, $w - 1, $h - 1, 10);
     $img->SetColor('gray:0.7');
     $img->FilledRectangle(5, 5, $w - 3, $h - 3, 10);
     // Window background
     $img->SetColor(array(188, 209, 193));
     $img->FilledRectangle(1, 1, $w - 5, $h - 5);
     $img->CopyCanvasH($img->img, $erricon, 5, 30, 0, 0, 40, 40);
     // Window border
     $img->SetColor('black');
     $img->Rectangle(1, 1, $w - 5, $h - 5);
     $img->Rectangle(0, 0, $w - 4, $h - 4);
     // Window top row
     $img->SetColor('darkred');
     for ($y = 3; $y < 18; $y += 2) {
         $img->Line(1, $y, $w - 6, $y);
     }
     // 'White shadow'
     $img->SetColor('white');
     // Left window edge
     $img->Line(2, 2, 2, $h - 5);
     $img->Line(2, 2, $w - 6, 2);
     // 'Gray button shadow'
     $img->SetColor('darkgray');
     // Gray window shadow
     $img->Line(2, $h - 6, $w - 5, $h - 6);
     $img->Line(3, $h - 7, $w - 5, $h - 7);
     // Window title
     $m = floor($w / 2 - 5);
     $l = 100;
     $img->SetColor('lightgray:1.3');
     $img->FilledRectangle($m - $l, 2, $m + $l, 16);
     // Stroke text
     $img->SetColor('darkred:0.9');
     $img->SetFont(FF_FONT2, FS_BOLD);
     $img->StrokeText($m - 70, 15, $this->iTitle);
     $img->SetColor('black');
     $img->SetFont(FF_FONT1, FS_NORMAL);
     $txt = new Text($aMsg, 52, 25);
     $txt->Align('left', 'top');
     $txt->Stroke($img);
     if ($this->iDest) {
         $img->Stream($this->iDest);
     } else {
         $img->Headers();
         $img->Stream();
     }
 }
Ejemplo n.º 19
0
 function strokeLabels()
 {
     $t = new Text();
     $t->SetColor($this->labelColor);
     $t->SetFont($this->labelFF, $this->labelFS, $this->labelFSize);
     $t->SetAlign('center', 'center');
     foreach ($this->labels as $cont_idx => $pos) {
         if ($cont_idx >= 10) {
             return;
         }
         foreach ($pos as $idx => $coord) {
             $t->Set(sprintf("%.1f", $coord[2]));
             $t->SetAngle($coord[3]);
             $t->Stroke($this->g->img, $coord[0], $coord[1]);
         }
     }
 }
Ejemplo n.º 20
0
 function Stroke($aData, $aFile = '', $aShowDetails = false, $aShowEncodingDetails = false)
 {
     $textmargin = 5;
     $this->iEncoder->AddChecksum($this->iUseChecksum);
     $spec = $this->iEncoder->Enc($aData);
     $this->AdjustSpec($spec);
     if ($this->iFontFam == -1) {
         if ($this->iModuleWidth > 1) {
             $this->iFontFam = FF_FONT2;
             $this->iFontStyle = FS_BOLD;
         } else {
             $this->iFontFam = FF_FONT1;
             $this->iFontStyle = FS_BOLD;
         }
     }
     $s = '';
     $n = count($spec->iBar);
     $g = new CanvasGraph(0, 0);
     $g->img->SetImgFormat($this->iImgFormat);
     if ($aShowDetails) {
         $s = $spec->iEncoding . "\n";
         $s .= 'Data: ' . $spec->iData . "\n";
         if ($spec->iInfo != '') {
             $s .= 'Info: ' . $spec->iInfo . "\n";
         }
     }
     $w = round($spec->iModuleWidth);
     $totwidth = $spec->iLeftMargin * $w;
     $n = count($spec->iBar);
     for ($i = 0; $i < $n; ++$i) {
         $b = $spec->iBar[$i];
         $bn = strlen($b[3]);
         for ($j = 0; $j < $bn; ++$j) {
             $wb = substr($b[3], $j, 1) * $w;
             $totwidth += $wb;
         }
     }
     if ($spec->iInterCharModuleSpace) {
         $totwidth += ($n - 2) * $w;
     }
     $totwidth += $spec->iRightMargin * $w + 1;
     $height = $this->iHeight;
     if ($aShowDetails) {
         $g->img->SetFont(FF_FONT2);
         $height += $g->img->GetTextHeight($s);
     }
     $g->img->SetFont($this->iFontFam, $this->iFontStyle, $this->iFontSize);
     $th = $g->img->GetTextHeight($spec->iData);
     if ($spec->iStrokeDataBelow) {
         $height += $th + $this->iDataBelowMargin;
     }
     if ($height < round(0.15 * ($totwidth - $spec->iRightMargin * $w - $spec->iLeftMargin * $w))) {
         $height = round(0.15 * $totwidth);
     }
     $g->img->SetFont(FF_FONT2);
     $tw = 2 * $textmargin + $g->img->GetTextWidth($s);
     $width = $totwidth;
     if ($width < $tw) {
         $width = $tw;
     }
     if ($aShowEncodingDetails) {
         $g->img->SetFont(FF_FONT2);
         $height += $n * $g->img->GetTextHeight('0');
         $width = max(300, $totwidth);
     }
     $g = new CanvasGraph($width, $height);
     $g->img->SetImgFormat($this->iImgFormat);
     $g->SetMarginColor('white');
     if ($this->iShowFrame) {
         $g->frame_color = $this->iFrameColor;
         $g->InitFrame();
     }
     $g->img->SetColor('black');
     $x = $w * $spec->iLeftMargin;
     $ystart = $this->iTopMargin;
     $yend = $height - $this->iBottomMargin - 1;
     if ($aShowDetails) {
         $ystart += $g->img->GetTextHeight($s);
     }
     if ($aShowEncodingDetails) {
         $g->img->SetFont(FF_FONT2);
         $ystart += $n * $g->img->GetTextHeight('0');
     }
     if ($spec->iStrokeDataBelow) {
         $yend -= $th + $this->iDataBelowMargin;
     }
     $inunder = false;
     $under_s = '';
     $under_x = 0;
     for ($i = 0; $i < $n; ++$i) {
         $b = $spec->iBar[$i];
         if ($aShowEncodingDetails) {
             $s .= sprintf("%02d", $i) . " : {$b['0']}, {$b['1']}, {$b['2']}, {$b['3']}\n";
         }
         $bn = strlen($b[3]);
         if ($b[2] == 0 && !$this->iNoHumanText) {
             if (!$inunder) {
                 $inunder = true;
                 $under_x = $x;
                 $under_s = $b[0];
             } else {
                 $under_s .= $b[0];
             }
         } else {
             if ($inunder) {
                 $inunder = false;
                 if ($under_s != '') {
                     $t = new Text($under_s, ($under_x + $x - 1) / 2, $yend - $th / 1.3);
                     $t->SetFont($this->iFontFam, $this->iFontStyle, $this->iFontSize);
                     $t->Align('center', 'top');
                     $t->Stroke($g->img);
                 }
             }
         }
         $startx = $x;
         for ($j = 0; $j < $bn; ++$j) {
             $wb = substr($b[3], $j, 1) * $w;
             if ($j % 2 == $b[1]) {
                 $g->img->SetColor($this->iBkgColor);
             } else {
                 $g->img->SetColor($this->iColor);
             }
             if ($b[2] == 1 || $this->iNoHumanText) {
                 $g->img->FilledRectangle($x, $ystart, $x + $wb - 1, $yend);
             } else {
                 $g->img->FilledRectangle($x, $ystart, $x + $wb - 1, $yend - $th);
             }
             $x += $wb;
         }
         if ($this->iDebugBackground) {
             $g->SetAlphaBlending();
             if (($i & 1) == 0) {
                 $g->img->SetColor('lightblue@0.5');
             } else {
                 $g->img->SetColor('yellow@0.5');
             }
             $g->img->FilledRectangle($startx, $ystart - 2, $x, $yend);
         }
         if ($spec->iInterCharModuleSpace) {
             $x += $w;
         }
     }
     $g->img->SetColor($this->iColor);
     if (!($spec->iLeftData === '')) {
         $g->img->SetTextAlign('right', 'top');
         $g->img->SetFont($this->iSmallFontFam, $this->iSmallFontStyle, $this->iSmallFontSize);
         $g->img->StrokeText($w * $spec->iLeftMargin - 3, $yend - $th, $spec->iLeftData);
     }
     if (!($spec->iRightData === '')) {
         $g->img->SetTextAlign('left', 'top');
         $g->img->SetFont($this->iSmallFontFam, $this->iSmallFontStyle, $this->iSmallFontSize);
         $g->img->StrokeText($x + 3, $yend - $th, $spec->iRightData);
     }
     if ($spec->iStrokeDataBelow) {
         $y = $yend + $this->iDataBelowMargin;
         $bw = $totwidth - $spec->iLeftMargin * $w - $spec->iRightMargin * $w;
         $x = $spec->iLeftMargin * $w + floor($bw / 2);
         $g->img->SetTextAlign('center', 'top');
         $g->img->SetFont($this->iFontFam, $this->iFontStyle, $this->iFontSize);
         if ($this->iHumanTxt !== '') {
             $g->img->StrokeText($x, $y, $this->iHumanTxt);
         } else {
             $g->img->StrokeText($x, $y, $spec->iData);
         }
     }
     if ($aShowDetails) {
         $g->img->SetColor('navy');
         $g->img->SetTextAlign('left', 'top');
         $g->img->SetFont(FF_FONT2);
         $g->img->StrokeText($textmargin, $this->iTopMargin, $s);
     }
     if (ADD_DEMOTXT === true) {
         $t = new Text("<<DEMO>>", $totwidth / 2, $ystart);
         if ($this->iModuleWidth > 1) {
             if ($this->iModuleWidth > 4) {
                 $t->SetFont(FF_ARIAL, FS_BOLD, 32);
                 $step = 140;
                 $yadj = 50;
             } else {
                 $t->SetFont(FF_ARIAL, FS_BOLD, 24);
                 $step = 110;
                 $yadj = 40;
             }
         } else {
             $t->SetFont(FF_ARIAL, FS_BOLD, 18);
             $step = 80;
             $yadj = 30;
         }
         $t->SetColor('red@0.4');
         $t->Align('center', 'center');
         $t->SetAngle(-25);
         $n = ceil($totwidth / $step);
         for ($i = 0; $i < $n; ++$i) {
             $t->SetPos(-30 + $i * $step, ($yend - $ystart) / 2 - $yadj);
             $t->Stroke($g->img);
         }
     }
     if ($this->iVertical) {
         $g->img->img = $this->Rotate($g->img->img, 90);
     }
     if ($this->iScale != 1) {
         $nwidth = round($width * $this->iScale);
         $nheight = round($height * $this->iScale);
         if ($this->iVertical) {
             $tmp = $height;
             $height = $width;
             $width = $tmp;
             $tmp = $nheight;
             $nheight = $nwidth;
             $nwidth = $tmp;
         }
         $img = @imagecreatetruecolor($nwidth, $nheight);
         if ($img) {
             imagealphablending($img, true);
             imagecopyresampled($img, $g->img->img, 0, 0, 0, 0, $nwidth, $nheight, $width, $height);
             $g->img->CreateImgCanvas($nwidth, $nheight);
             $g->img->img = $img;
         } else {
             return false;
         }
     }
     return $g->Stroke($aFile);
 }
 function Stroke(&$img, &$xscale, &$yscale)
 {
     $numpoints = count($this->coords[0]);
     if (isset($this->coords[1])) {
         if (count($this->coords[1]) != $numpoints) {
             JpGraphError::Raise("JpGraph Error: Number of X and Y points are not equal.<br>\r\n\t\t\t\t\tNumber of X-points:" . count($this->coords[1]) . "<br>\r\n\t\t\t\t\tNumber of Y-points:{$numpoints}");
         } else {
             $exist_x = true;
         }
     } else {
         $exist_x = false;
     }
     if ($exist_x) {
         $xs = $this->coords[1][0];
     } else {
         $xs = 0;
     }
     $img->SetStartPoint($xscale->Translate($xs), $yscale->Translate($this->coords[0][0]));
     if ($this->filled) {
         $cord[] = $xscale->Translate($xs);
         $cord[] = $yscale->Translate($yscale->GetMinVal());
     }
     $cord[] = $xscale->Translate($xs);
     $cord[] = $yscale->Translate($this->coords[0][0]);
     $yt_old = $yscale->Translate($this->coords[0][0]);
     $img->SetColor($this->color);
     $img->SetLineWeight($this->weight);
     $img->SetLineStyle($this->line_style);
     for ($pnts = 1; $pnts < $numpoints; ++$pnts) {
         if ($exist_x) {
             $x = $this->coords[1][$pnts];
         } else {
             $x = $pnts;
         }
         $xt = $xscale->Translate($x);
         $yt = $yscale->Translate($this->coords[0][$pnts]);
         $cord[] = $xt;
         $cord[] = $yt;
         if ($this->step_style) {
             $img->StyleLineTo($xt, $yt_old);
             $img->StyleLineTo($xt, $yt);
         } else {
             $y = $this->coords[0][$pnts];
             if (is_numeric($y) || is_string($y) && $y != "-") {
                 $tmp1 = $this->coords[0][$pnts];
                 $tmp2 = $this->coords[0][$pnts - 1];
                 if (is_numeric($tmp1) && (is_numeric($tmp2) || $tmp2 == "-")) {
                     $img->StyleLineTo($xt, $yt);
                 } else {
                     $img->SetStartPoint($xt, $yt);
                 }
             }
         }
         $yt_old = $yt;
         if ($this->value->show) {
             $sval = sprintf($this->value->format, $this->coords[0][$pnts]);
             $txt = new Text($sval, $xt, $yt - $this->value->margin);
             $txt->SetFont($this->value->ff, $this->value->fs, $this->value->fsize);
             $txt->Align("center", "bottom");
             $txt->SetOrientation($this->value->angle);
             $txt->SetColor($this->value->color);
             $txt->Stroke($img);
         }
     }
     if ($this->filled) {
         $cord[] = $xt;
         $cord[] = $yscale->Translate($yscale->GetMinVal());
         $img->SetColor($this->fill_color);
         $img->FilledPolygon($cord);
         $img->SetColor($this->color);
         $img->Polygon($cord);
     }
     $adjust = 0;
     if ($this->filled) {
         $adjust = 2;
     }
     for ($i = $adjust; $i < count($cord) - $adjust; $i += 2) {
         if (is_numeric($this->coords[0][($i - $adjust) / 2])) {
             $this->mark->Stroke($img, $cord[$i], $cord[$i + 1]);
         }
     }
 }
Ejemplo n.º 22
0
 function Stroke($aImg, $ax = -1, $ay = -1)
 {
     // To position the super script correctly we need different
     // cases to handle the alignmewnt specified since that will
     // determine how we can interpret the x,y coordinates
     $w = parent::GetWidth($aImg);
     $h = parent::GetTextHeight($aImg);
     switch ($this->valign) {
         case 'top':
             $sy = $this->y;
             break;
         case 'center':
             $sy = $this->y - $h / 2;
             break;
         case 'bottom':
             $sy = $this->y - $h;
             break;
         default:
             JpGraphError::RaiseL(25052);
             //('PANIC: Internal error in SuperScript::Stroke(). Unknown vertical alignment for text');
             break;
     }
     switch ($this->halign) {
         case 'left':
             $sx = $this->x + $w;
             break;
         case 'center':
             $sx = $this->x + $w / 2;
             break;
         case 'right':
             $sx = $this->x;
             break;
         default:
             JpGraphError::RaiseL(25053);
             //('PANIC: Internal error in SuperScript::Stroke(). Unknown horizontal alignment for text');
             break;
     }
     $sx += $this->iSuperMargin;
     $sy += $this->iVertOverlap;
     // Should we automatically determine the font or
     // has the user specified it explicetly?
     if ($this->sfont_family == '') {
         if ($this->font_family <= FF_FONT2) {
             if ($this->font_family == FF_FONT0) {
                 $sff = FF_FONT0;
             } elseif ($this->font_family == FF_FONT1) {
                 if ($this->font_style == FS_NORMAL) {
                     $sff = FF_FONT0;
                 } else {
                     $sff = FF_FONT1;
                 }
             } else {
                 $sff = FF_FONT1;
             }
             $sfs = $this->font_style;
             $sfz = $this->font_size;
         } else {
             // TTF fonts
             $sff = $this->font_family;
             $sfs = $this->font_style;
             $sfz = floor($this->font_size * $this->iSuperScale);
             if ($sfz < 8) {
                 $sfz = 8;
             }
         }
         $this->sfont_family = $sff;
         $this->sfont_style = $sfs;
         $this->sfont_size = $sfz;
     } else {
         $sff = $this->sfont_family;
         $sfs = $this->sfont_style;
         $sfz = $this->sfont_size;
     }
     parent::Stroke($aImg, $ax, $ay);
     // For the builtin fonts we need to reduce the margins
     // since the bounding bx reported for the builtin fonts
     // are much larger than for the TTF fonts.
     if ($sff <= FF_FONT2) {
         $sx -= 2;
         $sy += 3;
     }
     $aImg->SetTextAlign('left', 'bottom');
     $aImg->SetFont($sff, $sfs, $sfz);
     $aImg->PushColor($this->color);
     $aImg->StrokeText($sx, $sy, $this->iSuper, $this->iSDir, 'left');
     $aImg->PopColor();
 }
Ejemplo n.º 23
0
 function Stroke(&$img, &$xscale, &$yscale)
 {
     $img->SetLineWeight($this->weight);
     for ($i = 0; $i < $this->numpoints - 1; $i++) {
         $accy = 0;
         $accy_neg = 0;
         for ($j = 0; $j < $this->nbrplots; ++$j) {
             $img->SetColor($this->plots[$j]->color);
             if ($this->plots[$j]->coords[0][$i] > 0) {
                 $yt = $yscale->Translate($this->plots[$j]->coords[0][$i] + $accy);
                 $accyt = $yscale->Translate($accy);
                 $accy += $this->plots[$j]->coords[0][$i];
             } else {
                 $yt = $yscale->Translate($this->plots[$j]->coords[0][$i] + $accy_neg);
                 $accyt = $yscale->Translate($accy_neg);
                 $accy_neg += $this->plots[$j]->coords[0][$i];
             }
             $xt = $xscale->Translate($i);
             $abswidth = round($this->width * $xscale->scale_factor, 0);
             $pts = array($xt, $accyt, $xt, $yt, $xt + $abswidth, $yt, $xt + $abswidth, $accyt);
             if ($this->plots[$j]->grad) {
                 $grad = new Gradient($img);
                 $grad->FilledRectangle($pts[2], $pts[3], $pts[6], $pts[7], $this->plots[$j]->grad_fromcolor, $this->plots[$j]->grad_tocolor, $this->plots[$j]->grad_style);
             } elseif ($this->plots[$j]->fill_color) {
                 $img->SetColor($this->plots[$j]->fill_color);
                 $img->FilledPolygon($pts, 4);
                 $img->SetColor($this->plots[$j]->color);
             }
             if ($this->bar_shadow) {
                 $ssh = $this->bar_shadow_hsize;
                 $ssv = $this->bar_shadow_vsize;
                 // Create points to create a "upper-right" shadow
                 $sp[0] = $pts[6];
                 $sp[1] = $pts[7];
                 $sp[2] = $pts[4];
                 $sp[3] = $pts[5];
                 $sp[4] = $pts[2];
                 $sp[5] = $pts[3];
                 $sp[6] = $pts[2] + $ssh;
                 $sp[7] = $pts[3] - $ssv;
                 $sp[8] = $pts[4] + $ssh;
                 $sp[9] = $pts[5] - $ssv;
                 $sp[10] = $pts[6] + $ssh;
                 $sp[11] = $pts[7] - $ssv;
                 $img->SetColor($this->bar_shadow_color);
                 $img->FilledPolygon($sp, 4);
             }
             if ($i < count($this->plots[$j]->csimtargets)) {
                 $this->csimareas .= "<area shape=\"rect\" coords=\"";
                 // Hmmm, this is fishy.  Fixes a bug in Opera whereby if Y2<Y1 or X2<X1 the csim doesn't work
                 // This means that the area MUST specify top left and bottom right corners
                 if ($pts[3] < $pts[7]) {
                     if ($pts[2] < $pts[6]) {
                         $this->csimareas .= "{$pts['2']}, {$pts['3']}, {$pts['6']}, {$pts['7']}\"";
                     } else {
                         $this->csimareas .= "{$pts['6']}, {$pts['3']}, {$pts['2']}, {$pts['7']}\"";
                     }
                 } else {
                     if ($pts[2] < $pts[6]) {
                         $this->csimareas .= "{$pts['2']}, {$pts['7']}, {$pts['6']}, {$pts['3']}\"";
                     } else {
                         $this->csimareas .= "{$pts['6']}, {$pts['7']}, {$pts['2']}, {$pts['3']}\"";
                     }
                 }
                 $this->csimareas .= " href=\"" . $this->plots[$j]->csimtargets[$i] . "\"";
                 if (!empty($this->plots[$j]->csimalts[$i])) {
                     $sval = sprintf($this->plots[$j]->csimalts[$i], $this->plots[$j]->coords[0][$i]);
                     $this->csimareas .= " alt=\"{$sval}\"";
                 }
                 $this->csimareas .= ">\r\n";
             }
             $img->Polygon($pts, 4);
         }
         $yt = $yscale->Translate($accy);
         if ($this->show_value) {
             $sval = sprintf($this->show_value_format, $accy);
             $txt = new Text($sval);
             $txt->SetFont($this->show_value_ff, $this->show_value_fs, $this->show_value_fsize);
             $txt->SetColor($this->show_value_color);
             $x = $pts[2] + ($pts[4] - $pts[2]) / 2;
             if ($this->bar_shadow) {
                 $x += $ssh;
             }
             $txt->Pos($x, $yt - $this->show_value_margin);
             $txt->Align("center", "bottom");
             $txt->SetOrientation($this->show_value_angle);
             $txt->Stroke($img);
         }
     }
     return true;
 }
Ejemplo n.º 24
0
 function Stroke($img, $aVal, $x, $y)
 {
     if ($this->show) {
         if ($this->negformat == "") {
             $this->negformat = $this->format;
         }
         if ($this->negcolor == "") {
             $this->negcolor = $this->color;
         }
         if ($aVal === NULL || is_string($aVal) && ($aVal == "" || $aVal == "-" || $aVal == "x")) {
             return;
         }
         if (is_numeric($aVal) && $aVal == 0 && $this->iHideZero) {
             return;
         }
         // Since the value is used in different cirumstances we need to check what
         // kind of formatting we shall use. For example, to display values in a line
         // graph we simply display the formatted value, but in the case where the user
         // has already specified a text string we don't fo anything.
         if ($this->iFormCallback != '') {
             $f = $this->iFormCallback;
             $sval = call_user_func($f, $aVal);
         } elseif (is_numeric($aVal)) {
             if ($aVal >= 0) {
                 $sval = sprintf($this->format, $aVal);
             } else {
                 $sval = sprintf($this->negformat, $aVal);
             }
         } else {
             $sval = $aVal;
         }
         $y = $y - sign($aVal) * $this->margin;
         $txt = new Text($sval, $x, $y);
         $txt->SetFont($this->ff, $this->fs, $this->fsize);
         if ($this->valign == "") {
             if ($aVal >= 0) {
                 $valign = "bottom";
             } else {
                 $valign = "top";
             }
         } else {
             $valign = $this->valign;
         }
         $txt->Align($this->halign, $valign);
         $txt->SetOrientation($this->angle);
         if ($aVal > 0) {
             $txt->SetColor($this->color);
         } else {
             $txt->SetColor($this->negcolor);
         }
         $txt->Stroke($img);
     }
 }
Ejemplo n.º 25
0
 public function StrokeLabels($aImg, $xc, $yc, $ri, $rr)
 {
     if ($this->iHideLabels) {
         return;
     }
     // Setup some convinient vairables
     $a = $this->iAngle * M_PI / 180.0;
     $n = $this->iNumCirc;
     $d = $this->iDelta;
     // Setup the font and font color
     $val = new Text();
     $val->SetFont($this->iFontFamily, $this->iFontStyle, $this->iFontSize);
     $val->SetColor($this->iFontColor);
     if ($this->iFontBkgColor !== false) {
         $val->SetBox($this->iFontBkgColor, $this->iFontFrameColor);
     }
     // Position the labels relative to the radiant circles
     if ($this->iLblAlign == LBLALIGN_TOP) {
         if ($a > 0 && $a <= M_PI / 2) {
             $val->SetAlign('left', 'bottom');
         } elseif ($a > M_PI / 2 && $a <= M_PI) {
             $val->SetAlign('right', 'bottom');
         }
     } elseif ($this->iLblAlign == LBLALIGN_CENTER) {
         $val->SetAlign('center', 'center');
     }
     // Stroke the labels close to each circle
     $v = $d;
     $si = sin($a);
     $co = cos($a);
     for ($i = 0; $i < $n; ++$i, $v += $d) {
         $r = $ri + ($i + 1) * $rr;
         $x = $xc + $co * $r;
         $y = $yc - $si * $r;
         $val->Set(sprintf($this->iLblFmt, $v));
         $val->Stroke($aImg, $x, $y);
     }
     // Print the text in the zero circle
     if ($this->iLblZeroTxt === null) {
         $this->iLblZeroTxt = sprintf($this->iLblFmt, $this->iZeroSum);
     } else {
         $this->iLblZeroTxt = sprintf($this->iLblZeroTxt, $this->iZeroSum);
     }
     $val->Set($this->iLblZeroTxt);
     $val->SetAlign('center', 'center');
     $val->SetParagraphAlign('center');
     $val->SetColor($this->iZFontColor);
     $val->SetFont($this->iZFontFamily, $this->iZFontStyle, $this->iZFontSize);
     $val->Stroke($aImg, $xc, $yc);
 }