Esempio n. 1
0
 function __construct($aData)
 {
     $this->iData = $aData;
     $this->legend = new LegendStyle();
     // Setup the scale
     $this->scale = new WindrosePlotScale($this->iData);
     // default label for free type i agle and a degree sign
     $this->iLabelFormatString = '%.1f' . SymChar::Get('degree');
     $delta = 2 * M_PI / 16;
     for ($i = 0, $a = 0; $i < 16; ++$i, $a += $delta) {
         $this->iStandardDirections[$this->iAllDirectionLabels[$i]] = $a;
     }
 }
Esempio n. 2
0
// Create some random data for the plot. We use the current time for the
// first X-position
//
$f = new FuncGenerator('cos($x)+1.5*cos(2*$x)');
list($datax, $datay) = $f->E(0, 10);
// Now get labels at 1/2 PI intervall
$tickPositions = array();
$tickLabels = array();
$tickPositions[0] = 0;
$tickLabels[0] = '0';
for ($i = 1; $i / 2 * M_PI < 11; ++$i) {
    $tickPositions[$i] = $i / 2 * M_PI;
    if ($i % 2) {
        $tickLabels[$i] = $i . '/2' . SymChar::Get('pi');
    } else {
        $tickLabels[$i] = $i / 2 . SymChar::Get('pi');
    }
}
$n = count($datax);
$xmin = $datax[0];
$xmax = $datax[$n - 1];
//
// The code to setup a very basic graph
//
$graph = new Graph(400, 200);
//
// We use an integer scale on the X-axis since the positions on the X axis
// are assumed to be UNI timestamps
$graph->SetScale('linlin', 0, 0, $xmin, $xmax);
$graph->title->Set('Example with manual tick labels');
$graph->title->SetFont(FF_ARIAL, FS_NORMAL, 12);
 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) {
         // Corner angles of the four corners
         $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->scale->clockwise) {
                     $t->Set(360 - $a);
                 } else {
                     $t->Set($a);
                 }
                 if ($this->show_angle_mark && $t->font_family > 4) {
                     $a .= SymChar::Get('degree');
                 }
                 $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 && $t->font_family > 4) {
                 $a .= SymChar::Get('degree');
             }
             $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;
         }
     }
 }
