public function draw()
 {
     $start_time = microtime(true);
     set_image_header();
     $this->selectData();
     $this->shiftY = 30;
     $this->shiftYLegend = 20;
     $this->shiftXleft = 10;
     $this->shiftXright = 0;
     $this->fullSizeX = $this->sizeX;
     $this->fullSizeY = $this->sizeY;
     if ($this->sizeX < 300 || $this->sizeY < 200) {
         $this->showLegend(0);
     }
     if ($this->drawLegend == 1) {
         $this->sizeX -= $this->shiftXleft + $this->shiftXright + $this->shiftlegendright;
         $this->sizeY -= $this->shiftY + $this->shiftYLegend + 12 * $this->num + 8;
     } else {
         $this->sizeX -= $this->shiftXleft * 2;
         $this->sizeY -= $this->shiftY * 2;
     }
     $this->sizeX = min($this->sizeX, $this->sizeY);
     $this->sizeY = min($this->sizeX, $this->sizeY);
     $this->calc3dheight($this->sizeY);
     $this->exploderad = (int) $this->sizeX / 100;
     $this->exploderad3d = (int) $this->sizeX / 60;
     if (function_exists('ImageColorExactAlpha') && function_exists('ImageCreateTrueColor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     // for each metric
     for ($item = 0; $item < $this->num; $item++) {
         $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
         if (!isset($data)) {
             continue;
         }
         $calc_fnc = $this->items[$item]['calc_fnc'];
         switch ($calc_fnc) {
             case CALC_FNC_MAX:
                 $values[$item] = abs($data->max);
                 break;
             case CALC_FNC_MIN:
                 $values[$item] = abs($data->min);
                 break;
             case CALC_FNC_AVG:
                 $values[$item] = abs($data->avg);
                 break;
             case CALC_FNC_LST:
                 $values[$item] = abs($data->lst);
                 break;
         }
     }
     switch ($this->type) {
         case GRAPH_TYPE_EXPLODED:
             $this->drawElementPie($values);
             break;
         case GRAPH_TYPE_3D:
             $this->drawElementPie3D($values);
             break;
         case GRAPH_TYPE_3D_EXPLODED:
             $this->drawElementPie3D($values);
             break;
         default:
             $this->drawElementPie($values);
             break;
     }
     $this->drawLogo();
     if ($this->drawLegend == 1) {
         $this->drawLegend();
     }
     $str = sprintf('%0.2f', microtime(true) - $start_time);
     $str = _s('Data from %1$s. Generated in %2$s sec.', $this->dataFrom, $str);
     $strSize = imageTextSize(6, 0, $str);
     imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str);
     unset($this->items, $this->data);
     imageOut($this->im);
 }
Exemple #2
0
    $page['file'] = basename($_SERVER['PHP_SELF']);
}
if ($_REQUEST['fullscreen'] = get_request('fullscreen', 0)) {
    define('ZBX_PAGE_NO_MENU', 1);
}
include_once 'include/locales/en_gb.inc.php';
process_locales();
set_zbx_locales();
require_once 'include/menu.inc.php';
zbx_define_menu_restrictions();
/* Init CURRENT NODE ID */
init_nodes();
/* switch($page["type"]) */
switch ($page['type']) {
    case PAGE_TYPE_IMAGE:
        set_image_header();
        define('ZBX_PAGE_NO_MENU', 1);
        break;
    case PAGE_TYPE_XML:
        header('Content-Type: text/xml');
        header('Content-Disposition: attachment; filename="' . $page['file'] . '"');
        if (!defined('ZBX_PAGE_NO_MENU')) {
            define('ZBX_PAGE_NO_MENU', 1);
        }
        break;
    case PAGE_TYPE_JS:
        header('Content-Type: application/javascript; charset=UTF-8');
        if (!defined('ZBX_PAGE_NO_MENU')) {
            define('ZBX_PAGE_NO_MENU', 1);
        }
        break;
 public function draw()
 {
     $start_time = getmicrotime();
     set_image_header();
     check_authorisation();
     $this->selectData();
     $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_LEFT);
     $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_RIGHT);
     $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_LEFT);
     $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_RIGHT);
     //*
     if ($this->m_minY[GRAPH_YAXIS_SIDE_LEFT] == $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT]) {
         if ($this->graphOrientation[GRAPH_YAXIS_SIDE_LEFT] == '-') {
             $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = 0;
         } else {
             if ($this->m_minY[GRAPH_YAXIS_SIDE_LEFT] == 0) {
                 $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = 1;
             } else {
                 $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = 0;
             }
         }
     } else {
         if ($this->m_minY[GRAPH_YAXIS_SIDE_LEFT] > $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT]) {
             if ($this->graphOrientation[GRAPH_YAXIS_SIDE_LEFT] == '-') {
                 $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = 0.2 * $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT];
             } else {
                 $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = 0;
             }
         }
     }
     if ($this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] == $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]) {
         if ($this->graphOrientation[GRAPH_YAXIS_SIDE_RIGHT] == '-') {
             $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = 0;
         } else {
             if ($this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] == 0) {
                 $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = 1;
                 //				$this->skipRightScale = 1;
             } else {
                 $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = 0;
             }
         }
     } else {
         if ($this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] > $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]) {
             if ($this->graphOrientation[GRAPH_YAXIS_SIDE_RIGHT] == '-') {
                 $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = 0.2 * $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT];
             } else {
                 $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = 0;
             }
         }
     }
     //*/
     $this->calcMinMaxInterval();
     $this->updateShifts();
     $this->calcTriggers();
     $this->calcZero();
     $this->calcPercentile();
     $this->fullSizeX = $this->sizeX + $this->shiftXleft + $this->shiftXright + 1;
     $this->fullSizeY = $this->sizeY + $this->shiftY + $this->legendOffsetY;
     if ($this->drawLegend) {
         $trCount = $this->m_showTriggers ? count($this->triggers) : 0;
         $this->fullSizeY += 14 * ($this->num + 1 + ($this->sizeY < 120 ? 0 : count($this->triggers))) + 8;
     }
     //if graph height is big enough, we reserve space for percent line legend
     if ($this->sizeY >= ZBX_GRAPH_LEGEND_HEIGHT) {
         foreach ($this->percentile as $percentile) {
             if ($percentile['percent'] > 0 && $percentile['value']) {
                 $this->fullSizeY += 14;
             }
         }
     }
     if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     $this->drawWorkPeriod();
     //*/ grid
     $this->drawTimeGrid();
     $this->drawVerticalGrid();
     $this->drawXYAxisScale($this->graphtheme['gridbordercolor']);
     //-----*/
     $maxX = $this->sizeX;
     // For each metric
     for ($item = 0; $item < $this->num; $item++) {
         $minY = $this->m_minY[$this->items[$item]['axisside']];
         $maxY = $this->m_maxY[$this->items[$item]['axisside']];
         $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
         if (!isset($data)) {
             continue;
         }
         if ($this->items[$item]['calc_type'] == GRAPH_ITEM_AGGREGATED) {
             $drawtype = GRAPH_ITEM_DRAWTYPE_LINE;
             $max_color = $this->getColor('HistoryMax');
             $avg_color = $this->getColor('HistoryAvg');
             $min_color = $this->getColor('HistoryMin');
             $minmax_color = $this->getColor('HistoryMinMax');
             $calc_fnc = CALC_FNC_ALL;
         } else {
             if ($this->type == GRAPH_TYPE_STACKED) {
                 $drawtype = $this->items[$item]['drawtype'];
                 $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA);
                 $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
                 $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA);
                 $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA);
                 $calc_fnc = $this->items[$item]['calc_fnc'];
             } else {
                 $drawtype = $this->items[$item]['drawtype'];
                 $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA);
                 $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
                 $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA);
                 $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA);
                 $calc_fnc = $this->items[$item]['calc_fnc'];
             }
         }
         // For each X
         $draw = true;
         $prevDraw = true;
         for ($i = 1, $j = 0; $i < $maxX; $i++) {
             // new point
             if ($data['count'][$i] == 0 && $i != $maxX - 1) {
                 continue;
             }
             $diff = abs($data['clock'][$i] - $data['clock'][$j]);
             $cell = ($this->to_time - $this->from_time) / $this->sizeX;
             $delay = $this->items[$item]['delay'];
             if ($cell > $delay) {
                 $draw = (bool) ($diff < ZBX_GRAPH_MAX_SKIP_CELL * $cell);
             } else {
                 $draw = (bool) ($diff < ZBX_GRAPH_MAX_SKIP_DELAY * $delay);
             }
             if ($draw == false && $this->items[$item]['calc_type'] == GRAPH_ITEM_AGGREGATED) {
                 $draw = $i - $j < 5;
             }
             if ($this->items[$item]['type'] == ITEM_TYPE_TRAPPER) {
                 $draw = true;
             }
             if (!$draw && !$prevDraw) {
                 $draw = true;
                 $valueDrawType = GRAPH_ITEM_DRAWTYPE_BOLD_DOT;
             } else {
                 $valueDrawType = $drawtype;
                 $prevDraw = $draw;
             }
             if ($draw) {
                 $this->drawElement($data, $i, $j, 0, $this->sizeX, $minY, $maxY, $valueDrawType, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $this->items[$item]['axisside']);
             }
             $j = $i;
         }
     }
     $this->drawLeftSide();
     $this->drawRightSide();
     if ($this->drawLegend) {
         $this->drawTriggers();
         $this->drawPercentile();
         $this->drawLegend();
     }
     $this->drawLogo();
     $end_time = getmicrotime();
     $str = sprintf('%0.2f', getmicrotime() - $start_time);
     // if we get chart from config by get method
     $datafrom = '';
     if (isset($this->dataFrom)) {
         $datafrom = 'Data from ' . $this->dataFrom . '. ';
     }
     imagestring($this->im, 0, $this->fullSizeX - 210, $this->fullSizeY - 12, $datafrom . 'Generated in ' . $str . ' sec', $this->getColor('Gray'));
     unset($this->items, $this->data);
     //debug info
     //		show_messages();
     ImageOut($this->im);
 }
 public function draw()
 {
     $start_time = microtime(true);
     set_image_header();
     $this->selectData();
     $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_LEFT);
     $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_RIGHT);
     $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_LEFT);
     $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_RIGHT);
     if ($this->m_minY[GRAPH_YAXIS_SIDE_LEFT] == $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT]) {
         if ($this->graphOrientation[GRAPH_YAXIS_SIDE_LEFT] == '-') {
             $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = 0;
         } elseif ($this->m_minY[GRAPH_YAXIS_SIDE_LEFT] == 0) {
             $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = 1;
         } else {
             $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = 0;
         }
     } elseif ($this->m_minY[GRAPH_YAXIS_SIDE_LEFT] > $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT]) {
         if ($this->graphOrientation[GRAPH_YAXIS_SIDE_LEFT] == '-') {
             $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = 0.2 * $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT];
         } else {
             $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = 0;
         }
     }
     if ($this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] == $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]) {
         if ($this->graphOrientation[GRAPH_YAXIS_SIDE_RIGHT] == '-') {
             $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = 0;
         } elseif ($this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] == 0) {
             $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = 1;
         } else {
             $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = 0;
         }
     } elseif ($this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] > $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]) {
         if ($this->graphOrientation[GRAPH_YAXIS_SIDE_RIGHT] == '-') {
             $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = 0.2 * $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT];
         } else {
             $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = 0;
         }
     }
     $this->calcMinMaxInterval();
     $this->updateShifts();
     $this->calcTriggers();
     $this->calcZero();
     $this->calcPercentile();
     $this->fullSizeX = $this->sizeX + $this->shiftXleft + $this->shiftXright + 1;
     $this->fullSizeY = $this->sizeY + $this->shiftY + $this->legendOffsetY - 40;
     //减去日期所占用的距离35
     if ($this->drawLegend) {
         $this->fullSizeY += 14 * ($this->num + 1 + ($this->sizeY < 120 ? 0 : count($this->triggers))) + 8;
     }
     // if graph height is big enough, we reserve space for percent line legend
     if ($this->sizeY >= ZBX_GRAPH_LEGEND_HEIGHT) {
         foreach ($this->percentile as $percentile) {
             if ($percentile['percent'] > 0 && $percentile['value']) {
                 $this->fullSizeY += 14;
             }
         }
     }
     if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     $this->drawWorkPeriod();
     $this->drawTimeGrid();
     $this->drawVerticalGrid();
     $this->drawXYAxisScale($this->graphtheme['gridbordercolor']);
     $maxX = $this->sizeX;
     // for each metric
     for ($item = 0; $item < $this->num; $item++) {
         $minY = $this->m_minY[$this->items[$item]['axisside']];
         $maxY = $this->m_maxY[$this->items[$item]['axisside']];
         $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
         if (!isset($data)) {
             continue;
         }
         if ($this->type == GRAPH_TYPE_STACKED) {
             $drawtype = $this->items[$item]['drawtype'];
             $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA);
             $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
             $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA);
             $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA);
             $calc_fnc = $this->items[$item]['calc_fnc'];
         } else {
             $drawtype = $this->items[$item]['drawtype'];
             $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA);
             $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
             $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA);
             $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA);
             $calc_fnc = $this->items[$item]['calc_fnc'];
         }
         // for each X
         $draw = true;
         $prevDraw = true;
         for ($i = 1, $j = 0; $i < $maxX; $i++) {
             // new point
             if ($data['count'][$i] == 0 && $i != $maxX - 1) {
                 continue;
             }
             $diff = abs($data['clock'][$i] - $data['clock'][$j]);
             $cell = ($this->to_time - $this->from_time) / $this->sizeX;
             $delay = $this->items[$item]['delay'];
             if ($cell > $delay) {
                 $draw = (bool) ($diff < ZBX_GRAPH_MAX_SKIP_CELL * $cell);
             } else {
                 $draw = (bool) ($diff < ZBX_GRAPH_MAX_SKIP_DELAY * $delay);
             }
             if ($this->items[$item]['type'] == ITEM_TYPE_TRAPPER) {
                 $draw = true;
             }
             if (!$draw && !$prevDraw) {
                 $draw = true;
                 $valueDrawType = GRAPH_ITEM_DRAWTYPE_BOLD_DOT;
             } else {
                 $valueDrawType = $drawtype;
                 $prevDraw = $draw;
             }
             if ($draw) {
                 $this->drawElement($data, $i, $j, 0, $this->sizeX, $minY, $maxY, $valueDrawType, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $this->items[$item]['axisside']);
             }
             $j = $i;
         }
     }
     $this->drawLeftSide();
     $this->drawRightSide();
     if ($this->drawLegend) {
         //画出时间
         //$this->drawDate();
         $this->drawTriggers();
         $this->drawPercentile();
         $this->drawLegend();
     }
     /*
     $this->drawLogo();
              
     $str = sprintf('%0.2f', microtime(true) - $start_time);
     $str = _s('Data from %1$s. Generated in %2$s sec.', $this->dataFrom, $str);
     $strSize = imageTextSize(6, 0, $str);
     imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str);
     */
     $this->newData = $this->data;
     unset($this->items, $this->data);
     imageOut($this->im);
 }
 public function draw()
 {
     $start_time = microtime(true);
     set_image_header();
     $this->column = uint_in_array($this->type, array(GRAPH_TYPE_COLUMN, GRAPH_TYPE_COLUMN_STACKED));
     $this->fullSizeX = $this->sizeX;
     $this->fullSizeY = $this->sizeY;
     if ($this->sizeX < 300 || $this->sizeY < 200) {
         $this->showLegend(0);
     }
     $this->calcShifts();
     $this->sizeX -= $this->shiftXleft + $this->shiftXright + $this->shiftlegendright + $this->shiftXCaptionLeft + $this->shiftXCaptionRight;
     $this->sizeY -= $this->shiftY + $this->shiftYLegend + $this->shiftYCaptionBottom + $this->shiftYCaptionTop;
     $this->calcSeriesWidth();
     $this->calcMiniMax();
     $this->correctMiniMax();
     if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     $this->drawGrid();
     $this->drawSideValues();
     $this->drawLogo();
     $this->drawLegend();
     $count = 0;
     if ($this->column) {
         $start = $this->shiftXleft + $this->shiftXCaptionLeft + floor($this->seriesDistance / 2);
     } else {
         $start = $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - floor($this->seriesDistance / 2);
     }
     foreach ($this->series as $key => $series) {
         foreach ($series as $num => $serie) {
             $axis = $serie['axis'];
             $value = $serie['value'];
             $color = $this->getColor($this->seriesColor[$num], $this->opacity);
             if ($this->column) {
                 imagefilledrectangle($this->im, $start, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - round($this->sizeY / $this->maxValue[$axis] * $value), $start + $this->columnWidth, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop, $color);
                 imagerectangle($this->im, $start, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - round($this->sizeY / $this->maxValue[$axis] * $value), $start + $this->columnWidth, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop, $this->getColor('Black No Alpha'));
             } else {
                 imagefilledrectangle($this->im, $this->shiftXleft + $this->shiftXCaptionLeft, $start - $this->columnWidth, $this->shiftXleft + $this->shiftXCaptionLeft + round($this->sizeX / $this->maxValue[$axis] * $value), $start, $color);
                 imagerectangle($this->im, $this->shiftXleft + $this->shiftXCaptionLeft, $start - $this->columnWidth, $this->shiftXleft + $this->shiftXCaptionLeft + round($this->sizeX / $this->maxValue[$axis] * $value), $start, $this->getColor('Black No Alpha'));
             }
             $start = $this->column ? $start + $this->columnWidth : $start - $this->columnWidth;
         }
         $count++;
         if ($this->column) {
             $start = $count * ($this->seriesWidth + $this->seriesDistance) + $this->shiftXleft + $this->shiftXCaptionLeft + floor($this->seriesDistance / 2);
         } else {
             $start = $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - $count * ($this->seriesWidth + $this->seriesDistance) - floor($this->seriesDistance / 2);
         }
     }
     $str = sprintf('%0.2f', microtime(true) - $start_time);
     $str = _s('Generated in %s sec', $str);
     $strSize = imageTextSize(6, 0, $str);
     imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str);
     unset($this->items, $this->data);
     imageOut($this->im);
 }
