working on pmGauge for dashboards

This commit is contained in:
Fernando Ontiveros
2011-10-31 22:16:18 -04:00
parent 387b8c9f66
commit e849c2281f
3 changed files with 55 additions and 3 deletions

View File

@@ -55,6 +55,19 @@ Array
else {
$this->value = 0;
}
switch ( $config['DAS_INS_CONTEXT_TIME'] ) {
case 'TODAY' : $this->centerLabel = 'Today'; break;
case 'YESTERDAY' : $this->centerLabel = 'Yesterday'; break;
case 'THIS_WEEK' : $this->centerLabel = 'This week'; break;
case 'PREVIOUS_WEEK' : $this->centerLabel = 'Previous week'; break;
case 'THIS_MONTH' : $this->centerLabel = 'This month'; break;
case 'PREVIOUS_MONTH' : $this->centerLabel = 'Previous month'; break;
case 'THIS_QUARTER' : $this->centerLabel = 'This quarter'; break;
case 'PREVIOUS_QUARTER' : $this->centerLabel = 'Previous quarter'; break;
case 'THIS_YEAR' : $this->centerLabel = 'This year'; break;
case 'PREVIOUS_YEAR' : $this->centerLabel = 'Previous year'; break;
default : $this->centerLabel = '';break;
}
return $row[0];
}
@@ -63,7 +76,14 @@ Array
$g = new pmGauge();
$g->w = $width;
$g->value = $this->value;
$g->maxValue = 100;
$g->maxValue = 100;
$g->greenFrom = 90;
$g->greenTo = 100;
$g->yellowFrom = 70;
$g->yellowTo = 90;
$g->redFrom = 100;
$g->redTo = 100;
$g->centerLabel = $this->centerLabel;
$g->render();
}

View File

@@ -39,6 +39,21 @@
yellowTo
*/
var $yellowTo = 80;
/**
greenFrom
*/
var $greenFrom = 0;
/**
greenTo
*/
var $greenTo = 60;
/**
centerLabel, the label in the middle of the gauge
*/
var $centerLabel = '';
function render () {
$this->h = $this->w / 2;
@@ -57,7 +72,7 @@
$arrowLine = ImageColorAllocate($im, 207, 74, 42);
$redArc = ImageColorAllocate($im, 220, 57, 18);
$yellowArc = ImageColorAllocate($im, 255, 153, 0);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255, 255, 255);
$gray = ImageColorAllocate($im, 190, 190, 190);
@@ -102,6 +117,7 @@
$arrowLine = ImageColorAllocate($im, 207, 74, 42);
$redArc = ImageColorAllocate($im, 220, 57, 18);
$yellowArc = ImageColorAllocate($im, 255, 153, 0);
$greenArc = ImageColorAllocate($im, 0, 136, 0);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255, 255, 255);
@@ -129,17 +145,25 @@
if ( $this->redTo > $this->maxValue ) $this->redTo = $this->maxValue;
if ( $this->yellowFrom > $this->maxValue ) $this->yellowFrom = $this->maxValue;
if ( $this->yellowTo > $this->maxValue ) $this->yellowTo = $this->maxValue;
if ( $this->greenFrom > $this->maxValue ) $this->greenFrom = $this->maxValue;
if ( $this->greenTo > $this->maxValue ) $this->greenTo = $this->maxValue;
$redFrom = $this->redFrom/$this->maxValue*300 - 240 ;
$redTo = $this->redTo/$this->maxValue*300 - 240;
$yellowFrom = $this->yellowFrom/$this->maxValue*300 - 240;
$yellowTo = $this->yellowTo/$this->maxValue*300 - 240;
$greenFrom = $this->greenFrom/$this->maxValue*300 - 240;
$greenTo = $this->greenTo/$this->maxValue*300 - 240;
if ( $this->redFrom != $this->redTo && $this->redTo != $maxValue ) {
imagefilledarc ($im, $cX, $cY, $dXRingColor, $dYRingColor, $redFrom, $redTo, $redArc, IMG_ARC_PIE );
}
if ( $this->yellowFrom != $this->yellowTo && $this->yellowTo != $maxValue ) {
imagefilledarc ($im, $cX, $cY, $dXRingColor, $dYRingColor, $yellowFrom, $yellowTo, $yellowArc, IMG_ARC_PIE );
}
if ( $this->greenFrom != $this->greenTo && $this->greenTo != $maxValue ) {
imagefilledarc ($im, $cX, $cY, $dXRingColor, $dYRingColor, $greenFrom, $greenTo, $greenArc, IMG_ARC_PIE );
}
imagefilledellipse($im, $cX, $cY, $dXRingCenter, $dYRingCenter, $bgcolor);
//ticks
@@ -171,6 +195,14 @@
$min++;
}
if (trim($this->centerLabel) != '' ) {
$textToDisplay = trim($this->centerLabel);
$bbox = imagettfbbox(8, 0, $fontArial, $textToDisplay );
$x1 = $cX - $bbox[4] / 2;
$y1 = $cY *3/4 + abs($bbox[5]);
imagettftext ( $im, 8, 0, $x1, $y1, $black, $fontArial, $textToDisplay );
}
//drawing the arrow, simple way
$radiusX = intval($dX * 0.35);
$radiusY = intval($dY * 0.35);

View File

@@ -158,7 +158,7 @@ Ext.onReady(function(){
}
});
pd.items.items[0].add( np );
pd.items.items[i % 3].add( np );
} //for
pd.doLayout();