Esempio n. 4
0
// Create a new odometer graph (width=250, height=200 pixels)
$graph = new OdoGraph(250, 170);
// Setup graph titles
$graph->title->Set('Custom formatting');
$graph->title->SetColor('white');
$graph->title->SetFont(FF_ARIAL, FS_BOLD);
// Add drop shadow for graph
$graph->SetShadow();
// Now we need to create an odometer to add to the graph.
$odo = new Odometer();
$odo->SetColor("lightgray:1.9");
// Setup the scale
$odo->scale->Set(100, 600);
$odo->scale->SetTicks(50, 2);
$odo->scale->SetTickColor('brown');
$odo->scale->SetTickLength(0.05);
$odo->scale->SetTickWeight(2);
$odo->scale->SetLabelPos(0.75);
$odo->scale->label->SetFont(FF_FONT1, FS_BOLD);
$odo->scale->label->SetColor('brown');
$odo->scale->label->SetFont(FF_ARIAL, FS_NORMAL, 10);
// Setup a label with a degree mark
$odo->scale->SetLabelFormat('%dC' . SymChar::Get('degree'));
// Set display value for the odometer
$odo->needle->Set(280);
// Add drop shadow for needle
$odo->needle->SetShadow();
// Add the odometer to the graph
$graph->Add($odo);
// ... and finally stroke and stream the image back to the browser
$graph->Stroke();
Esempio n. 5
0
 function GetView()
 {
     global $TMP_PATH;
     $req = $this->req->CreateDataRequest();
     $x = $req->GetProp("view_x", false);
     if (!$x) {
         throw new ADEIException(translate("Parameter view_x is not set"));
     }
     list($x_gid, $x_id) = explode(":", $x);
     if ($this->object) {
         $width = $req->GetProp($this->object . "_width", $this->min_width + 20) - 20;
         if ($width < $this->min_width) {
             $width = $this->min_width;
         }
         $height = $width - 40;
         //$req->GetProp($this->object . "_height", $this->min_height);
     } else {
         $width = $req->GetProp("page_width", $this->min_width + 5) - 5;
         $height = $req->GetProp("page_height", $this->min_height);
         if ($width < $this->min_width) {
             $width = $this->min_width;
         }
         if ($height < $this->min_height) {
             $height = $this->min_height;
         }
     }
     $rdr = $req->CreateReader();
     $group = $rdr->CreateGroup();
     $caches = $rdr->CreateCacheSet($group, $mask);
     $myreq = $this->req->CreateDataRequest();
     $iv = $caches->CreateInterval($req, true);
     $window_size = $iv->GetWindowSize();
     $window_start = $iv->GetWindowStart();
     $window_end = $iv->GetWindowEnd();
     $rescfg = array('limit' => $this->max_points, 'resolution' => $res);
     $gid = 0;
     $res = array();
     foreach ($caches as $key => $cachewrap) {
         if ($gid != $x_gid) {
             $gid++;
             continue;
         }
         $resolution = $cachewrap->GetResolution();
         $r = $resolution->Get($iv, $width);
         $size = $resolution->GetWindowSize($r);
         if ($size > 0 && $window_size / $size > $this->max_points) {
             $new_r = $resolution->Larger($r);
             if ($new_r !== false) {
                 $r = $new_r;
             }
             $size = $resolution->GetWindowSize($r);
         }
         $rescfg['resolution'] = $r;
         $points = $cachewrap->GetIntervals($iv, $rescfg, CACHE::TRUNCATE_INTERVALS);
         $operation_info = $points->GetOperationInfo();
         if ($gid == $x_gid) {
             $res_x = $size;
         }
         foreach ($points as $t => $v) {
             /*	    if (($t < $window_start)||(($t + $size) > $window_end)) {
               	        continue;
               	    }*/
             if ($gid == $x_gid && is_numeric($v['mean' . $x_id])) {
                 if (!is_array($res[$t])) {
                     $res[$t] = array();
                 }
                 $res[$t]['x'] = $v['mean' . $x_id];
                 $res[$t]['t'] = $t;
             }
         }
         $gid++;
     }
     $x = array();
     $t = array();
     foreach ($res as $val) {
         if (isset($val['x'])) {
             array_push($x, $val['x']);
         }
     }
     if (!$x) {
         throw new ADEIException(translate("No data found"));
     }
     $bins = $req->GetProp("view_bins", 0);
     if (!$bins) {
         $bins = ceil(sqrt(sizeof($x)));
     }
     $norm = $req->GetProp("view_hist_norm", 0);
     $fit = $req->GetProp("view_hist_fit", 0);
     $min = min($x);
     $max = max($x);
     $step = ($max - $min) / $bins;
     $coef = $norm ? 1 / ($step * sizeof($x)) : 1;
     $h = array_fill(0, $bins, 0);
     foreach ($x as $val) {
         $idx = ($val - $min) / $step;
         if ($idx == $bins) {
             $idx--;
         }
         $h[$idx] += $coef;
     }
     for ($i = 0; $i < $bins; $i++) {
         array_push($t, sprintf("%3.1e", $min + $i * $step));
     }
     $tmp_file = ADEI::GetTmpFile();
     $graph = new Graph($width, $height);
     /*        $title = "Resolution: $res_x";
     
             $graph->title->SetFont(FF_ARIAL,FS_BOLD,10);
             $graph->title->Set($title);*/
     $graph->SetTickDensity(TICKD_SPARSE, TICKD_SPARSE);
     $graph->img->SetMargin(55, 5, 10, 20);
     $graph->SetScale("textlin");
     $graph->xaxis->SetPos("min");
     $graph->yaxis->SetPos("min");
     //        $graph->xaxis->SetLabelFormat('%3.1e');
     //        if (abs(max($h))<9999 && (abs(min($h))>0.01)) $graph->yaxis->SetLabelFormat('%01.2f');
     //        else $graph->yaxis->SetLabelFormat('%3.1e');
     $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
     $graph->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
     //        $graph->yaxis->HideFirstTickLabel();
     $graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD);
     //$graph->xaxis->title->Set($arr[0]['select']['options'][$x_idg]['label']);
     if ($bins > 8) {
         $graph->xaxis->SetTextLabelInterval(ceil($bins / 6));
     }
     $graph->xaxis->SetTickLabels($t);
     $bplot = new BarPlot($h);
     $bplot->SetWidth(1);
     $graph->Add($bplot);
     $graph->yaxis->scale->SetGrace(14);
     $mean = array_sum($x) / sizeof($x);
     $stddev = stats_standard_deviation($x);
     $var = stats_variance($x);
     $sigma = sqrt($var);
     $re = 100 * $sigma / $mean;
     sort($x);
     if (sizeof($x) % 2) {
         $median = $x[(sizeof($x) - 1) / 2];
     } else {
         $median = ($x[sizeof($x) / 2 - 1] + $x[sizeof($x) / 2]) / 2;
     }
     // Gaussian fitting
     if ($fit) {
         $ydata = array();
         $xdata = array();
         if ($norm) {
             $coef = 1 / sqrt(2 * pi() * $var);
         } else {
             $coef = sizeof($x) * $step / sqrt(2 * pi() * $var);
         }
         $xi2 = 0;
         for ($i = 0; $i <= $bins; $i++) {
             $offset = $i * $step;
             $y = $coef * exp(-pow($min + $offset - $mean, 2) / (2 * $var));
             array_push($xdata, $i);
             array_push($ydata, $y);
             $xi2 += pow($y - $h[$i], 2) / $y;
         }
         $xi2 /= $bins;
         $lineplot = new LinePlot($ydata, $xdata);
         $graph->Add($lineplot);
     }
     $char_sigma = SymChar::Get('sigma', false);
     /*
             $txt = new Text();
             $txt->SetFont(FF_ARIAL,FS_BOLD,10);
             if( $req->GetProp("view_GFit", false) == "true")
                 $txt->Set("m=$mean\n$char_sigma=$sigma\nRE=$RE%\nx^2=$xi2");//\ns=$stdDev
             else
                 $txt->Set("m=$mean\n$char_sigma=$sigma\nRE=$RE%");//\ns=$stdDev
             $txt->ParagraphAlign('right');
             $txt->SetPos(0.96,0.1,'right');
             //$txt->SetBox('white');
             $graph->Add($txt);
     */
     $graph->Stroke("{$TMP_PATH}/{$tmp_file}");
     if ($this->object) {
         $res = array(array("img" => array("id" => $tmp_file)), array("info" => array(array("title" => _("From"), "value" => date('c', $iv->GetWindowStart())), array("title" => _("To"), "value" => date('c', $iv->GetWindowEnd())), array("title" => _("Resolution"), "value" => $res_x), array("title" => _("Bins"), "value" => $bins), array("title" => _("First Bin"), "value" => $min), array("title" => _("Last Bin"), "value" => $min + $bins * $step), array("title" => _("Mean"), "value" => $mean), array("title" => _("Median"), "value" => $median), array("title" => _("StdDev"), "value" => $stddev), array("title" => _("Sigma"), "value" => $sigma), array("title" => _("RE"), "value" => $re . "%"))));
         if ($fit) {
             array_push($res[1]["info"], array("title" => _("xi2"), "value" => $xi2));
         }
         return $res;
     } else {
         return array("img" => array("id" => $tmp_file));
     }
 }
Esempio n. 6
0
 /**
  * Internal ramewrok method to setup the legend to be used for this plot.
  * @param $aGraph The parent graph class
  */
 function Legend($aGraph)
 {
     if (!$this->showLegend) {
         return;
     }
     if ($aGraph->legend->font_family <= FF_FONT2 + 1) {
         $lte = "<=";
     } else {
         $lte = SymChar::Get('lte');
     }
     if ($this->invertLegend) {
         for ($i = 0; $i < $this->nbrContours; $i++) {
             $aGraph->legend->Add(sprintf($lte . ' %.1f', $this->contourVal[$i]), $this->contourColor[$i]);
         }
     } else {
         for ($i = $this->nbrContours - 1; $i >= 0; $i--) {
             $aGraph->legend->Add(sprintf($lte . ' %.1f', $this->contourVal[$i]), $this->contourColor[$i]);
         }
     }
 }