public 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
         die($this->iTitle . ' ' . $aMsg);
     }
     $aMsg = wordwrap($aMsg, 55);
     $lines = substr_count($aMsg, "\n");
     // Create the error icon GD
     $erricon = Image\Image::CreateFromString(base64_decode($img_iconerror));
     // Create an image that contains the error text.
     $w = 400;
     $h = 100 + 15 * max(0, $lines - 3);
     $img = new Image\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("lightblue");
     $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 = 110;
     $img->SetColor("lightgray:1.3");
     $img->FilledRectangle($m - $l, 2, $m + $l, 16);
     // Stroke text
     $img->SetColor("darkred");
     $img->SetFont(FF_FONT2, FS_BOLD);
     $img->StrokeText($m - 90, 15, $this->iTitle);
     $img->SetColor("black");
     $img->SetFont(FF_FONT1, FS_NORMAL);
     $txt = new Text\Text($aMsg, 52, 25);
     $txt->SetFont(FF_FONT1);
     $txt->Align("left", "top");
     $txt->Stroke($img);
     if ($this->iDest) {
         $img->Stream($this->iDest);
     } else {
         $img->Headers();
         $img->Stream();
     }
     if ($aHalt) {
         die;
     }
 }
Beispiel #2
0
 public function Stroke($aGraph)
 {
     $aImg = $aGraph->img;
     if ($this->iX > 0 && $this->iX < 1) {
         $this->iX = round($aImg->width * $this->iX);
     }
     if ($this->iY > 0 && $this->iY < 1) {
         $this->iY = round($aImg->height * $this->iY);
     }
     if ($this->iSize > 0 && $this->iSize < 1) {
         $this->iSize *= min($aImg->width, $aImg->height);
     }
     if ($this->iCenterSize > 0 && $this->iCenterSize < 1) {
         $this->iCenterSize *= $this->iSize;
     }
     $this->scale->AutoScale(($this->iSize - $this->iCenterSize) / 2, round(2.5 * $this->scale->iFontSize));
     $scaling = $this->iAntiAlias ? 2 : 1;
     $value = new Text\Text();
     $value->SetFont($this->iFontFamily, $this->iFontStyle, $this->iFontSize * $scaling);
     $value->SetColor($this->iFontColor);
     $legendheight = round($this->legend->iShow ? 1 : 0);
     $legendheight *= max($this->legend->iCircleRadius * 2, $this->legend->iTxtFontSize * 2) + $this->legend->iMargin + $this->legend->iBottomMargin + 2;
     $legendheight *= $scaling;
     $w = $scaling * $this->getWidth($aImg);
     $h = $scaling * $this->getHeight($aImg);
     // Copy back the double buffered image to the proper canvas
     $ww = $w / $scaling;
     $hh = $h / $scaling;
     // Create the double buffer
     if ($this->iAntiAlias) {
         $dblImg = new RotImage($w, $h);
         // Set the background color
         $dblImg->SetColor($this->iColor);
         $dblImg->FilledRectangle(0, 0, $w, $h);
     } else {
         $dblImg = $aImg;
         // Make sure the ix and it coordinates correpond to the new top left center
         $dblImg->SetTranslation($this->iX - $w / 2, $this->iY - $h / 2);
     }
     if (__DEBUG) {
         $dblImg->SetColor('red');
         $dblImg->Rectangle(0, 0, $w - 1, $h - 1);
     }
     $dblImg->SetColor('black');
     if ($this->iShowBox) {
         $dblImg->SetColor($this->iBoxColor);
         $old = $dblImg->SetLineWeight($this->iBoxWeight);
         $dblImg->SetLineStyle($this->iBoxStyle);
         $dblImg->Rectangle(0, 0, $w - 1, $h - 1);
         $dblImg->SetLineWeight($old);
     }
     $xc = round($w / 2);
     $yc = round(($h - $legendheight) / 2);
     if (__DEBUG) {
         $dblImg->SetColor('red');
         $old = $dblImg->SetLineWeight(2);
         $dblImg->Line($xc - 5, $yc - 5, $xc + 5, $yc + 5);
         $dblImg->Line($xc + 5, $yc - 5, $xc - 5, $yc + 5);
         $dblImg->SetLineWeight($old);
     }
     $this->iSize *= $scaling;
     // Inner circle size
     $ri = $this->iCenterSize / 2;
     // Full circle radius
     $r = round($this->iSize / 2);
     // Get number of grid circles
     $n = $this->scale->GetNumCirc();
     // Plot circle grids
     $ri *= $scaling;
     $rr = round(($r - $ri) / $n);
     for ($i = 1; $i <= $n; ++$i) {
         $this->_ThickCircle($dblImg, $xc, $yc, $rr * $i + $ri, $this->iCircGridWeight, $this->iGridColor1);
     }
     $num = 0;
     if ($this->iType == WINDROSE_TYPEFREE) {
         $this->_StrokeFreeRose($dblImg, $value, $scaling, $xc, $yc, $r, $ri);
     } else {
         // Check if we need to re-code the interpretation of the ordinal
         // number in the data. Internally ordinal value 0 is East and then
         // counted anti-clockwise. The user might choose an encoding
         // that have 0 being the first axis to the right of the "N" axis and then
         // counted clock-wise
         if ($this->iOrdinalEncoding == KEYENCODING_CLOCKWISE) {
             if ($this->iType == WINDROSE_TYPE16) {
                 $const1 = 19;
                 $const2 = 16;
             } elseif ($this->iType == WINDROSE_TYPE8) {
                 $const1 = 9;
                 $const2 = 8;
             } else {
                 $const1 = 4;
                 $const2 = 4;
             }
             $tmp = [];
             $n = count($this->iData);
             foreach ($this->iData as $key => $val) {
                 if (is_numeric($key)) {
                     $key = ($const1 - $key) % $const2;
                 }
                 $tmp[$key] = $val;
             }
             $this->iData = $tmp;
         }
         $this->_StrokeRegularRose($dblImg, $value, $scaling, $xc, $yc, $r, $ri);
     }
     // Stroke the labels
     $this->scale->iFontSize *= $scaling;
     $this->scale->iZFontSize *= $scaling;
     $this->scale->StrokeLabels($dblImg, $xc, $yc, $ri, $rr);
     // Stroke the inner circle again since the legs
     // might have written over it
     $this->_ThickCircle($dblImg, $xc, $yc, $ri, $this->iCircGridWeight, $this->iGridColor1);
     if ($ww > $aImg->width) {
         Util\JpGraphError::RaiseL(22020);
         //('Windrose plot is too large to fit the specified Graph size. Please use WindrosePlot::SetSize() to make the plot smaller or increase the size of the Graph in the initial WindroseGraph() call.');
     }
     $x = $xc;
     $y = $h;
     $this->_StrokeLegend($dblImg, $x, $y, $scaling);
     if ($this->iAntiAlias) {
         $aImg->Copy($dblImg->img, $this->iX - $ww / 2, $this->iY - $hh / 2, 0, 0, $ww, $hh, $w, $h);
     }
     // We need to restore the translation matrix
     $aImg->SetTranslation(0, 0);
 }
