83
83
$p = $this->to_time - $this->from_time; // graph size in time
84
84
$z = $p - $this->from_time % $p; //<strong></strong>
85
$x = $this->sizeX; // graph size in px
85
$x = $this->sizeX; // graph size in px
86
86
$strvaluelength = 0; // we need to know how long in px will be our legend
88
88
for($i=0; $i < $this->num; $i++){
90
90
$real_item = get_item_by_itemid($this->items[$i]['itemid']);
91
91
$type = $this->items[$i]['calc_type'];
93
93
$from_time = $this->from_time;
94
94
$to_time = $this->to_time;
96
96
$sql_arr = array();
98
98
if((($real_item['history']*86400) > (time()-($from_time+$this->period/2))) && // should pick data from history or trends
99
99
(($this->period / $this->sizeX) <= (ZBX_MAX_TREND_DIFF / ZBX_GRAPH_MAX_SKIP_CELL))) // is reasonable to take data from history?
163
163
$curr_data->clock = $row['clock'];
164
164
$curr_data->shift_min = 0;
165
165
$curr_data->shift_max = 0;
166
$curr_data->shift_avg = 0;
166
$curr_data->shift_avg = 0;
171
171
switch($this->items[$i]['calc_fnc']){
173
173
$item_value = abs($curr_data->min);
177
177
$item_value = abs($curr_data->max);
180
180
$item_value = abs($curr_data->lst);
182
182
case CALC_FNC_AVG:
184
184
$item_value = abs($curr_data->avg);
188
188
$this->background = $i;
189
189
$graph_sum = $item_value;
192
192
$this->sum += $item_value;
193
193
$strvaluelength = max($strvaluelength,strlen(convert_units($item_value,$this->items[$i]['unit'])));
196
196
if(isset($graph_sum)) $this->sum = $graph_sum;
197
197
$this->shiftlegendright += $strvaluelength * 7;
286
286
function drawLegend(){
288
288
$shiftY = $this->shiftY + $this->shiftYLegend;
293
293
for($i=0;$i<$this->num;$i++){
294
294
if(strlen($this->items[$i]['host'])>$max_host_len) $max_host_len=strlen($this->items[$i]['host']);
295
295
if(strlen($this->items[$i]['description'])>$max_desc_len) $max_desc_len=strlen($this->items[$i]['description']);
300
300
$color = $this->GetColor($this->items[$i]['color']);
301
301
$data = &$this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
303
303
switch($this->items[$i]['calc_fnc']){
305
305
$fnc_name = 'min';
306
306
$datavalue = $data->min;
310
310
$datavalue = $data->max;
314
314
$datavalue = $data->lst;
316
316
case CALC_FNC_AVG:
318
318
$fnc_name = 'avg';
319
319
$datavalue = $data->avg;
322
322
$proc = ($datavalue * 100)/ $this->sum;
323
323
// convert_units($datavalue,$this->items[$i]["units"]),
324
324
if(isset($data) && isset($datavalue)){
348
348
$shiftX = $this->fullSizeX - $this->shiftlegendright - $this->shiftXright + 10;
349
349
// SDI($shiftX.','.$this->sizeX);
351
351
ImageFilledRectangle($this->im,$shiftX,$this->shiftY+10+5+12*$i,$shiftX+5,$this->shiftY+10+10+12*$i,$color);
352
352
ImageRectangle($this->im,$shiftX,$this->shiftY+10+5+12*$i,$shiftX+5,$this->shiftY+10+10+12*$i,$this->GetColor('Black No Alpha'));
354
354
ImageString($this->im, 2,
356
356
$this->shiftY+10+12*$i,
377
377
$values[$this->background] -= $least;
381
381
$this->items[0]['color'] = 'FFFFFF';
382
382
$values = array(0 => 1);
385
385
// asort($values);
387
387
$sizeX = $this->sizeX;
388
388
$sizeY = $this->sizeY;
390
390
if($this->type == GRAPH_TYPE_EXPLODED){
391
391
list($sizeX,$sizeY) = $this->calcExplodedRadius($sizeX,$sizeY,count($values));
397
397
$xc = $x = (int) $this->sizeX/2 + ($this->shiftXleft);
398
398
$yc = $y = (int) $this->sizeY/2 + $this->shiftY;
402
402
foreach($values as $item => $value){
403
403
$angleend += (int)(360 * $value/$sum)+1;
404
404
$angleend = ($angleend > 360)?(360):($angleend);
405
405
if(($angleend - $anglestart) < 1) continue;
407
407
if($this->type == GRAPH_TYPE_EXPLODED){
408
408
list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values));
411
411
imagefilledarc($this->im, $x, $y, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor($this->items[$item]['color'],0), IMG_ARC_PIE);
412
412
imagefilledarc($this->im, $x, $y, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor('Black'), IMG_ARC_PIE|IMG_ARC_EDGED|IMG_ARC_NOFILL);
413
413
$anglestart = $angleend;
429
429
$values[$this->background] -= $least;
433
433
$this->items[0]['color'] = 'FFFFFF';
434
434
$values = array(0 => 1);
437
437
// asort($values);
439
439
$sizeX = $this->sizeX;
440
440
$sizeY = $this->sizeY;
442
442
$this->exploderad = $this->exploderad3d;
444
444
if($this->type == GRAPH_TYPE_3D_EXPLODED){
445
445
list($sizeX,$sizeY) = $this->calcExplodedRadius($sizeX,$sizeY,count($values));
448
448
list($sizeX,$sizeY) = $this->calc3DAngle($sizeX,$sizeY);
450
450
$xc = $x = (int) $this->sizeX/2 + ($this->shiftXleft);
451
451
$yc = $y = (int) $this->sizeY/2 + $this->shiftY;
453
453
// ----- bottom angle line ----
456
456
foreach($values as $item => $value){
458
458
$angleend += (int)(360 * $value/$sum)+1;
459
459
$angleend = ($angleend > 360)?(360):($angleend);
460
460
if(($angleend - $anglestart) < 1) continue;
462
462
if($this->type == GRAPH_TYPE_3D_EXPLODED){
463
463
list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values));
465
465
imagefilledarc($this->im, $x, $y+$this->graphheight3d+1, $sizeX, $sizeY, $anglestart, $angleend, $this->GetShadow($this->items[$item]['color'],0), IMG_ARC_PIE);
466
imagefilledarc($this->im, $x, $y+$this->graphheight3d+1, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor('Black'), IMG_ARC_PIE|IMG_ARC_EDGED|IMG_ARC_NOFILL);
466
imagefilledarc($this->im, $x, $y+$this->graphheight3d+1, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor('Black'), IMG_ARC_PIE|IMG_ARC_EDGED|IMG_ARC_NOFILL);
467
467
$anglestart = $angleend;
470
470
// ------ 3d effect ------
471
471
for ($i = $this->graphheight3d; $i > 0; $i--) {
474
474
foreach($values as $item => $value){
475
475
$angleend += (int)(360 * $value/$sum)+1;
476
476
$angleend = ($angleend > 360)?(360):($angleend);
478
478
if(($angleend - $anglestart) < 1) continue;
479
479
elseif($this->sum == 0) continue;
481
481
if($this->type == GRAPH_TYPE_3D_EXPLODED){
482
482
list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values));
485
485
imagefilledarc($this->im, $x, $y+$i, $sizeX, $sizeY, $anglestart, $angleend, $this->GetShadow($this->items[$item]['color'],0), IMG_ARC_PIE);
486
486
$anglestart = $angleend;
492
492
foreach($values as $item => $value){
494
494
$angleend += (int)(360 * $value/$sum)+1;
495
495
$angleend = ($angleend > 360)?(360):($angleend);
496
496
if(($angleend - $anglestart) < 1) continue;
498
498
if($this->type == GRAPH_TYPE_3D_EXPLODED){
499
499
list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values));
502
502
imagefilledarc($this->im, $x, $y, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor($this->items[$item]['color'],0), IMG_ARC_PIE);
503
503
imagefilledarc($this->im, $x, $y, $sizeX, $sizeY, $anglestart, $angleend, $this->GetColor('Black'), IMG_ARC_PIE|IMG_ARC_EDGED|IMG_ARC_NOFILL);
504
504
$anglestart = $angleend;
509
509
$start_time=getmicrotime();
510
510
set_image_header();
511
511
check_authorisation();
513
513
$this->selectData();
515
515
$this->shiftY = 20;
516
516
$this->shiftYLegend = 20;
517
517
$this->shiftXleft = 10;
518
518
$this->shiftXright = 0;
520
520
$this->fullSizeX = $this->sizeX;
521
521
$this->fullSizeY = $this->sizeY;
523
523
if(($this->sizeX < 300) || ($this->sizeY < 200)) $this->switchlegend(0);
525
525
if($this->drawlegendallow == 1){
526
526
$this->sizeX -= ($this->shiftXleft+$this->shiftXright+$this->shiftlegendright);
527
527
$this->sizeY -= ($this->shiftY+$this->shiftYLegend+12*$this->num+8);
530
530
$this->sizeX -= ($this->shiftXleft*2);
531
531
$this->sizeY -= ($this->shiftY*2);
534
534
// SDI($this->sizeX.','.$this->sizeY);
536
536
$this->sizeX = min($this->sizeX,$this->sizeY);
537
537
$this->sizeY = min($this->sizeX,$this->sizeY);
539
539
$this->calc3dhight($this->sizeY);
541
541
$this->exploderad = (int) $this->sizeX / 100;
542
542
$this->exploderad3d = (int) $this->sizeX / 60;
544
544
if(function_exists('ImageColorExactAlpha')&&function_exists('ImageCreateTrueColor')&&@imagecreatetruecolor(1,1))
545
545
$this->im = imagecreatetruecolor($this->fullSizeX,$this->fullSizeY);
550
550
$this->initColors();
551
551
$this->drawRectangle();
552
552
$this->drawHeader();
554
554
$maxX = $this->sizeX;
556
556
// For each metric
557
557
for($item = 0; $item < $this->num; $item++){
558
558
$minY = $this->m_minY[$this->items[$item]['axisside']];
559
559
$maxY = $this->m_maxY[$this->items[$item]['axisside']];
561
561
$data = &$this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
563
563
if(!isset($data)) continue;
565
565
$drawtype = $this->items[$item]['drawtype'];
605
605
$this->drawLogo();
607
607
if($this->drawlegendallow == 1) $this->drawLegend();
609
609
$end_time=getmicrotime();
610
610
$str=sprintf("%0.2f",(getmicrotime()-$start_time));
611
611
ImageString($this->im, 0,$this->fullSizeX-120,$this->fullSizeY-12,"Generated in $str sec", $this->GetColor('Gray'));
613
613
unset($this->items, $this->data);