~kampka/ubuntu/quantal/zabbix/upstart-support

« back to all changes in this revision

Viewing changes to frontends/php/include/classes/pie.inc.php

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2009-06-28 19:11:29 UTC
  • mfrom: (19.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090628191129-5esmmf2h3tbff1fv
* New upstream release
* Merge upstream config file to template (Closes: #528426)
* Move logrotate from Depends to Suggests (Closes: #534096)
* Server should not crash anymore if postgresql transaction fails
  (Closes: #520197)
* Update fr.po (Closes: #527559)
* Update es.po (Closes: #527600)
* Update sv.po (Closes: #528571)
* Update it.po (Closes: #529157)
* Update cs.po (Closes: #529502)
* Update de.po (Closes: #532344)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php 
2
 
/* 
 
1
<?php
 
2
/*
3
3
** ZABBIX
4
4
** Copyright (C) 2000-2007 SIA Zabbix
5
5
**
25
25
 
26
26
function Pie($type = GRAPH_TYPE_PIE){
27
27
        parent::Graph($type);
28
 
        
 
28
 
29
29
        $this->background = false;
30
30
        $this->sum = false;
31
31
        $this->exploderad = 1;
61
61
        $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
62
62
        $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
63
63
        $this->items[$this->num]['periods_cnt'] = is_null($periods_cnt) ? 0 : $periods_cnt;
64
 
        
 
64
 
65
65
        $this->num++;
66
66
}
67
67
 
82
82
 
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
87
87
 
88
88
        for($i=0; $i < $this->num; $i++){
89
 
        
 
89
 
90
90
                $real_item = get_item_by_itemid($this->items[$i]['itemid']);
91
91
                $type = $this->items[$i]['calc_type'];
92
92
 
93
93
                $from_time      = $this->from_time;
94
94
                $to_time        = $this->to_time;
95
 
                
 
95
 
96
96
                $sql_arr = array();
97
 
                                
 
97
 
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?
100
100
                {
145
145
                                ' GROUP BY t.itemid'
146
146
                                );
147
147
                }
148
 
                
 
148
 
149
149
                $curr_data = &$this->data[$this->items[$i]['itemid']][$type];
150
150
                $curr_data->min = NULL;
151
151
                $curr_data->max = NULL;
154
154
 
155
155
                foreach($sql_arr as $sql){
156
156
                        $result=DBselect($sql);
157
 
                        
 
157
 
158
158
                        while($row=DBfetch($result)){
159
159
                                $curr_data->min = $row['min'];
160
160
                                $curr_data->max = $row['max'];
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;
167
167
                        }
168
168
                        unset($row);
169
169
                }
170
 
                
 
170
 
171
171
                switch($this->items[$i]['calc_fnc']){
172
 
                        case CALC_FNC_MIN:      
 
172
                        case CALC_FNC_MIN:
173
173
                                $item_value = abs($curr_data->min);
174
174
 
175
175
                                break;
176
 
                        case CALC_FNC_MAX:      
 
176
                        case CALC_FNC_MAX:
177
177
                                $item_value = abs($curr_data->max);
178
178
                                break;
179
 
                        case CALC_FNC_LST:      
 
179
                        case CALC_FNC_LST:
180
180
                                $item_value = abs($curr_data->lst);
181
181
                                break;
182
182
                        case CALC_FNC_AVG:
183
 
                        default:                
 
183
                        default:
184
184
                                $item_value = abs($curr_data->avg);
185
185
                }
186
186
 
188
188
                        $this->background = $i;
189
189
                        $graph_sum = $item_value;
190
190
                }
191
 
                
 
191
 
192
192
                $this->sum += $item_value;
193
193
                $strvaluelength = max($strvaluelength,strlen(convert_units($item_value,$this->items[$i]['unit'])));
194
194
        }
195
 
        
 
195
 
196
196
        if(isset($graph_sum)) $this->sum = $graph_sum;
197
197
        $this->shiftlegendright += $strvaluelength * 7;
198
198
}
201
201
/*function set3DAngle($angle = 70){
202
202
        if(is_numeric($angle) && ($angle < 85) && ($angle > 10)){
203
203
                $this->angle3d = (int) $angle;
204
 
        } 
 
204
        }
205
205
        else {
206
206
                $this->angle3d = 70;
207
207
        }
254
254
                                $this->type = GRAPH_TYPE_PIE;
255
255
                }
256
256
        }
257
 
return $this->type;     
 
257
return $this->type;
258
258
}
259
259
 
260
260
function calc3dhight($height){
268
268
        $y+= round($count * sin(deg2rad($anglemid)));
269
269
        $x+= round($count * cos(deg2rad($anglemid)));
270
270
 
271
 
return array($x,$y);            
 
271
return array($x,$y);
272
272
}
273
273
 
274
274
function calcExplodedRadius($sizeX,$sizeY,$count){
286
286
function drawLegend(){
287
287
 
288
288
        $shiftY = $this->shiftY + $this->shiftYLegend;
289
 
        
 
289
 
290
290
        $max_host_len=0;
291
291
        $max_desc_len=0;
292
 
        
 
292
 
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']);
299
299
 
300
300
                $color = $this->GetColor($this->items[$i]['color']);
301
301
                $data = &$this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
302
 
                
 
302
 
303
303
                switch($this->items[$i]['calc_fnc']){
304
 
                        case CALC_FNC_MIN:      
 
304
                        case CALC_FNC_MIN:
305
305
                                $fnc_name = 'min';
306
306
                                $datavalue = $data->min;
307
307
                                break;
308
 
                        case CALC_FNC_MAX:      
309
 
                                $fnc_name = 'max';      
 
308
                        case CALC_FNC_MAX:
 
309
                                $fnc_name = 'max';
310
310
                                $datavalue = $data->max;
311
311
                                break;
312
 
                        case CALC_FNC_LST:      
313
 
                                $fnc_name = 'last';     
 
312
                        case CALC_FNC_LST:
 
313
                                $fnc_name = 'last';
314
314
                                $datavalue = $data->lst;
315
315
                                break;
316
316
                        case CALC_FNC_AVG:
317
 
                        default:                
 
317
                        default:
318
318
                                $fnc_name = 'avg';
319
319
                                $datavalue = $data->avg;
320
320
                }
321
 
                
 
321
 
322
322
                $proc = ($datavalue * 100)/ $this->sum;
323
323
//              convert_units($datavalue,$this->items[$i]["units"]),
324
324
                if(isset($data) && isset($datavalue)){
347
347
 
348
348
                $shiftX = $this->fullSizeX - $this->shiftlegendright - $this->shiftXright + 10;
349
349
//              SDI($shiftX.','.$this->sizeX);
350
 
                
 
350
 
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'));
353
 
                
 
353
 
354
354
                ImageString($this->im, 2,
355
355
                        $shiftX+9,
356
356
                        $this->shiftY+10+12*$i,
365
365
function drawElementPie($values){
366
366
 
367
367
        $sum = $this->sum;
368
 
        
 
368
 
369
369
        if($this->background !== false){
370
370
                $least = 0;
371
371
                foreach($values as $item => $value){
376
376
                }
377
377
                $values[$this->background] -= $least;
378
378
        }
379
 
        
 
379
 
380
380
        if($sum <= 0){
381
381
                $this->items[0]['color'] = 'FFFFFF';
382
382
                $values = array(0 => 1);
383
383
                $sum = 1;
384
384
        }
385
385
//              asort($values);
386
 
        
 
386
 
387
387
        $sizeX = $this->sizeX;
388
388
        $sizeY = $this->sizeY;
389
 
        
 
389
 
390
390
        if($this->type == GRAPH_TYPE_EXPLODED){
391
391
                list($sizeX,$sizeY) = $this->calcExplodedRadius($sizeX,$sizeY,count($values));
392
392
        } else {
396
396
 
397
397
        $xc = $x = (int) $this->sizeX/2 + ($this->shiftXleft);
398
398
        $yc = $y = (int) $this->sizeY/2 + $this->shiftY;
399
 
        
 
399
 
400
400
        $anglestart = 0;
401
401
        $angleend = 0;
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;
406
 
                
 
406
 
407
407
                if($this->type == GRAPH_TYPE_EXPLODED){
408
408
                        list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values));
409
409
                }
410
 
                
 
410
 
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;
418
418
function drawElementPie3D($values){
419
419
 
420
420
        $sum = $this->sum;
421
 
        
 
421
 
422
422
        if($this->background !== false){
423
423
                $least = 0;
424
424
                foreach($values as $item => $value){
428
428
                }
429
429
                $values[$this->background] -= $least;
430
430
        }
431
 
        
 
431
 
432
432
        if($sum <= 0){
433
433
                $this->items[0]['color'] = 'FFFFFF';
434
434
                $values = array(0 => 1);
435
435
                $sum = 1;
436
436
        }
437
437
//              asort($values);
438
 
        
 
438
 
439
439
        $sizeX = $this->sizeX;
440
440
        $sizeY = $this->sizeY;
441
 
        
 
441
 
442
442
        $this->exploderad = $this->exploderad3d;
443
 
        
 
443
 
444
444
        if($this->type == GRAPH_TYPE_3D_EXPLODED){
445
445
                list($sizeX,$sizeY) = $this->calcExplodedRadius($sizeX,$sizeY,count($values));
446
446
        }
447
447
 
448
448
        list($sizeX,$sizeY) = $this->calc3DAngle($sizeX,$sizeY);
449
 
        
 
449
 
450
450
        $xc = $x = (int) $this->sizeX/2 + ($this->shiftXleft);
451
451
        $yc = $y = (int) $this->sizeY/2 + $this->shiftY;
452
 
        
 
452
 
453
453
// ----- bottom angle line ----
454
454
        $anglestart = 0;
455
455
        $angleend = 0;
456
456
        foreach($values as $item => $value){
457
 
                
 
457
 
458
458
                $angleend += (int)(360 * $value/$sum)+1;
459
459
                $angleend = ($angleend > 360)?(360):($angleend);
460
460
                if(($angleend - $anglestart) < 1) continue;
461
 
                
 
461
 
462
462
                if($this->type == GRAPH_TYPE_3D_EXPLODED){
463
463
                        list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values));
464
464
                }
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;
468
468
        }//*/
469
 
        
 
469
 
470
470
//      ------ 3d effect        ------
471
471
        for ($i = $this->graphheight3d; $i > 0; $i--) {
472
472
                $anglestart = 0;
474
474
                foreach($values as $item => $value){
475
475
                        $angleend += (int)(360 * $value/$sum)+1;
476
476
                        $angleend = ($angleend > 360)?(360):($angleend);
477
 
                        
 
477
 
478
478
                        if(($angleend - $anglestart) < 1) continue;
479
479
                        elseif($this->sum == 0) continue;
480
 
                        
 
480
 
481
481
                        if($this->type == GRAPH_TYPE_3D_EXPLODED){
482
482
                                list($x,$y) = $this->calcExplodedCenter($anglestart,$angleend,$xc,$yc,count($values));
483
483
                        }
484
 
                        
 
484
 
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;
487
487
                }
488
488
        }
489
 
        
 
489
 
490
490
        $anglestart = 0;
491
491
        $angleend = 0;
492
492
        foreach($values as $item => $value){
493
 
                
 
493
 
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));
500
500
                }
501
 
                        
 
501
 
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();
512
 
        
 
512
 
513
513
        $this->selectData();
514
514
 
515
515
        $this->shiftY = 20;
516
516
        $this->shiftYLegend = 20;
517
517
        $this->shiftXleft = 10;
518
518
        $this->shiftXright = 0;
519
 
        
 
519
 
520
520
        $this->fullSizeX = $this->sizeX;
521
521
        $this->fullSizeY = $this->sizeY;
522
 
        
 
522
 
523
523
        if(($this->sizeX < 300) || ($this->sizeY < 200)) $this->switchlegend(0);
524
 
        
 
524
 
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);
532
532
        }
533
 
        
 
533
 
534
534
//      SDI($this->sizeX.','.$this->sizeY);
535
 
        
 
535
 
536
536
        $this->sizeX = min($this->sizeX,$this->sizeY);
537
537
        $this->sizeY = min($this->sizeX,$this->sizeY);
538
 
        
 
538
 
539
539
        $this->calc3dhight($this->sizeY);
540
 
        
 
540
 
541
541
        $this->exploderad = (int) $this->sizeX / 100;
542
542
        $this->exploderad3d = (int) $this->sizeX / 60;
543
 
        
 
543
 
544
544
        if(function_exists('ImageColorExactAlpha')&&function_exists('ImageCreateTrueColor')&&@imagecreatetruecolor(1,1))
545
545
                $this->im = imagecreatetruecolor($this->fullSizeX,$this->fullSizeY);
546
546
        else
550
550
        $this->initColors();
551
551
        $this->drawRectangle();
552
552
        $this->drawHeader();
553
 
        
 
553
 
554
554
        $maxX = $this->sizeX;
555
 
        
 
555
 
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']];
560
560
 
561
561
                $data = &$this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
562
 
                
 
562
 
563
563
                if(!isset($data))       continue;
564
564
 
565
565
                $drawtype       = $this->items[$item]['drawtype'];
568
568
                $avg_color      = $this->GetColor($this->items[$item]['color']);
569
569
                $min_color      = $this->GetColor('ValueMin');
570
570
                $minmax_color   = $this->GetColor('ValueMinMax');
571
 
                
 
571
 
572
572
                $calc_fnc = $this->items[$item]['calc_fnc'];
573
573
 
574
574
                switch($calc_fnc){
586
586
                                break;
587
587
                }
588
588
        }
589
 
        
 
589
 
590
590
        switch($this->type){
591
591
                case GRAPH_TYPE_EXPLODED:
592
592
                        $this->drawElementPie($values);
605
605
        $this->drawLogo();
606
606
 
607
607
        if($this->drawlegendallow == 1) $this->drawLegend();
608
 
        
 
608
 
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'));
612
612
 
613
613
        unset($this->items, $this->data);
614
614
 
615
 
        ImageOut($this->im); 
 
615
        ImageOut($this->im);
616
616
}
617
617
 
618
618
}