Beispiel #3
0
// content="text/plain; charset=utf-8"
require_once '../../vendor/autoload.php';
use Amenadiel\JpGraph\Graph;
use Amenadiel\JpGraph\Plot;
use Amenadiel\JpGraph\Text;
$l1datay = array(11, 9, 2, 4, 3, 13, 17);
$l2datay = array(23, 12, 5, 19, 17, 10, 15);
$datax = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul");
// Create the graph.
$graph = new Graph\Graph(350, 200);
$graph->img->SetMargin(40, 70, 20, 40);
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->SetColor(array(250, 250, 250));
$graph->img->SetTransparent("white");
$t1 = new Text\Text("This is a text");
$t1->SetPos(0.5, 0.5);
$t1->SetOrientation("h");
$t1->SetFont(FF_FONT1, FS_BOLD);
$t1->SetBox("white", "black", "gray");
$t1->SetColor("black");
$graph->AddText($t1);
// Create the linear error plot
$l1plot = new Plot\LinePlot($l1datay);
$l1plot->SetColor("blue");
$l1plot->SetWeight(2);
$l1plot->SetLegend("Prediction");
// Create the bar plot
$l2plot = new Plot\BarPlot($l2datay);
$l2plot->SetFillColor("orange");
$l2plot->SetLegend("Result");