Source
xxxxxxxxxx
<?php
/*
** Zabbix
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
class CPieGraphDraw extends CGraphDraw {
const DEFAULT_HEADER_PADDING_TOP = 30;
const GRAPH_WIDTH_MIN = 20;
const GRAPH_HEIGHT_MIN = 20;
private $background;
private $sum;
private $exploderad;
private $exploderad3d;
private $graphheight3d;
private $shiftlegendright;
private $dataFrom;
private $shiftYLegend;
public function __construct($type = GRAPH_TYPE_PIE) {
parent::__construct($type);
$this->background = false;
$this->sum = false;
$this->exploderad = 1;
$this->exploderad3d = 3;
$this->graphheight3d = 12;
$this->shiftlegendright = 17 * 7 + 7 + 10; // count of static chars * px/char + for color rectangle + space
}
/********************************************************************************************************/
/* PRE CONFIG: ADD / SET / APPLY
/********************************************************************************************************/
public function addItem($itemid, $calc_fnc = CALC_FNC_AVG, $color = null, $type = null) {
$items = API::Item()->get([
'output' => ['itemid', 'hostid', 'name', 'key_', 'units', 'value_type', 'valuemapid', 'history', 'trends'],
'itemids' => [$itemid],
'webitems' => true
]);
if (!$items) {
$items = API::ItemPrototype()->get([
'output' => ['itemid', 'hostid', 'name', 'key_', 'units', 'value_type', 'valuemapid', 'history',
'trends'
],
'itemids' => [$itemid]
]);
}
$this->items[$this->num] = reset($items);
$host = get_host_by_hostid($this->items[$this->num]['hostid']);
$this->items[$this->num]['host'] = $host['host'];
$this->items[$this->num]['hostname'] = $host['name'];
$this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
$this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
$this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
$this->num++;
}
public function switchPie3D($type = false) {
if ($type) {
$this->type = $type;
}
else {
switch ($this->type) {
case GRAPH_TYPE_EXPLODED:
$this->type = GRAPH_TYPE_3D_EXPLODED;
break;
case GRAPH_TYPE_3D_EXPLODED:
$this->type = GRAPH_TYPE_EXPLODED;
break;