Ejemplo n.º 1
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.º 2
0
include "../jpgraph_line.php";
include "../jpgraph_error.php";
include "../jpgraph_bar.php";
$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(350, 200, "auto");
$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("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 LinePlot($l1datay);
$l1plot->SetColor("blue");
$l1plot->SetWeight(2);
$l1plot->SetLegend("Prediction");
// Create the bar plot
$l2plot = new BarPlot($l2datay);
$l2plot->SetFillColor("orange");
$l2plot->SetLegend("Result");
// Add the plots to the graph
$graph->Add($l1plot);
Ejemplo n.º 3
0
    function top($VAR)
    {
        global $smarty, $C_translate, $C_auth;
        # Get the period type, default to month
        if (empty($VAR['period'])) {
            $p = 'm';
        } else {
            $p = $VAR['period'];
        }
        # Load the jpgraph class
        include PATH_GRAPH . "jpgraph.php";
        include PATH_GRAPH . "jpgraph_bar.php";
        # check the validation for this function
        if (!$C_auth->auth_method_by_name($this->module, 'search')) {
            $error = $C_translate->translate('module_non_auth', '', '');
            include PATH_GRAPH . "jpgraph_canvas.php";
            $graph = new CanvasGraph(460, 55, "auto");
            $t1 = new Text($error);
            $t1->Pos(0.2, 0.5);
            $t1->SetOrientation("h");
            $t1->SetBox("white", "black", 'gray');
            $t1->SetFont(FF_FONT1, FS_NORMAL);
            $t1->SetColor("black");
            $graph->AddText($t1);
            $graph->Stroke();
            exit;
        }
        # Get the period start & end
        switch ($p) {
            # By Weeks:
            case 'w':
                $interval = "1";
                $width = ".9";
                $title = 'Top Accounts for Last Last Week';
                $dow = date('w');
                $start_str = mktime(0, 0, 0, date('m'), date('d') - $dow, date('y'));
                $end_str = mktime(23, 59, 59, date('m'), date('d'), date('y'));
                break;
                # By Months:
            # By Months:
            case 'm':
                $interval = "3";
                $width = ".6";
                $title = 'Top Accounts for Last Last Month';
                $start_str = mktime(0, 0, 0, date('m'), 1, date('y'));
                $end_str = mktime(23, 59, 59, date('m'), date('d'), date('y'));
                break;
                # By Years:
            # By Years:
            case 'y':
                $interval = "1";
                $width = ".8";
                $title = 'Top Accounts for Last Last Year';
                $start_str = mktime(0, 0, 0, 1, 1, date('y'));
                $end_str = mktime(23, 59, 59, date('m'), date('d'), date('y'));
                break;
        }
        ##############################@@@@@@@@
        # Get accounts & sales for this period
        ##############################@@@@@@@@
        $db =& DB();
        $sql = 'SELECT account_id,total_amt FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
				   date_orig    >=  ' . $db->qstr($start_str) . ' AND  date_orig    <=  ' . $db->qstr($end_str) . ' AND
				   site_id      =  ' . $db->qstr(DEFAULT_SITE);
        $result = $db->Execute($sql);
        if (@$result->RecordCount() == 0) {
            $file = fopen(PATH_THEMES . 'default_admin/images/invisible.gif', 'r');
            fpassthru($file);
            exit;
        }
        while (!$result->EOF) {
            $amt = $result->fields['total_amt'];
            $acct = $result->fields['account_id'];
            if (!isset($arr[$acct])) {
                $arr[$acct] = 0;
            }
            $arr[$acct] += $amt;
            $result->MoveNext();
        }
        $i = 0;
        while (list($key, $var) = each(@$arr)) {
            # Get the user name
            $sql = 'SELECT first_name,last_name FROM ' . AGILE_DB_PREFIX . 'account WHERE
						   id           =  ' . $db->qstr($key) . ' AND
						   site_id      =  ' . $db->qstr(DEFAULT_SITE);
            $rs = $db->Execute($sql);
            $_lbl[] = strtoupper(substr($rs->fields['first_name'], 0, 1)) . ". " . $rs->fields['last_name'];
            $_datay[] = $var;
            $i++;
        }
        ### Sort the arrays
        array_multisort($_datay, SORT_DESC, SORT_NUMERIC, $_lbl);
        ### Limit the results to 10 or less
        for ($i = 0; $i < count($_lbl); $i++) {
            $lbl[$i] = $_lbl[$i];
            $datay[$i] = $_datay[$i];
            if ($i >= 9) {
                $i = count($_lbl);
            }
        }
        $i = count($lbl);
        # Get the Currency
        $sql = 'SELECT symbol FROM ' . AGILE_DB_PREFIX . 'currency WHERE
					id           =  ' . $db->qstr(DEFAULT_CURRENCY) . ' AND
					site_id      =  ' . $db->qstr(DEFAULT_SITE);
        $rs = $db->Execute($sql);
        $currency_iso = $rs->fields['symbol'];
        // Size of graph
        $width = 265;
        $height = 75 + $i * 15;
        // Set the basic parameters of the graph
        $graph = new Graph($width, $height, 'auto');
        $graph->SetScale("textlin");
        $graph->yaxis->scale->SetGrace(50);
        $graph->SetMarginColor('#F9F9F9');
        $graph->SetFrame(true, '#CCCCCC', 1);
        $graph->SetColor('#FFFFFF');
        $top = 45;
        $bottom = 10;
        $left = 95;
        $right = 15;
        $graph->Set90AndMargin($left, $right, $top, $bottom);
        // Label align for X-axis
        $graph->xaxis->SetLabelAlign('right', 'center', 'right');
        // Label align for Y-axis
        $graph->yaxis->SetLabelAlign('center', 'bottom');
        $graph->xaxis->SetTickLabels($lbl);
        // Titles
        $graph->title->SetFont(FF_FONT1, FS_BOLD, 9.5);
        $title = $C_translate->translate('graph_top', 'account_admin', '');
        $graph->title->Set($title);
        // Create a bar pot
        $bplot = new BarPlot($datay);
        $bplot->SetFillColor("#506DC7");
        $bplot->SetWidth(0.2);
        // Show the values
        $bplot->value->Show();
        $bplot->value->SetFont(FF_FONT1, FS_NORMAL, 8);
        $bplot->value->SetAlign('center', 'center');
        $bplot->value->SetColor("black", "darkred");
        $bplot->value->SetFormat($currency_iso . '%.2f');
        $graph->Add($bplot);
        $graph->Stroke();
        return;
    }
Ejemplo n.º 4
0
 function __construct($img, $aScale, $color = array(0, 0, 0))
 {
     $this->img = $img;
     $this->scale = $aScale;
     $this->color = $color;
     $this->title = new Text('');
     if ($aScale->type == 'y') {
         $this->title_margin = 25;
         $this->title_adjust = 'middle';
         $this->title->SetOrientation(90);
         $this->tick_label_margin = 7;
         $this->labelPos = SIDE_LEFT;
     } else {
         $this->title_margin = 5;
         $this->title_adjust = 'high';
         $this->title->SetOrientation(0);
         $this->tick_label_margin = 5;
         $this->labelPos = SIDE_DOWN;
         $this->title_side = SIDE_DOWN;
     }
 }
Ejemplo n.º 5
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.º 6
0
 function BAR_graph($module, $type, $start, $extra_fields)
 {
     global $C_translate, $C_auth;
     include_once PATH_CORE . 'validate.inc.php';
     $dt = new CORE_validate();
     include PATH_GRAPH . "jpgraph.php";
     ####################################################################
     ### Check if 'search' is authorized for this account
     ####################################################################
     # check the validation for this function
     if ($C_auth->auth_method_by_name($module, 'search')) {
         # validate this file exists, and include it.
         if (file_exists(PATH_MODULES . '/' . $module . '/' . $module . '.inc.php')) {
             include_once PATH_MODULES . '/' . $module . '/' . $module . '.inc.php';
         } else {
             ### Not exist!
             $error = $C_translate->translate('module_non_existant', '', '');
         }
     } else {
         ### Not auth
         $error = $C_translate->translate('module_non_auth', '', '');
     }
     if (isset($error)) {
         include PATH_GRAPH . "jpgraph_canvas.php";
         // Create the graph.
         $graph = new CanvasGraph(460, 55, "auto");
         $t1 = new Text($error);
         $t1->Pos(0.2, 0.5);
         $t1->SetOrientation("h");
         $t1->SetBox("white", "black", 'gray');
         $t1->SetFont(FF_FONT1, FS_NORMAL);
         $t1->SetColor("black");
         $graph->AddText($t1);
         $graph->Stroke();
         exit;
     }
     ####################################################################
     ### BY WEEK
     ####################################################################
     if ($type == 'week') {
         $FONT_SIZE = 7;
         $AbsWidth = 12;
         $interval = 4;
         $type = $C_translate->translate('week', '', '');
         if ($start == "" || $start <= 12) {
             ## Get the beginning/end of this week
             $start_str = mktime(24, 0, 0, 12, 31, date("Y") - 1);
             $start = date(UNIX_DATE_FORMAT, $start_str);
             $end_str = mktime(24, 0, 0, 12, 30, date("Y", $start_str));
             $end = date(UNIX_DATE_FORMAT, $end_str);
         } else {
             ## Get the beginning/end of the specified week
             $start_str = mktime(24, 0, 0, 12, 31, date("{$start}") - 1);
             $start = date(UNIX_DATE_FORMAT, $start_str);
             $end_str = mktime(24, 0, 0, 12, 30, date("Y", $start_str));
             $end = date(UNIX_DATE_FORMAT, $end_str);
         }
         ### Set the constraint array:
         $curr_str = $start_str;
         while ($curr_str <= $end_str) {
             $new_curr_str = mktime(0, 0, 0, date("m", $curr_str), date("d", $curr_str) + 7, date("Y", $curr_str));
             $constraint_array[] = array('start' => $curr_str, 'end' => $new_curr_str);
             $curr_str = $new_curr_str;
             $default_array[] = 0;
         }
     } else {
         if ($type == 'month') {
             $FONT_SIZE = 10;
             $AbsWidth = 12;
             $TickLables = $gDateLocale->GetShortMonth();
             $interval = 1;
             $type = $C_translate->translate('month', '', '');
             if ($start == "" || $start < 12) {
                 ## Get the beginning/end of this week
                 $start_str = mktime(24, 0, 0, 12, 31, date("Y") - 1);
                 $start = date(UNIX_DATE_FORMAT, $start_str);
                 $end_str = mktime(24, 0, 0, 12, 30, date("Y", $start_str));
                 $end = date(UNIX_DATE_FORMAT, $end_str);
             } else {
                 ## Get the beginning/end of the specified week
                 ## Get the beginning/end of this week
                 $start_str = mktime(24, 0, 0, 12, 31, date("{$start}") - 1);
                 $start = date(UNIX_DATE_FORMAT, $start_str);
                 $end_str = mktime(24, 0, 0, 12, 30, date("Y", $start_str));
                 $end = date(UNIX_DATE_FORMAT, $end_str);
             }
             ### Set the constraint array:
             $curr_str = $start_str;
             while ($curr_str <= $end_str) {
                 $new_curr_str = mktime(0, 0, 0, date("m", $curr_str) + 1, date("d", $curr_str), date("Y", $curr_str));
                 $constraint_array[] = array('start' => $curr_str, 'end' => $new_curr_str);
                 $curr_str = $new_curr_str;
                 $default_array[] = 0;
             }
         } else {
             if ($type == 'year') {
                 $FONT_SIZE = 10;
                 $interval = 1;
                 $AbsWidth = 13;
                 $type = $C_translate->translate('year', '', '');
                 ## Get the beginning/end of this year - 10
                 $start_str = mktime(0, 0, 0, 1, 1, date("Y") - 9);
                 $start = date(UNIX_DATE_FORMAT, $start_str);
                 $end_str = mktime(0, 0, 0, 12, 30, date("Y", $start_str) + 9);
                 $end = date(UNIX_DATE_FORMAT, $end_str);
                 ### Set the constraint array:
                 $curr_str = $start_str;
                 while ($curr_str <= $end_str) {
                     $new_curr_str = mktime(0, 0, 0, date("m", $curr_str), date("d", $curr_str), date("Y", $curr_str) + 1);
                     $constraint_array[] = array('start' => $curr_str, 'end' => $new_curr_str);
                     $TickLables[] = date("Y", $curr_str);
                     $curr_str = $new_curr_str;
                     $default_array[] = 0;
                 }
             } else {
                 $FONT_SIZE = 8;
                 $interval = 3;
                 $AbsWidth = 4;
                 $type = $C_translate->translate('day', '', '');
                 if ($start == "" || $start > 12 || $start < 1) {
                     ## Get the beginning/end of this week
                     $start_str = mktime(0, 0, 0, date("m"), 1, date("Y"));
                     $start = date(UNIX_DATE_FORMAT, $start_str);
                     $end_str = mktime(0, 0, 0, date("m", $start_str) + 1, 1, date("Y", $start_str));
                     $end = date(UNIX_DATE_FORMAT, $end_str);
                 } else {
                     ## Get the beginning/end of the specified week
                     $start_str = mktime(0, 0, 0, date("{$start}"), 1, date("Y"));
                     $start = date(UNIX_DATE_FORMAT, $start_str);
                     $end_str = mktime(0, 0, 0, date("m", $start_str) + 1, 1, date("Y", $start_str));
                     $end = date(UNIX_DATE_FORMAT, $end_str);
                 }
                 ### Set the constraint array:
                 $curr_str = $start_str;
                 while ($curr_str < $end_str) {
                     $new_curr_str = mktime(0, 0, 0, date("m", $curr_str), date("d", $curr_str) + 1, date("Y", $curr_str));
                     $constraint_array[] = array('start' => $curr_str, 'end' => $new_curr_str);
                     $TickLables[] = date("j", $curr_str);
                     $curr_str = $new_curr_str;
                     $default_array[] = 0;
                 }
             }
         }
     }
     # initialize the module, if it has not already been initialized
     $eval = '$' . $module . ' = new ' . $module . '; ';
     $eval .= '$this_Obj  = $' . $module . ';';
     eval($eval);
     # run the function
     $array = call_user_func(array($module, "graph"), $start_str, $end_str, $constraint_array, $default_array, $extra_fields);
     include PATH_GRAPH . "jpgraph_bar.php";
     $datay = $array['results'];
     // Create the graph. These two calls are always required
     $graph = new Graph(550, 200, "auto");
     $graph->SetScale("textlin");
     $graph->yaxis->scale->SetGrace(25);
     $graph->SetMarginColor('#F9F9F9');
     $graph->SetFrame(true, 'darkgreen', 0);
     $graph->SetColor('#FFFFFF');
     #$graph->SetFrame(false);
     // Adjust the margin a bit to make more room for titles
     $graph->img->SetMargin(45, 10, 15, 25);
     // Create a bar pot
     $bplot = new BarPlot($datay);
     // Set the X
     if (isset($TickLables)) {
         $graph->xaxis->SetTickLabels($TickLables);
     }
     $graph->xaxis->SetTextLabelInterval($interval);
     $graph->xaxis->SetColor("navy");
     $graph->yaxis->SetColor("navy");
     // Adjust fill color
     $bplot->SetFillColor('#506DC7');
     $bplot->value->Show();
     $bplot->value->SetFont(FF_FONT1, FS_NORMAL, $FONT_SIZE);
     $bplot->value->SetAngle(90);
     $bplot->value->SetFormat('%0.0f');
     $bplot->value->SetColor("darkblue");
     $graph->Add($bplot);
     // Setup the titles
     $title = $array['title'];
     $graph->title->Set($title . "     {$start} - {$end}");
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->title->SetColor("black");
     // Display the graph
     $graph->Stroke();
 }
 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.º 8
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);
     }
 }
 /** Constroi o gráfico entre periodos de anos 
 			retorna true se o grafico foi montado e false se não foi
 		**/
 function buildGraphicByYear($stats, $startYear, $lastYear)
 {
     $graficoStatus = false;
     // Para descobrir se entrou no for e vai construir um gráfico
     $stat = $stats->getRequests();
     // Pega todos os anos entre o Ano Inicial e o Ano Final
     $anos = array();
     for ($j = 0, $year = $startYear; $year <= $lastYear; $year++, $j++) {
         $anos[$j] = $year;
     }
     foreach ($stat as $s) {
         $mes = intval($s->getMonth());
         $ano = intval($s->getYear());
         $values[$ano][$mes] = $s->getNumberOfRequests();
     }
     /*
     "gabarito" da linha dos graficos com 12 posicoes, uma para cada mes
     os valores "-" sao considerados NULLs pelo jpgraph
     */
     $data = array("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0");
     /*
     "gabarito" para as cores das linhas do gráfico
     */
     $cores = array("blue", "yellow", "purple", "cyan", "pink", "red", "orange", "green", "black", "sienna", "darkred", "darkgreen");
     // Create the graph. These two calls are always required
     //			$graph = new Graph(700,400,"auto");
     $graph = new Graph(900, 300, "auto");
     $graph->SetScale("textlin");
     /*
     cria um array bi-dimencional contendo array(ano{array com a quantidade de acessos por mes})
     */
     $colorIndex = 0;
     $bars = array();
     foreach ($values as $ano => $meses) {
         /*
         valores será a variavel que servirá de "datasource" para a barra do grafico
         inicialmente ele eh inicializada com o gabarito, e serao preenchidos os valores
         dos meses no laço for logo abaixo
         */
         $valores = $data;
         for ($k = 0; $k <= count($valores); $k++) {
             if ($meses[$k]) {
                 $valores[$k] = $meses[$k];
             }
         }
         if (count($valores) > 12) {
             unset($valores[0]);
         }
         $valores = array_values($valores);
         /*
         aqui eu uso "Variáveis Variáveis" do PHP para poder
         inserir vária linhas no gráfico
         */
         $nome = "barplot" . $ano;
         ${$nome} = new BarPlot($valores);
         $cor = $cores[$colorIndex];
         ${$nome}->SetFillColor($cor);
         ${$nome}->SetColor($cor);
         /*configs para os valores do ponto*/
         ${$nome}->value->SetColor("darkred");
         ${$nome}->value->SetFont(FF_FONT1, FS_BOLD);
         ${$nome}->value->SetFormat("%0.1d");
         //				$$nome->SetWeight(20);
         // Arrumando para um tamanho mais amigavel
         if (count($anos) < 3) {
             ${$nome}->SetWidth(20);
         } else {
             if (count($anos) < 4) {
                 ${$nome}->SetWidth(15);
             } else {
                 if (count($anos) < 6) {
                     ${$nome}->SetWidth(10);
                 } else {
                     if (count($anos) < 8) {
                         ${$nome}->SetWidth(5);
                     } else {
                         if (count($anos) < 11) {
                             ${$nome}->SetWidth(3);
                         }
                     }
                 }
             }
         }
         ${$nome}->value->Show();
         ${$nome}->value->iHideZero = true;
         ${$nome}->setLegend($ano);
         /*adicionando a linha ao grafico*/
         $colorIndex++;
         // Somente monta o gráfico dos anos exigidos pelo usuário
         for ($i = 0; $i < count($anos); $i++) {
             if ($ano == $startYear + $i) {
                 $graficoStatus = true;
                 // entrou no for significa que o gráfico vai ser construido
                 array_push($bars, ${$nome});
             }
         }
     }
     /****************************************************************
      * Se não existir dados estatísticos para o período selecionado	*
      * Então ele constroi uma imagem com a mensagem de que não		*
      * existem dados estatísticos.									*
      *****************************************************************/
     if ($graficoStatus == false) {
         $graph = new CanvasGraph(600, 30);
         $t1 = new Text(GRAFIC_STATS_FALSE);
         $t1->Pos(0.05, 0.5);
         $t1->SetOrientation('h');
         $t1->SetFont(FF_FONT1, FS_BOLD);
         $t1->SetColor('black');
         $graph->AddText($t1);
         $graph->Stroke();
         return $graficoStatus;
     }
     $gbplot = new GroupBarPlot($bars);
     $gbplot->SetWidth(0.9);
     $graph->Add($gbplot);
     $graph->yaxis->scale->SetGrace(20);
     $graph->img->SetMargin(40, 20, 20, 40);
     $graph->title->Set(ARTICLE_ACCESS);
     $graph->xaxis->title->Set(MONTHS);
     $graph->yaxis->title->Set(ACCESSES);
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->SetShadow();
     $graph->xaxis->SetTickLabels(explode(",", MONTH_LIST));
     // Adjust the legend position
     //			$graph->legend->SetLayout(LEGEND_VER);
     $graph->legend->Pos(0.04, 0.092, "", "center");
     $graph->legend->SetLayout(LEGEND_HOR);
     // Mostra o gráfico somente se, o ano que o usuario entrou existir estatisticas
     if ($graficoStatus == true) {
         $graph->Stroke();
     }
     return $graficoStatus;
 }
Ejemplo n.º 10
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);
     }
 }