Exemple #6
0
 public function draw()
 {
     $start_time = getmicrotime();
     set_image_header();
     check_authorisation();
     $this->selectData();
     $this->shiftY = 20;
     $this->shiftYLegend = 20;
     $this->shiftXleft = 10;
     $this->shiftXright = 0;
     $this->fullSizeX = $this->sizeX;
     $this->fullSizeY = $this->sizeY;
     if ($this->sizeX < 300 || $this->sizeY < 200) {
         $this->switchlegend(0);
     }
     if ($this->drawlegendallow == 1) {
         $this->sizeX -= $this->shiftXleft + $this->shiftXright + $this->shiftlegendright;
         $this->sizeY -= $this->shiftY + $this->shiftYLegend + 12 * $this->num + 8;
     } else {
         $this->sizeX -= $this->shiftXleft * 2;
         $this->sizeY -= $this->shiftY * 2;
     }
     //	SDI($this->sizeX.','.$this->sizeY);
     $this->sizeX = min($this->sizeX, $this->sizeY);
     $this->sizeY = min($this->sizeX, $this->sizeY);
     $this->calc3dhight($this->sizeY);
     $this->exploderad = (int) $this->sizeX / 100;
     $this->exploderad3d = (int) $this->sizeX / 60;
     if (function_exists('ImageColorExactAlpha') && function_exists('ImageCreateTrueColor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     $maxX = $this->sizeX;
     // For each metric
     for ($item = 0; $item < $this->num; $item++) {
         $minY = $this->m_minY[$this->items[$item]['axisside']];
         $maxY = $this->m_maxY[$this->items[$item]['axisside']];
         $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
         if (!isset($data)) {
             continue;
         }
         $drawtype = $this->items[$item]['drawtype'];
         $max_color = $this->GetColor('ValueMax');
         $avg_color = $this->GetColor($this->items[$item]['color']);
         $min_color = $this->GetColor('ValueMin');
         $minmax_color = $this->GetColor('ValueMinMax');
         $calc_fnc = $this->items[$item]['calc_fnc'];
         switch ($calc_fnc) {
             case CALC_FNC_MAX:
                 $values[$item] = abs($data->max);
                 break;
             case CALC_FNC_MIN:
                 $values[$item] = abs($data->min);
                 break;
             case CALC_FNC_AVG:
                 $values[$item] = abs($data->avg);
                 break;
             case CALC_FNC_LST:
                 $values[$item] = abs($data->lst);
                 break;
         }
     }
     switch ($this->type) {
         case GRAPH_TYPE_EXPLODED:
             $this->drawElementPie($values);
             break;
         case GRAPH_TYPE_3D:
             $this->drawElementPie3D($values);
             break;
         case GRAPH_TYPE_3D_EXPLODED:
             $this->drawElementPie3D($values);
             break;
         default:
             $this->drawElementPie($values);
             break;
     }
     $this->drawLogo();
     if ($this->drawlegendallow == 1) {
         $this->drawLegend();
     }
     $end_time = getmicrotime();
     $str = sprintf("%0.2f", getmicrotime() - $start_time);
     ImageString($this->im, 0, $this->fullSizeX - 120, $this->fullSizeY - 12, "Generated in {$str} sec", $this->GetColor('Gray'));
     unset($this->items, $this->data);
     ImageOut($this->im);
 }
 public function draw()
 {
     $start_time = microtime(true);
     set_image_header();
     $this->selectData();
     if (isset($this->axis_valuetype[GRAPH_YAXIS_SIDE_RIGHT])) {
         $sides[] = GRAPH_YAXIS_SIDE_RIGHT;
     }
     if (isset($this->axis_valuetype[GRAPH_YAXIS_SIDE_LEFT]) || !isset($sides)) {
         $sides[] = GRAPH_YAXIS_SIDE_LEFT;
     }
     foreach ($sides as $graphSide) {
         $this->m_minY[$graphSide] = $this->calculateMinY($graphSide);
         $this->m_maxY[$graphSide] = $this->calculateMaxY($graphSide);
         if ($this->m_minY[$graphSide] === null) {
             $this->m_minY[$graphSide] = 0;
         }
         if ($this->m_maxY[$graphSide] === null) {
             $this->m_maxY[$graphSide] = 1;
         }
         if ($this->m_minY[$graphSide] == $this->m_maxY[$graphSide]) {
             if ($this->graphOrientation[$graphSide] == '-') {
                 $this->m_maxY[$graphSide] = 0;
             } elseif ($this->m_minY[$graphSide] == 0) {
                 $this->m_maxY[$graphSide] = 1;
             } else {
                 $this->m_minY[$graphSide] = 0;
             }
         } elseif ($this->m_minY[$graphSide] > $this->m_maxY[$graphSide]) {
             if ($this->graphOrientation[$graphSide] == '-') {
                 $this->m_minY[$graphSide] = bcmul($this->m_maxY[$graphSide], 0.2);
             } else {
                 $this->m_minY[$graphSide] = 0;
             }
         }
         // If max Y-scale bigger min Y-scale only for 10% or less, then we don't allow Y-scale duplicate
         if ($this->m_maxY[$graphSide] && $this->m_minY[$graphSide]) {
             if ($this->m_minY[$graphSide] < 0) {
                 $absMinY = bcmul($this->m_minY[$graphSide], '-1');
             } else {
                 $absMinY = $this->m_minY[$graphSide];
             }
             if ($this->m_maxY[$graphSide] < 0) {
                 $absMaxY = bcmul($this->m_maxY[$graphSide], '-1');
             } else {
                 $absMaxY = $this->m_maxY[$graphSide];
             }
             if ($absMaxY < $absMinY) {
                 $oldAbMaxY = $absMaxY;
                 $absMaxY = $absMinY;
                 $absMinY = $oldAbMaxY;
             }
             if (bcdiv(bcsub($absMaxY, $absMinY), $absMaxY) <= 0.1) {
                 if ($this->m_minY[$graphSide] > 0) {
                     $this->m_minY[$graphSide] = bcmul($this->m_minY[$graphSide], 0.95);
                 } else {
                     $this->m_minY[$graphSide] = bcmul($this->m_minY[$graphSide], 1.05);
                 }
                 if ($this->m_maxY[$graphSide] > 0) {
                     $this->m_maxY[$graphSide] = bcmul($this->m_maxY[$graphSide], 1.05);
                 } else {
                     $this->m_maxY[$graphSide] = bcmul($this->m_maxY[$graphSide], 0.95);
                 }
             }
         }
     }
     $this->calcMinMaxInterval();
     $this->updateShifts();
     $this->calcTriggers();
     $this->calcZero();
     $this->calcPercentile();
     $this->fullSizeX = $this->sizeX + $this->shiftXleft + $this->shiftXright + 1;
     $this->fullSizeY = $this->sizeY + $this->shiftY + $this->legendOffsetY;
     if ($this->drawLegend) {
         $this->fullSizeY += 14 * ($this->num + 1 + ($this->sizeY < 120 ? 0 : count($this->triggers))) + 8;
     }
     // if graph height is big enough, we reserve space for percent line legend
     if ($this->sizeY >= ZBX_GRAPH_LEGEND_HEIGHT) {
         foreach ($this->percentile as $percentile) {
             if ($percentile['percent'] > 0 && $percentile['value']) {
                 $this->fullSizeY += 14;
             }
         }
     }
     if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     $this->drawWorkPeriod();
     $this->drawTimeGrid();
     $this->drawHorizontalGrid();
     $this->drawXYAxisScale();
     $maxX = $this->sizeX;
     // for each metric
     for ($item = 0; $item < $this->num; $item++) {
         $minY = $this->m_minY[$this->items[$item]['axisside']];
         $maxY = $this->m_maxY[$this->items[$item]['axisside']];
         $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
         if (!isset($data)) {
             continue;
         }
         if ($this->type == GRAPH_TYPE_STACKED) {
             $drawtype = $this->items[$item]['drawtype'];
             $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA);
             $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
             $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA);
             $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA);
             $calc_fnc = $this->items[$item]['calc_fnc'];
         } else {
             $drawtype = $this->items[$item]['drawtype'];
             $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA);
             $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
             $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA);
             $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA);
             $calc_fnc = $this->items[$item]['calc_fnc'];
         }
         // for each X
         $prevDraw = true;
         for ($i = 1, $j = 0; $i < $maxX; $i++) {
             // new point
             if ($data['count'][$i] == 0 && $i != $maxX - 1) {
                 continue;
             }
             $delay = $this->items[$item]['delay'];
             $has_scheduling = false;
             foreach ($this->items[$item]['intervals'] as $interval) {
                 if ($interval['type'] == ITEM_DELAY_FLEX_TYPE_SCHEDULING) {
                     $has_scheduling = true;
                     break;
                 }
             }
             if ($this->items[$item]['type'] == ITEM_TYPE_TRAPPER || $has_scheduling && $delay == 0) {
                 $draw = true;
             } else {
                 $diff = abs($data['clock'][$i] - $data['clock'][$j]);
                 $cell = ($this->to_time - $this->from_time) / $this->sizeX;
                 if ($cell > $delay) {
                     $draw = $diff < ZBX_GRAPH_MAX_SKIP_CELL * $cell;
                 } else {
                     $draw = $diff < ZBX_GRAPH_MAX_SKIP_DELAY * $delay;
                 }
             }
             if (!$draw && !$prevDraw) {
                 $draw = true;
                 $valueDrawType = GRAPH_ITEM_DRAWTYPE_BOLD_DOT;
             } else {
                 $valueDrawType = $drawtype;
                 $prevDraw = $draw;
             }
             if ($draw) {
                 $this->drawElement($data, $i, $j, 0, $this->sizeX, $minY, $maxY, $valueDrawType, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $this->items[$item]['axisside']);
             }
             $j = $i;
         }
     }
     $this->drawSides();
     if ($this->drawLegend) {
         $this->drawTriggers();
         $this->drawPercentile();
         $this->drawLegend();
     }
     $this->drawLogo();
     $str = sprintf('%0.2f', microtime(true) - $start_time);
     $str = _s('Data from %1$s. Generated in %2$s sec.', $this->dataFrom, $str);
     $strSize = imageTextSize(6, 0, $str);
     imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str);
     unset($this->items, $this->data);
     imageOut($this->im);
 }
