} $start = $start - ($wday - 1) * SEC_PER_DAY; $weeks = (int) (date('z') / 7 + 1); for ($i = 0; $i < $weeks; $i++) { $periodStart = $start + SEC_PER_WEEK * $i; $periodEnd = $start + SEC_PER_WEEK * ($i + 1); $stat = calculateAvailability(getRequest('triggerid'), $periodStart, $periodEnd); $true[$i] = $stat['true']; $false[$i] = $stat['false']; $count_now[$i] = 1; } for ($i = 0; $i <= $sizeY; $i += $sizeY / 10) { dashedLine($im, $shiftX, $i + $shiftYup, $sizeX + $shiftX, $i + $shiftYup, $gray); } for ($i = 0, $periodStart = $start; $i <= $sizeX; $i += $sizeX / 52) { dashedLine($im, $i + $shiftX, $shiftYup, $i + $shiftX, $sizeY + $shiftYup, $gray); imageText($im, 6, 90, $i + $shiftX + 4, $sizeY + $shiftYup + 30, $black, zbx_date2str(_('d.M'), $periodStart)); $periodStart += SEC_PER_WEEK; } $maxY = max(max($true), 100); $minY = 0; $maxX = 900; $minX = 0; for ($i = 1; $i <= $weeks; $i++) { $x1 = 900 / 52 * $sizeX * ($i - 1 - $minX) / ($maxX - $minX); $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;
protected function drawTriggers() { if ($this->m_showTriggers != 1) { return; } $opposite = hex2rgb(GRAPH_TRIGGER_LINE_OPPOSITE_COLOR); $oppColor = imagecolorallocate($this->im, $opposite[0], $opposite[1], $opposite[2]); foreach ($this->triggers as $tnum => $trigger) { if ($trigger['skipdraw']) { continue; } $triggerColor = $this->getColor($trigger['color']); $lineStyle = array($triggerColor, $triggerColor, $triggerColor, $triggerColor, $triggerColor, $oppColor, $oppColor, $oppColor); dashedLine($this->im, $this->shiftXleft, $trigger['y'], $this->sizeX + $this->shiftXleft, $trigger['y'], $lineStyle); dashedLine($this->im, $this->shiftXleft, $trigger['y'] + 1, $this->sizeX + $this->shiftXleft, $trigger['y'] + 1, $lineStyle); } }
protected function drawGrid() { $this->drawSmallRectangle(); if ($this->column) { $hline_count = $this->gridLinesCount; for ($i = 1; $i < $hline_count; $i++) { dashedLine($this->im, $this->shiftXleft + $this->shiftXCaptionLeft, $i * ($this->sizeY / $hline_count) + $this->shiftY + $this->shiftYCaptionTop, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft, $i * ($this->sizeY / $hline_count) + $this->shiftY + $this->shiftYCaptionTop, $this->getColor('Gray')); } $i = 0; foreach ($this->series as $key => $serie) { $caption = $this->periodCaption[$key]; $dims = imageTextSize(7, 90, $caption); imageText($this->im, 7, 90, $i * ($this->seriesWidth + $this->seriesDistance) + $this->shiftXleft + $this->shiftXCaptionLeft + round($this->seriesWidth / 2) + $dims['width'] * 2, $this->sizeY + $this->shiftY + $dims['height'] + 6, $this->getColor($this->graphtheme['textcolor'], 0), $caption); $i++; } } else { $vline_count = $this->gridLinesCount; for ($i = 1; $i < $vline_count; $i++) { dashedLine($this->im, $i * ($this->sizeX / $vline_count) + $this->shiftXleft + $this->shiftXCaptionLeft, $this->shiftY + $this->shiftYCaptionTop, $i * ($this->sizeX / $vline_count) + $this->shiftXleft + $this->shiftXCaptionLeft, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop, $this->getColor('Gray')); } $i = 0; foreach ($this->series as $key => $serie) { $caption = $this->periodCaption[$key]; $caption = str_pad($caption, $this->maxCaption, ' ', STR_PAD_LEFT); imageText($this->im, 8, 0, $this->shiftXleft, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - ($i * ($this->seriesWidth + $this->seriesDistance) + $this->seriesDistance + round($this->seriesWidth / 2)), $this->getColor($this->graphtheme['textcolor'], 0), $caption); $i++; } } }
function dashedRectangle($image, $x1, $y1, $x2, $y2, $color) { dashedLine($image, $x1, $y1, $x1, $y2, $color); dashedLine($image, $x1, $y2, $x2, $y2, $color); dashedLine($image, $x2, $y2, $x2, $y1, $color); dashedLine($image, $x2, $y1, $x1, $y1, $color); }
$period_end = time(); } $intervals[] = ['from' => $period_start, 'to' => $period_end]; } $sla = API::Service()->getSla(['serviceids' => $service['serviceid'], 'intervals' => $intervals]); $sla = reset($sla); foreach ($sla['sla'] as $i => $intervalSla) { $problem[$i] = 100 - $intervalSla['problemTime']; $ok[$i] = $intervalSla['sla']; $count_now[$i] = 1; } for ($i = 0; $i <= $sizeY; $i += $sizeY / 10) { dashedLine($im, $shiftX, $i + $shiftYup, $sizeX + $shiftX, $i + $shiftYup, $gridcolor); } for ($i = 0, $period_start = $start; $i <= $sizeX; $i += $sizeX / 52) { dashedLine($im, $i + $shiftX, $shiftYup, $i + $shiftX, $sizeY + $shiftYup, $gridcolor); imageText($im, 6, 90, $i + $shiftX + 4, $sizeY + $shiftYup + 35, $textcolor, zbx_date2str(_('d.M'), $period_start)); $period_start += 7 * 24 * 3600; } $maxY = max(max($problem), 100); $minY = 0; $maxX = $sizeX; $minX = 0; for ($i = 1; $i <= $weeks; $i++) { if (!isset($ok[$i - 1])) { continue; } $x2 = $sizeX / 52 * ($i - 1 - $minX) * $sizeX / ($maxX - $minX); $y2 = $sizeY * ($ok[$i - 1] - $minY) / ($maxY - $minY); $maxSizeY = $sizeY; if ($i == $weeks) {