Esempio n. 1
0
/**
 * Calculates coordinates from elements inside areas
 *
 * @param array $map
 * @param array $areas
 * @param array $mapInfo
 *
 * @return void
 */
function processAreasCoordinates(array &$map, array $areas, array $mapInfo)
{
    foreach ($areas as $area) {
        $rowPlaceCount = ceil(sqrt(count($area['selementids'])));
        // offset from area borders
        $area['x'] += 5;
        $area['y'] += 5;
        $area['width'] -= 5;
        $area['height'] -= 5;
        $xOffset = floor($area['width'] / $rowPlaceCount);
        $yOffset = floor($area['height'] / $rowPlaceCount);
        $colNum = 0;
        $rowNum = 0;
        // some offset is required so that icon highlights are not drawn outside area
        $borderOffset = 20;
        foreach ($area['selementids'] as $selementId) {
            $selement = $map['selements'][$selementId];
            $image = get_png_by_selement($mapInfo[$selementId]);
            $iconX = imagesx($image);
            $iconY = imagesy($image);
            $labelLocation = is_null($selement['label_location']) || $selement['label_location'] < 0 ? $map['label_location'] : $selement['label_location'];
            switch ($labelLocation) {
                case MAP_LABEL_LOC_TOP:
                    $newX = $area['x'] + $xOffset / 2 - $iconX / 2;
                    $newY = $area['y'] + $yOffset - $iconY - ($iconY >= $iconX ? 0 : abs($iconX - $iconY) / 2) - $borderOffset;
                    break;
                case MAP_LABEL_LOC_LEFT:
                    $newX = $area['x'] + $xOffset - $iconX - $borderOffset;
                    $newY = $area['y'] + $yOffset / 2 - $iconY / 2;
                    break;
                case MAP_LABEL_LOC_RIGHT:
                    $newX = $area['x'] + $borderOffset;
                    $newY = $area['y'] + $yOffset / 2 - $iconY / 2;
                    break;
                case MAP_LABEL_LOC_BOTTOM:
                    $newX = $area['x'] + $xOffset / 2 - $iconX / 2;
                    $newY = $area['y'] + abs($iconX - $iconY) / 2 + $borderOffset;
                    break;
            }
            $map['selements'][$selementId]['x'] = $newX + $colNum * $xOffset;
            $map['selements'][$selementId]['y'] = $newY + $rowNum * $yOffset;
            $colNum++;
            if ($colNum == $rowPlaceCount) {
                $colNum = 0;
                $rowNum++;
            }
        }
    }
}
Esempio n. 2
0
function drawMapLabels(&$im, &$map, &$map_info)
{
    global $colors;
    if ($map['label_type'] == MAP_LABEL_TYPE_NOTHING) {
        return;
    }
    $selements = $map['selements'];
    $all_strings = '';
    $label_lines = array();
    $status_lines = array();
    foreach ($selements as $selementid => $selement) {
        if (!isset($label_lines[$selementid])) {
            $label_lines[$selementid] = array();
        }
        if (!isset($status_lines[$selementid])) {
            $status_lines[$selementid] = array();
        }
        $msg = resolveMapLabelMacrosAll($selement);
        $all_strings .= $msg;
        $msgs = explode("\n", $msg);
        foreach ($msgs as $msg) {
            $label_lines[$selementid][] = array('msg' => $msg);
        }
        $el_info = $map_info[$selementid];
        $el_msgs = array('problem', 'unack', 'maintenance', 'unknown', 'ok', 'status');
        foreach ($el_msgs as $key => $caption) {
            if (!isset($el_info['info'][$caption]) || zbx_empty($el_info['info'][$caption]['msg'])) {
                continue;
            }
            $status_lines[$selementid][] = array('msg' => $el_info['info'][$caption]['msg'], 'color' => $el_info['info'][$caption]['color']);
            $all_strings .= $el_info['info'][$caption]['msg'];
        }
    }
    $allLabelsSize = imageTextSize(8, 0, str_replace("\r", '', str_replace("\n", '', $all_strings)));
    $labelFontHeight = $allLabelsSize['height'];
    $labelFontBaseline = $allLabelsSize['baseline'];
    foreach ($selements as $selementid => $selement) {
        if (empty($selement)) {
            continue;
        }
        $el_info = $map_info[$selementid];
        $hl_color = null;
        $st_color = null;
        if (!isset($_REQUEST['noselements']) && $map['highlight'] % 2 == SYSMAP_HIGHLIGH_ON) {
            if ($el_info['icon_type'] == SYSMAP_ELEMENT_ICON_ON) {
                $hl_color = true;
            }
            if ($el_info['icon_type'] == SYSMAP_ELEMENT_ICON_UNKNOWN) {
                $hl_color = true;
            }
            if ($el_info['icon_type'] == SYSMAP_ELEMENT_ICON_MAINTENANCE) {
                $st_color = true;
            }
            if ($el_info['icon_type'] == SYSMAP_ELEMENT_ICON_DISABLED) {
                $st_color = true;
            }
        }
        if (in_array($selement['elementtype'], array(SYSMAP_ELEMENT_TYPE_HOST_GROUP, SYSMAP_ELEMENT_TYPE_MAP)) && !is_null($hl_color)) {
            $st_color = null;
        } else {
            if (!is_null($st_color)) {
                $hl_color = null;
            }
        }
        $label_location = is_null($selement['label_location']) || $selement['label_location'] < 0 ? $map['label_location'] : $selement['label_location'];
        $label = array();
        if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && $map['label_type'] == MAP_LABEL_TYPE_IP) {
            $host = get_host_by_hostid($selement['elementid']);
            $label[] = array('msg' => $host['ip']);
            $label = array_merge($label, $status_lines[$selementid]);
        } else {
            if ($map['label_type'] == MAP_LABEL_TYPE_STATUS) {
                $label = $status_lines[$selementid];
            } else {
                if ($map['label_type'] == MAP_LABEL_TYPE_NAME) {
                    $label[] = array('msg' => $el_info['name']);
                } else {
                    $label = array_merge($label_lines[$selementid], $status_lines[$selementid]);
                }
            }
        }
        if (zbx_empty($label)) {
            continue;
        }
        $w = 0;
        foreach ($label as $str) {
            $dims = imageTextSize(8, 0, $str['msg']);
            $w = max($w, $dims['width']);
        }
        $h = count($label) * $labelFontHeight;
        $x = $selement['x'];
        $y = $selement['y'];
        $img = get_png_by_selement($selement, $el_info);
        $iconX = imagesx($img);
        $iconY = imagesy($img);
        if (!is_null($hl_color)) {
            $icon_hl = 14;
        } else {
            if (!is_null($st_color)) {
                $icon_hl = 6;
            } else {
                $icon_hl = 2;
            }
        }
        switch ($label_location) {
            case MAP_LABEL_LOC_TOP:
                $y_rec = $y - $icon_hl - $h - 6;
                $x_rec = $x + $iconX / 2 - $w / 2;
                break;
            case MAP_LABEL_LOC_LEFT:
                $y_rec = $y - $h / 2 + $iconY / 2;
                $x_rec = $x - $icon_hl - $w;
                break;
            case MAP_LABEL_LOC_RIGHT:
                $y_rec = $y - $h / 2 + $iconY / 2;
                $x_rec = $x + $iconX + $icon_hl;
                break;
            case MAP_LABEL_LOC_BOTTOM:
            default:
                $y_rec = $y + $iconY + $icon_hl;
                $x_rec = $x + $iconX / 2 - $w / 2;
        }
        //		$y_rec += 30;
        //		imagerectangle($im, $x_rec-2-1, $y_rec-3, $x_rec+$w+2+1, $y_rec+($oc*4)+$h+3, $label_color);
        //		imagefilledrectangle($im, $x_rec-2, $y_rec-2, $x_rec+$w+2, $y_rec+($oc*4)+$h-2, $colors['White']);
        $increasey = 12;
        foreach ($label as $line) {
            if (zbx_empty($line['msg'])) {
                continue;
            }
            $str = str_replace("\r", '', $line['msg']);
            $color = isset($line['color']) ? $line['color'] : $colors['Black'];
            $dims = imageTextSize(8, 0, $str);
            //				$dims['height'] = $labelFontHeight;
            //$str .= ' - '.$labelFontHeight.' - '.$dims['height'];
            //$str = $dims['width'].'x'.$dims['height'];
            if ($label_location == MAP_LABEL_LOC_TOP || $label_location == MAP_LABEL_LOC_BOTTOM) {
                $x_label = $x + ceil($iconX / 2) - ceil($dims['width'] / 2);
            } else {
                if ($label_location == MAP_LABEL_LOC_LEFT) {
                    $x_label = $x_rec + $w - $dims['width'];
                } else {
                    $x_label = $x_rec;
                }
            }
            imagefilledrectangle($im, $x_label - 1, $y_rec + $increasey - $labelFontHeight + $labelFontBaseline, $x_label + $dims['width'] + 1, $y_rec + $increasey + $labelFontBaseline, $colors['White']);
            imagetext($im, 8, 0, $x_label, $y_rec + $increasey, $color, $str);
            $increasey += $labelFontHeight + 1;
        }
    }
}