Exemplo n.º 1
0
 protected function drawLegend()
 {
     $leftXShift = 13;
     $units = array('left' => 0, 'right' => 0);
     $legend = new CImageTextTable_Zabbix($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + $this->legendOffsetY - 35);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     //原来14
     $legend->fontsize = 7;
     //原来9
     $row = array(array('text' => ''), array('text' => _('last'), 'align' => 1, 'fontsize' => 7), array('text' => _('min'), 'align' => 1, 'fontsize' => 7), array('text' => _('avg'), 'align' => 1, 'fontsize' => 7), array('text' => _('max'), 'align' => 1, 'fontsize' => 7));
     $legend->addRow($row);
     $colNum = $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:
                 $fnc_name = _('min');
                 break;
             case CALC_FNC_MAX:
                 $fnc_name = _('max');
                 break;
             case CALC_FNC_ALL:
                 $fnc_name = _('all');
                 break;
             case CALC_FNC_AVG:
             default:
                 $fnc_name = _('avg');
         }
         $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
         if ($this->itemsHost) {
             $item_caption = $this->items[$i]['name'];
             //标题即itme名称
         } else {
             $item_caption = $this->items[$i]['hostname'] . ': ' . $this->items[$i]['name'];
         }
         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' => ''));
             $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' => '[ ' . _('no data') . ' ]'));
         }
         imagefilledrectangle($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35 - 10, $leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35, $color);
         imagerectangle($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35 - 10, $leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35, $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_Zabbix($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 7;
     // 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 - 35, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35 - 10), 3, $this->getColor($color));
                 imagepolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35 - 10), 3, $this->getColor('Black No Alpha'));
                 $colNum++;
             }
         }
     }
     $legend->draw();
     $legend = new CImageTextTable_Zabbix($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35 + 5);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 7;
     // draw triggers
     foreach ($this->triggers as $trigger) {
         imagefilledellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35, 10, 10, $this->getColor($trigger['color']));
         imageellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 35, 10, 10, $this->getColor('Black No Alpha'));
         $legend->addRow(array(array('text' => $trigger['description']), array('text' => $trigger['constant'])));
         $colNum++;
     }
     $legend->draw();
 }
Exemplo n.º 2
0
 protected function drawLegend()
 {
     $leftXShift = 13;
     //原来是20 item向左偏移量
     $units = array('left' => 0, 'right' => 0);
     // draw item legend
     $legend = new CImageTextTable_Zabbix($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + $this->legendOffsetY - $this->date_cell_hight);
     //后面多减了一个35
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = $this->img_rowheight;
     //原来14
     $legend->fontsize = $this->img_fontsize;
     //原来9
     // item legend table header
     $row = array(array('text' => '', 'marginRight' => 5), array('text' => ''), array('text' => _('last'), 'align' => 1, 'fontsize' => 7), array('text' => _('min'), 'align' => 1, 'fontsize' => 7), array('text' => _('avg'), 'align' => 1, 'fontsize' => 7), array('text' => _('max'), 'align' => 1, 'fontsize' => 7));
     $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_Zabbix($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - $this->date_cell_hight);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = $this->img_rowheight;
     //原来14
     $legend->fontsize = $this->img_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 - $this->date_cell_hight, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - $this->date_cell_hight, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - 10 - $this->date_cell_hight), 3, $this->getColor($color));
                 imagepolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - $this->date_cell_hight, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - $this->date_cell_hight, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - 10 - $this->date_cell_hight), 3, $this->getColor('Black No Alpha'));
                 $rowNum++;
             }
         }
     }
     $legend->draw();
     $legend = new CImageTextTable_Zabbix($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY + 5 - $this->date_cell_hight);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = $this->img_rowheight;
     //原来14
     $legend->fontsize = $this->img_fontsize;
     //原来9
     // draw triggers
     foreach ($this->triggers as $trigger) {
         imagefilledellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - $this->date_cell_hight, 10, 10, $this->getColor($trigger['color']));
         imageellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $rowNum + $this->legendOffsetY - $this->date_cell_hight, 10, 10, $this->getColor('Black No Alpha'));
         $legend->addRow(array(array('text' => $trigger['description']), array('text' => $trigger['constant'])));
         $rowNum++;
     }
     $legend->draw();
 }