Exemple #8
0
 public function draw()
 {
     $start_time = getmicrotime();
     set_image_header();
     check_authorisation();
     $this->selectData();
     $this->m_minY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_LEFT);
     $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMinY(GRAPH_YAXIS_SIDE_RIGHT);
     $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_LEFT);
     $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT] = $this->calculateMaxY(GRAPH_YAXIS_SIDE_RIGHT);
     $this->correctMinMax();
     $this->updateShifts();
     $this->calcTriggers();
     $this->calcZero();
     $this->calcPercentile();
     $this->fullSizeX = $this->sizeX + $this->shiftXleft + $this->shiftXright + 1;
     $this->fullSizeY = $this->sizeY + $this->shiftY + 62;
     $this->fullSizeY += 12 * ($this->num + ($this->sizeY < 120 ? 0 : count($this->triggers))) + 8;
     foreach ($this->percentile as $side => $percentile) {
         if ($percentile['percent'] > 0 && $percentile['value']) {
             $this->fullSizeY += 12;
         }
     }
     if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     if ($this->num == 0) {
         //				$this->noDataFound();
     }
     $this->drawWorkPeriod();
     $this->drawGrid();
     $maxX = $this->sizeX;
     // For each metric
     for ($item = 0; $item < $this->num; $item++) {
         $minY = $this->m_minY[$this->items[$item]['axisside']];
         $maxY = $this->m_maxY[$this->items[$item]['axisside']];
         $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
         if (!isset($data)) {
             continue;
         }
         if ($this->items[$item]['calc_type'] == GRAPH_ITEM_AGGREGATED) {
             $drawtype = GRAPH_ITEM_DRAWTYPE_LINE;
             $max_color = $this->getColor('HistoryMax');
             $avg_color = $this->getColor('HistoryAvg');
             $min_color = $this->getColor('HistoryMin');
             $minmax_color = $this->getColor('HistoryMinMax');
             $calc_fnc = CALC_FNC_ALL;
         } else {
             if ($this->type == GRAPH_TYPE_STACKED) {
                 $drawtype = $this->items[$item]['drawtype'];
                 $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA);
                 $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
                 $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA);
                 $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA);
                 $calc_fnc = $this->items[$item]['calc_fnc'];
             } else {
                 $drawtype = $this->items[$item]['drawtype'];
                 $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA);
                 $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
                 $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA);
                 $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA);
                 $calc_fnc = $this->items[$item]['calc_fnc'];
             }
         }
         // For each X
         for ($i = 1, $j = 0; $i < $maxX; $i++) {
             // new point
             if ($data->count[$i] == 0 && $i != $maxX - 1) {
                 continue;
             }
             $diff = abs($data->clock[$i] - $data->clock[$j]);
             $cell = ($this->to_time - $this->from_time) / $this->sizeX;
             $delay = $this->items[$item]['delay'];
             if ($cell > $delay) {
                 $draw = (bool) ($diff < ZBX_GRAPH_MAX_SKIP_CELL * $cell);
             } else {
                 $draw = (bool) ($diff < ZBX_GRAPH_MAX_SKIP_DELAY * $delay);
             }
             if ($draw == false && $this->items[$item]['calc_type'] == GRAPH_ITEM_AGGREGATED) {
                 $draw = $i - $j < 5;
             }
             if ($this->items[$item]['type'] == ITEM_TYPE_TRAPPER) {
                 $draw = true;
             }
             //SDI($draw);
             if ($draw) {
                 $this->drawElement($data, $i, $j, 0, $this->sizeX, $minY, $maxY, $drawtype, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $this->items[$item]['axisside']);
             }
             //echo '\nDraw II \n'; printf('%0.4f',(getmicrotime()-$start_time));
             $j = $i;
         }
     }
     $this->drawLeftSide();
     $this->drawRightSide();
     $this->drawTriggers();
     $this->drawPercentile();
     $this->drawLogo();
     $this->drawLegend();
     $end_time = getmicrotime();
     $str = sprintf('%0.2f', getmicrotime() - $start_time);
     imagestring($this->im, 0, $this->fullSizeX - 160, $this->fullSizeY - 12, 'Generated in ' . $str . ' sec (' . $this->dataFrom . ')', $this->getColor('Gray'));
     unset($this->items, $this->data);
     ImageOut($this->im);
 }