public function draw() { $this->calcRows(); $coly = $this->y; foreach ($this->table as $numRow => $row) { $rowx = $this->x; foreach ($row as $numCol => $col) { $text_color = isset($col['color']) ? $col['color'] : $this->color; //SDI($text_color); $align = $this->align; if (isset($col['align'])) { if ($col['align'] == 1) { $align = floor(($col['width'] - $col['size']['width']) / 2); } else { if ($col['align'] == 2) { $align = $col['width'] - $col['size']['width']; } } // right } //SDI(array($col['fontsize'], 0, $rowx+$align, $coly, $text_color, $col['text'])); imageText($this->image, $col['fontsize'], 0, $rowx + $align, $coly, $text_color, $col['text']); $rowx += $col['width'] + 20; $height = $col['height']; } $coly += $height; } }
$yf = $sizeY * $false[$i - 1] / 100; if ($yf > 0) { imagefilledrectangle($im, $x1 + $shiftX, $yt + $yu + $shiftYup, $x1 + $shiftX + 8, $sizeY + $shiftYup, imagecolorallocate($im, 120, 235, 120)); } // GREEN //SDI($yt.'+'.$yf.'+'.$yu); if ($yt + $yf + $yu > 0) { imagerectangle($im, $x1 + $shiftX, $shiftYup, $x1 + $shiftX + 8, $sizeY + $shiftYup, $black); } } for ($i = 0; $i <= $sizeY; $i += $sizeY / 10) { //imagestring($im, 1, $sizeX+5+$shiftX, $sizeY-$i-4+$shiftYup, $i*($maxY-$minY)/$sizeY+$minY , $darkred); imageText($im, 7, 0, $sizeX + 5 + $shiftX, $sizeY - $i - 4 + $shiftYup + 8, $darkred, $i * ($maxY - $minY) / $sizeY + $minY); } imagefilledrectangle($im, $shiftX, $sizeY + $shiftYup + 39 + 15 * 0, $shiftX + 5, $sizeY + $shiftYup + 35 + 9 + 15 * 0, imagecolorallocate($im, 120, 235, 120)); imagerectangle($im, $shiftX, $sizeY + $shiftYup + 39 + 15 * 0, $shiftX + 5, $sizeY + $shiftYup + 35 + 9 + 15 * 0, $black); imageText($im, 8, 0, $shiftX + 9, $sizeY + $shiftYup + 15 * 0 + 45, $black, S_OK . " (%)"); //imagestring($im, 2,$shiftX+9,$sizeY+$shiftYup+15*0+35, S_OK." (%)", $black); imagefilledrectangle($im, $shiftX, $sizeY + $shiftYup + 39 + 15 * 1, $shiftX + 5, $sizeY + $shiftYup + 35 + 9 + 15 * 1, imagecolorallocate($im, 235, 120, 120)); imagerectangle($im, $shiftX, $sizeY + $shiftYup + 39 + 15 * 1, $shiftX + 5, $sizeY + $shiftYup + 15 + 9 + 35 * 1, $black); imageText($im, 8, 0, $shiftX + 9, $sizeY + $shiftYup + 15 * 1 + 45, $black, S_PROBLEMS . " (%)"); //imagestring($im, 2,$shiftX+9,$sizeY+$shiftYup+15*1+35, S_PROBLEMS." (%)", $black); imagefilledrectangle($im, $shiftX, $sizeY + $shiftYup + 39 + 15 * 2, $shiftX + 5, $sizeY + $shiftYup + 35 + 9 + 15 * 2, imagecolorallocate($im, 220, 220, 220)); imagerectangle($im, $shiftX, $sizeY + $shiftYup + 39 + 15 * 2, $shiftX + 5, $sizeY + $shiftYup + 35 + 9 + 15 * 2, $black); imageText($im, 8, 0, $shiftX + 9, $sizeY + $shiftYup + 15 * 2 + 45, $black, S_UNKNOWN . " (%)"); imagestringup($im, 0, imagesx($im) - 10, imagesy($im) - 50, 'http://www.zabbix.com', $gray); $end_time = time(NULL); imagestring($im, 0, imagesx($im) - 100, imagesy($im) - 12, 'Generated in ' . ($end_time - $start_time) . ' sec', $gray); ImageOut($im); imagedestroy($im); include_once 'include/page_footer.php';
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); }
imagestring($im, 0, imagesx($im) - 120, imagesy($im) - 12, $str, $colors['Gray']); if (isset($_REQUEST['grid'])) { $grid = get_request('grid', 50); if (!is_numeric($grid)) { $grid = 50; } $dims = imageTextSize(8, 0, '11'); for ($x = $grid; $x < $width; $x += $grid) { MyDrawLine($im, $x, 0, $x, $height, $colors['Black'], MAP_LINK_DRAWTYPE_DASHED_LINE); imageText($im, 8, 0, $x + 3, $dims['height'] + 3, $colors['Black'], $x); } for ($y = $grid; $y < $height; $y += $grid) { MyDrawLine($im, 0, $y, $width, $y, $colors['Black'], MAP_LINK_DRAWTYPE_DASHED_LINE); imageText($im, 8, 0, 3, $y + $dims['height'] + 3, $colors['Black'], $y); } imageText($im, 8, 0, 2, $dims['height'] + 3, $colors['Black'], 'Y X:'); } // ACTION ///////////////////////////////////////////////////////////////////////////// $json = new CJSON(); if (isset($_REQUEST['selements']) || isset($_REQUEST['noselements'])) { $map['selements'] = get_request('selements', '[]'); $map['selements'] = $json->decode($map['selements'], true); } else { $map['selements'] = zbx_toHash($map['selements'], 'selementid'); } if (isset($_REQUEST['links']) || isset($_REQUEST['nolinks'])) { $map['links'] = get_request('links', '[]'); $map['links'] = $json->decode($map['links'], true); } else { $map['links'] = zbx_toHash($map['links'], 'linkid'); }
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); }
public function draw() { $this->calcRows(); $coly = $this->y; foreach ($this->table as $row) { $rowx = $this->x; foreach ($row as $col) { $col['marginRight'] = isset($col['marginRight']) ? $col['marginRight'] : 20; // draw image if (isset($col['image'])) { $imageWidth = imagesx($col['image']); $imageHeight = imagesy($col['image']); imagecopy($this->image, $col['image'], $rowx, $coly - $imageHeight + 1, 0, 0, $imageWidth, $imageHeight); } else { $text_color = isset($col['color']) ? $col['color'] : $this->color; $align = $this->align; if (isset($col['align'])) { if ($col['align'] == 1) { $align = floor(($col['width'] - $col['size']['width']) / 2); // center } elseif ($col['align'] == 2) { $align = $col['width'] - $col['size']['width']; // right } } imageText($this->image, $col['fontsize'], 0, $rowx + $align, $coly, $text_color, $col['text']); } $rowx += $col['width'] + $col['marginRight']; $height = $col['height']; } $coly += $height; } }
public function drawDate() { $str = $this->getDateFormat(); imageText($this->im, 8, 0, 8, $this->sizeY + $this->shiftY + $this->legendOffsetY - 43, $this->getColor($this->graphtheme['highlightcolor'], 0), $str); }
private function drawRightSide() { if ($this->yaxisright == 0 || $this->skipRightScale == 1) { return; } $minY = $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT]; $maxY = $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]; $units = null; $unitsLong = null; for ($item = 0; $item < $this->num; $item++) { if ($this->items[$item]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) { if (is_null($units)) { $units = $this->items[$item]['units']; } else { if ($this->items[$item]['units'] != $units) { $units = false; } } } } if (is_null($units) || $units === false) { $units = ''; } else { for ($item = 0; $item < $this->num; $item++) { if ($this->items[$item]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT && !empty($this->items[$item]['unitsLong'])) { $unitsLong = $this->items[$item]['unitsLong']; break; } } } if (!empty($unitsLong)) { $dims = imageTextSize(9, 90, $unitsLong); $tmpY = $this->sizeY / 2 + $this->shiftY + $dims['height'] / 2; if ($tmpY < $dims['height']) { $tmpY = $dims['height'] + 6; } imageText($this->im, 9, 90, $this->fullSizeX - $dims['width'], $tmpY, $this->getColor($this->graphtheme['textcolor'], 0), $unitsLong); } $step = $this->gridStep[GRAPH_YAXIS_SIDE_RIGHT]; $hstr_count = $this->gridLinesCount[GRAPH_YAXIS_SIDE_RIGHT]; for ($i = 0; $i <= $hstr_count; $i++) { if ($hstr_count == 0) { continue; } //using bc module in case of large numbers $val = bcadd(bcmul($i, $step), $minY); if (bccomp(bcadd($val, bcdiv($step, 2)), $maxY) == 1) { continue; } $str = convert_units($val, $units, ITEM_CONVERT_NO_UNITS); imageText($this->im, 8, 0, $this->sizeX + $this->shiftXleft + 12, $this->sizeY - $this->gridStepX[GRAPH_YAXIS_SIDE_RIGHT] * $i + $this->shiftY + 4, $this->getColor($this->graphtheme['textcolor'], 0), $str); } $str = convert_units($maxY, $units, ITEM_CONVERT_NO_UNITS); imageText($this->im, 8, 0, $this->sizeX + $this->shiftXleft + 12, $this->shiftY + 4, $this->getColor($this->graphtheme['textcolor'], 0), $str); if ($this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->sizeY + $this->shiftY && $this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->shiftY) { imageline($this->im, $this->shiftXleft, $this->zero[GRAPH_YAXIS_SIDE_RIGHT], $this->shiftXleft + $this->sizeX, $this->zero[GRAPH_YAXIS_SIDE_RIGHT], $this->getColor(GRAPH_ZERO_LINE_COLOR_RIGHT)); //*/ } }
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($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->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); }
private function drawSides() { if (isset($this->axis_valuetype[GRAPH_YAXIS_SIDE_RIGHT]) && ($this->yaxisright != 0 || $this->skipRightScale != 1)) { $sides[] = GRAPH_YAXIS_SIDE_RIGHT; } if (isset($this->axis_valuetype[GRAPH_YAXIS_SIDE_LEFT]) && ($this->yaxisleft != 0 || $this->skipLeftScale != 1) || !isset($sides)) { $sides[] = GRAPH_YAXIS_SIDE_LEFT; } foreach ($sides as $side) { $minY = $this->m_minY[$side]; $maxY = $this->m_maxY[$side]; $units = null; $unitsLong = null; $byteStep = false; for ($item = 0; $item < $this->num; $item++) { if ($this->items[$item]['axisside'] == $side) { // check if items use B or Bps units if ($this->items[$item]['units'] == 'B' || $this->items[$item]['units'] == 'Bps') { $byteStep = true; } if (is_null($units)) { $units = $this->items[$item]['units']; } elseif ($this->items[$item]['units'] != $units) { $units = ''; } } } if (is_null($units) || $units === false) { $units = ''; } else { for ($item = 0; $item < $this->num; $item++) { if ($this->items[$item]['axisside'] == $side && !empty($this->items[$item]['unitsLong'])) { $unitsLong = $this->items[$item]['unitsLong']; break; } } } if (!empty($unitsLong)) { $dims = imageTextSize(9, 90, $unitsLong); $tmpY = $this->sizeY / 2 + $this->shiftY + $dims['height'] / 2; if ($tmpY < $dims['height']) { $tmpY = $dims['height'] + 6; } $tmpX = $side == GRAPH_YAXIS_SIDE_LEFT ? $dims['width'] + 8 : $this->fullSizeX - $dims['width']; imageText($this->im, 9, 90, $tmpX, $tmpY, $this->getColor($this->graphtheme['textcolor'], 0), $unitsLong); } $step = $this->gridStep[$side]; $hstr_count = $this->gridLinesCount[$side]; // ignore milliseconds if -1 <= maxY => 1 or -1 <= minY => 1 $ignoreMillisec = bccomp($maxY, -1) <= 0 || bccomp($maxY, 1) >= 0 || bccomp($minY, -1) <= 0 || bccomp($minY, 1) >= 0; $newPow = false; if ($byteStep) { $maxYPow = convertToBase1024($maxY, 1024); $minYPow = convertToBase1024($minY, 1024); $powStep = 1024; } else { $maxYPow = convertToBase1024($maxY); $minYPow = convertToBase1024($minY); $powStep = 1000; } if (abs($maxYPow['pow']) > abs($minYPow['pow']) && $maxYPow['value'] != 0) { $newPow = $maxYPow['pow']; if (abs(bcdiv($minYPow['value'], bcpow($powStep, $maxYPow['pow']))) > 1000) { $newPow = $minYPow['pow']; } } if (abs($maxYPow['pow']) < abs($minYPow['pow']) && $minYPow['value'] != 0) { $newPow = $minYPow['pow']; if (abs(bcdiv($maxYPow['value'], bcpow($powStep, $minYPow['pow']))) > 1000) { $newPow = $maxYPow['pow']; } } if ($maxYPow['pow'] == $minYPow['pow']) { $newPow = $maxYPow['pow']; } $maxLength = false; // get all values in y-axis if units != 's' if ($units != 's') { $calcValues = array(); for ($i = 0; $i <= $hstr_count; $i++) { $hstr_count = $hstr_count == 0 ? 1 : $hstr_count; $val = bcadd(bcmul($i, $step), $minY); if (bccomp(bcadd($val, bcdiv($step, 2)), $maxY) == 1) { continue; } $calcValues[] = convert_units(array('value' => $val, 'convert' => ITEM_CONVERT_NO_UNITS, 'byteStep' => $byteStep, 'pow' => $newPow)); } $calcValues[] = convert_units(array('value' => $maxY, 'convert' => ITEM_CONVERT_NO_UNITS, 'byteStep' => $byteStep, 'pow' => $newPow)); $maxLength = calcMaxLengthAfterDot($calcValues); } for ($i = 0; $i <= $hstr_count; $i++) { $hstr_count = $hstr_count == 0 ? 1 : $hstr_count; $val = bcadd(bcmul($i, $step), $minY); if (bccomp(bcadd($val, bcdiv($step, 2)), $maxY) == 1) { continue; } $str = convert_units(array('value' => $val, 'units' => $units, 'convert' => ITEM_CONVERT_NO_UNITS, 'byteStep' => $byteStep, 'pow' => $newPow, 'ignoreMillisec' => $ignoreMillisec, 'length' => $maxLength)); if ($side == GRAPH_YAXIS_SIDE_LEFT) { $dims = imageTextSize(8, 0, $str); $posX = $this->shiftXleft - $dims['width'] - 9; } else { $posX = $this->sizeX + $this->shiftXleft + 12; } // marker Y coordinate $posY = $this->sizeY + $this->shiftY - $this->gridStepX[$side] * $i + 4; imageText($this->im, 8, 0, $posX, $posY, $this->getColor($this->graphtheme['textcolor'], 0), $str); } $str = convert_units(array('value' => $maxY, 'units' => $units, 'convert' => ITEM_CONVERT_NO_UNITS, 'byteStep' => $byteStep, 'pow' => $newPow, 'ignoreMillisec' => $ignoreMillisec, 'length' => $maxLength)); if ($side == GRAPH_YAXIS_SIDE_LEFT) { $dims = imageTextSize(8, 0, $str); $posX = $this->shiftXleft - $dims['width'] - 9; $color = $this->getColor(GRAPH_ZERO_LINE_COLOR_LEFT); } else { $posX = $this->sizeX + $this->shiftXleft + 12; $color = $this->getColor(GRAPH_ZERO_LINE_COLOR_RIGHT); } imageText($this->im, 8, 0, $posX, $this->shiftY + 4, $this->getColor($this->graphtheme['textcolor'], 0), $str); if ($this->zero[$side] != $this->sizeY + $this->shiftY && $this->zero[$side] != $this->shiftY) { zbx_imageline($this->im, $this->shiftXleft, $this->zero[$side], $this->shiftXleft + $this->sizeX, $this->zero[$side], $color); } } }
public function draw() { $this->calcRows(); $coly = $this->y; foreach ($this->table as $row) { $rowx = $this->x; foreach ($row as $col) { $text_color = isset($col['color']) ? $col['color'] : $this->color; $align = $this->align; if (isset($col['align'])) { if ($col['align'] == 1) { $align = floor(($col['width'] - $col['size']['width']) / 2); // center } elseif ($col['align'] == 2) { $align = $col['width'] - $col['size']['width']; // right } } imageText($this->image, $col['fontsize'], 0, $rowx + $align, $coly, $text_color, $col['text']); $rowx += $col['width'] + 9; //原来加的是20 $height = $col['height']; } $coly += $height; } }
function show_messages($good = false, $okmsg = null, $errmsg = null) { global $page, $ZBX_MESSAGES; if (!defined('PAGE_HEADER_LOADED')) { // return null; } if (defined('ZBX_API_REQUEST')) { return null; } if (!isset($page['type'])) { $page['type'] = PAGE_TYPE_HTML; } $imageMessages = []; $title = $good ? $okmsg : $errmsg; $messages = isset($ZBX_MESSAGES) ? $ZBX_MESSAGES : []; $ZBX_MESSAGES = []; switch ($page['type']) { case PAGE_TYPE_IMAGE: if ($title !== null) { $imageMessages[] = ['text' => $title, 'color' => !$good ? ['R' => 255, 'G' => 0, 'B' => 0] : ['R' => 34, 'G' => 51, 'B' => 68]]; } foreach ($messages as $message) { $imageMessages[] = ['text' => $message['message'], 'color' => $message['type'] == 'error' ? ['R' => 255, 'G' => 55, 'B' => 55] : ['R' => 155, 'G' => 155, 'B' => 55]]; } break; case PAGE_TYPE_XML: if ($title !== null) { echo htmlspecialchars($title) . "\n"; } foreach ($messages as $message) { echo '[' . $message['type'] . '] ' . $message['message'] . "\n"; } break; case PAGE_TYPE_HTML: default: if ($title || $messages) { makeMessageBox($good, $messages, $title, true, !$good)->show(); } break; } // draw an image with the messages if ($imageMessages) { $imageFontSize = 8; // calculate the size of the text $imageWidth = 0; $imageHeight = 0; foreach ($imageMessages as &$msg) { $size = imageTextSize($imageFontSize, 0, $msg['text']); $msg['height'] = $size['height'] - $size['baseline']; // calculate the total size of the image $imageWidth = max($imageWidth, $size['width']); $imageHeight += $size['height'] + 1; } unset($msg); // additional padding $imageWidth += 2; $imageHeight += 2; // create the image $canvas = imagecreate($imageWidth, $imageHeight); imagefilledrectangle($canvas, 0, 0, $imageWidth, $imageHeight, imagecolorallocate($canvas, 255, 255, 255)); // draw each message $y = 1; foreach ($imageMessages as $msg) { $y += $msg['height']; imageText($canvas, $imageFontSize, 0, 1, $y, imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']), $msg['text']); } imageOut($canvas); imagedestroy($canvas); } }
$yt = $sizeY * $true[$i - 1] / 100; if ($yt > 0) { imagefilledrectangle($im, $x1 + $shiftX, $shiftYup, $x1 + $shiftX + 8, $yt + $shiftYup, imagecolorallocate($im, 235, 120, 120)); // red } $yf = $sizeY * $false[$i - 1] / 100; if ($yf > 0) { imagefilledrectangle($im, $x1 + $shiftX, $yt + $shiftYup, $x1 + $shiftX + 8, $sizeY + $shiftYup, imagecolorallocate($im, 120, 235, 120)); // green } if ($yt + $yf > 0) { imagerectangle($im, $x1 + $shiftX, $shiftYup, $x1 + $shiftX + 8, $sizeY + $shiftYup, $black); } } for ($i = 0; $i <= $sizeY; $i += $sizeY / 10) { imageText($im, 7, 0, $sizeX + 5 + $shiftX, $sizeY - $i - 4 + $shiftYup + 8, $darkred, $i * ($maxY - $minY) / $sizeY + $minY); } imagefilledrectangle($im, $shiftX, $sizeY + $shiftYup + 39, $shiftX + 5, $sizeY + $shiftYup + 44, imagecolorallocate($im, 120, 235, 120)); imagerectangle($im, $shiftX, $sizeY + $shiftYup + 39, $shiftX + 5, $sizeY + $shiftYup + 44, $black); imageText($im, 8, 0, $shiftX + 9, $sizeY + $shiftYup + 45, $black, _('OK') . ' (%)'); imagefilledrectangle($im, $shiftX, $sizeY + $shiftYup + 54, $shiftX + 5, $sizeY + $shiftYup + 59, imagecolorallocate($im, 235, 120, 120)); imagerectangle($im, $shiftX, $sizeY + $shiftYup + 54, $shiftX + 5, $sizeY + $shiftYup + 59, $black); imageText($im, 8, 0, $shiftX + 9, $sizeY + $shiftYup + 60, $black, _('Problems') . ' (%)'); imagestringup($im, 1, imagesx($im) - 10, imagesy($im) - 50, ZABBIX_HOMEPAGE, $gray); $str = sprintf('%0.2f', microtime(true) - $startTime); $str = _s('Generated in %s sec', $str); $strSize = imageTextSize(6, 0, $str); imageText($im, 6, 0, imagesx($im) - $strSize['width'] - 5, imagesy($im) - 5, $gray, $str); imageOut($im); imagedestroy($im); require_once dirname(__FILE__) . '/include/page_footer.php';
function show_messages($bool = true, $okmsg = null, $errmsg = null) { global $page, $ZBX_MESSAGES; if (!defined('PAGE_HEADER_LOADED')) { return null; } if (defined('ZBX_API_REQUEST')) { return null; } if (!isset($page['type'])) { $page['type'] = PAGE_TYPE_HTML; } $imageMessages = array(); if (!$bool && !is_null($errmsg)) { $msg = _('ERROR') . ': ' . $errmsg; } elseif ($bool && !is_null($okmsg)) { $msg = $okmsg; } if (isset($msg)) { switch ($page['type']) { case PAGE_TYPE_IMAGE: // save all of the messages in an array to display them later in an image $imageMessages[] = array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68)); break; case PAGE_TYPE_XML: echo htmlspecialchars($msg) . "\n"; break; case PAGE_TYPE_HTML: default: $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr'); $msg_tab->setCellPadding(0); $msg_tab->setCellSpacing(0); $row = array(); $msg_col = new CCol(bold($msg), 'msg_main msg'); $msg_col->setAttribute('id', 'page_msg'); $row[] = $msg_col; if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) { $msg_details = new CDiv(_('Details'), 'blacklink'); $msg_details->setAttribute('onclick', 'javascript: showHide("msg_messages", IE ? "block" : "table");'); $msg_details->setAttribute('title', _('Maximize') . '/' . _('Minimize')); array_unshift($row, new CCol($msg_details, 'clr')); } $msg_tab->addRow($row); $msg_tab->show(); break; } } if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) { if ($page['type'] == PAGE_TYPE_IMAGE) { foreach ($ZBX_MESSAGES as $msg) { // save all of the messages in an array to display them later in an image if ($msg['type'] == 'error') { $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55)); } else { $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55)); } } } elseif ($page['type'] == PAGE_TYPE_XML) { foreach ($ZBX_MESSAGES as $msg) { echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n"; } } else { $lst_error = new CList(null, 'messages'); foreach ($ZBX_MESSAGES as $msg) { $lst_error->addItem($msg['message'], $msg['type']); $bool = $bool && 'error' !== strtolower($msg['type']); } $msg_show = 6; $msg_count = count($ZBX_MESSAGES); if ($msg_count > $msg_show) { $msg_count = $msg_show * 16; $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;'); } $tab = new CTable(null, $bool ? 'msgok' : 'msgerr'); $tab->setCellPadding(0); $tab->setCellSpacing(0); $tab->setAttribute('id', 'msg_messages'); $tab->setAttribute('style', 'width: 100%;'); if (isset($msg_tab) && $bool) { $tab->setAttribute('style', 'display: none;'); } $tab->addRow(new CCol($lst_error, 'msg')); $tab->show(); } $ZBX_MESSAGES = null; } // draw an image with the messages if ($page['type'] == PAGE_TYPE_IMAGE && count($imageMessages) > 0) { $imageFontSize = 8; // calculate the size of the text $imageWidth = 0; $imageHeight = 0; foreach ($imageMessages as &$msg) { $size = imageTextSize($imageFontSize, 0, $msg['text']); $msg['height'] = $size['height'] - $size['baseline']; // calculate the total size of the image $imageWidth = max($imageWidth, $size['width']); $imageHeight += $size['height'] + 1; } unset($msg); // additional padding $imageWidth += 2; $imageHeight += 2; // create the image $canvas = imagecreate($imageWidth, $imageHeight); imagefilledrectangle($canvas, 0, 0, $imageWidth, $imageHeight, imagecolorallocate($canvas, 255, 255, 255)); // draw each message $y = 1; foreach ($imageMessages as $msg) { $y += $msg['height']; imageText($canvas, $imageFontSize, 0, 1, $y, imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']), $msg['text']); } imageOut($canvas); imagedestroy($canvas); } }
public function drawHeader() { if (!isset($this->header)) { $str = $this->items[0]['hostname'] . ': ' . $this->items[0]['name']; } else { $str = $this->header; } $str .= $this->period2str($this->period); // calculate largest font size that can fit graph header // TODO: font size must be dynamic in other parts of the graph as well, like legend, timeline, etc for ($fontsize = 11; $fontsize > 7; $fontsize--) { $dims = imageTextSize($fontsize, 0, $str); $x = $this->fullSizeX / 2 - $dims['width'] / 2; // most important information must be displayed, period can be out of the graph if ($x < 2) { $x = 2; } if ($dims['width'] <= $this->fullSizeX) { break; } } imageText($this->im, $fontsize, 0, $x, 24, $this->getColor($this->graphtheme['textcolor'], 0), $str); }
protected function drawLegend() { if (!$this->drawLegend) { return; } $shiftY = $this->shiftY; $shiftX = $this->fullSizeX - $this->shiftlegendright - $this->shiftXright; $count = 0; foreach ($this->series as $key => $serie) { foreach ($serie as $num => $value) { $caption = $this->seriesLegend[$num]; $color = $this->getColor($this->seriesColor[$num], 0); imagefilledrectangle($this->im, $shiftX - 5, $shiftY + 14 * $count - 5, $shiftX + 5, $shiftY + 5 + 14 * $count, $color); imagerectangle($this->im, $shiftX - 5, $shiftY + 14 * $count - 5, $shiftX + 5, $shiftY + 5 + 14 * $count, $this->getColor('Black No Alpha')); $dims = imageTextSize(8, 0, $caption); imageText($this->im, 8, 0, $shiftX + 10, $shiftY - 5 + 14 * $count + 10, $this->getColor($this->graphtheme['textcolor'], 0), $caption); $count++; } break; //!!!! } }
$color = array('red' => 255, 'green' => 255, 'blue' => 255); $shadow = array('red' => 105, 'green' => 105, 'blue' => 105); break; case 'black': default: $color = array('red' => 0, 'green' => 0, 'blue' => 0); $shadow = array('red' => 175, 'green' => 175, 'blue' => 175); } $size = imageTextSize($font, $angle, $text); $im = imagecreatetruecolor($size['width'] + 4, $size['height'] + 4); $width = imagesx($im); $height = imagesy($im); $white = imagecolorallocate($im, $shadow['red'], $shadow['green'], $shadow['blue']); imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $white); $text_color = imagecolorallocate($im, $color['red'], $color['green'], $color['blue']); imageText($im, $font, 0, 0, $size['height'], $text_color, $text); $newImage = imagecreatetruecolor($height, $width); $white = imagecolorallocate($newImage, $shadow['red'], $shadow['green'], $shadow['blue']); // imagealphablending($newImage, false); // imagesavealpha($newImage, true); for ($w = 0; $w < $width; $w++) { for ($h = 0; $h < $height; $h++) { $ref = imagecolorat($im, $w, $h); imagesetpixel($newImage, $h, $width - 1 - $w, $ref); } } imagecolortransparent($newImage, $white); imageOut($newImage); imagedestroy($newImage); imagedestroy($im); include_once 'include/page_footer.php';
protected function drawLegend() { $shiftY = $this->shiftY + $this->shiftYLegend; $max_host_len = 0; $max_desc_len = 0; for ($i = 0; $i < $this->num; $i++) { if (zbx_strlen($this->items[$i]['host']) > $max_host_len) { $max_host_len = zbx_strlen($this->items[$i]['host']); } if (zbx_strlen($this->items[$i]['description']) > $max_desc_len) { $max_desc_len = zbx_strlen($this->items[$i]['description']); } } for ($i = 0; $i < $this->num; $i++) { $color = $this->getColor($this->items[$i]['color'], 0); $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']]; switch ($this->items[$i]['calc_fnc']) { case CALC_FNC_MIN: $fnc_name = 'min'; $datavalue = $data->min; break; case CALC_FNC_MAX: $fnc_name = 'max'; $datavalue = $data->max; break; case CALC_FNC_LST: $fnc_name = 'last'; $datavalue = $data->lst; break; case CALC_FNC_AVG: default: $fnc_name = 'avg'; $datavalue = $data->avg; } $proc = $datavalue * 100 / $this->sum; // convert_units($datavalue,$this->items[$i]["units"]), if (isset($data) && isset($datavalue)) { $strvalue = sprintf(S_VALUE . ': %s (' . (round($proc) != $proc ? '%0.2f' : '%s') . '%%)', convert_units($datavalue, $this->items[$i]['units']), $proc); $str = sprintf('%s: %s [%s] ', str_pad($this->items[$i]['host'], $max_host_len, ' '), str_pad($this->items[$i]['description'], $max_desc_len, ' '), $fnc_name); } else { $strvalue = sprintf(S_VALUE . ': ' . S_NO_DATA_SMALL); $str = sprintf('%s: %s [ ' . S_NO_DATA_SMALL . ' ]', str_pad($this->items[$i]['host'], $max_host_len, ' '), str_pad($this->items[$i]['description'], $max_desc_len, ' ')); } imagefilledrectangle($this->im, $this->shiftXleft, $this->sizeY + $shiftY + 14 * $i - 5, $this->shiftXleft + 10, $this->sizeY + $shiftY + 5 + 14 * $i, $color); imagerectangle($this->im, $this->shiftXleft, $this->sizeY + $shiftY + 14 * $i - 5, $this->shiftXleft + 10, $this->sizeY + $shiftY + 5 + 14 * $i, $this->getColor('Black No Alpha')); $dims = imageTextSize(8, 0, $str); imageText($this->im, 8, 0, $this->shiftXleft + 15, $this->sizeY + $shiftY + 14 * $i + 5, $this->getColor($this->graphtheme['textcolor'], 0), $str); $shiftX = $this->fullSizeX - $this->shiftlegendright - $this->shiftXright + 25; // SDI($shiftX.','.$this->sizeX); imagefilledrectangle($this->im, $shiftX - 10, $this->shiftY + 10 + 14 * $i, $shiftX, $this->shiftY + 10 + 10 + 14 * $i, $color); imagerectangle($this->im, $shiftX - 10, $this->shiftY + 10 + 14 * $i, $shiftX, $this->shiftY + 10 + 10 + 14 * $i, $this->GetColor('Black No Alpha')); imagetext($this->im, 8, 0, $shiftX + 5, $this->shiftY + 10 + 14 * $i + 10, $this->getColor($this->graphtheme['textcolor'], 0), $strvalue); } if ($this->sizeY < 120) { return; } }
public function drawText($fontsize, $angle, $x, $y, $color, $string) { imageText($this->canvas, $fontsize, $angle, $x, $y, $this->getColor($color), $string); }
$maxSizeY = $sizeY * (date('w') / 7); $y2 = $maxSizeY * ($ok[$i - 1] - $minY) / ($maxY - $minY); /* SDI($ok[$i-1]); SDI($maxSizeY); SDI($y2); //*/ } imagefilledrectangle($im, $x2 + $shiftX, $shiftYup + $sizeY - $y2, $x2 + $shiftX + 8, $shiftYup + $sizeY, imagecolorallocate($im, 120, 235, 120)); imagerectangle($im, $x2 + $shiftX, $shiftYup + $sizeY - $y2, $x2 + $shiftX + 8, $shiftYup + $sizeY, $black); //* imagefilledrectangle($im, $x2 + $shiftX, $shiftYup + $sizeY - $maxSizeY, $x2 + $shiftX + 8, $shiftYup + $sizeY - $y2, imagecolorallocate($im, 235, 120, 120)); imagerectangle($im, $x2 + $shiftX, $shiftYup + $sizeY - $maxSizeY, $x2 + $shiftX + 8, $shiftYup + $sizeY - $y2, $black); //*/ } for ($i = 0; $i <= $sizeY; $i += $sizeY / 10) { // imagestring($im, 1, $sizeX+5+$shiftX, $sizeY-$i-4+$shiftYup, ($i*($maxY-$minY)/$sizeY+$minY).'%' , imagecolorallocate($im,200,40,40)); imageText($im, 7, 0, $sizeX + 5 + $shiftX, $sizeY - $i - 4 + $shiftYup + 8, $darkred, $i * ($maxY - $minY) / $sizeY + $minY . '%'); } imagefilledrectangle($im, $shiftX, $sizeY + $shiftYup + 34 + 15 * 1, $shiftX + 5, $sizeY + $shiftYup + 30 + 9 + 15 * 1, imagecolorallocate($im, 120, 235, 120)); imagerectangle($im, $shiftX, $sizeY + $shiftYup + 34 + 15 * 1, $shiftX + 5, $sizeY + $shiftYup + 30 + 9 + 15 * 1, $black); imageText($im, 8, 0, $shiftX + 9, $sizeY + $shiftYup + 15 * 1 + 41, $black, S_OK_BIG . ' (%)'); imagefilledrectangle($im, $shiftX, $sizeY + $shiftYup + 34 + 15 * 2, $shiftX + 5, $sizeY + $shiftYup + 30 + 9 + 15 * 2, $darkred); imagerectangle($im, $shiftX, $sizeY + $shiftYup + 34 + 15 * 2, $shiftX + 5, $sizeY + $shiftYup + 30 + 9 + 15 * 2, $black); imageText($im, 8, 0, $shiftX + 9, $sizeY + $shiftYup + 15 * 2 + 41, $black, S_PROBLEM_BIG . ' (%)'); imagestringup($im, 0, imagesx($im) - 10, imagesy($im) - 50, 'http://www.zabbix.com', $gray); $end_time = time(NULL); imagestring($im, 0, imagesx($im) - 100, imagesy($im) - 12, 'Generated in ' . ($end_time - $start_time) . ' sec', $gray); ImageOut($im); imagedestroy($im); include_once 'include/page_footer.php';