<?php
// $Header: /cvsroot/phptsmadmin/phpTSMadmin/htdocs/image.server.stats.php,v 1.6 2009/04/19 03:54:40 wurley Exp $

# Required Libraries
require './common.php';
initJPGraph(true);

$activity = $_REQUEST['activity'];
if (! isset($_SESSION['graph'][$activity]))
	exit;

$color_array = array(
	'darkred','aquamarine','blue','violet','blueviolet','red','brown','burlywood','cadetblue','chocolate','red','darkred');

$graph = new Graph(900,300,'auto');
$graph->SetScale('datlin',0,(isset($_SESSION['graph'][$activity]['mode']) ? $_SESSION['graph'][$activity]['mode']*2 : 0));

ksort($_SESSION['graph'][$activity]['data']);

$counter = 0;
foreach ($_SESSION['graph'][$activity]['data'] as $process => $detail) {
	$color = $counter%count($color_array);

	$$process = new LinePlot(array_values($detail),array_keys($detail));
	$$process->SetLegend($process);
	$$process->SetColor($color_array[$color]);
	$$process->mark->SetType(MARK_IMG_MBALL,$color,0.3);
	$graph->Add($$process);
	$counter++;
}

$graph->xaxis->SetLabelAngle(90);
$graph->img->SetMargin(60,160,20,80);
$graph->legend->Pos(0.01,0.50,'right','center');
$graph->legend->SetFillColor('azure');
$graph->yaxis->SetLabelFormatCallback('labelformat');
$graph->yaxis->SetTitleMargin(45);
$graph->SetMarginColor('azure2');

switch($activity) {
	case 'mediawait' :
		$graph->yaxis->title->Set('Wait Time (mins)'); 
		$graph->title->Set(sprintf('Media Wait Time %s',$app['server']->GetStatusDetail('SERVER_NAME')));
		break;

	case 'thruput' :
		$graph->yaxis->title->Set('Thruput (MB/s)'); 
		$graph->title->Set(sprintf('Data Thruput %s',$app['server']->GetStatusDetail('SERVER_NAME')));
		break;

	default :
		$graph->yaxis->title->Set('Unknown');
		$graph->title->Set(sprintf('Unknown Report %s',$app['server']->GetStatusDetail('SERVER_NAME')));
}
# Display the chart
$graph->Stroke();
unset($_SESSION['graph'][$activity]);

function labelformat($label) {
    return sprintf('%3.1f',$label/60);
}
?>