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); }
$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"); // Add the plots to the graph $graph->Add($l1plot); $graph->Add($l2plot); $graph->title->Set("Example 16.3"); $graph->xaxis->title->Set("Month");