Ejemplo n.º 1
0
 public function drawRoundedRectangle($x1, $y1, $x2, $y2, $radius, $color)
 {
     $color = $this->getColor($color);
     $arcRadius = $radius * 2;
     imagearc($this->canvas, $x1 + $radius, $y1 + $radius, $arcRadius, $arcRadius, 180, 270, $color);
     imagearc($this->canvas, $x1 + $radius, $y2 - $radius, $arcRadius, $arcRadius, 90, 180, $color);
     imagearc($this->canvas, $x2 - $radius, $y1 + $radius, $arcRadius, $arcRadius, 270, 0, $color);
     imagearc($this->canvas, $x2 - $radius, $y2 - $radius, $arcRadius, $arcRadius, 0, 90, $color);
     zbx_imageline($this->canvas, $x1 + $radius, $y1, $x2 - $radius, $y1, $color);
     zbx_imageline($this->canvas, $x1 + $radius, $y2, $x2 - $radius, $y2, $color);
     zbx_imageline($this->canvas, $x1, $y1 + $radius, $x1, $y2 - $radius, $color);
     zbx_imageline($this->canvas, $x2, $y1 + $radius, $x2, $y2 - $radius, $color);
 }
Ejemplo n.º 2
0
function myDrawLine($image, $x1, $y1, $x2, $y2, $color, $drawtype)
{
    if ($drawtype == MAP_LINK_DRAWTYPE_BOLD_LINE) {
        zbx_imagealine($image, $x1, $y1, $x2, $y2, $color, LINE_TYPE_BOLD);
    } elseif ($drawtype == MAP_LINK_DRAWTYPE_DASHED_LINE) {
        if (function_exists('imagesetstyle')) {
            // use imagesetstyle + imageline instead of bugged ImageDashedLine
            $style = array($color, $color, $color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT);
            imagesetstyle($image, $style);
            zbx_imageline($image, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
        } else {
            imagedashedline($image, $x1, $y1, $x2, $y2, $color);
        }
    } elseif ($drawtype == MAP_LINK_DRAWTYPE_DOT && function_exists('imagesetstyle')) {
        $style = array($color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT);
        imagesetstyle($image, $style);
        zbx_imageline($image, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
    } else {
        zbx_imagealine($image, $x1, $y1, $x2, $y2, $color);
    }
}
Ejemplo n.º 3
0
 protected function drawElement(&$data, $from, $to, $minX, $maxX, $minY, $maxY, $drawtype, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $axisside)
 {
     if (!isset($data['max'][$from]) || !isset($data['max'][$to])) {
         return;
     }
     $oxy = $this->oxy[$axisside];
     $zero = $this->zero[$axisside];
     $unit2px = $this->unit2px[$axisside];
     $shift_min_from = $shift_min_to = 0;
     $shift_max_from = $shift_max_to = 0;
     $shift_avg_from = $shift_avg_to = 0;
     if (isset($data['shift_min'][$from])) {
         $shift_min_from = $data['shift_min'][$from];
     }
     if (isset($data['shift_min'][$to])) {
         $shift_min_to = $data['shift_min'][$to];
     }
     if (isset($data['shift_max'][$from])) {
         $shift_max_from = $data['shift_max'][$from];
     }
     if (isset($data['shift_max'][$to])) {
         $shift_max_to = $data['shift_max'][$to];
     }
     if (isset($data['shift_avg'][$from])) {
         $shift_avg_from = $data['shift_avg'][$from];
     }
     if (isset($data['shift_avg'][$to])) {
         $shift_avg_to = $data['shift_avg'][$to];
     }
     $min_from = $data['min'][$from] + $shift_min_from;
     $min_to = $data['min'][$to] + $shift_min_to;
     $max_from = $data['max'][$from] + $shift_max_from;
     $max_to = $data['max'][$to] + $shift_max_to;
     $avg_from = $data['avg'][$from] + $shift_avg_from;
     $avg_to = $data['avg'][$to] + $shift_avg_to;
     $x1 = $from + $this->shiftXleft - 1;
     $x2 = $to + $this->shiftXleft;
     $y1min = $zero - ($min_from - $oxy) / $unit2px;
     $y2min = $zero - ($min_to - $oxy) / $unit2px;
     $y1max = $zero - ($max_from - $oxy) / $unit2px;
     $y2max = $zero - ($max_to - $oxy) / $unit2px;
     $y1avg = $zero - ($avg_from - $oxy) / $unit2px;
     $y2avg = $zero - ($avg_to - $oxy) / $unit2px;
     switch ($calc_fnc) {
         case CALC_FNC_MAX:
             $y1 = $y1max;
             $y2 = $y2max;
             $shift_from = $shift_max_from;
             $shift_to = $shift_max_to;
             break;
         case CALC_FNC_MIN:
             $y1 = $y1min;
             $y2 = $y2min;
             $shift_from = $shift_min_from;
             $shift_to = $shift_min_to;
             break;
         case CALC_FNC_ALL:
             // max
             $y1x = $y1max > $this->sizeY + $this->shiftY || $y1max < $this->shiftY;
             $y2x = $y2max > $this->sizeY + $this->shiftY || $y2max < $this->shiftY;
             if ($y1x) {
                 $y1max = $y1max > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY;
             }
             if ($y2x) {
                 $y2max = $y2max > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY;
             }
             // min
             $y1n = $y1min > $this->sizeY + $this->shiftY || $y1min < $this->shiftY;
             $y2n = $y2min > $this->sizeY + $this->shiftY || $y2min < $this->shiftY;
             if ($y1n) {
                 $y1min = $y1min > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY;
             }
             if ($y2n) {
                 $y2min = $y2min > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY;
             }
             $a[0] = $x1;
             $a[1] = $y1max;
             $a[2] = $x1;
             $a[3] = $y1min;
             $a[4] = $x2;
             $a[5] = $y2min;
             $a[6] = $x2;
             $a[7] = $y2max;
             // don't use break, avg must be drawn in this statement
         // don't use break, avg must be drawn in this statement
         case CALC_FNC_AVG:
             // don't use break, avg must be drawn in this statement
         // don't use break, avg must be drawn in this statement
         default:
             $y1 = $y1avg;
             $y2 = $y2avg;
             $shift_from = $shift_avg_from;
             $shift_to = $shift_avg_to;
     }
     $shift_from -= $shift_from != 0 ? $oxy : 0;
     $shift_to -= $shift_to != 0 ? $oxy : 0;
     $y1_shift = $zero - $shift_from / $unit2px;
     $y2_shift = $zero - $shift_to / $unit2px;
     if (!$this->limitToBounds($y1, $y2, $this->shiftY, $this->sizeY, $drawtype)) {
         return true;
     }
     if (!$this->limitToBounds($y1_shift, $y2_shift, $this->shiftY, $this->sizeY, $drawtype)) {
         return true;
     }
     // draw main line
     switch ($drawtype) {
         case GRAPH_ITEM_DRAWTYPE_BOLD_LINE:
             if ($calc_fnc == CALC_FNC_ALL) {
                 imagefilledpolygon($this->im, $a, 4, $minmax_color);
                 if (!$y1x || !$y2x) {
                     zbx_imagealine($this->im, $x1, $y1max, $x2, $y2max, $max_color, LINE_TYPE_BOLD);
                 }
                 if (!$y1n || !$y2n) {
                     zbx_imagealine($this->im, $x1, $y1min, $x2, $y2min, $min_color, LINE_TYPE_BOLD);
                 }
             }
             zbx_imagealine($this->im, $x1, $y1, $x2, $y2, $avg_color, LINE_TYPE_BOLD);
             break;
         case GRAPH_ITEM_DRAWTYPE_LINE:
             if ($calc_fnc == CALC_FNC_ALL) {
                 imagefilledpolygon($this->im, $a, 4, $minmax_color);
                 if (!$y1x || !$y2x) {
                     zbx_imagealine($this->im, $x1, $y1max, $x2, $y2max, $max_color);
                 }
                 if (!$y1n || !$y2n) {
                     zbx_imagealine($this->im, $x1, $y1min, $x2, $y2min, $min_color);
                 }
             }
             zbx_imagealine($this->im, $x1, $y1, $x2, $y2, $avg_color);
             break;
         case GRAPH_ITEM_DRAWTYPE_FILLED_REGION:
             $a[0] = $x1;
             $a[1] = $y1;
             $a[2] = $x1;
             $a[3] = $y1_shift;
             $a[4] = $x2;
             $a[5] = $y2_shift;
             $a[6] = $x2;
             $a[7] = $y2;
             imagefilledpolygon($this->im, $a, 4, $avg_color);
             break;
         case GRAPH_ITEM_DRAWTYPE_DOT:
             imagefilledrectangle($this->im, $x1 - 1, $y1 - 1, $x1, $y1, $avg_color);
             break;
         case GRAPH_ITEM_DRAWTYPE_BOLD_DOT:
             imagefilledrectangle($this->im, $x2 - 1, $y2 - 1, $x2 + 1, $y2 + 1, $avg_color);
             break;
         case GRAPH_ITEM_DRAWTYPE_DASHED_LINE:
             if (function_exists('imagesetstyle')) {
                 // use imagesetstyle+imageline instead of bugged imagedashedline
                 $style = array($avg_color, $avg_color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT);
                 imagesetstyle($this->im, $style);
                 zbx_imageline($this->im, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
             } else {
                 imagedashedline($this->im, $x1, $y1, $x2, $y2, $avg_color);
             }
             break;
         case GRAPH_ITEM_DRAWTYPE_GRADIENT_LINE:
             imageLine($this->im, $x1, $y1, $x2, $y2, $avg_color);
             // draw the initial line
             imageLine($this->im, $x1, $y1 - 1, $x2, $y2 - 1, $avg_color);
             $bitmask = 255;
             $blue = $avg_color & $bitmask;
             // $blue_diff = 255 - $blue;
             $bitmask = $bitmask << 8;
             $green = ($avg_color & $bitmask) >> 8;
             // $green_diff = 255 - $green;
             $bitmask = $bitmask << 8;
             $red = ($avg_color & $bitmask) >> 16;
             // $red_diff = 255 - $red;
             // note: though gradients on the chart looks ok, the formula used is completely incorrect
             // if you plan to fix something here, it would be better to start from scratch
             $maxAlpha = 110;
             $startAlpha = 50;
             $alphaRatio = $maxAlpha / ($this->sizeY - $startAlpha);
             $diffX = $x1 - $x2;
             for ($i = 0; $i <= $diffX; $i++) {
                 $Yincr = $diffX > 0 ? abs($y2 - $y1) / $diffX : 0;
                 $gy = $y1 > $y2 ? $y2 + $Yincr * $i : $y2 - $Yincr * $i;
                 $steps = $this->sizeY + $this->shiftY - $gy + 1;
                 for ($j = 0; $j < $steps; $j++) {
                     if ($gy + $j < $this->shiftY + $startAlpha) {
                         $alpha = 0;
                     } else {
                         $alpha = 127 - abs(127 - $alphaRatio * ($gy + $j - $this->shiftY - $startAlpha));
                     }
                     $color = imagecolorexactalpha($this->im, $red, $green, $blue, $alpha);
                     imagesetpixel($this->im, $x2 + $i, $gy + $j, $color);
                 }
             }
             break;
     }
 }
Ejemplo n.º 4
0
 public function drawSmallRectangle()
 {
     $gbColor = $this->getColor($this->graphtheme['gridbordercolor'], 0);
     imagefilledrectangle($this->im, $this->shiftXleft + $this->shiftXCaptionLeft - 1, $this->shiftY - 1 + $this->shiftYCaptionTop, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft - 1, $this->sizeY + $this->shiftY + 1 + $this->shiftYCaptionTop, $this->getColor($this->graphtheme['graphcolor'], 0));
     dashedRectangle($this->im, $this->shiftXleft + $this->shiftXCaptionLeft - 1, $this->shiftY - 1 + $this->shiftYCaptionTop, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft - 1, $this->sizeY + $this->shiftY + 1 + $this->shiftYCaptionTop, $this->getColor($this->graphtheme['gridcolor'], 0));
     zbx_imageline($this->im, $this->shiftXleft + $this->shiftXCaptionLeft - 1, $this->shiftY - 5, $this->shiftXleft + $this->shiftXCaptionLeft - 1, $this->sizeY + $this->shiftY + 4, $gbColor);
     $sides = array();
     if ($this->axisSideLeft) {
         $sides[] = GRAPH_YAXIS_SIDE_LEFT;
     }
     if ($this->axisSideRight) {
         $sides[] = GRAPH_YAXIS_SIDE_RIGHT;
     }
     foreach ($sides as $axis) {
         if ($axis == GRAPH_YAXIS_SIDE_LEFT) {
             $sideCorrection = -1;
             $triangle = 0;
         } else {
             $sideCorrection = $this->sizeX;
             $triangle = $this->sizeX + 1;
         }
         zbx_imageline($this->im, $this->shiftXCaptionLeft + $this->shiftXleft + $sideCorrection, $this->shiftY - 5, $this->shiftXCaptionLeft + $this->shiftXleft + $sideCorrection, $this->sizeY + $this->shiftY + 4, $this->getColor($this->graphtheme['gridbordercolor'], 0));
         imagefilledpolygon($this->im, array($this->shiftXleft + $this->shiftXCaptionLeft + $triangle - 4, $this->shiftY - 5, $this->shiftXleft + $this->shiftXCaptionLeft + $triangle + 2, $this->shiftY - 5, $this->shiftXleft + $this->shiftXCaptionLeft + $triangle - 1, $this->shiftY - 10), 3, $this->getColor('White'));
         imagepolygon($this->im, array($this->shiftXleft + $this->shiftXCaptionLeft + $triangle - 4, $this->shiftY - 5, $this->shiftXleft + $this->shiftXCaptionLeft + $triangle + 2, $this->shiftY - 5, $this->shiftXleft + $this->shiftXCaptionLeft + $triangle - 1, $this->shiftY - 10), 3, $this->getColor($this->graphtheme['gridbordercolor'], 0));
     }
     zbx_imageline($this->im, $this->shiftXleft + $this->shiftXCaptionLeft - 4, $this->sizeY + $this->shiftY + 1, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft + 5, $this->sizeY + $this->shiftY + 1, $gbColor);
     imagefilledpolygon($this->im, array($this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft + 5, $this->sizeY + $this->shiftY - 2, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft + 5, $this->sizeY + $this->shiftY + 4, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft + 10, $this->sizeY + $this->shiftY + 1), 3, $this->getColor('White'));
     // draw X axis triangle
     zbx_imageline($this->im, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft + 5, $this->sizeY + $this->shiftY - 2, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft + 5, $this->sizeY + $this->shiftY + 4, $gbColor);
     zbx_imagealine($this->im, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft + 5, $this->sizeY + $this->shiftY + 4, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft + 10, $this->sizeY + $this->shiftY + 1, $gbColor);
     zbx_imagealine($this->im, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft + 10, $this->sizeY + $this->shiftY + 1, $this->sizeX + $this->shiftXleft + $this->shiftXCaptionLeft + 5, $this->sizeY + $this->shiftY - 2, $gbColor);
 }
Ejemplo n.º 5
0
function dashedLine($image, $x1, $y1, $x2, $y2, $color)
{
    // style for dashed lines
    if (!is_array($color)) {
        $style = array($color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT);
    } else {
        $style = $color;
    }
    imagesetstyle($image, $style);
    zbx_imageline($image, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
}