示例#1
0
 protected function drawLegend()
 {
     $leftXShift = 20;
     $units = array('left' => 0, 'right' => 0);
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + $this->legendOffsetY);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     $row = array(array('text' => ''), array('text' => ''), array('text' => S_LST_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_MIN_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_AVG_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_MAX_SMALL, 'align' => 1, 'fontsize' => 9));
     $legend->addRow($row);
     $colNum = $legend->getNumRows();
     $i = $this->type == GRAPH_TYPE_STACKED ? $this->num - 1 : 0;
     while ($i >= 0 && $i < $this->num) {
         if ($this->items[$i]['calc_type'] == GRAPH_ITEM_AGGREGATED) {
             $fnc_name = 'agr(' . $this->items[$i]['periods_cnt'] . ')';
             $color = $this->getColor('HistoryMinMax');
         } else {
             $color = $this->getColor($this->items[$i]['color'], GRAPH_STACKED_ALFA);
             switch ($this->items[$i]['calc_fnc']) {
                 case CALC_FNC_MIN:
                     $fnc_name = S_MIN_SMALL;
                     break;
                 case CALC_FNC_MAX:
                     $fnc_name = S_MAX_SMALL;
                     break;
                 case CALC_FNC_ALL:
                     $fnc_name = S_ALL_SMALL;
                     break;
                 case CALC_FNC_AVG:
                 default:
                     $fnc_name = S_AVG_SMALL;
             }
         }
         $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
         if ($this->itemsHost) {
             $item_caption = $this->items[$i]['description'];
         } else {
             $item_caption = $this->items[$i]['host'] . ': ' . $this->items[$i]['description'];
         }
         if (isset($data) && isset($data['min'])) {
             if ($this->items[$i]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
                 $units['left'] = $this->items[$i]['units'];
             } else {
                 $units['right'] = $this->items[$i]['units'];
             }
             $legend->addCell($colNum, array('text' => $item_caption));
             $legend->addCell($colNum, array('text' => '[' . $fnc_name . ']'));
             $legend->addCell($colNum, array('text' => convert_units($this->getLastValue($i), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
             $legend->addCell($colNum, array('text' => convert_units(min($data['min']), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
             $legend->addCell($colNum, array('text' => convert_units($data['avg_orig'], $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
             $legend->addCell($colNum, array('text' => convert_units(max($data['max']), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
         } else {
             $legend->addCell($colNum, array('text' => $item_caption));
             $legend->addCell($colNum, array('text' => '[ ' . S_NO_DATA_SMALL . ' ]'));
         }
         imagefilledrectangle($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10, $leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $color);
         imagerectangle($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10, $leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $this->getColor('Black'));
         $colNum++;
         if ($this->type == GRAPH_TYPE_STACKED) {
             $i--;
         } else {
             $i++;
         }
     }
     $legend->draw();
     // if graph is small, we are not drawing percent line and trigger legends
     if ($this->sizeY < ZBX_GRAPH_LEGEND_HEIGHT) {
         return true;
     }
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // Draw percentile
     if ($this->type == GRAPH_TYPE_NORMAL) {
         foreach ($this->percentile as $side => $percentile) {
             if ($percentile['percent'] > 0 && $percentile['value']) {
                 $percentile['percent'] = (double) $percentile['percent'];
                 $legend->addCell($colNum, array('text' => $percentile['percent'] . 'th percentile: ' . convert_units($percentile['value'], $units[$side]) . '  (' . $side . ')', ITEM_CONVERT_NO_UNITS));
                 if ($side == 'left') {
                     $color = $this->graphtheme['leftpercentilecolor'];
                 } else {
                     $color = $this->graphtheme['rightpercentilecolor'];
                 }
                 imagefilledpolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10), 3, $this->getColor($color));
                 imagepolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10), 3, $this->getColor('Black No Alpha'));
                 $colNum++;
             }
         }
     }
     $legend->draw();
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY + 5);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // Draw triggers
     foreach ($this->triggers as $trigger) {
         imagefilledellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, 10, 10, $this->getColor($trigger['color']));
         imageellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, 10, 10, $this->getColor('Black No Alpha'));
         $legend->addRow(array(array('text' => $trigger['description']), array('text' => $trigger['constant'])));
         $colNum++;
     }
     $legend->draw();
 }
示例#2
0
 protected function drawLegend()
 {
     $leftXShift = 20;
     $units = array('left' => 0, 'right' => 0);
     // draw item legend
     $legend = new CImageTextTable($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + $this->legendOffsetY);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // item legend table header
     $row = array(array('text' => '', 'marginRight' => 5), array('text' => ''), array('text' => ''), array('text' => _('last'), 'align' => 1, 'fontsize' => 9), array('text' => _('min'), 'align' => 1, 'fontsize' => 9), array('text' => _('avg'), 'align' => 1, 'fontsize' => 9), array('text' => _('max'), 'align' => 1, 'fontsize' => 9));
     $legend->addRow($row);
     $rowNum = $legend->getNumRows();
     $i = $this->type == GRAPH_TYPE_STACKED ? $this->num - 1 : 0;
     while ($i >= 0 && $i < $this->num) {
         $color = $this->getColor($this->items[$i]['color'], GRAPH_STACKED_ALFA);
         switch ($this->items[$i]['calc_fnc']) {
             case CALC_FNC_MIN:
                 $fncRealName = _('min');
                 break;
             case CALC_FNC_MAX:
                 $fncRealName = _('max');
                 break;
             case CALC_FNC_ALL:
                 $fncRealName = _('all');
                 break;
             case CALC_FNC_AVG:
             default:
                 $fncRealName = _('avg');
         }
         $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
         // draw color square
         if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
             $colorSquare = imagecreatetruecolor(11, 11);
         } else {
             $colorSquare = imagecreate(11, 11);
         }
         imagefill($colorSquare, 0, 0, $this->getColor($this->graphtheme['backgroundcolor'], 0));
         imagefilledrectangle($colorSquare, 0, 0, 10, 10, $color);
         imagerectangle($colorSquare, 0, 0, 10, 10, $this->getColor('Black'));
         // caption
         $itemCaption = $this->itemsHost ? $this->items[$i]['name_expanded'] : $this->items[$i]['hostname'] . NAME_DELIMITER . $this->items[$i]['name_expanded'];
         // draw legend of an item with data
         if (isset($data) && isset($data['min'])) {
             if ($this->items[$i]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
                 $units['left'] = $this->items[$i]['units'];
             } else {
                 $units['right'] = $this->items[$i]['units'];
             }
             $legend->addCell($rowNum, array('image' => $colorSquare, 'marginRight' => 5));
             $legend->addCell($rowNum, array('text' => $itemCaption));
             $legend->addCell($rowNum, array('text' => '[' . $fncRealName . ']'));
             $legend->addCell($rowNum, array('text' => convert_units(array('value' => $this->getLastValue($i), 'units' => $this->items[$i]['units'], 'convert' => ITEM_CONVERT_NO_UNITS)), 'align' => 2));
             $legend->addCell($rowNum, array('text' => convert_units(array('value' => min($data['min']), 'units' => $this->items[$i]['units'], 'convert' => ITEM_CONVERT_NO_UNITS)), 'align' => 2));
             $legend->addCell($rowNum, array('text' => convert_units(array('value' => $data['avg_orig'], 'units' => $this->items[$i]['units'], 'convert' => ITEM_CONVERT_NO_UNITS)), 'align' => 2));
             $legend->addCell($rowNum, array('text' => convert_units(array('value' => max($data['max']), 'units' => $this->items[$i]['units'], 'convert' => ITEM_CONVERT_NO_UNITS)), 'align' => 2));
         } else {
             $legend->addCell($rowNum, array('image' => $colorSquare, 'marginRight' => 5));
             $legend->addCell($rowNum, array('text' => $itemCaption));
             $legend->addCell($rowNum, array('text' => '[ ' . _('no data') . ' ]'));
         }
         $rowNum++;
         if ($this->type == GRAPH_TYPE_STACKED) {
             $i--;
         } else {
             $i++;
         }
     }
     $legend->draw();
     // if graph is small, we are not drawing percent line and trigger legends
     if ($this->sizeY < ZBX_GRAPH_LEGEND_HEIGHT) {
         return true;
     }
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // draw percentile
     if ($this->type == GRAPH_TYPE_NORMAL) {
         foreach ($this->percentile as $side => $percentile) {
             if ($percentile['percent'] > 0 && $percentile['value']) {
                 $percentile['percent'] = (double) $percentile['percent'];
                 $convertedUnit = convert_units(array('value' => $percentile['value'], 'units' => $units[$side]));
                 $legend->addCell($rowNum, array('text' => $percentile['percent'] . 'th percentile: ' . $convertedUnit . ' (' . $side . ')', ITEM_CONVERT_NO_UNITS));
                 if ($side == 'left') {
                     $color = $this->graphtheme['leftpercentilecolor'];
                 } else {
                     $color = $this->graphtheme['rightpercentilecolor'];
                 }
                 imagefilledpolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - 10), 3, $this->getColor($color));
                 imagepolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - 10), 3, $this->getColor('Black No Alpha'));
                 $rowNum++;
             }
         }
     }
     $legend->draw();
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY + 5);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // draw triggers
     foreach ($this->triggers as $trigger) {
         imagefilledellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, 10, 10, $this->getColor($trigger['color']));
         imageellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY, 10, 10, $this->getColor('Black No Alpha'));
         $legend->addRow(array(array('text' => $trigger['description']), array('text' => $trigger['constant'])));
         $rowNum++;
     }
     $legend->draw();
 }