2011-03-30 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_graph.php, include/graphs/*, include/graphs/fgraph.php:
	added first version of common graph libraries with Integria and Babel.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4146 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-03-30 12:34:25 +00:00
parent 7502c19cf4
commit c38a7f0fd7
65 changed files with 14332 additions and 0 deletions

11
.project Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>pandora</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@ -1,3 +1,8 @@
2011-03-30 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_graph.php, include/graphs/*, include/graphs/fgraph.php:
added first version of common graph libraries with Integria and Babel.
2011-03-30 Javier Lanz <javier.lanz@artica.es>
* include/functions_reporting.php: Fixed get_agentmodule_sla_array and

View File

@ -0,0 +1,264 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2011 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
// 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.
include_once($config["homedir"] . "/include/graphs/fgraph.php");
function grafico_modulo_sparse2 ($agent_module_id, $period, $show_events,
$width, $height , $title, $unit_name,
$show_alerts, $avg_only = 0, $pure = false,
$date = 0, $baseline = 0, $return_data = 0, $show_title = true) {
global $config;
global $graphic_type;
// Set variables
if ($date == 0) $date = get_system_time();
$datelimit = $date - $period;
$resolution = $config['graph_res'] * 50; //Number of points of the graph
$interval = (int) ($period / $resolution);
$agent_name = get_agentmodule_agent_name ($agent_module_id);
$agent_id = get_agent_id ($agent_name);
$module_name = get_agentmodule_name ($agent_module_id);
$id_module_type = get_agentmodule_type ($agent_module_id);
$module_type = get_moduletype_name ($id_module_type);
$uncompressed_module = is_module_uncompressed ($module_type);
if ($uncompressed_module) {
$avg_only = 1;
}
// Get event data (contains alert data too)
if ($show_events == 1 || $show_alerts == 1) {
$events = get_db_all_rows_filter ('tevento',
array ('id_agentmodule' => $agent_module_id,
"utimestamp > $datelimit",
"utimestamp < $date",
'order' => 'utimestamp ASC'),
array ('evento', 'utimestamp', 'event_type'));
if ($events === false) {
$events = array ();
}
}
// Get module data
$data = get_db_all_rows_filter ('tagente_datos',
array ('id_agente_modulo' => $agent_module_id,
"utimestamp > $datelimit",
"utimestamp < $date",
'order' => 'utimestamp ASC'),
array ('datos', 'utimestamp'), 'AND', true);
if ($data === false) {
$data = array ();
}
// Uncompressed module data
if ($uncompressed_module) {
$min_necessary = 1;
// Compressed module data
} else {
// Get previous data
$previous_data = get_previous_data ($agent_module_id, $datelimit);
if ($previous_data !== false) {
$previous_data['utimestamp'] = $datelimit;
array_unshift ($data, $previous_data);
}
// Get next data
$nextData = get_next_data ($agent_module_id, $date);
if ($nextData !== false) {
array_push ($data, $nextData);
} else if (count ($data) > 0) {
// Propagate the last known data to the end of the interval
$nextData = array_pop ($data);
array_push ($data, $nextData);
$nextData['utimestamp'] = $date;
array_push ($data, $nextData);
}
$min_necessary = 2;
}
// Check available data
if (count ($data) < $min_necessary) {
if (!$graphic_type) {
return fs_error_image ();
}
graphic_error ();
}
// Data iterator
$j = 0;
// Event iterator
$k = 0;
// Set initial conditions
$chart = array();
if ($data[0]['utimestamp'] == $datelimit) {
$previous_data = $data[0]['datos'];
$j++;
} else {
$previous_data = 0;
}
// Get baseline data
$baseline_data = array ();
if ($baseline == 1) {
$baseline_data = enterprise_hook ('enterprise_get_baseline', array ($agent_module_id, $period, $width, $height , $title, $unit_name, $date));
if ($baseline_data === ENTERPRISE_NOT_HOOK) {
$baseline_data = array ();
}
}
// Calculate chart data
for ($i = 0; $i < $resolution; $i++) {
$timestamp = $datelimit + ($interval * $i);
$total = 0;
$count = 0;
// Read data that falls in the current interval
$interval_min = false;
$interval_max = false;
while (isset ($data[$j]) && $data[$j]['utimestamp'] >= $timestamp && $data[$j]['utimestamp'] < ($timestamp + $interval)) {
if ($interval_min === false) {
$interval_min = $data[$j]['datos'];
}
if ($interval_max === false) {
$interval_max = $data[$j]['datos'];
}
if ($data[$j]['datos'] > $interval_max) {
$interval_max = $data[$j]['datos'];
} else if ($data[$j]['datos'] < $interval_max) {
$interval_min = $data[$j]['datos'];
}
$total += $data[$j]['datos'];
$count++;
$j++;
}
// Data in the interval
if ($count > 0) {
$total /= $count;
}
// Read events and alerts that fall in the current interval
$event_value = 0;
$alert_value = 0;
while (isset ($events[$k]) && $events[$k]['utimestamp'] >= $timestamp && $events[$k]['utimestamp'] <= ($timestamp + $interval)) {
if ($show_events == 1) {
$event_value++;
}
if ($show_alerts == 1 && substr ($events[$k]['event_type'], 0, 5) == 'alert') {
$alert_value++;
}
$k++;
}
// Data
if ($count > 0) {
$chart[$timestamp]['sum'] = $total;
$chart[$timestamp]['min'] = $interval_min;
$chart[$timestamp]['max'] = $interval_max;
$previous_data = $total;
// Compressed data
} else {
if ($uncompressed_module || ($timestamp > time ())) {
$chart[$timestamp]['sum'] = 0;
$chart[$timestamp]['min'] = 0;
$chart[$timestamp]['max'] = 0;
} else {
$chart[$timestamp]['sum'] = $previous_data;
$chart[$timestamp]['min'] = $previous_data;
$chart[$timestamp]['max'] = $previous_data;
}
}
$chart[$timestamp]['count'] = 0;
/////////
//$chart[$timestamp]['timestamp_bottom'] = $timestamp;
//$chart[$timestamp]['timestamp_top'] = $timestamp + $interval;
/////////
$chart[$timestamp]['event'] = $event_value;
$chart[$timestamp]['alert'] = $alert_value;
$chart[$timestamp]['baseline'] = array_shift ($baseline_data);
if ($chart[$timestamp]['baseline'] == NULL) {
$chart[$timestamp]['baseline'] = 0;
}
}
// Return chart data and don't draw
if ($return_data == 1) {
return $chart;
}
// Get min, max and avg (less efficient but centralized for all modules and reports)
$min_value = round(get_agentmodule_data_min ($agent_module_id, $period, $date), 2);
$max_value = round(get_agentmodule_data_max ($agent_module_id, $period, $date), 2);
$avg_value = round(get_agentmodule_data_average ($agent_module_id, $period, $date), 2);
// Fix event and alert scale
$event_max = $max_value * 1.25;
foreach ($chart as $timestamp => $chart_data) {
if ($chart_data['event'] > 0) {
$chart[$timestamp]['event'] = $event_max;
}
if ($chart_data['alert'] > 0) {
$chart[$timestamp]['alert'] = $event_max;
}
}
// Set the title and time format
if ($period <= 3600) {
$title_period = __('Last hour');
$time_format = 'G:i:s';
}
elseif ($period <= 86400) {
$title_period = __('Last day');
$time_format = 'G:i';
}
elseif ($period <= 604800) {
$title_period = __('Last week');
$time_format = 'M j';
}
elseif ($period <= 2419200) {
$title_period = __('Last month');
$time_format = 'M j';
}
else {
$title_period = __('Last %s days', format_numeric (($period / (3600 * 24)), 2));
$time_format = 'M j';
}
// Only show caption if graph is not small
if ($width > MIN_WIDTH_CAPTION && $height > MIN_HEIGHT)
// Flash chart
$caption = __('Max. Value') . ': ' . $max_value . ' ' . __('Avg. Value') . ': ' . $avg_value . ' ' . __('Min. Value') . ': ' . $min_value;
else
$caption = array();
///////
$color = array();
$color['sum'] = array('border' => '#000000', 'color' => $config['graph_color2'], 'alpha' => 100);
$color['event'] = array('border' => '#ff7f00', 'color' => '#ff7f00', 'alpha' => 50);
$color['alert'] = array('border' => '#ff0000', 'color' => '#ff0000', 'alpha' => 50);
$color['max'] = array('border' => '#000000', 'color' => $config['graph_color3'], 'alpha' => 100);
$color['min'] = array('border' => '#000000', 'color' => $config['graph_color1'], 'alpha' => 100);
$color['min'] = array('border' => null, 'color' => '#0097BD', 'alpha' => 10);
area_graph(0, $chart, $width, $height, $avg_only, $resolution / 10, $time_format, $show_events, $show_alerts, $caption, $baseline, $color);
}
?>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,311 @@
/**
* FusionCharts: Flash Player detection and Chart embedding.
* Version: vFree.1.2 (1st November, 2007) - Added Player detection, New conditional fixes for IE, supports FORM in IE
*
* Morphed from SWFObject (http://blog.deconcept.com/swfobject/) under MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
*/
if(typeof infosoftglobal == "undefined") var infosoftglobal = new Object();
if(typeof infosoftglobal.FusionChartsUtil == "undefined") infosoftglobal.FusionChartsUtil = new Object();
infosoftglobal.FusionCharts = function(swf, id, w, h, debugMode, registerWithJS, c, scaleMode, lang, detectFlashVersion, autoInstallRedirect){
if (!document.getElementById) { return; }
//Flag to see whether data has been set initially
this.initialDataSet = false;
//Create container objects
this.params = new Object();
this.variables = new Object();
this.attributes = new Array();
//Set attributes for the SWF
if(swf) { this.setAttribute('swf', swf); }
if(id) { this.setAttribute('id', id); }
if(w) { this.setAttribute('width', w); }
if(h) { this.setAttribute('height', h); }
//Set background color
if(c) { this.addParam('bgcolor', c); }
//Set Quality
this.addParam('quality', 'high');
//Add scripting access parameter
this.addParam('allowScriptAccess', 'always');
//Pass width and height to be appended as chartWidth and chartHeight
this.addVariable('chartWidth', w);
this.addVariable('chartHeight', h);
//Whether in debug mode
debugMode = debugMode ? debugMode : 0;
this.addVariable('debugMode', debugMode);
//Pass DOM ID to Chart
this.addVariable('DOMId', id);
//Whether to registed with JavaScript
registerWithJS = registerWithJS ? registerWithJS : 0;
this.addVariable('registerWithJS', registerWithJS);
//Scale Mode of chart
scaleMode = scaleMode ? scaleMode : 'noScale';
this.addVariable('scaleMode', scaleMode);
//Application Message Language
lang = lang ? lang : 'EN';
this.addVariable('lang', lang);
//Whether to auto detect and re-direct to Flash Player installation
this.detectFlashVersion = detectFlashVersion?detectFlashVersion:1;
this.autoInstallRedirect = autoInstallRedirect?autoInstallRedirect:1;
//Ger Flash Player version
this.installedVer = infosoftglobal.FusionChartsUtil.getPlayerVersion();
if (!window.opera && document.all && this.installedVer.major > 7) {
// Only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
infosoftglobal.FusionCharts.doPrepUnload = true;
}
}
infosoftglobal.FusionCharts.prototype = {
setAttribute: function(name, value){
this.attributes[name] = value;
},
getAttribute: function(name){
return this.attributes[name];
},
addParam: function(name, value){
this.params[name] = value;
},
getParams: function(){
return this.params;
},
addVariable: function(name, value){
this.variables[name] = value;
},
getVariable: function(name){
return this.variables[name];
},
getVariables: function(){
return this.variables;
},
getVariablePairs: function(){
var variablePairs = new Array();
var key;
var variables = this.getVariables();
for(key in variables){
variablePairs.push(key +"="+ variables[key]);
}
return variablePairs;
},
getSWFHTML: function() {
var swfNode = "";
if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
// netscape plugin architecture
swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" ';
swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
var params = this.getParams();
for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
var pairs = this.getVariablePairs().join("&");
if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
swfNode += '/>';
} else { // PC IE
swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
var params = this.getParams();
for(var key in params) {
swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
}
var pairs = this.getVariablePairs().join("&");
if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
swfNode += "</object>";
}
return swfNode;
},
setDataURL: function(strDataURL){
//This method sets the data URL for the chart.
//If being set initially
if (this.initialDataSet==false){
this.addVariable('dataURL',strDataURL);
//Update flag
this.initialDataSet = true;
}else{
//Else, we update the chart data using External Interface
//Get reference to chart object
var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(this.getAttribute('id'));
chartObj.setDataURL(strDataURL);
}
},
setDataXML: function(strDataXML){
//If being set initially
if (this.initialDataSet==false){
//This method sets the data XML for the chart INITIALLY.
this.addVariable('dataXML',strDataXML);
//Update flag
this.initialDataSet = true;
}else{
//Else, we update the chart data using External Interface
//Get reference to chart object
var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(this.getAttribute('id'));
chartObj.setDataXML(strDataXML);
}
},
render: function(elementId){
//First check for installed version of Flash Player - we need a minimum of 6
if((this.detectFlashVersion==1) && (this.installedVer.major < 6)){
if (this.autoInstallRedirect==1){
//If we can auto redirect to install the player?
var installationConfirm = window.confirm("You need Adobe Flash Player 6 (or above) to view the charts. It is a free and lightweight installation from Adobe.com. Please click on Ok to install the same.");
if (installationConfirm){
window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
}else{
return false;
}
}else{
//Else, do not take an action. It means the developer has specified a message in the DIV (and probably a link).
//So, expect the developers to provide a course of way to their end users.
//window.alert("You need Adobe Flash Player 6 (or above) to view the charts. It is a free and lightweight installation from Adobe.com. ");
return false;
}
}else{
//Render the chart
var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
n.innerHTML = this.getSWFHTML();
//Added for .NET AJAX and <FORM> compatibility
if(!document.embeds[this.getAttribute('id')] && !window[this.getAttribute('id')])
window[this.getAttribute('id')]=document.getElementById(this.getAttribute('id'));
//or else document.forms[formName/formIndex][chartId]
return true;
}
}
}
/* ---- detection functions ---- */
infosoftglobal.FusionChartsUtil.getPlayerVersion = function(){
var PlayerVersion = new infosoftglobal.PlayerVersion([0,0,0]);
if(navigator.plugins && navigator.mimeTypes.length){
var x = navigator.plugins["Shockwave Flash"];
if(x && x.description) {
PlayerVersion = new infosoftglobal.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
}
}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){
//If Windows CE
var axo = 1;
var counter = 3;
while(axo) {
try {
counter++;
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
PlayerVersion = new infosoftglobal.PlayerVersion([counter,0,0]);
} catch (e) {
axo = null;
}
}
} else {
// Win IE (non mobile)
// Do minor version lookup in IE, but avoid Flash Player 6 crashing issues
try{
var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
}catch(e){
try {
var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
PlayerVersion = new infosoftglobal.PlayerVersion([6,0,21]);
axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
} catch(e) {
if (PlayerVersion.major == 6) {
return PlayerVersion;
}
}
try {
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
} catch(e) {}
}
if (axo != null) {
PlayerVersion = new infosoftglobal.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
}
}
return PlayerVersion;
}
infosoftglobal.PlayerVersion = function(arrVersion){
this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
// ------------ Fix for Out of Memory Bug in IE in FP9 ---------------//
/* Fix for video streaming bug */
infosoftglobal.FusionChartsUtil.cleanupSWFs = function() {
var objects = document.getElementsByTagName("OBJECT");
for (var i = objects.length - 1; i >= 0; i--) {
objects[i].style.display = 'none';
for (var x in objects[i]) {
if (typeof objects[i][x] == 'function') {
objects[i][x] = function(){};
}
}
}
}
// Fixes bug in fp9
if (infosoftglobal.FusionCharts.doPrepUnload) {
if (!infosoftglobal.unloadSet) {
infosoftglobal.FusionChartsUtil.prepUnload = function() {
__flash_unloadHandler = function(){};
__flash_savedUnloadHandler = function(){};
window.attachEvent("onunload", infosoftglobal.FusionChartsUtil.cleanupSWFs);
}
window.attachEvent("onbeforeunload", infosoftglobal.FusionChartsUtil.prepUnload);
infosoftglobal.unloadSet = true;
}
}
/* Add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}
/* Add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}
/* Function to return Flash Object from ID */
infosoftglobal.FusionChartsUtil.getChartObject = function(id)
{
// set off to test in .NET AJAX and <FORM> environment
//if (window.document[id]) {
// return window.document[id];
//}
var chartRef=null;
if (navigator.appName.indexOf("Microsoft Internet")==-1) {
if (document.embeds && document.embeds[id])
chartRef = document.embeds[id];
else
chartRef = window.document[id];
}
else {
chartRef = window[id];
}
if (!chartRef)
chartRef = document.getElementById(id);
return chartRef;
}
/*
Function to update chart's data at client side (FOR FusionCharts vFREE and 2.x
*/
infosoftglobal.FusionChartsUtil.updateChartXML = function(chartId, strXML){
//Get reference to chart object
var chartObj = infosoftglobal.FusionChartsUtil.getChartObject(chartId);
//Set dataURL to null
chartObj.SetVariable("_root.dataURL","");
//Set the flag
chartObj.SetVariable("_root.isNewData","1");
//Set the actual data
chartObj.SetVariable("_root.newData",strXML);
//Go to the required frame
chartObj.TGotoLabel("/", "JavaScriptHandler");
}
/* Aliases for easy usage */
var getChartFromId = infosoftglobal.FusionChartsUtil.getChartObject;
var updateChartXML = infosoftglobal.FusionChartsUtil.updateChartXML;
var FusionCharts = infosoftglobal.FusionCharts;

View File

@ -0,0 +1,144 @@
<?php
// Page: FusionCharts.php
// Author: InfoSoft Global (P) Ltd.
// This page contains functions that can be used to render FusionCharts.
// encodeDataURL function encodes the dataURL before it's served to FusionCharts.
// If you've parameters in your dataURL, you necessarily need to encode it.
// Param: $strDataURL - dataURL to be fed to chart
// Param: $addNoCacheStr - Whether to add aditional string to URL to disable caching of data
function encodeDataURL($strDataURL, $addNoCacheStr=false) {
//Add the no-cache string if required
if ($addNoCacheStr==true) {
// We add ?FCCurrTime=xxyyzz
// If the dataURL already contains a ?, we add &FCCurrTime=xxyyzz
// We replace : with _, as FusionCharts cannot handle : in URLs
if (strpos(strDataURL,"?")<>0)
$strDataURL .= "&FCCurrTime=" . Date("H_i_s");
else
$strDataURL .= "?FCCurrTime=" . Date("H_i_s");
}
// URL Encode it
return urlencode($strDataURL);
}
// datePart function converts MySQL database based on requested mask
// Param: $mask - what part of the date to return "m' for month,"d" for day, and "y" for year
// Param: $dateTimeStr - MySQL date/time format (yyyy-mm-dd HH:ii:ss)
function datePart($mask, $dateTimeStr) {
@list($datePt, $timePt) = explode(" ", $dateTimeStr);
$arDatePt = explode("-", $datePt);
$dataStr = "";
// Ensure we have 3 parameters for the date
if (count($arDatePt) == 3) {
list($year, $month, $day) = $arDatePt;
// determine the request
switch ($mask) {
case "m": return (int)$month;
case "d": return (int)$day;
case "y": return (int)$year;
}
// default to mm/dd/yyyy
return (trim($month . "/" . $day . "/" . $year));
}
return $dataStr;
}
// renderChart renders the JavaScript + HTML code required to embed a chart.
// This function assumes that you've already included the FusionCharts JavaScript class
// in your page.
// $chartSWF - SWF File Name (and Path) of the chart which you intend to plot
// $strURL - If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)
// $strXML - If you intend to use dataXML method for this chart, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)
// $chartId - Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id.
// $chartWidth - Intended width for the chart (in pixels)
// $chartHeight - Intended height for the chart (in pixels)
function renderChart($chartSWF, $strURL, $strXML, $chartId, $chartWidth, $chartHeight) {
//First we create a new DIV for each chart. We specify the name of DIV as "chartId"Div.
//DIV names are case-sensitive.
// The Steps in the script block below are:
//
// 1)In the DIV the text "Chart" is shown to users before the chart has started loading
// (if there is a lag in relaying SWF from server). This text is also shown to users
// who do not have Flash Player installed. You can configure it as per your needs.
//
// 2) The chart is rendered using FusionCharts Class. Each chart's instance (JavaScript) Id
// is named as chart_"chartId".
//
// 3) Check whether we've to provide data using dataXML method or dataURL method
// save the data for usage below
if ($strXML=="")
$tempData = "//Set the dataURL of the chart\n\t\tchart_$chartId.setDataURL(\"$strURL\")";
else
$tempData = "//Provide entire XML data using dataXML method\n\t\tchart_$chartId.setDataXML(\"$strXML\")";
// Set up necessary variables for the RENDERCAHRT
$chartIdDiv = $chartId . "Div";
// create a string for outputting by the caller
$render_chart = <<<RENDERCHART
<!-- START Script Block for Chart $chartId -->
<div id="$chartIdDiv" align="center">
Chart.
</div>
<script type="text/javascript">
//Instantiate the Chart
var chart_$chartId = new FusionCharts("$chartSWF", "$chartId", "$chartWidth", "$chartHeight");
$tempData
//Finally, render the chart.
chart_$chartId.render("$chartIdDiv");
</script>
<!-- END Script Block for Chart $chartId -->
RENDERCHART;
return $render_chart;
}
//renderChartHTML function renders the HTML code for the JavaScript. This
//method does NOT embed the chart using JavaScript class. Instead, it uses
//direct HTML embedding. So, if you see the charts on IE 6 (or above), you'll
//see the "Click to activate..." message on the chart.
// $chartSWF - SWF File Name (and Path) of the chart which you intend to plot
// $strURL - If you intend to use dataURL method for this chart, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)
// $strXML - If you intend to use dataXML method for this chart, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)
// $chartId - Id for the chart, using which it will be recognized in the HTML page. Each chart on the page needs to have a unique Id.
// $chartWidth - Intended width for the chart (in pixels)
// $chartHeight - Intended height for the chart (in pixels)
function renderChartHTML($chartSWF, $strURL, $strXML, $chartId, $chartWidth, $chartHeight) {
// Generate the FlashVars string based on whether dataURL has been provided
// or dataXML.
$strFlashVars = "&chartWidth=" . $chartWidth . "&chartHeight=" . $chartHeight ;
if ($strXML=="")
// DataURL Mode
$strFlashVars .= "&dataURL=" . $strURL;
else
//DataXML Mode
$strFlashVars .= "&dataXML=" . $strXML;
$HTML_chart = <<<HTMLCHART
<!-- START Code Block for Chart $chartId -->
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="$chartWidth" height="$chartHeight" id="$chartId">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="$chartSWF"/>
<param name="FlashVars" value="$strFlashVars" />
<param name="quality" value="high" />
<embed src="$chartSWF" FlashVars="$strFlashVars" quality="high" width="$chartWidth" height="$chartHeight" name="$chartId" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<!-- END Code Block for Chart $chartId -->
HTMLCHART;
return $HTML_chart;
}
// boolToNum function converts boolean values to numeric (1/0)
function boolToNum($bVal) {
return (($bVal==true) ? 1 : 0);
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,124 @@
<?php
// INTEGRIA - the ITIL Management System
// http://integria.sourceforge.net
// ==================================================
// Copyright (c) 2008-2011 Ártica Soluciones Tecnológicas
// http://www.artica.es <info@artica.es>
// 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; version 2
// 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.
include_once('functions_fsgraph.php');
function vbar_graph($flash_chart, $chart_data, $width, $height) {
if($flash_chart) {
echo fs_2d_column_chart ($chart_data, $width, $height);
}
else {
echo "<img src='include/graphs/functions_pchart.php?graph_type=vbar&data=".json_encode($chart_data)."&width=".$width."&height=".$height."'>";
}
}
function threshold_graph($flash_chart, $chart_data, $width, $height) {
if($flash_chart) {
echo fs_2d_column_chart ($chart_data, $width, $height);
}
else {
echo "<img src='include/graphs/functions_pchart.php?graph_type=threshold&data=".json_encode($chart_data)."&width=".$width."&height=".$height."'>";
}
}
function area_graph($flash_chart, $chart_data, $width, $height, $avg_only, $resolution, $time_format, $show_events, $show_alerts, $caption, $baseline, $color) {
if($flash_chart) {
echo fs_module_chart ($chart_data, $width, $height, $avg_only, $resolution, $time_format, $show_events, $show_alerts, $caption, $baseline);
}
else {
$id_graph = uniqid();
$graph = array();
$graph['data'] = $chart_data;
$graph['width'] = $width;
$graph['height'] = $height;
$graph['color'] = $color;
// $graph['avg_only'] = $avg_only;
// $graph['resolution'] = $resolution;
// $graph['time_format'] = $time_format;
// $graph['show_events'] = $show_events;
// $graph['show_alerts'] = $show_alerts;
// $graph['caption'] = $caption;
// $graph['baseline'] = $baseline;
session_start();
$_SESSION['graph'][$id_graph] = $graph;
session_write_close();
//echo "<img src='include/graphs/functions_pchart.php?graph_type=area&data=".json_encode($chart_data)."&width=".$width."&height=".$height."'>";
echo "<img src='http://127.0.0.1/pandora_console/include/graphs/functions_pchart.php?graph_type=area&id_graph=" . $id_graph . "'>";
}
}
function hbar_graph($flash_chart, $chart_data, $width, $height) {
if($flash_chart) {
echo fs_hbar_chart (array_values($chart_data), array_keys($chart_data), $width, $height);
}
else {
echo "<img src='include/graphs/functions_pchart.php?graph_type=hbar&data=".json_encode($chart_data)."&width=".$width."&height=".$height."'>";
}
}
function pie3d_graph($flash_chart, $chart_data, $width, $height, $others_str = "other") {
return pie_graph('3d', $flash_chart, $chart_data, $width, $height, $others_str);
}
function pie2d_graph($flash_chart, $chart_data, $width, $height, $others_str = "other") {
return pie_graph('2d', $flash_chart, $chart_data, $width, $height, $others_str);
}
function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height, $others_str) {
// This library allows only 9 colors
$max_values = 9;
if(count($chart_data) > $max_values) {
$chart_data_trunc = array();
$n = 1;
foreach($chart_data as $key => $value) {
if($n < $max_values) {
$chart_data_trunc[$key] = $value;
}
else {
$chart_data_trunc[$others_str] += $value;
}
$n++;
}
$chart_data = $chart_data_trunc;
}
switch($graph_type) {
case "2d":
if($flash_chart) {
return fs_2d_pie_chart (array_values($chart_data), array_keys($chart_data), $width, $height);
}
else {
return "<img src='include/graphs/functions_pchart.php?graph_type=pie2d&data=".json_encode($chart_data)."&width=".$width."&height=".$height."&other_str=".$other_str."'>";
}
break;
case "3d":
if($flash_chart) {
return fs_3d_pie_chart (array_values($chart_data), array_keys($chart_data), $width, $height);
}
else {
return "<img src='include/graphs/functions_pchart.php?graph_type=pie3d&data=".json_encode($chart_data)."&width=".$width."&height=".$height."&other_str=".$other_str."'>";
}
break;
}
}
function gantt_graph($project_name, $from, $to, $tasks, $milestones, $width, $height) {
return fs_gantt_chart ($project_name, $from, $to, $tasks, $milestones, $width, $height);
}
?>

View File

@ -0,0 +1,472 @@
<?PHP
// INTEGRIA IMS v2.0
// http://www.integriaims.com
// ===========================================================
// Copyright (c) 2007-2008 Sancho Lerena, slerena@gmail.com
// Copyright (c) 2008 Esteban Sanchez, estebans@artica.es
// Copyright (c) 2007-2011 Artica, info@artica.es
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// (LGPL) as published by the Free Software Foundation; version 2
// 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 Lesser General Public License for more details.
require_once ("FusionCharts/FusionCharts_Gen.php");
///////////////////////////////
///////////////////////////////
///////////////////////////////
function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $time_format = 'G:i', $show_events = 0, $show_alerts = 0, $caption = '', $baseline = 0, $color) {
global $config;
$graph_type = "MSArea2D"; //MSLine is possible also
// Generate the XML
$chart = new FusionCharts($graph_type, $width, $height);
$num_vlines = 0;
$count = 0;
// NO caption needed (graph avg/max/min stats are in the legend now)
/*
if ($caption != '') {
$chart->setChartParam("caption", $caption);
}
*/
$total_max = 0;
$total_avg = 0;
$total_min = 0;
// Create categories
foreach ($data as $value) {
$total_avg +=$value["sum"];
if ($avg_only != 1){
if ($value["max"] > $total_max)
$total_max =$value["max"];
if ($value["min"] < $total_min)
$total_min =$value["min"];
}
if ($count++ % $step == 0) {
$show_name = '1';
$num_vlines++;
} else {
$show_name = '0';
}
$chart->addCategory(date($time_format, $value['timestamp_bottom']), 'hoverText=' . date (html_entity_decode ($config['date_format'], ENT_QUOTES, "UTF-8"), $value['timestamp_bottom']) . ';showName=' . $show_name);
}
if ($count > 0)
$total_avg = format_for_graph($total_avg / $count);
else
$total_avg = 0;
$total_min = format_for_graph ($total_min);
$total_max = format_for_graph ($total_max);
// Event chart
if ($show_events == 1) {
$chart->addDataSet(__('Events'), 'alpha=50;showAreaBorder=1;areaBorderColor=#ff7f00;color=#ff7f00');
foreach ($data as $value) {
$chart->addChartData($value['event']);
}
}
// Alert chart
if ($show_alerts == 1) {
$chart->addDataSet(__('Alerts'), 'alpha=50;showAreaBorder=1;areaBorderColor=#ff0000;color=#ff0000');
foreach ($data as $value) {
$chart->addChartData($value['alert']);
}
}
// Max chart
if ($avg_only == 0) {
$chart->addDataSet(__('Max')." ($total_max)", 'color=' . $config['graph_color3']);
foreach ($data as $value) {
$chart->addChartData($value['max']);
}
}
// Avg chart
$empty = 1;
$chart->addDataSet(__('Avg'). " ($total_avg)", 'color=' . $config['graph_color2']);
foreach ($data as $value) {
if ($value['sum'] > 0) {
$empty = 0;
}
$chart->addChartData($value['sum']);
}
// Min chart
if ($avg_only == 0) {
$chart->addDataSet(__('Min'). " ($total_min)", 'color=' . $config['graph_color1']);
foreach ($data as $value) {
$chart->addChartData($value['min']);
}
}
// Baseline chart
if ($baseline == 1) {
$chart->addDataSet(__('Baseline'), 'color=0097BD;alpha=10;showAreaBorder=0;');
foreach ($data as $value) {
$chart->addChartData($value['baseline']);
}
}
$chart->setChartParams('animation=0;numVDivLines=' . $num_vlines . ';showShadow=0;showAlternateVGridColor=1;showNames=1;rotateNames=1;lineThickness=0.1;anchorRadius=0.5;showValues=0;baseFontSize=9;showLimits=0;showAreaBorder=1;areaBorderThickness=0.1;areaBorderColor=000000' . ($empty == 1 ? ';yAxisMinValue=0;yAxisMaxValue=1' : ''));
$random_number = rand ();
$div_id = 'chart_div_' . $random_number;
$chart_id = 'chart_' . $random_number;
$output = '<div id="' . $div_id. '" style="z-index:1;"></div>';
$pre_url = ($config["homeurl"] == "/") ? '' : $config["homeurl"];
$output .= '<script language="JavaScript" src="' . $pre_url . '/include/FusionCharts/FusionCharts.js"></script>';
$output .= '<script type="text/javascript">
<!--
function pie_' . $chart_id . ' () {
var myChart = new FusionCharts("' . $pre_url . '/include/FusionCharts/FCF_'.$graph_type.'.swf", "' . $chart_id . '", "' . $width. '", "' . $height. '", "0", "1");
myChart.setDataXML("' . addslashes($chart->getXML ()) . '");
myChart.addParam("WMode", "Transparent");
myChart.render("' . $div_id . '");
}
pie_' . $chart_id . ' ();
-->
</script>';
return $output;
}
///////////////////////////////
///////////////////////////////
///////////////////////////////
// Returns the number of seconds since the Epoch for a date in the format dd/mm/yyyy
function date_to_epoch ($date) {
$date_array = explode ('/', $date);
return mktime (0, 0, 0, $date_array [1], $date_array [0], $date_array [2]);
}
// Returns the code needed to display the chart
function get_chart_code ($chart, $width, $height, $swf) {
$random_number = rand ();
$div_id = 'chart_div_' . $random_number;
$chart_id = 'chart_' . $random_number;
$output = '<div id="' . $div_id. '"></div>';
$output .= '<script type="text/javascript">
<!--
$(document).ready(function pie_' . $chart_id . ' () {
var myChart = new FusionCharts("' . $swf . '", "' . $chart_id . '", "' . $width. '", "' . $height. '", "0", "1");
myChart.setDataXML("' . addslashes($chart->getXML ()) . '");
myChart.render("' . $div_id . '");
})
-->
</script>';
return $output;
}
// Prints a 3D pie chart
function fs_3d_pie_chart ($data, $names, $width, $height, $background = "EEEEEE") {
if ((sizeof ($data) != sizeof ($names)) OR (sizeof($data) == 0) ){
return;
}
// Generate the XML
$chart = new FusionCharts("Pie3D", $width, $height);
$chart->setSWFPath("FusionCharts/");
$params="showNames=1;showValues=0;showPercentageValues=0;baseFontSize=9;bgColor=$background;bgAlpha=100;canvasBgAlpha=100;";
$chart->setChartParams($params);
for ($i = 0; $i < sizeof ($data); $i++) {
$chart->addChartData($data[$i], 'name=' . clean_flash_string($names[$i]));
}
// Return the code
return get_chart_code ($chart, $width, $height, 'include/graphs/FusionCharts/FCF_Pie3D.swf');
}
// Prints a 2D pie chart
function fs_2d_pie_chart ($data, $names, $width, $height, $background = "EEEEEE") {
if ((sizeof ($data) != sizeof ($names)) OR (sizeof($data) == 0) ){
return;
}
// Generate the XML
$chart = new FusionCharts("Pie3D", $width, $height);
$chart->setSWFPath("FusionCharts/");
$params="showNames=1;showValues=0;showPercentageValues=0;baseFontSize=9;bgColor=$background;bgAlpha=100;canvasBgAlpha=100;";
$chart->setChartParams($params);
for ($i = 0; $i < sizeof ($data); $i++) {
$chart->addChartData($data[$i], 'name=' . clean_flash_string($names[$i]));
}
// Return the code
return get_chart_code ($chart, $width, $height, 'include/graphs/FusionCharts/FCF_Pie2D.swf');
}
// Prints a BAR Horizontalchart
function fs_hbar_chart ($data, $names, $width, $height) {
if (sizeof ($data) != sizeof ($names)) {
return;
}
// Generate the XML
$chart = new FusionCharts("Bar2D", $width, $height);
$chart->setSWFPath("FusionCharts/");
$params="showNames=1;showValues=0;showPercentageValues=0;baseFontSize=9;rotateNames=1;chartLeftMargin=0;chartRightMargin=0;chartBottomMargin=0;chartTopMargin=0;showBarShadow=1;showLimits=1";
$chart->setChartParams($params);
for ($i = 0; $i < sizeof ($data); $i++) {
$chart->addChartData($data[$i], 'name=' . clean_flash_string($names[$i]));
}
// Return the code
return get_chart_code ($chart, $width, $height, 'include/graphs/FusionCharts/FCF_Bar2D.swf');
}
// Returns a 2D column chart
function fs_2d_column_chart ($data, $width, $height) {
if (sizeof ($data) == 0) {
return;
}
// Generate the XML
$chart = new FusionCharts('Column2D', $width, $height);
$empty = 0;
$num_vlines = 0;
$count = 0;
$step = 3;
foreach ($data as $name => $value) {
if ($count++ % $step == 0) {
$show_name = '1';
$num_vlines++;
} else {
$show_name = '0';
}
if ($value > 0) {
$empty = 0;
}
$chart->addChartData($value, 'name=' . clean_flash_string($name) . ';showName=' . $show_name . ';color=95BB04');
}
$chart->setChartParams('decimalPrecision=0;showAlternateVGridColor=1; numVDivLines='.$num_vlines.';showNames=1;rotateNames=1;showValues=0;showPercentageValues=0;showLimits=0;baseFontSize=9;'
. ($empty == 1 ? ';yAxisMinValue=0;yAxisMaxValue=1' : ''));
// Return the code
return get_chart_code ($chart, $width, $height, 'include/graphs/FusionCharts/FCF_Column2D.swf');
}
// Returns a 3D column chart
function fs_3d_column_chart ($data, $width, $height) {
if (sizeof ($data) == 0) {
return;
}
// Generate the XML
$chart = new FusionCharts('Column2D', $width, $height);
$empty = 0;
$num_vlines = 0;
$count = 0;
$step = 3;
foreach ($data as $name => $value) {
if ($count++ % $step == 0) {
$show_name = '1';
$num_vlines++;
} else {
$show_name = '0';
}
if ($value > 0) {
$empty = 0;
}
$chart->addChartData($value, 'name=' . clean_flash_string($name) . ';showName=' . $show_name . ';color=95BB04');
}
$chart->setChartParams('decimalPrecision=0;showAlternateVGridColor=1; numVDivLines='.$num_vlines.';showNames=1;rotateNames=1;showValues=0;showPercentageValues=0;showLimits=0;baseFontSize=9;'
. ($empty == 1 ? ';yAxisMinValue=0;yAxisMaxValue=1' : ''));
// Return the code
return get_chart_code ($chart, $width, $height, 'include/graphs/FusionCharts/FCF_Column3D.swf');
}
// Prints a Gantt chart
function fs_gantt_chart ($title, $from, $to, $tasks, $milestones, $width, $height) {
// Generate the XML
$chart = new FusionCharts("Gantt", $width, $height, "1", "0");
$chart->setSWFPath("FusionCharts/");
$chart->setChartParams('dateFormat=dd/mm/yyyy;hoverCapBorderColor=2222ff;hoverCapBgColor=e1f5ff;ganttLineAlpha=80;canvasBorderColor=024455;canvasBorderThickness=0;gridBorderColor=2179b1;gridBorderAlpha=20;ganttWidthPercent=80');
$chart->setGanttProcessesParams('headerText=' . __('Task') . ';fontColor=ffffff;fontSize=9;isBold=1;isAnimated=1;bgColor=2179b1;headerbgColor=2179b1;headerFontColor=ffffff;headerFontSize=12;align=left');
$chart->setGanttTasksParams('');
$start_date = explode ('/', $from);
$start_day = $start_date[0];
$start_month = $start_date[1];
$start_year = $start_date[2];
$end_date = explode ('/', $to);
$end_day = $end_date[0];
$end_month = $end_date[1];
$end_year = $end_date[2];
$time_span = date_to_epoch ($to) - date_to_epoch ($from);
// Years
$chart->addGanttCategorySet ('bgColor=2179b1;fontColor=ff0000');
for ($i = $start_year; $i <= $end_year; $i++) {
if ($i == $start_year) {
$start = sprintf ('%02d/%02d/%04d', $start_day, $start_month, $start_year);
} else {
$start = sprintf ('%02d/%02d/%04d', 1, 1, $i);
}
if ($i == $end_year) {
$end = sprintf ('%02d/%02d/%04d', $end_day, $end_month, $end_year);
} else {
$end = sprintf ('%02d/%02d/%04d', cal_days_in_month (CAL_GREGORIAN, 12, $i), 12, $i);
}
$chart->addGanttCategory ($i, ';start=' . $start . ';end=' . $end . ';align=center;fontColor=ffffff;isBold=1;fontSize=16');
}
// Months
$chart->addGanttCategorySet ('bgColor=ffffff;fontColor=1288dd;fontSize=10');
for ($i = $start_year ; $i <= $end_year; $i++) {
for ($j = 1 ; $j <= 12; $j++) {
if ($i == $start_year && $j < $start_month) {
continue;
} else if ($i == $end_year && $j > $end_month) {
break;
}
if ($i == $start_year && $j == $start_month) {
$start = sprintf ('%02d/%02d/%04d', $start_day, $start_month, $start_year);
} else {
$start = sprintf ('%02d/%02d/%04d', 1, $j, $i);
}
if ($i == $end_year && $j == $end_month) {
$end = sprintf ('%02d/%02d/%04d', $end_day, $end_month, $end_year);
} else {
$end = sprintf ('%02d/%02d/%04d', cal_days_in_month (CAL_GREGORIAN, $j, $i), $j, $i);
}
$chart->addGanttCategory (date('F', mktime(0,0,0,$j,1)), ';start=' . $start . ';end=' . $end . ';align=center;isBold=1');
}
}
// Days
if ($time_span < 2592000) {
$chart->addGanttCategorySet ();
for ($i = $start_year ; $i <= $end_year; $i++) {
for ($j = 1 ; $j <= 12; $j++) {
if ($i == $start_year && $j < $start_month) {
continue;
} else if ($i == $end_year && $j > $end_month) {
break;
}
$num_days = cal_days_in_month (CAL_GREGORIAN, $j, $i);
for ($k = 1 ; $k <= $num_days; $k++) {
if ($i == $start_year && $j == $start_month && $k < $start_day) {
continue;
} else if ($i == $end_year && $j == $end_month && $k > $end_day) {
break;
}
$start = sprintf ('%02d/%02d/%04d', $k, $j, $i);
$end = sprintf ('%02d/%02d/%04d', $k, $j, $i);
$chart->addGanttCategory ($k, ';start=' . $start . ';end=' . $end . ';fontSize=8;isBold=0');
}
}
}
}
// Weeks
else if ($time_span < 10368000) {
$chart->addGanttCategorySet ();
for ($i = $start_year ; $i <= $end_year; $i++) {
for ($j = 1 ; $j <= 12; $j++) {
if ($i == $start_year && $j < $start_month) {
continue;
} else if ($i == $end_year && $j > $end_month) {
break;
}
$num_days = cal_days_in_month (CAL_GREGORIAN, $j, $i);
for ($k = 1, $l = 1; $k <= $num_days; $k += 8, $l++) {
if ($i == $start_year && $j == $start_month && $k + 7 < $start_day) {
continue;
}
if ($i == $end_year && $j == $end_month && $k > $end_day) {
break;
}
if ($i == $start_year && $j == $start_month && $k < $start_day) {
$start = sprintf ('%02d/%02d/%04d', $start_day, $j, $i);
} else {
$start = sprintf ('%02d/%02d/%04d', $k, $j, $i);
}
if ($i == $end_year && $j == $end_month && $k + 7 > $end_day) {
$end = sprintf ('%02d/%02d/%04d', $end_day, $j, $i);
} else if ($k + 7 > $num_days) {
$end = sprintf ('%02d/%02d/%04d', $num_days, $j, $i);
} else {
$end = sprintf ('%02d/%02d/%04d', $k + 7, $j, $i);
}
$chart->addGanttCategory (__('Week') . " $l", ';start=' . $start . ';end=' . $end . ';fontSize=8;isBold=0');
}
}
}
}
// Tasks
foreach ($tasks as $task) {
$chart->addGanttProcess (clean_flash_string($task['name']), 'id=' . $task['id'] . ';link=' . urlencode($task['link']));
$chart->addGanttTask (__('Planned'), 'start=' . $task['start'] . ';end=' . $task['end'] . ';id=' . $task['id'] . ';processId=' . $task['id'] . ';color=4b3cff;height=5;topPadding=10;animation=0');
if ($task['real_start'] !== false && $task['real_end']) {
$chart->addGanttTask (__('Actual'), 'start=' . $task['real_start'] . ';end=' . $task['real_end'] . ';processId=' . $task['id'] . ';color=ff3c4b;alpha=100;topPadding=15;height=5');
}
if ($task['completion'] != 0) {
$task_span = date_to_epoch ($task['end']) - date_to_epoch ($task['start']);
$end = date ('d/m/Y', date_to_epoch ($task['start']) + $task_span * $task['completion'] / 100.0);
$chart->addGanttTask (__('Completion')." (".$task['completion'].")", 'start=' . $task['start'] . ';end=' . $end . ';processId=' . $task['id'] . ';color=32cd32;alpha=100;topPadding=20;height=5');
}
if ($task['parent'] != 0) {
$chart->addGanttConnector ($task['parent'], $task['id'], 'color=2179b1;thickness=2;fromTaskConnectStart=1');
}
}
// Milestones
if ($milestones !== '') {
$chart->addGanttProcess (__('Milestones'), 'id=0');
foreach ($milestones as $milestone) {
$chart->addGanttTask (clean_flash_string($milestone['name']), 'start=' . $milestone['date'] . ';end=' . $milestone['date'] . ';id=ms-' . $milestone['id'] . ';processId=0;color=ffffff;alpha=0;height=60;topPadding=0;animation=0');
$chart->addGanttMilestone ('ms-' . $milestone['id'], 'date=' . $milestone['date'] . ';radius=8;color=efbb07;shape=star;numSides=3;borderThickness=1');
}
}
// Today
$chart->addTrendLine ('start=' . date ('d/m/Y') . ';displayValue='. __('Today') . ';color=666666;isTrendZone=1;alpha=20');
// Return the code
return get_chart_code ($chart, $width, $height, 'include/graphs/FusionCharts/FCF_Gantt.swf');
}
?>

View File

@ -0,0 +1,986 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// 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 for version 2.
// 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.
include_once("../functions.php");
/* pChart library inclusions */
include_once("pChart/pData.class.php");
include_once("pChart/pDraw.class.php");
include_once("pChart/pImage.class.php");
include_once("pChart/pPie.class.php");
include_once("pChart/pScatter.class.php");
include_once("pChart/pRadar.class.php");
$graph_type = get_parameter('graph_type', '');
$width = get_parameter('width', 700);
$height = get_parameter('height', 300);
$xaxisname = get_parameter('xaxisname', '');
$yaxisname = get_parameter('yaxisname', '');
$title = get_parameter('title', '');
$data = json_decode(safe_output(get_parameter('data')), true);
$id_graph = get_parameter('id_graph', false);
if ($id_graph) {
session_start();
$graph = $_SESSION['graph'][$id_graph];
unset($_SESSION['graph'][$id_graph]);
session_write_close();
if (isset($graph)) {
$data = $graph['data'];
$width = $graph['width'];
$height = $graph['height'];
$color = $graph['color'];
// $graph['avg_only'] = $avg_only;
// $graph['resolution'] = $resolution;
// $graph['time_format'] = $time_format;
// $graph['show_events'] = $show_events;
// $graph['show_alerts'] = $show_alerts;
// $graph['caption'] = $caption;
// $graph['baseline'] = $baseline;
}
}
if($graph_type != 'pie3d' && $graph_type != 'pie2d') {
foreach($data as $i => $d) {
$data_values[] = $d;
$data_keys[] = $i;
}
}
switch($graph_type) {
case 'pie3d':
case 'pie2d':
pch_pie_graph($graph_type, array_values($data), array_keys($data), $width, $height);
break;
case 'polar':
case 'radar':
pch_radar_graph($graph_type, $data_values, $data_keys, $width, $height);
break;
case 'hbar':
pch_horizontal_graph($graph_type, $data_keys, $data_values, $width, $height, $xaxisname, $yaxisname);
break;
case 'progress':
pch_progress_graph($graph_type, $data_keys, $data_values, $width, $height, $xaxisname, $yaxisname);
break;
case 'vbar':
case 'area':
case 'spline':
pch_vertical_graph($graph_type, $data_keys, $data_values, $width, $height, $xaxisname, $yaxisname);
break;
case 'threshold':
pch_threshold_graph($graph_type, $data_keys, $data_values, $width, $height, $xaxisname, $yaxisname, $title);
break;
case 'scatter':
pch_scatter_graph($data_keys, $data_values, $width, $height, $xaxisname, $yaxisname);
break;
}
function pch_pie_graph ($graph_type, $data_values, $legend_values, $width, $height) {
/* CAT:Pie charts */
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints($data_values,"ScoreA");
$MyData->setSerieDescription("ScoreA","Application A");
$legend_values = array('日本語', '九州', '訓読み', '北海道');
/* Define the absissa serie */
$MyData->addPoints($legend_values,"Labels");
$MyData->setAbscissa("Labels");
/* Create the pChart object */
$myPicture = new pImage($width,$height,$MyData,TRUE);
/* Set the default font properties */
//$myPicture->setFontProperties(array("FontName"=>"pChart/fonts/verdana.ttf","FontSize"=>8,"R"=>80,"G"=>80,"B"=>80));
$myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>8,"R"=>80,"G"=>80,"B"=>80));
/* Create the pPie object */
$PieChart = new pPie($myPicture,$MyData);
/* Draw an AA pie chart */
switch($graph_type) {
case "pie2d":
$PieChart->draw2DPie($width/4,$height/2,array("DataGapAngle"=>0,"DataGapRadius"=>0, "Border"=>FALSE, "BorderR"=>200, "BorderG"=>200, "BorderB"=>200, "Radius"=>$width/4, "ValueR"=>0, "ValueG"=>0, "ValueB"=>0));
break;
case "pie3d":
$PieChart->draw3DPie($width/4,$height/2,array("DataGapAngle"=>10,"DataGapRadius"=>6, "Border"=>TRUE, "Radius"=>$width/4, "ValueR"=>0, "ValueG"=>0, "ValueB"=>0, "WriteValues"=>FALSE));
break;
}
/* Write down the legend next to the 2nd chart*/
$PieChart->drawPieLegend($width/1.5,$height/4, array("R"=>255,"G"=>255,"B"=>255));
/* Enable shadow computing */
$myPicture->setShadow(TRUE,array("X"=>3,"Y"=>3,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
/* Render the picture */
$myPicture->stroke();
}
function pch_radar_graph ($graph_type, $data_values, $legend_values, $width, $height) {
/* CAT:Radar/Polar charts */
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints($data_values,"ScoreA");
$MyData->setSerieDescription("ScoreA","Application A");
/* Define the absissa serie */
$MyData->addPoints($legend_values,"Labels");
$MyData->setAbscissa("Labels");
/* Create the pChart object */
$myPicture = new pImage($width,$height,$MyData,TRUE);
/* Set the default font properties */
$myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>8,"R"=>80,"G"=>80,"B"=>80));
/* Create the pRadar object */
$SplitChart = new pRadar();
/* Draw a radar chart */
$myPicture->setGraphArea(20,25,$width-10,$height-10);
/* Draw an AA pie chart */
switch($graph_type) {
case "radar":
$Options = array("SkipLabels"=>0,"LabelPos"=>RADAR_LABELS_HORIZONTAL, "LabelMiddle"=>FALSE,"Layout"=>RADAR_LAYOUT_STAR,"BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>100,"EndR"=>207,"EndG"=>227,"EndB"=>125,"EndAlpha"=>50), "FontName"=>"pChart/fonts/pf_arma_five.ttf","FontSize"=>6);
$SplitChart->drawRadar($myPicture,$MyData,$Options);
break;
case "polar":
$Options = array("Layout"=>RADAR_LAYOUT_CIRCLE,"BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>100,"EndR"=>207,"EndG"=>227,"EndB"=>125,"EndAlpha"=>50), "FontName"=>"pChart/fonts/pf_arma_five.ttf","FontSize"=>6);
$SplitChart->drawRadar($myPicture,$MyData,$Options);
break;
}
/* Render the picture */
$myPicture->stroke();
}
function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $xaxisname = "", $yaxisname = "", $show_values = false, $show_legend = false) {
/* CAT:Bar Chart */
if(is_array($data[0])) {
$data2 = array();
foreach($data as $i =>$values) {
$c = 0;
foreach($values as $value) {
$data2[$c][$i] = $value;
$c++;
}
}
$data = $data2;
}
else {
$data = array($data);
}
/* Create and populate the pData object */
$MyData = new pData();
foreach($data as $i => $values) {
$MyData->addPoints($values,"Yaxis_".$i);
}
//$MyData->addPoints($data,"Yaxis");
$MyData->setAxisName(0,$yaxisname);
$MyData->addPoints($index,"Xaxis");
$MyData->setSerieDescription("Xaxis", $xaxisname);
$MyData->setAbscissa("Xaxis");
/* Create the pChart object */
$myPicture = new pImage($width,$height,$MyData);
/* Turn of Antialiasing */
$myPicture->Antialias = FALSE;
/* Add a border to the picture */
//$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0));
/* Set the default font */
$myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>7));
/* Define the chart area */
$myPicture->setGraphArea(30,20,$width,$height-100);
/* Draw the scale */
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_START0, "XMargin" => 40, "LabelRotation" => 90);
$myPicture->drawScale($scaleSettings);
if($show_legend) {
/* Write the chart legend */
$myPicture->drawLegend(580,12,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
}
/* Turn on shadow computing */
$myPicture->setShadow(TRUE,array("X"=>0,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
/* Draw the chart */
$settings = array("Gradient"=>TRUE,"GradientMode"=>GRADIENT_EFFECT_CAN,"DisplayValues"=>$show_values,"DisplayZeroValues"=>FALSE,"DisplayR"=>100,"DisplayG"=>100,"DisplayB"=>100,"DisplayShadow"=>TRUE,"Surrounding"=>5,"AroundZero"=>FALSE);
switch($graph_type) {
case "vbar":
$myPicture->drawBarChart($settings);
break;
case "area":
$myPicture->drawAreaChart($settings);
break;
case "line":
$myPicture->drawLineChart($settings);
break;
}
/* Render the picture */
$myPicture->stroke();
}
function pch_threshold_graph ($graph_type, $index, $data, $width, $height, $xaxisname = "", $yaxisname = "", $title = "", $show_values = false, $show_legend = false) {
/* CAT:Bar Chart */
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints($data,"DEFCA");
$MyData->setAxisName(0,$yaxisname);
$MyData->setAxisDisplay(0,AXIS_FORMAT_CURRENCY);
$MyData->addPoints($index,"Labels");
$MyData->setSerieDescription("Labels",$xaxisname);
$MyData->setAbscissa("Labels");
$MyData->setPalette("DEFCA",array("R"=>55,"G"=>91,"B"=>127));
/* Create the pChart object */
$myPicture = new pImage(700,230,$MyData);
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,array("StartR"=>220,"StartG"=>220,"StartB"=>220,"EndR"=>255,"EndG"=>255,"EndB"=>255,"Alpha"=>100));
$myPicture->drawRectangle(0,0,699,229,array("R"=>200,"G"=>200,"B"=>200));
/* Write the picture title */
$myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>11));
$myPicture->drawText(60,35,$title,array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMLEFT));
/* Do some cosmetic and draw the chart */
$myPicture->setGraphArea(60,40,670,190);
$myPicture->drawFilledRectangle(60,40,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
$myPicture->drawScale(array("GridR"=>180,"GridG"=>180,"GridB"=>180, "Mode" => SCALE_MODE_START0));
$myPicture->setShadow(TRUE,array("X"=>2,"Y"=>2,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>6));
$settings = array("Gradient"=>TRUE,"GradientMode"=>GRADIENT_EFFECT_CAN,"DisplayValues"=>$show_values,"DisplayZeroValues"=>FALSE,"DisplayR"=>100,"DisplayG"=>100,"DisplayB"=>100,"DisplayShadow"=>TRUE,"Surrounding"=>5,"AroundZero"=>FALSE);
$myPicture->drawSplineChart($settings);
$myPicture->setShadow(FALSE);
if($show_legend) {
/* Write the chart legend */
$myPicture->drawLegend(643,210,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
}
/* Render the picture */
$myPicture->stroke();
}
function pch_horizontal_graph ($graph_type, $index, $data, $width, $height, $xaxisname = "", $yaxisname = "", $show_values = false, $show_legend = false) {
/* CAT:Bar Chart */
/* Create and populate the pData object */
$MyData = new pData();
$MyData->addPoints($data,"Xaxis");
$MyData->setAxisName(0,$yaxisname);
$MyData->addPoints($index,"Yaxis");
$MyData->setSerieDescription("Yaxis", $xaxisname);
$MyData->setAbscissa("Yaxis");
/* Create the pChart object */
$myPicture = new pImage($width,$height,$MyData);
$myPicture->drawGradientArea(0,0,$width,500,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100));
$myPicture->drawGradientArea(0,0,$width,500,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20));
/* Add a border to the picture */
//$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0));
/* Set the default font */
$myPicture->setFontProperties(array("FontName"=>"pChart/fonts/code.ttf","FontSize"=>7));
/* Define the chart area */
$myPicture->setGraphArea(75,20,$width,$height);
if(count($data) == 1) {
$xmargin = 110;
}
elseif(count($data) == 2) {
$xmargin = 70;
}
else {
$xmargin = 45;
}
/* Draw the scale */
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_START0, "XMargin" => $xmargin,"Pos"=>SCALE_POS_TOPBOTTOM);
$myPicture->drawScale($scaleSettings);
if($show_legend) {
/* Write the chart legend */
$myPicture->drawLegend(580,12,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
}
/* Turn on shadow computing */
$myPicture->setShadow(TRUE,array("X"=>0,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
/* Draw the chart */
$settings = array("Gradient"=>TRUE,"GradientMode"=>GRADIENT_EFFECT_CAN,"DisplayValues"=>$show_values,"DisplayZeroValues"=>FALSE,"DisplayR"=>100,"DisplayG"=>100,"DisplayB"=>100,"DisplayShadow"=>TRUE,"Surrounding"=>5,"AroundZero"=>FALSE);
$settings = array("DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"Rounded"=>TRUE,"Surrounding"=>30);
switch($graph_type) {
case "hbar":
$myPicture->drawBarChart($settings);
break;
case "area":
$myPicture->drawAreaChart($settings);
break;
case "line":
$myPicture->drawLineChart($settings);
break;
}
/* Render the picture */
$myPicture->stroke();
}
/*
class PchartGraph extends PandoraGraphAbstract {
public $palette_path = false;
private $graph = NULL;
private $dataset = NULL;
private $x1;
private $x2;
private $y1;
private $y2;
public function load_palette ($palette_path) {
$this->palette_path = $palette_path;
}
public function pie_graph () {
// dataset definition
$this->dataset = new pData;
$this->dataset->AddPoint ($this->data, "Serie1", $this->legend);
$this->dataset->AddPoint ($this->legend, "Serie2");
$this->dataset->AddAllSeries ();
$this->dataset->SetAbsciseLabelSerie ("Serie2");
// Initialise the graph
$this->graph = new pChart ($this->width, $this->height);
$this->graph->setFontProperties ($this->fontpath, 8);
if ($this->palette_path) {
$this->graph->loadColorPalette ($this->palette_path);
}
$this->add_background ();
// Draw the pie chart
if ($this->three_dimensions) {
$this->graph->drawPieGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
$this->width / 2,
$this->height / 2 - 15, $this->zoom,
PIE_PERCENTAGE_LABEL, 5, 70, 20, 5);
} else {
$this->graph->drawFlatPieGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
$this->width / 2,
$this->height / 2, $this->zoom,
PIE_PERCENTAGE_LABEL, 5);
}
if ($this->show_legend) {
$this->graph->drawPieLegend (10, 10, $this->dataset->GetData (),
$this->dataset->GetDataDescription (), 255, 255, 255);
}
$this->graph->Stroke ();
}
public function horizontal_bar_graph () {
// dataset definition
$this->dataset = new pData;
foreach ($this->data as $x => $y) {
$this->dataset->AddPoint ($y, "Serie1", $x);
}
$this->dataset->AddAllSeries ();
$this->dataset->SetXAxisFormat ("label");
$this->dataset->SetYAxisFormat ($this->yaxis_format);
// Initialise the graph
$this->graph = new pChart ($this->width, $this->height);
if ($this->palette_path) {
$this->graph->loadColorPalette ($this->palette_path);
}
$this->graph->setFontProperties ($this->fontpath, 8);
$this->add_background ();
$this->graph->drawGraphArea (255, 255, 255, true);
if ($this->show_grid)
$this->graph->drawGrid (4, true, 230, 230, 230, 50);
// Draw the bar graph
$this->graph->setFontProperties ($this->fontpath, 8);
$this->graph->setFixedScale (0, max ($this->data));
$this->graph->drawOverlayBarGraphH ($this->dataset->GetData (),
$this->dataset->GetDataDescription (), 50);
// Finish the graph
$this->add_legend ();
$this->graph->Stroke ();
}
public function single_graph () {
// Dataset definition
$this->dataset = new pData;
$this->graph = new pChart ($this->width, $this->height+2);
foreach ($this->data as $x => $y) {
$this->dataset->AddPoint ($y, "Serie1", $x);
}
$color = $this->get_rgb_values ($this->graph_color[2]);
$this->graph->setColorPalette (0, $color['r'], $color['g'], $color['b']);
$this->dataset->AddAllSeries ();
if ($this->legend !== false)
$this->dataset->SetSerieName ($this->legend[0], "Serie1");
if ($this->palette_path)
$this->graph->loadColorPalette ($this->palette_path);
$this->graph->setFontProperties ($this->fontpath, 8);
// White background
$this->graph->drawFilledRoundedRectangle(1,1,$this->width,$this->height,0,254,254,254);
$this->add_background ();
$this->dataset->SetXAxisFormat ($this->xaxis_format);
$this->dataset->SetYAxisFormat ($this->yaxis_format);
$this->graph->drawGraphArea (254, 254, 254, true);
if ($this->max_value == 0 || $this->max_value == 1)
$this->graph->setFixedScale (0, 1, 1);
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_START0, 80, 80, 80, $this->show_axis,
0, 0, false,
$this->xaxis_interval);
if ($this->show_grid)
$this->graph->drawGrid (1, false, 200, 200, 200);
if ($this->max_value > 0) {
// Draw the graph
$this->graph->drawFilledLineGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
50, true);
}
// Finish the graph
// $this->add_legend ();
$this->add_events ();
$this->add_alert_levels ();
$this->graph->Stroke ();
}
public function sparse_graph ($period, $avg_only, $min_value, $max_value, $unit_name, $baseline = 0) {
// Dataset definition
$this->dataset = new pData;
$this->graph = new pChart ($this->width, $this->height+5);
$this->graph->setFontProperties ($this->fontpath, 8);
$this->legend = array ();
if ($avg_only) {
foreach ($this->data as $data) {
$this->dataset->AddPoint ($data['sum'], "AVG", $data['timestamp_bottom']);
}
$color = $this->get_rgb_values ($this->graph_color[2]);
$this->graph->setColorPalette (0, $color['r'], $color['g'], $color['b']);
} else {
foreach ($this->data as $data) {
$this->dataset->AddPoint ($data['sum'], "AVG", $data['timestamp_bottom']);
$this->dataset->AddPoint ($data['min'], "MIN");
$this->dataset->AddPoint ($data['max'], "MAX");
}
$this->legend[1] = __("Min");
$this->legend[0] = __("Avg");
$this->legend[2] = __("Max");
$this->dataset->SetSerieName (__("Min"), "MIN");
$this->dataset->SetSerieName (__("Avg"), "AVG");
$this->dataset->SetSerieName (__("Max"), "MAX");
$this->set_colors ();
}
// Draw baseline
if ($baseline == 1) {
foreach ($this->data as $data) {
$this->dataset->AddPoint ($data['baseline'], "BLINE");
}
}
$this->dataset->SetXAxisFormat ('datetime');
$this->graph->setDateFormat ("Y");
$this->dataset->SetYAxisFormat ('metric');
$this->dataset->AddAllSeries ();
$this->dataset->SetSerieName (__("Avg"), "AVG");
$this->legend[0] = __("Avg");
if ($this->palette_path) {
$this->graph->loadColorPalette ($this->palette_path);
}
// White background
$this->graph->drawFilledRoundedRectangle(1,1,$this->width,$this->height+2,0,254,254,254);
// Graph border
// Now graph border is in the style image attribute
//$this->graph->drawRoundedRectangle(1,1,$this->width-1,$this->height+4,5,230,230,230);
$this->add_background ();
// If graph is small remove blank spaces
if ($this->width < MIN_WIDTH || $this->height < MIN_HEIGHT)
$this->graph->setGraphArea (5,5,$this->width-5,$this->height-5);
$this->graph->drawGraphArea (254, 254, 254, false);
$this->xaxis_interval = ($this->xaxis_interval / 7 >= 1) ? ($this->xaxis_interval / 7) : 10;
// Remove axis values if graph is small
if ($this->width > MIN_WIDTH && $this->height > MIN_HEIGHT){
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (), SCALE_START0,
80, 80, 80, $this->show_axis, 0, 50, false,
$this->xaxis_interval);
}else{
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (), SCALE_START0,
80, 80, 80, false, 0, 50, false,
$this->xaxis_interval);
}
/// NOTICE: The final "false" is a Pandora modificaton of pChart to avoid showing vertical lines.
if ($this->show_grid)
$this->graph->drawGrid (1, true, 225, 225, 225, 100, false);
// Draw the graph
$this->graph->drawFilledLineGraph ($this->dataset->GetData(), $this->dataset->GetDataDescription(), 50, true);
// Remove legends if graph is small
if ($this->width > MIN_WIDTH && $this->height > MIN_HEIGHT)
$this->add_legend ();
$this->add_events ("AVG");
$this->add_alert_levels ();
$this->graph->Stroke ();
}
public function vertical_bar_graph () {
// dataset definition
$this->dataset = new pData;
foreach ($this->data as $x => $y) {
$this->dataset->AddPoint ($y, "Serie1", $x);
}
$this->dataset->AddAllSeries ();
$this->dataset->SetAbsciseLabelSerie ();
$this->dataset->SetXAxisFormat ($this->xaxis_format);
$this->dataset->SetYAxisFormat ($this->yaxis_format);
// Initialise the graph
$this->graph = new pChart ($this->width, $this->height);
if ($this->palette_path) {
$this->graph->loadColorPalette ($this->palette_path);
}
$this->graph->setFontProperties ($this->fontpath, 8);
$this->add_background ();
$this->graph->drawGraphArea (255, 255, 255, true);
if ($this->show_grid)
$this->graph->drawGrid (4, true, 230, 230, 230, 50);
// Draw the bar graph
$this->graph->setFontProperties ($this->fontpath, 8);
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_START0, 80, 80, 80,
$this->show_axis, 0, 0, false,
$this->xaxis_interval);
$this->graph->drawOverlayBarGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
50);
$this->add_events ("Serie1");
$this->add_alert_levels ();
// Finish the graph
$this->graph->Stroke ();
}
public function combined_graph ($values, $events, $alerts, $unit_name, $max_value, $stacked) {
set_time_limit (0);
// Dataset definition
$this->dataset = new pData;
$this->graph = new pChart ($this->width, $this->height+5);
$graph_items = 0;
// $previo stores values from last series to made the stacked graph
foreach ($this->data as $i => $data) {
$graph_items++;
$max = 0;
$min = 10000000000000;
$avg = 0;
$count = 0;
foreach ($data as $j => $value) {
$count ++;
$avg += $value;
if ($value > $max )
$max = $value;
if ($value < $min )
$min = $value;
// New code for stacked. Due pchart doesnt not support stacked
// area graph, we "made it", adding to a series the values of the
// previous one consecutive sum.
if ((($stacked == 1) OR ($stacked==3)) AND ($i >0)){
$this->dataset->AddPoint ($value+$previo[$j], $this->legend[$i],
$values[$j]['timestamp_bottom']);
} else {
$this->dataset->AddPoint ($value, $this->legend[$i],
$values[$j]['timestamp_bottom']);
}
if ($i == 0)
$previo[$j] = $value;
else
$previo[$j] = $previo[$j] + $value;
}
if ($count > 0)
$avgdata[$i] = $avg / $count;
else
$avgdata[$i] = 0;
$maxdata[$i] = format_for_graph($max);
$mindata[$i] = format_for_graph($min);
$avgdata[$i] = format_for_graph($avgdata[$i]);
}
$i = 0;
foreach ($this->legend as $name) {
$legend = $name . " (".__("Max"). ":$maxdata[$i], ".__("Min"). ":$mindata[$i], ". __("Avg"). ": $avgdata[$i])";
$this->dataset->setSerieName ($legend, $name);
$this->dataset->AddSerie ($name);
$i++;
}
// Set different colors for combined graphs because need to be
// very different.
$this->graph_color[1] = "#FF0000"; // Red
$this->graph_color[2] = "#00FF00"; // Green
$this->graph_color[3] = "#0000FF"; // Blue
// White background
$this->graph->drawFilledRoundedRectangle(1,1,$this->width,$this->height,0,254,254,254);
$this->set_colors ();
$this->graph->setFontProperties ($this->fontpath, 8);
$this->dataset->SetXAxisFormat ('datetime');
$this->dataset->SetYAxisFormat ('metric');
$this->dataset->AddAllSeries ();
$this->add_background ();
$legend_offset = $this->height - 21 - ($graph_items*15);
$this->graph->setGraphArea (35,10,$this->width-10, $legend_offset);
$this->graph->drawGraphArea (254, 254, 254, false);
// Fixed missing X-labels (6Ago09)
$this->xaxis_interval = ($this->xaxis_interval / 7 >= 1) ? ($this->xaxis_interval / 7) : 10;
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (), SCALE_START0,
80, 80, 80, $this->show_axis, 0, 50, false,
$this->xaxis_interval);
$this->graph->drawGrid (1, true, 225, 225, 225, 100, false);
// Draw the graph
if ($stacked == 1) { // Stacked solid
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false,
$this->xaxis_interval);
$this->graph->drawFilledCubicCurve ($this->dataset->GetData(),
$this->dataset->GetDataDescription(), 1, 30, true);
}
elseif ($stacked == 3) { // Stacked wired
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false,
$this->xaxis_interval);
$this->graph->drawFilledCubicCurve ($this->dataset->GetData(),
$this->dataset->GetDataDescription(), 1, 0, true);
}
else if ($stacked == 2) { // Wired mode
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false,
$this->xaxis_interval);
$this->graph->drawLineGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription ());
}
else { // Non-stacked, area overlapped
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_START0, 80, 80, 80, $this->show_axis, 0, 0, false,
$this->xaxis_interval);
$this->graph->drawFilledCubicCurve ($this->dataset->GetData(),
$this->dataset->GetDataDescription(), 1, 30, true);
}
$this->graph->setFontProperties($this->fontpath,7);
$this->graph->drawLegend(15,$legend_offset+29,$this->dataset->GetDataDescription(),92,92,92,50,50,50,45,45,45,0);
// Legend line separator
// $this->graph->drawFilledRoundedRectangle(35, $legend_offset + 30 ,$this->width-35,$legend_offset+30,0,220,220,220);
$this->add_events ($this->legend[0]);
$this->add_alert_levels ();
$this->graph->Stroke ();
}
public function progress_bar ($value, $color) {
set_time_limit (0);
// Dataset definition
$this->graph = new pChart ($this->width, $this->height);
$this->graph->setFontProperties ($this->fontpath, 8);
// Round corners defined in global setup
global $config;
if ($config["round_corner"] != 0)
$radius = ($this->height > 18) ? 8 : 0;
else
$radius = 0;
$ratio = (int) $value / 100 * $this->width;
// Color stuff
$bgcolor = $this->get_rgb_values ($this->background_color);
$r = hexdec (substr ($this->background_color, 1, 2));
$g = hexdec (substr ($this->background_color, 3, 2));
$b = hexdec (substr ($this->background_color, 5, 2));
// Actual percentage
if (! $this->show_title || $value > 0) {
$color = $this->get_rgb_values ($color);
$this->graph->drawFilledRoundedRectangle (0, 0, $ratio,
$this->height, $radius, $color['r'], $color['g'], $color['b']);
}
if ($config["round_corner"]) {
// Under this value, the rounded rectangle is painted great
if ($ratio <= 16) {
// Clean a bit of pixels
for ($i = 0; $i < 7; $i++) {
$this->graph->drawLine (0, $i, 6 - $i, $i, 255, 255, 255);
}
$end = $this->height - 1;
for ($i = 0; $i < 7; $i++) {
$this->graph->drawLine (0, $end - $i, 5 - $i, $end - $i, 255, 255, 255);
}
}
}
if ($ratio <= 60) {
if ($this->show_title) {
$this->graph->drawTextBox (0, 0, $this->width, $this->height,
$this->title, 0, 0, 0, 0, ALIGN_CENTER, false);
}
} else {
if ($this->show_title) {
$this->graph->drawTextBox (0, 0, $this->width, $this->height,
$this->title, 0, 255, 255, 255, ALIGN_CENTER, false);
}
}
if ($this->border) {
$this->graph->drawRoundedRectangle (0, 0, $this->width - 1,
$this->height - 1,
$radius, 157, 157, 157);
}
$this->graph->Stroke ();
}
// Gets an array with each the components of a RGB string
private static function get_rgb_values ($rgb_string) {
$color = array ('r' => 0, 'g' => 0, 'b' => 0);
$offset = 0;
if ($rgb_string[0] == '#')
$offset = 1;
$color['r'] = hexdec (substr ($rgb_string, $offset, 2));
$color['g'] = hexdec (substr ($rgb_string, $offset + 2, 2));
$color['b'] = hexdec (substr ($rgb_string, $offset + 4, 2));
return $color;
}
private function add_alert_levels () {
if ($this->alert_top !== false) {
$this->graph->drawTreshold ($this->alert_top, 57,
96, 255, true, true, 4,
"Alert top");
}
if ($this->alert_bottom !== false) {
$this->graph->drawTreshold ($this->alert_bottom, 7,
96, 255, true, true, 4,
"Alert bottom");
}
}
private function add_events ($serie = "Serie1") {
if (! $this->events)
return;
// Unfortunatelly, the events must be draw manually
$first = $this->dataset->Data[0]["Name"];
$len = count ($this->dataset->Data) - 1;
$last = $this->dataset->Data[$len]["Name"];
$ylen = $this->y2 - $this->y1;
foreach ($this->data as $i => $data) {
// Finally, check if there were events
if (! $data['events'])
continue;
if (!isset($this->dataset->Data[$i]))
continue;
$x1 = (int) ($this->x1 + $i * $this->graph->DivisionWidth);
$y1 = (int) ($this->y2 - ($this->dataset->Data[$i][$serie] * $this->graph->DivisionRatio));
$this->graph->drawFilledCircle ($x1, $y1, 1.5, 255, 0, 0);
if ($y1 == $this->y2)
// Lines in the same dot fails
continue;
$this->graph->drawDottedLine ($x1 - 1, $y1,
$x1 - 1, $this->y2,
5, 255, 150, 150);
}
}
private function add_background () {
if ($this->graph == NULL)
return;
$this->graph->setDateFormat ($this->date_format);
$this->x1 = ($this->width > 300) ? 30 : 35;
// $this->y1 = ($this->height > 200) ? 25 : 10;
$this->x2 = ($this->width > 300) ? $this->width - 15 : $this->width - 15;
$this->y2 = ($this->height > 200) ? $this->height - 25 : $this->height - 25;
if ($this->max_value > 10000 && $this->show_axis)
$this->x1 += 20;
$this->graph->drawGraphArea (255, 255, 255, true);
$this->graph->setFontProperties ($this->fontpath, 7);
$size = $this->graph->getLegendBoxSize ($this->dataset->GetDataDescription ());
// Old resize code for graph area, discard, we need all area in pure mode
//if (is_array ($size)) {
// while ($size[1] > $this->y1)
// $this->y1 += (int) $size[1] / 2;
// if ($this->y1 > $this->y2)
// $this->y1 = $this->y2;
//}
if ($this->show_title == 1){
$this->y1=40;
} else {
$this->y1=10;
}
// No title for combined
if ($this->stacked !== false){
$this->y1=10;
}
$this->graph->setGraphArea ($this->x1, $this->y1, $this->x2, $this->y2);
if ($this->show_title) {
$this->graph->setFontProperties ($this->fontpath, 12);
$this->graph->drawTextBox (2, 7, $this->width, 20, $this->title, 0, 0, 0, 0, ALIGN_LEFT, false);
$this->graph->setFontProperties ($this->fontpath, 9);
$this->graph->drawTextBox (0, 10, $this->width, 20, $this->subtitle,
0, 0, 0, 0, ALIGN_CENTER, false);
$this->graph->setFontProperties ($this->fontpath, 6);
}
// This is a tiny watermark
if ($this->watermark) {
if ($this->show_title){
$this->graph->setFontProperties ($this->fontpath, 7);
$this->graph->drawTextBox ($this->width - 8, 40,
$this->width - 240, 90, 'PANDORA FMS', 90,
174, 214, 174, ALIGN_BOTTOM_LEFT, false);
}
else {
$this->graph->setFontProperties ($this->fontpath, 7);
$this->graph->drawTextBox ($this->width - 8, 50,
$this->width - 240, 60, 'PANDORA FMS', 90,
174, 214, 174, ALIGN_BOTTOM_LEFT, false);
}
}
}
private function add_legend () {
if ((! $this->show_title || $this->legend === false) && ($this->stacked === false)) {
return;
}
// Add legend
$this->graph->setFontProperties ($this->fontpath, 6);
$size = $this->graph->getLegendBoxSize ($this->dataset->GetDataDescription ());
// No title for combined, so legends goes up
if ($this->stacked !== false)
$this->graph->drawLegend ( 35, 12,
$this->dataset->GetDataDescription (),
245, 245, 245);
else
$this->graph->drawLegend ( 35, 52,
$this->dataset->GetDataDescription (),
245, 245, 245);
}
private function set_colors () {
if ($this->graph == NULL)
return;
for ($a = 0; $a<9; $a++){
$color = $this->get_rgb_values ($this->graph_color[$a+1]);
$this->graph->setColorPalette ($a, $color['r'], $color['g'], $color['b']);
}
}
}
*/
?>

View File

@ -0,0 +1,107 @@
0;32;11011001100
1;33;11001101100
2;34;11001100110
3;35;10010011000
4;36;10010001100
5;37;10001001100
6;38;10011001000
7;39;10011000100
8;40;10001100100
9;41;11001001000
10;42;11001000100
11;43;11000100100
12;44;10110011100
13;45;10011011100
14;46;10011001110
15;47;10111001100
16;48;10011101100
17;49;10011100110
18;50;11001110010
19;51;11001011100
20;52;11001001110
21;53;11011100100
22;54;11001110100
23;55;11101101110
24;56;11101001100
25;57;11100101100
26;58;11100100110
27;59;11101100100
28;60;11100110100
29;61;11100110010
30;62;11011011000
31;63;11011000110
32;64;11000110110
33;65;10100011000
34;66;10001011000
35;67;10001000110
36;68;10110001000
37;69;10001101000
38;70;10001100010
39;71;11010001000
40;72;11000101000
41;73;11000100010
42;74;10110111000
43;75;10110001110
44;76;10001101110
45;77;10111011000
46;78;10111000110
47;79;10001110110
48;80;11101110110
49;81;11010001110
50;82;11000101110
51;83;11011101000
52;84;11011100010
53;85;11011101110
54;86;11101011000
55;87;11101000110
56;88;11100010110
57;89;11101101000
58;90;11101100010
59;91;11100011010
60;92;11101111010
61;93;11001000010
62;94;11110001010
63;95;10100110000
64;96;10100001100
65;97;10010110000
66;98;10010000110
67;99;10000101100
68;100;10000100110
69;101;10110010000
70;102;10110000100
71;103;10011010000
72;104;10011000010
73;105;10000110100
74;106;10000110010
75;107;11000010010
76;108;11001010000
77;109;11110111010
78;110;11000010100
79;111;10001111010
80;112;10100111100
81;113;10010111100
82;114;10010011110
83;115;10111100100
84;116;10011110100
85;117;10011110010
86;118;11110100100
87;119;11110010100
88;120;11110010010
89;121;11011011110
90;122;11011110110
91;123;11110110110
92;124;10101111000
93;125;10100011110
94;126;10001011110
95;200;10111101000
96;201;10111100010
97;202;11110101000
98;203;11110100010
99;204;10111011110
100;205;10111101110
101;206;11101011110
102;207;11110101110
103;208;11010000100
104;209;11010010000
105;210;11010011100
106;211;1100011101011

View File

@ -0,0 +1,44 @@
0;101001101101
1;110100101011
2;101100101011
3;110110010101
4;101001101011
5;110100110101
6;101100110101
7;101001011011
8;110100101101
9;101100101101
A;110101001011
B;101101001011
C;110110100101
D;101011001011
E;110101100101
F;101101100101
G;101010011011
H;110101001101
I;101101001101
J;101011001101
K;110101010011
L;101101010011
M;110110101001
N;101011010011
O;110101101001
P;101101101001
Q;101010110011
R;110101011001
S;101101011001
T;101011011001
U;110010101011
V;100110101011
W;110011010101
X;100101101011
Y;110010110101
Z;100110110101
-;100101011011
.;110010101101
;100110101101
$;100100100101
/;100100101001
+;100101001001
%;101001001001
*;100101101101

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,184 @@
<?php
/*
pBarcode128 - class to create barcodes (128B)
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
/* pData class definition */
class pBarcode128
{
var $Codes;
var $Reverse;
var $Result;
var $pChartObject;
var $CRC;
/* Class creator */
function pBarcode128($BasePath="")
{
$this->Codes = "";
$this->Reverse = "";
$FileHandle = @fopen($BasePath."data/128B.db", "r");
if (!$FileHandle) { die("Cannot find barcode database (".$BasePath."128B.db)."); }
while (!feof($FileHandle))
{
$Buffer = fgets($FileHandle,4096);
$Buffer = str_replace(chr(10),"",$Buffer);
$Buffer = str_replace(chr(13),"",$Buffer);
$Values = preg_split("/;/",$Buffer);
$this->Codes[$Values[1]]["ID"] = $Values[0];
$this->Codes[$Values[1]]["Code"] = $Values[2];
$this->Reverse[$Values[0]]["Code"] = $Values[2];
$this->Reverse[$Values[0]]["Asc"] = $Values[1];
}
fclose($FileHandle);
}
/* Return the projected size of a barcode */
function getSize($TextString,$Format="")
{
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
$ShowLegend = isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
$LegendOffset = isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
$DrawArea = isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
$FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : 12;
$Height = isset($Format["Height"]) ? $Format["Height"] : 30;
$TextString = $this->encode128($TextString);
$BarcodeLength = strlen($this->Result);
if ( $DrawArea ) { $WOffset = 20; } else { $WOffset = 0; }
if ( $ShowLegend ) { $HOffset = $FontSize+$LegendOffset+$WOffset; } else { $HOffset = 0; }
$X1 = cos($Angle * PI / 180) * ($WOffset+$BarcodeLength);
$Y1 = sin($Angle * PI / 180) * ($WOffset+$BarcodeLength);
$X2 = $X1 + cos(($Angle+90) * PI / 180) * ($HOffset+$Height);
$Y2 = $Y1 + sin(($Angle+90) * PI / 180) * ($HOffset+$Height);
$AreaWidth = max(abs($X1),abs($X2));
$AreaHeight = max(abs($Y1),abs($Y2));
return(array("Width"=>$AreaWidth,"Height"=>$AreaHeight));
}
function encode128($Value,$Format="")
{
$this->Result = "11010010000";
$this->CRC = 104;
$TextString = "";
for($i=1;$i<=strlen($Value);$i++)
{
$CharCode = ord($this->mid($Value,$i,1));
if ( isset($this->Codes[$CharCode]) )
{
$this->Result = $this->Result.$this->Codes[$CharCode]["Code"];
$this->CRC = $this->CRC + $i*$this->Codes[$CharCode]["ID"];
$TextString = $TextString.chr($CharCode);
}
}
$this->CRC = $this->CRC - floor($this->CRC/103)*103;
$this->Result = $this->Result.$this->Reverse[$this->CRC]["Code"];
$this->Result = $this->Result."1100011101011";
return($TextString);
}
/* Create the encoded string */
function draw($Object,$Value,$X,$Y,$Format="")
{
$this->pChartObject = $Object;
$R = isset($Format["R"]) ? $Format["R"] : 0;
$G = isset($Format["G"]) ? $Format["G"] : 0;
$B = isset($Format["B"]) ? $Format["B"] : 0;
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
$Height = isset($Format["Height"]) ? $Format["Height"] : 30;
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
$ShowLegend = isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
$LegendOffset = isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
$DrawArea = isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
$AreaR = isset($Format["AreaR"]) ? $Format["AreaR"] : 255;
$AreaG = isset($Format["AreaG"]) ? $Format["AreaG"] : 255;
$AreaB = isset($Format["AreaB"]) ? $Format["AreaB"] : 255;
$AreaBorderR = isset($Format["AreaBorderR"]) ? $Format["AreaBorderR"] : $AreaR;
$AreaBorderG = isset($Format["AreaBorderG"]) ? $Format["AreaBorderG"] : $AreaG;
$AreaBorderB = isset($Format["AreaBorderB"]) ? $Format["AreaBorderB"] : $AreaB;
$TextString = $this->encode128($Value);
if ( $DrawArea )
{
$X1 = $X + cos(($Angle-135) * PI / 180) * 10;
$Y1 = $Y + sin(($Angle-135) * PI / 180) * 10;
$X2 = $X1 + cos($Angle * PI / 180) * (strlen($this->Result)+20);
$Y2 = $Y1 + sin($Angle * PI / 180) * (strlen($this->Result)+20);
if ( $ShowLegend )
{
$X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
$Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
}
else
{
$X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+20);
$Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+20);
}
$X4 = $X3 + cos(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
$Y4 = $Y3 + sin(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
$Polygon = array($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4);
$Settings = array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"BorderR"=>$AreaBorderR,"BorderG"=>$AreaBorderG,"BorderB"=>$AreaBorderB);
$this->pChartObject->drawPolygon($Polygon,$Settings);
}
for($i=1;$i<=strlen($this->Result);$i++)
{
if ( $this->mid($this->Result,$i,1) == 1 )
{
$X1 = $X + cos($Angle * PI / 180) * $i;
$Y1 = $Y + sin($Angle * PI / 180) * $i;
$X2 = $X1 + cos(($Angle+90) * PI / 180) * $Height;
$Y2 = $Y1 + sin(($Angle+90) * PI / 180) * $Height;
$Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
$this->pChartObject->drawLine($X1,$Y1,$X2,$Y2,$Settings);
}
}
if ( $ShowLegend )
{
$X1 = $X + cos($Angle * PI / 180) * (strlen($this->Result)/2);
$Y1 = $Y + sin($Angle * PI / 180) * (strlen($this->Result)/2);
$LegendX = $X1 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
$LegendY = $Y1 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
$Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Angle"=>-$Angle,"Align"=>TEXT_ALIGN_TOPMIDDLE);
$this->pChartObject->drawText($LegendX,$LegendY,$TextString,$Settings);
}
}
function left($value,$NbChar) { return substr($value,0,$NbChar); }
function right($value,$NbChar) { return substr($value,strlen($value)-$NbChar,$NbChar); }
function mid($value,$Depart,$NbChar) { return substr($value,$Depart-1,$NbChar); }
}
?>

View File

@ -0,0 +1,200 @@
<?php
/*
pBarcode39 - class to create barcodes (39B)
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
/* pData class definition */
class pBarcode39
{
var $Codes;
var $Reverse;
var $Result;
var $pChartObject;
var $CRC;
var $MOD43;
/* Class creator */
function pBarcode39($BasePath="",$EnableMOD43=FALSE)
{
$this->MOD43 = $EnableMOD43;
$this->Codes = "";
$this->Reverse = "";
$FileHandle = @fopen($BasePath."data/39.db", "r");
if (!$FileHandle) { die("Cannot find barcode database (".$BasePath."data/39.db)."); }
while (!feof($FileHandle))
{
$Buffer = fgets($FileHandle,4096);
$Buffer = str_replace(chr(10),"",$Buffer);
$Buffer = str_replace(chr(13),"",$Buffer);
$Values = preg_split("/;/",$Buffer);
$this->Codes[$Values[0]] = $Values[1];
}
fclose($FileHandle);
}
/* Return the projected size of a barcode */
function getSize($TextString,$Format="")
{
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
$ShowLegend = isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
$LegendOffset = isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
$DrawArea = isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
$FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : 12;
$Height = isset($Format["Height"]) ? $Format["Height"] : 30;
$TextString = $this->encode39($TextString);
$BarcodeLength = strlen($this->Result);
if ( $DrawArea ) { $WOffset = 20; } else { $WOffset = 0; }
if ( $ShowLegend ) { $HOffset = $FontSize+$LegendOffset+$WOffset; } else { $HOffset = 0; }
$X1 = cos($Angle * PI / 180) * ($WOffset+$BarcodeLength);
$Y1 = sin($Angle * PI / 180) * ($WOffset+$BarcodeLength);
$X2 = $X1 + cos(($Angle+90) * PI / 180) * ($HOffset+$Height);
$Y2 = $Y1 + sin(($Angle+90) * PI / 180) * ($HOffset+$Height);
$AreaWidth = max(abs($X1),abs($X2));
$AreaHeight = max(abs($Y1),abs($Y2));
return(array("Width"=>$AreaWidth,"Height"=>$AreaHeight));
}
/* Create the encoded string */
function encode39($Value)
{
$this->Result = "100101101101"."0";
$TextString = "";
for($i=1;$i<=strlen($Value);$i++)
{
$CharCode = ord($this->mid($Value,$i,1));
if ( $CharCode >= 97 && $CharCode <= 122 ) { $CharCode = $CharCode - 32; }
if ( isset($this->Codes[chr($CharCode)]) )
{
$this->Result = $this->Result.$this->Codes[chr($CharCode)]."0";
$TextString = $TextString.chr($CharCode);
}
}
if ( $this->MOD43 )
{
$Checksum = $this->checksum($TextString);
$this->Result = $this->Result.$this->Codes[$Checksum]."0";
}
$this->Result = $this->Result."100101101101";
$TextString = "*".$TextString."*";
return($TextString);
}
/* Create the encoded string */
function draw($Object,$Value,$X,$Y,$Format="")
{
$this->pChartObject = $Object;
$R = isset($Format["R"]) ? $Format["R"] : 0;
$G = isset($Format["G"]) ? $Format["G"] : 0;
$B = isset($Format["B"]) ? $Format["B"] : 0;
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
$Height = isset($Format["Height"]) ? $Format["Height"] : 30;
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
$ShowLegend = isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
$LegendOffset = isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
$DrawArea = isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
$AreaR = isset($Format["AreaR"]) ? $Format["AreaR"] : 255;
$AreaG = isset($Format["AreaG"]) ? $Format["AreaG"] : 255;
$AreaB = isset($Format["AreaB"]) ? $Format["AreaB"] : 255;
$AreaBorderR = isset($Format["AreaBorderR"]) ? $Format["AreaBorderR"] : $AreaR;
$AreaBorderG = isset($Format["AreaBorderG"]) ? $Format["AreaBorderG"] : $AreaG;
$AreaBorderB = isset($Format["AreaBorderB"]) ? $Format["AreaBorderB"] : $AreaB;
$TextString = $this->encode39($Value);
if ( $DrawArea )
{
$X1 = $X + cos(($Angle-135) * PI / 180) * 10;
$Y1 = $Y + sin(($Angle-135) * PI / 180) * 10;
$X2 = $X1 + cos($Angle * PI / 180) * (strlen($this->Result)+20);
$Y2 = $Y1 + sin($Angle * PI / 180) * (strlen($this->Result)+20);
if ( $ShowLegend )
{
$X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
$Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
}
else
{
$X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+20);
$Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+20);
}
$X4 = $X3 + cos(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
$Y4 = $Y3 + sin(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
$Polygon = array($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4);
$Settings = array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"BorderR"=>$AreaBorderR,"BorderG"=>$AreaBorderG,"BorderB"=>$AreaBorderB);
$this->pChartObject->drawPolygon($Polygon,$Settings);
}
for($i=1;$i<=strlen($this->Result);$i++)
{
if ( $this->mid($this->Result,$i,1) == 1 )
{
$X1 = $X + cos($Angle * PI / 180) * $i;
$Y1 = $Y + sin($Angle * PI / 180) * $i;
$X2 = $X1 + cos(($Angle+90) * PI / 180) * $Height;
$Y2 = $Y1 + sin(($Angle+90) * PI / 180) * $Height;
$Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
$this->pChartObject->drawLine($X1,$Y1,$X2,$Y2,$Settings);
}
}
if ( $ShowLegend )
{
$X1 = $X + cos($Angle * PI / 180) * (strlen($this->Result)/2);
$Y1 = $Y + sin($Angle * PI / 180) * (strlen($this->Result)/2);
$LegendX = $X1 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
$LegendY = $Y1 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
$Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Angle"=>-$Angle,"Align"=>TEXT_ALIGN_TOPMIDDLE);
$this->pChartObject->drawText($LegendX,$LegendY,$TextString,$Settings);
}
}
function checksum( $string )
{
$checksum = 0;
$length = strlen( $string );
$charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%';
for( $i=0; $i < $length; ++$i )
$checksum += strpos( $charset, $string[$i] );
return substr( $charset, ($checksum % 43), 1 );
}
function left($value,$NbChar) { return substr($value,0,$NbChar); }
function right($value,$NbChar) { return substr($value,strlen($value)-$NbChar,$NbChar); }
function mid($value,$Depart,$NbChar) { return substr($value,$Depart-1,$NbChar); }
}
?>

View File

@ -0,0 +1,191 @@
<?php
/*
pBubble - class to draw bubble charts
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
/* pBubble class definition */
class pBubble
{
var $pChartObject;
var $pDataObject;
/* Class creator */
function pBubble($pChartObject,$pDataObject)
{
$this->pChartObject = $pChartObject;
$this->pDataObject = $pDataObject;
}
/* Prepare the scale */
function bubbleScale($DataSeries,$WeightSeries)
{
if ( !is_array($DataSeries) ) { $DataSeries = array($DataSeries); }
if ( !is_array($WeightSeries) ) { $WeightSeries = array($WeightSeries); }
/* Parse each data series to find the new min & max boundaries to scale */
$NewPositiveSerie = ""; $NewNegativeSerie = ""; $MaxValues = 0; $LastPositive = 0; $LastNegative = 0;
foreach($DataSeries as $Key => $SerieName)
{
$SerieWeightName = $WeightSeries[$Key];
$this->pDataObject->setSerieDrawable($SerieWeightName,FALSE);
if ( count($this->pDataObject->Data["Series"][$SerieName]["Data"]) > $MaxValues ) { $MaxValues = count($this->pDataObject->Data["Series"][$SerieName]["Data"]); }
foreach($this->pDataObject->Data["Series"][$SerieName]["Data"] as $Key => $Value)
{
if ( $Value >= 0 )
{
$BubbleBounds = $Value + $this->pDataObject->Data["Series"][$SerieWeightName]["Data"][$Key];
if ( !isset($NewPositiveSerie[$Key]) )
{ $NewPositiveSerie[$Key] = $BubbleBounds; }
elseif ( $NewPositiveSerie[$Key] < $BubbleBounds )
{ $NewPositiveSerie[$Key] = $BubbleBounds; }
$LastPositive = $BubbleBounds;
}
else
{
$BubbleBounds = $Value - $this->pDataObject->Data["Series"][$SerieWeightName]["Data"][$Key];
if ( !isset($NewNegativeSerie[$Key]) )
{ $NewNegativeSerie[$Key] = $BubbleBounds; }
elseif ( $NewNegativeSerie[$Key] > $BubbleBounds )
{ $NewNegativeSerie[$Key] = $BubbleBounds; }
$LastNegative = $BubbleBounds;
}
}
}
/* Check for missing values and all the fake positive serie */
if ( $NewPositiveSerie != "" )
{
for ($i=0; $i<$MaxValues; $i++) { if (!isset($NewPositiveSerie[$i])) { $NewPositiveSerie[$i] = $LastPositive; } }
$this->pDataObject->addPoints($NewPositiveSerie,"BubbleFakePositiveSerie");
}
/* Check for missing values and all the fake negative serie */
if ( $NewNegativeSerie != "" )
{
for ($i=0; $i<$MaxValues; $i++) { if (!isset($NewNegativeSerie[$i])) { $NewNegativeSerie[$i] = $LastNegative; } }
$this->pDataObject->addPoints($NewNegativeSerie,"BubbleFakeNegativeSerie");
}
}
function resetSeriesColors()
{
$Data = $this->pDataObject->getData();
$Palette = $this->pDataObject->getPalette();
$ID = 0;
foreach($Data["Series"] as $SerieName => $SeriesParameters)
{
if ( $SeriesParameters["isDrawable"] )
{
$this->pDataObject->Data["Series"][$SerieName]["Color"]["R"] = $Palette[$ID]["R"];
$this->pDataObject->Data["Series"][$SerieName]["Color"]["G"] = $Palette[$ID]["G"];
$this->pDataObject->Data["Series"][$SerieName]["Color"]["B"] = $Palette[$ID]["B"];
$this->pDataObject->Data["Series"][$SerieName]["Color"]["Alpha"] = $Palette[$ID]["Alpha"];
$ID++;
}
}
}
/* Prepare the scale */
function drawBubbleChart($DataSeries,$WeightSeries,$Format="")
{
$DrawBorder = isset($Format["DrawBorder"]) ? $Format["DrawBorder"] : TRUE;
$DrawSquare = isset($Format["DrawSquare"]) ? $Format["DrawSquare"] : FALSE;
$Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
$BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 0;
$BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 0;
$BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 0;
$BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 30;
if ( !is_array($DataSeries) ) { $DataSeries = array($DataSeries); }
if ( !is_array($WeightSeries) ) { $WeightSeries = array($WeightSeries); }
$Data = $this->pDataObject->getData();
$Palette = $this->pDataObject->getPalette();
if ( isset($Data["Series"]["BubbleFakePositiveSerie"] ) ) { $this->pDataObject->setSerieDrawable("BubbleFakePositiveSerie",FALSE); }
if ( isset($Data["Series"]["BubbleFakeNegativeSerie"] ) ) { $this->pDataObject->setSerieDrawable("BubbleFakeNegativeSerie",FALSE); }
$this->resetSeriesColors();
list($XMargin,$XDivs) = $this->pChartObject->scaleGetXSettings();
foreach($DataSeries as $Key => $SerieName)
{
$AxisID = $Data["Series"][$SerieName]["Axis"];
$Mode = $Data["Axis"][$AxisID]["Display"];
$Format = $Data["Axis"][$AxisID]["Format"];
$Unit = $Data["Axis"][$AxisID]["Unit"];
$XStep = ($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1-$XMargin*2)/$XDivs;
$X = $this->pChartObject->GraphAreaX1 + $XMargin;
$Y = $this->pChartObject->GraphAreaY1 + $XMargin;
$Color = array("R"=>$Palette[$Key]["R"],"G"=>$Palette[$Key]["G"],"B"=>$Palette[$Key]["B"],"Alpha"=>$Palette[$Key]["Alpha"]);
if ( $DrawBorder )
{
$Color["BorderAlpha"] = $BorderAlpha;
if ( $Surrounding != NULL )
{ $Color["BorderR"] = $Palette[$Key]["R"]+$Surrounding; $Color["BorderG"] = $Palette[$Key]["G"]+$Surrounding; $Color["BorderB"] = $Palette[$Key]["B"]+$Surrounding; }
else
{ $Color["BorderR"] = $BorderR; $Color["BorderG"] = $BorderG; $Color["BorderB"] = $BorderB; }
}
foreach($Data["Series"][$SerieName]["Data"] as $iKey => $Point)
{
$Weight = $Point + $Data["Series"][$WeightSeries[$Key]]["Data"][$iKey];
$PosArray = $this->pChartObject->scaleComputeY($Point,array("AxisID"=>$AxisID));
$WeightArray = $this->pChartObject->scaleComputeY($Weight,array("AxisID"=>$AxisID));
if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
{
if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1-$XMargin*2)/$XDivs; }
$Y = floor($PosArray); $CircleRadius = floor(abs($PosArray - $WeightArray)/2);
if ( $DrawSquare )
$this->pChartObject->drawFilledRectangle($X-$CircleRadius,$Y-$CircleRadius,$X+$CircleRadius,$Y+$CircleRadius,$Color);
else
$this->pChartObject->drawFilledCircle($X,$Y,$CircleRadius,$Color);
$X = $X + $XStep;
}
elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
{
if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1-$XMargin*2)/$XDivs; }
$X = floor($PosArray); $CircleRadius = floor(abs($PosArray - $WeightArray)/2);
if ( $DrawSquare )
$this->pChartObject->drawFilledRectangle($X-$CircleRadius,$Y-$CircleRadius,$X+$CircleRadius,$Y+$CircleRadius,$Color);
else
$this->pChartObject->drawFilledCircle($X,$Y,$CircleRadius,$Color);
$Y = $Y + $XStep;
}
}
}
}
}
?>

View File

@ -0,0 +1,271 @@
<?php
/*
pCache - speed up the rendering by caching up the pictures
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
/* pData class definition */
class pCache
{
var $CacheFolder;
var $CacheIndex;
var $CacheDB;
/* Class creator */
function pCache($Settings="")
{
$CacheFolder = isset($Settings["CacheFolder"]) ? $Settings["CacheFolder"] : "cache";
$CacheIndex = isset($Settings["CacheIndex"]) ? $Settings["CacheIndex"] : "index.db";
$CacheDB = isset($Settings["CacheDB"]) ? $Settings["CacheDB"] : "cache.db";
$this->CacheFolder = $CacheFolder;
$this->CacheIndex = $CacheIndex;
$this->CacheDB = $CacheDB;
if (!file_exists($this->CacheFolder."/".$this->CacheIndex)) { touch($this->CacheFolder."/".$this->CacheIndex); }
if (!file_exists($this->CacheFolder."/".$this->CacheDB)) { touch($this->CacheFolder."/".$this->CacheDB); }
}
/* Flush the cache contents */
function flush()
{
if (file_exists($this->CacheFolder."/".$this->CacheIndex)) { unlink($this->CacheFolder."/".$this->CacheIndex); touch($this->CacheFolder."/".$this->CacheIndex); }
if (file_exists($this->CacheFolder."/".$this->CacheDB)) { unlink($this->CacheFolder."/".$this->CacheDB); touch($this->CacheFolder."/".$this->CacheDB); }
}
/* Return the MD5 of the data array to clearly identify the chart */
function getHash($Data,$Marker="")
{ return(md5($Marker.serialize($Data->Data))); }
/* Write the generated picture to the cache */
function writeToCache($ID,$pChartObject)
{
/* Compute the paths */
$TemporaryFile = $this->CacheFolder."/tmp_".rand(0,1000).".png";
$Database = $this->CacheFolder."/".$this->CacheDB;
$Index = $this->CacheFolder."/".$this->CacheIndex;
/* Flush the picture to a temporary file */
imagepng($pChartObject->Picture ,$TemporaryFile);
/* Retrieve the files size */
$PictureSize = filesize($TemporaryFile);
$DBSize = filesize($Database);
/* Save the index */
$Handle = fopen($Index,"a");
fwrite($Handle, $ID.",".$DBSize.",".$PictureSize.",".time().",0 \r\n");
fclose($Handle);
/* Get the picture raw contents */
$Handle = fopen($TemporaryFile,"r");
$Raw = fread($Handle,$PictureSize);
fclose($Handle);
/* Save the picture in the solid database file */
$Handle = fopen($Database,"a");
fwrite($Handle, $Raw);
fclose($Handle);
/* Remove temporary file */
unlink($TemporaryFile);
}
/* Remove object older than the specified TS */
function removeOlderThan($Expiry)
{ $this->dbRemoval(array("Expiry"=>$Expiry)); }
/* Remove an object from the cache */
function remove($ID)
{ $this->dbRemoval(array("Name"=>$ID)); }
/* Remove with specified criterias */
function dbRemoval($Settings)
{
$ID = isset($Settings["Name"]) ? $Settings["Name"] : NULL;
$Expiry = isset($Settings["Expiry"]) ? $Settings["Expiry"] : -(24*60*60);
$TS = time()-$Expiry;
/* Compute the paths */
$Database = $this->CacheFolder."/".$this->CacheDB;
$Index = $this->CacheFolder."/".$this->CacheIndex;
$DatabaseTemp = $this->CacheFolder."/".$this->CacheDB.".tmp";
$IndexTemp = $this->CacheFolder."/".$this->CacheIndex.".tmp";
/* Single file removal */
if ( $ID != NULL )
{
/* Retrieve object informations */
$Object = $this->isInCache($ID,TRUE);
/* If it's not in the cache DB, go away */
if ( !$Object ) { return(0); }
}
/* Create the temporary files */
if (!file_exists($DatabaseTemp)) { touch($DatabaseTemp); }
if (!file_exists($IndexTemp)) { touch($IndexTemp); }
/* Open the file handles */
$IndexHandle = @fopen($Index, "r");
$IndexTempHandle = @fopen($IndexTemp, "w");
$DBHandle = @fopen($Database, "r");
$DBTempHandle = @fopen($DatabaseTemp, "w");
/* Remove the selected ID from the database */
while (!feof($IndexHandle))
{
$Entry = fgets($IndexHandle, 4096);
$Entry = str_replace("\r","",$Entry);
$Entry = str_replace("\n","",$Entry);
$Settings = preg_split("/,/",$Entry);
if ( $Entry != "" )
{
$PicID = $Settings[0];
$DBPos = $Settings[1];
$PicSize = $Settings[2];
$GeneratedTS = $Settings[3];
$Hits = $Settings[4];
if ( $Settings[0] != $ID && $GeneratedTS > $TS)
{
$CurrentPos = ftell($DBTempHandle);
fwrite($IndexTempHandle, $PicID.",".$CurrentPos.",".$PicSize.",".$GeneratedTS.",".$Hits."\r\n");
fseek($DBHandle,$DBPos);
$Picture = fread($DBHandle,$PicSize);
fwrite($DBTempHandle,$Picture);
}
}
}
/* Close the handles */
fclose($IndexHandle);
fclose($IndexTempHandle);
fclose($DBHandle);
fclose($DBTempHandle);
/* Remove the prod files */
unlink($Database);
unlink($Index);
/* Swap the temp & prod DB */
rename($DatabaseTemp,$Database);
rename($IndexTemp,$Index);
}
function isInCache($ID,$Verbose=FALSE,$UpdateHitsCount=FALSE)
{
/* Compute the paths */
$Index = $this->CacheFolder."/".$this->CacheIndex;
/* Search the picture in the index file */
$Handle = @fopen($Index, "r");
while (!feof($Handle))
{
$IndexPos = ftell($Handle);
$Entry = fgets($Handle, 4096);
if ( $Entry != "" )
{
$Settings = preg_split("/,/",$Entry);
$PicID = $Settings[0];
if ( $PicID == $ID )
{
fclose($Handle);
$DBPos = $Settings[1];
$PicSize = $Settings[2];
$GeneratedTS = $Settings[3];
$Hits = intval($Settings[4]);
if ( $UpdateHitsCount )
{
$Hits++;
if ( strlen($Hits) < 7 ) { $Hits = $Hits.str_repeat(" ",7-strlen($Hits)); }
$Handle = @fopen($Index, "r+");
fseek($Handle,$IndexPos);
fwrite($Handle, $PicID.",".$DBPos.",".$PicSize.",".$GeneratedTS.",".$Hits."\r\n");
fclose($Handle);
}
if ($Verbose)
{ return(array("DBPos"=>$DBPos,"PicSize"=>$PicSize,"GeneratedTS"=>$GeneratedTS,"Hits"=>$Hits)); }
else
{ return(TRUE); }
}
}
}
fclose($Handle);
/* Picture isn't in the cache */
return(FALSE);
}
function strokeFromCache($ID)
{
/* Get the raw picture from the cache */
$Picture = $this->getFromCache($ID);
/* Do we have a hit? */
if ( $Picture == NULL ) { return(FALSE); }
header('Content-type: image/png');
echo $Picture;
return(TRUE);
}
function saveFromCache($ID,$Destination)
{
/* Get the raw picture from the cache */
$Picture = $this->getFromCache($ID);
/* Do we have a hit? */
if ( $Picture == NULL ) { return(FALSE); }
/* Flush the picture to a file */
$Handle = fopen($Destination,"w");
fwrite($Handle,$Picture);
fclose($Handle);
/* All went fine */
return(TRUE);
}
function getFromCache($ID)
{
/* Compute the path */
$Database = $this->CacheFolder."/".$this->CacheDB;
/* Lookup for the picture in the cache */
$CacheInfo = $this->isInCache($ID,TRUE,TRUE);
/* Not in the cache */
if (!$CacheInfo) { return(NULL); }
/* Get the database extended information */
$DBPos = $CacheInfo["DBPos"];
$PicSize = $CacheInfo["PicSize"];
/* Extract the picture from the solid cache file */
$Handle = @fopen($Database, "r");
fseek($Handle,$DBPos);
$Picture = fread($Handle,$PicSize);
fclose($Handle);
/* Return back the raw picture data */
return($Picture);
}
}
?>

View File

@ -0,0 +1,555 @@
<?php
/*
pDraw - class to manipulate data arrays
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
/* Axis configuration */
define("AXIS_FORMAT_DEFAULT" , 680001);
define("AXIS_FORMAT_TIME" , 680002);
define("AXIS_FORMAT_DATE" , 680003);
define("AXIS_FORMAT_METRIC" , 680004);
define("AXIS_FORMAT_CURRENCY" , 680005);
/* Axis position */
define("AXIS_POSITION_LEFT" , 681001);
define("AXIS_POSITION_RIGHT" , 681002);
define("AXIS_POSITION_TOP" , 681001);
define("AXIS_POSITION_BOTTOM" , 681002);
/* Axis position */
define("AXIS_X" , 682001);
define("AXIS_Y" , 682002);
/* Define value limits */
define("ABSOLUTE_MIN" , -10000000000000);
define("ABSOLUTE_MAX" , 10000000000000);
/* Replacement to the PHP NULL keyword */
define("VOID" , 0.12345);
/* pData class definition */
class pData
{
var $Data;
var $Palette = array("0"=>array("R"=>188,"G"=>224,"B"=>46,"Alpha"=>100),
"1"=>array("R"=>224,"G"=>100,"B"=>46,"Alpha"=>100),
"2"=>array("R"=>224,"G"=>214,"B"=>46,"Alpha"=>100),
"3"=>array("R"=>46,"G"=>151,"B"=>224,"Alpha"=>100),
"4"=>array("R"=>176,"G"=>46,"B"=>224,"Alpha"=>100),
"5"=>array("R"=>224,"G"=>46,"B"=>117,"Alpha"=>100),
"6"=>array("R"=>92,"G"=>224,"B"=>46,"Alpha"=>100),
"7"=>array("R"=>224,"G"=>176,"B"=>46,"Alpha"=>100));
/* Class creator */
function pData()
{
$this->Data = "";
$this->Data["XAxisDisplay"] = AXIS_FORMAT_DEFAULT;
$this->Data["XAxisFormat"] = NULL;
$this->Data["XAxisName"] = NULL;
$this->Data["XAxisUnit"] = NULL;
$this->Data["Abscissa"] = NULL;
$this->Data["Axis"][0]["Display"] = AXIS_FORMAT_DEFAULT;
$this->Data["Axis"][0]["Position"] = AXIS_POSITION_LEFT;
$this->Data["Axis"][0]["Identity"] = AXIS_Y;
}
/* Add a single point or an array to the given serie */
function addPoints($Values,$SerieName="Serie1")
{
if (!isset($this->Data["Series"][$SerieName]))
$this->initialise($SerieName);
if ( is_array($Values) )
{
foreach($Values as $Key => $Value)
{ $this->Data["Series"][$SerieName]["Data"][] = $Value; }
}
else
$this->Data["Series"][$SerieName]["Data"][] = $Values;
if ( $Values != VOID )
{
$this->Data["Series"][$SerieName]["Max"] = max($this->stripVOID($this->Data["Series"][$SerieName]["Data"]));
$this->Data["Series"][$SerieName]["Min"] = min($this->stripVOID($this->Data["Series"][$SerieName]["Data"]));
}
}
/* Strip VOID values */
function stripVOID($Values)
{ $Result = ""; foreach($Values as $Key => $Value) { if ( $Value != VOID ) { $Result[] = $Value; } } return($Result); }
/* Return the number of values contained in a given serie */
function getSerieCount($Serie=NULL)
{ if (isset($this->Data["Series"][$Serie]["Data"])) { return(sizeof($this->Data["Series"][$Serie]["Data"])); } else { return(0); } }
/* Remove a serie from the pData object */
function removeSerie($Serie=NULL)
{ if (isset($this->Data["Series"][$Serie])) { unset($this->Data["Series"][$Serie]); } }
/* Return a value from given serie & index */
function getValueAt($Serie,$Index=0)
{ if (isset($this->Data["Series"][$Serie]["Data"][$Index])) { return($this->Data["Series"][$Serie]["Data"][$Index]); } else { return(NULL); } }
/* Return the values array */
function getValues($Serie=NULL)
{ if (isset($this->Data["Series"][$Serie]["Data"])) { return($this->Data["Series"][$Serie]["Data"]); } else { return(NULL); } }
/* Reverse the values in the given serie */
function reverseSerie($Serie=NULL)
{ if (isset($this->Data["Series"][$Serie]["Data"])) { $this->Data["Series"][$Serie]["Data"] = array_reverse($this->Data["Series"][$Serie]["Data"]); } }
/* Return the sum of the serie values */
function getSum($Serie)
{ if (isset($this->Data["Series"][$Serie])) { return(array_sum($this->Data["Series"][$Serie]["Data"])); } else { return(NULL); } }
/* Return the max value of a given serie */
function getMax($Serie)
{ if (isset($this->Data["Series"][$Serie]["Max"])) { return($this->Data["Series"][$Serie]["Max"]); } else { return(NULL); } }
/* Return the min value of a given serie */
function getMin($Serie)
{ if (isset($this->Data["Series"][$Serie]["Min"])) { return($this->Data["Series"][$Serie]["Min"]); } else { return(NULL); } }
/* Set the description of a given serie */
function setSerieDescription($Serie=NULL,$Description="My serie")
{ if (isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["Description"] = $Description; } }
/* Set a serie as "drawable" while calling a rendering function */
function setSerieDrawable($Serie=NULL ,$Drawable=TRUE)
{ if (isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["isDrawable"] = $Drawable; } }
/* Set the icon associated to a given serie */
function setSeriePicture($Serie=NULL,$Picture=NULL)
{ if (isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["Picture"] = $Picture; } }
/* Set the name of the X Axis */
function setXAxisName($Name=NULL)
{ $this->Data["XAxisName"] = $Name; }
/* Set the display mode of the X Axis */
function setXAxisDisplay($Mode,$Format=NULL)
{ $this->Data["XAxisDisplay"] = $Mode; $this->Data["XAxisFormat"] = $Format; }
/* Set the unit that will be displayed on the X axis */
function setXAxisUnit($Unit)
{ $this->Data["XAxisUnit"] = $Unit; }
/* Set the serie that will be used as abscissa */
function setAbscissa($Serie)
{ if (isset($this->Data["Series"][$Serie])) { $this->Data["Abscissa"] = $Serie; } }
/* Create a scatter group specifyin X and Y data series */
function setScatterSerie($SerieX,$SerieY,$ID=0)
{ if (isset($this->Data["Series"][$SerieX]) && isset($this->Data["Series"][$SerieY]) ) { $this->initScatterSerie($ID); $this->Data["ScatterSeries"][$ID]["X"] = $SerieX; $this->Data["ScatterSeries"][$ID]["Y"] = $SerieY; } }
/* Set the description of a given scatter serie */
function setScatterSerieDescription($ID,$Description="My serie")
{ if (isset($this->Data["ScatterSeries"][$ID]) ) { $this->Data["ScatterSeries"][$ID]["Description"] = $Description; } }
/* Set the icon associated to a given scatter serie */
function setScatterSeriePicture($ID,$Picture=NULL)
{ if (isset($this->Data["ScatterSeries"][$ID]) ) { $this->Data["ScatterSeries"][$ID]["Picture"] = $Picture; } }
/* Set a scatter serie as "drawable" while calling a rendering function */
function setScatterSerieDrawable($ID ,$Drawable=TRUE)
{ if (isset($this->Data["ScatterSeries"][ID]) ) { $this->Data["ScatterSeries"][ID]["isDrawable"] = $Drawable; } }
/* Define if a scatter serie should be draw with ticks */
function setScatterSerieTicks($ID,$Width=0)
{ if ( isset($this->Data["ScatterSeries"][$ID]) ) { $this->Data["ScatterSeries"][$ID]["Ticks"] = $Width; } }
/* Define if a scatter serie should be draw with a special weight */
function setScatterSerieWeight($ID,$Weight=0)
{ if ( isset($this->Data["ScatterSeries"][$ID]) ) { $this->Data["ScatterSeries"][$ID]["Weight"] = $Weight; } }
/* Associate a color to a scatter serie */
function setScatterSerieColor($ID,$Format)
{
$R = isset($Format["R"]) ? $Format["R"] : 0;
$G = isset($Format["G"]) ? $Format["G"] : 0;
$B = isset($Format["B"]) ? $Format["B"] : 0;
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
if ( isset($this->Data["ScatterSeries"][$ID]) )
{
$this->Data["ScatterSeries"][$ID]["Color"]["R"] = $R;
$this->Data["ScatterSeries"][$ID]["Color"]["G"] = $G;
$this->Data["ScatterSeries"][$ID]["Color"]["B"] = $B;
$this->Data["ScatterSeries"][$ID]["Color"]["Alpha"] = $Alpha;
}
}
/* Compute the series limits for an individual and global point of view */
function limits()
{
$GlobalMin = ABSOLUTE_MAX;
$GlobalMax = ABSOLUTE_MIN;
foreach($this->Data["Series"] as $Key => $Value)
{
if ( $this->Data["Abscissa"] != $Key && $this->Data["Series"][$Key]["isDrawable"] == TRUE)
{
if ( $GlobalMin > $this->Data["Series"][$Key]["Min"] ) { $GlobalMin = $this->Data["Series"][$Key]["Min"]; }
if ( $GlobalMax < $this->Data["Series"][$Key]["Max"] ) { $GlobalMax = $this->Data["Series"][$Key]["Max"]; }
}
}
$this->Data["Min"] = $GlobalMin;
$this->Data["Max"] = $GlobalMax;
return(array($GlobalMin,$GlobalMax));
}
/* Mark all series as drawable */
function drawAll()
{ foreach($this->Data["Series"] as $Key => $Value) { if ( $this->Data["Abscissa"] != $Key ) { $this->Data["Series"][$Key]["isDrawable"]=TRUE; } } }
/* Return the average value of the given serie */
function getSerieAverage($Serie)
{
if ( isset($this->Data["Series"][$Serie]) )
return(array_sum($this->Data["Series"][$Serie]["Data"])/sizeof($this->Data["Series"][$Serie]["Data"]));
else
return(NULL);
}
/* Return the x th percentil of the given serie */
function getSeriePercentile($Serie="Serie1",$Percentil=95)
{
if (!isset($this->Data["Series"][$Serie]["Data"])) { return(NULL); }
$Values = count($this->Data["Series"][$Serie]["Data"])-1;
if ( $Values < 0 ) { $Values = 0; }
$PercentilID = floor(($Values/100)*$Percentil+.5);
$SortedValues = $this->Data["Series"][$Serie]["Data"];
sort($SortedValues);
if ( is_numeric($SortedValues[$PercentilID]) )
return($SortedValues[$PercentilID]);
else
return(NULL);
}
/* Add random values to a given serie */
function addRandomValues($SerieName="Serie1",$Options="")
{
$Values = isset($Options["Values"]) ? $Options["Values"] : 20;
$Min = isset($Options["Min"]) ? $Options["Min"] : 0;
$Max = isset($Options["Max"]) ? $Options["Max"] : 100;
$withFloat = isset($Options["withFloat"]) ? $Options["withFloat"] : FALSE;
for ($i=0;$i<=$Values;$i++)
{
if ( $withFloat ) { $Value = rand($Min*100,$Max*100)/100; } else { $Value = rand($Min,$Max); }
$this->addPoints($Value,$SerieName);
}
}
/* Test if we have valid data */
function containsData()
{
if (!isset($this->Data["Series"])) { return(FALSE); }
$Result = FALSE;
foreach($this->Data["Series"] as $Key => $Value)
{ if ( $this->Data["Abscissa"] != $Key && $this->Data["Series"][$Key]["isDrawable"]==TRUE) { $Result=TRUE; } }
return($Result);
}
/* Set the display mode of an Axis */
function setAxisDisplay($AxisID,$Mode=AXIS_FORMAT_DEFAULT,$Format=NULL)
{
if ( isset($this->Data["Axis"][$AxisID] ) )
{
$this->Data["Axis"][$AxisID]["Display"] = $Mode;
if ( $Format != NULL ) { $this->Data["Axis"][$AxisID]["Format"] = $Format; }
}
}
/* Set the position of an Axis */
function setAxisPosition($AxisID,$Position=AXIS_POSITION_LEFT)
{ if ( isset($this->Data["Axis"][$AxisID] ) ) { $this->Data["Axis"][$AxisID]["Position"] = $Position; } }
/* Associate an unit to an axis */
function setAxisUnit($AxisID,$Unit)
{ if ( isset($this->Data["Axis"][$AxisID] ) ) { $this->Data["Axis"][$AxisID]["Unit"] = $Unit; } }
/* Associate a name to an axis */
function setAxisName($AxisID,$Name)
{ if ( isset($this->Data["Axis"][$AxisID] ) ) { $this->Data["Axis"][$AxisID]["Name"] = $Name; } }
/* Associate a color to an axis */
function setAxisColor($AxisID,$Format)
{
$R = isset($Format["R"]) ? $Format["R"] : 0;
$G = isset($Format["G"]) ? $Format["G"] : 0;
$B = isset($Format["B"]) ? $Format["B"] : 0;
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
if ( isset($this->Data["Axis"][$AxisID] ) )
{
$this->Data["Axis"][$AxisID]["Color"]["R"] = $R;
$this->Data["Axis"][$AxisID]["Color"]["G"] = $G;
$this->Data["Axis"][$AxisID]["Color"]["B"] = $B;
$this->Data["Axis"][$AxisID]["Color"]["Alpha"] = $Alpha;
}
}
/* Design an axis as X or Y member */
function setAxisXY($AxisID,$Identity=AXIS_Y)
{ if ( isset($this->Data["Axis"][$AxisID] ) ) { $this->Data["Axis"][$AxisID]["Identity"] = $Identity; } }
/* Associate one data serie with one axis */
function setSerieOnAxis($Serie,$AxisID)
{
$PreviousAxis = $this->Data["Series"][$Serie]["Axis"];
/* Create missing axis */
if ( !isset($this->Data["Axis"][$AxisID] ) )
{ $this->Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_LEFT; $this->Data["Axis"][$AxisID]["Identity"] = AXIS_Y;}
$this->Data["Series"][$Serie]["Axis"] = $AxisID;
/* Cleanup unused axis */
$Found = FALSE;
foreach($this->Data["Series"] as $SerieName => $Values) { if ( $Values["Axis"] == $PreviousAxis ) { $Found = TRUE; } }
if (!$Found) { unset($this->Data["Axis"][$PreviousAxis]); }
}
/* Define if a serie should be draw with ticks */
function setSerieTicks($Serie,$Width=0)
{ if ( isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["Ticks"] = $Width; } }
/* Define if a serie should be draw with a special weight */
function setSerieWeight($Serie,$Weight=0)
{ if ( isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["Weight"] = $Weight; } }
/* Set the color of one serie */
function setPalette($Serie,$Format=NULL)
{
$R = isset($Format["R"]) ? $Format["R"] : 0;
$G = isset($Format["G"]) ? $Format["G"] : 0;
$B = isset($Format["B"]) ? $Format["B"] : 0;
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
if ( isset($this->Data["Series"][$Serie]) )
{
$OldR = $this->Data["Series"][$Serie]["Color"]["R"]; $OldG = $this->Data["Series"][$Serie]["Color"]["G"]; $OldB = $this->Data["Series"][$Serie]["Color"]["B"];
$this->Data["Series"][$Serie]["Color"]["R"] = $R;
$this->Data["Series"][$Serie]["Color"]["G"] = $G;
$this->Data["Series"][$Serie]["Color"]["B"] = $B;
$this->Data["Series"][$Serie]["Color"]["Alpha"] = $Alpha;
/* Do reverse processing on the internal palette array */
foreach ($this->Palette as $Key => $Value)
{ if ($Value["R"] == $OldR && $Value["G"] == $OldG && $Value["B"] == $OldB) { $this->Palette[$Key]["R"] = $R; $this->Palette[$Key]["G"] = $G; $this->Palette[$Key]["B"] = $B; $this->Palette[$Key]["Alpha"] = $Alpha;} }
}
}
/* Load a palette file */
function loadPalette($FileName,$Overwrite=FALSE)
{
if ( !file_exists($FileName) ) { return(-1); }
if ( $Overwrite ) { $this->Palette = ""; }
$fileHandle = @fopen($FileName, "r");
if (!$fileHandle) { return(-1); }
while (!feof($fileHandle))
{
$buffer = fgets($fileHandle, 4096);
if ( preg_match("/,/",$buffer) )
{
list($R,$G,$B,$Alpha) = preg_split("/,/",$buffer);
if ( $this->Palette == "" ) { $ID = 0; } else { $ID = count($this->Palette); }
$this->Palette[$ID] = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
}
}
fclose($fileHandle);
/* Apply changes to current series */
$ID = 0;
if ( isset($this->Data["Series"]))
{
foreach($this->Data["Series"] as $Key => $Value)
{
if ( !isset($this->Palette[$ID]) )
$this->Data["Series"][$Key]["Color"] = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>0);
else
$this->Data["Series"][$Key]["Color"] = $this->Palette[$ID];
$ID++;
}
}
}
/* Initialise a given scatter serie */
function initScatterSerie($ID)
{
if ( isset($this->Data["ScatterSeries"][$ID]) ) { return(0); }
$this->Data["ScatterSeries"][$ID]["Description"] = "Scatter ".$ID;
$this->Data["ScatterSeries"][$ID]["isDrawable"] = TRUE;
$this->Data["ScatterSeries"][$ID]["Picture"] = NULL;
$this->Data["ScatterSeries"][$ID]["Ticks"] = 0;
$this->Data["ScatterSeries"][$ID]["Weight"] = 0;
if ( isset($this->Palette[$ID]) )
$this->Data["ScatterSeries"][$ID]["Color"] = $this->Palette[$ID];
else
{
$this->Data["ScatterSeries"][$ID]["Color"]["R"] = rand(0,255);
$this->Data["ScatterSeries"][$ID]["Color"]["G"] = rand(0,255);
$this->Data["ScatterSeries"][$ID]["Color"]["B"] = rand(0,255);
$this->Data["ScatterSeries"][$ID]["Color"]["Alpha"] = 100;
}
}
/* Initialise a given serie */
function initialise($Serie)
{
if ( isset($this->Data["Series"]) ) { $ID = count($this->Data["Series"]); } else { $ID = 0; }
$this->Data["Series"][$Serie]["Description"] = $Serie;
$this->Data["Series"][$Serie]["isDrawable"] = TRUE;
$this->Data["Series"][$Serie]["Picture"] = NULL;
$this->Data["Series"][$Serie]["Max"] = NULL;
$this->Data["Series"][$Serie]["Min"] = NULL;
$this->Data["Series"][$Serie]["Axis"] = 0;
$this->Data["Series"][$Serie]["Ticks"] = 0;
$this->Data["Series"][$Serie]["Weight"] = 0;
if ( isset($this->Palette[$ID]) )
$this->Data["Series"][$Serie]["Color"] = $this->Palette[$ID];
else
{
$this->Data["Series"][$Serie]["Color"]["R"] = rand(0,255);
$this->Data["Series"][$Serie]["Color"]["G"] = rand(0,255);
$this->Data["Series"][$Serie]["Color"]["B"] = rand(0,255);
$this->Data["Series"][$Serie]["Color"]["Alpha"] = 100;
}
}
function normalize($NormalizationFactor=100,$UnitChange=NULL,$Round=1)
{
$Abscissa = $this->Data["Abscissa"];
$SelectedSeries = "";
$MaxVal = 0;
foreach($this->Data["Axis"] as $AxisID => $Axis)
{
if ( $UnitChange != NULL ) { $this->Data["Axis"][$AxisID]["Unit"] = $UnitChange; }
foreach($this->Data["Series"] as $SerieName => $Serie)
{
if ($Serie["Axis"] == $AxisID && $Serie["isDrawable"] == TRUE && $SerieName != $Abscissa)
{
$SelectedSeries[$SerieName] = $SerieName;
if ( count($Serie["Data"] ) > $MaxVal ) { $MaxVal = count($Serie["Data"]); }
}
}
}
for($i=0;$i<=$MaxVal-1;$i++)
{
$Factor = 0;
foreach ($SelectedSeries as $Key => $SerieName )
{
$Value = $this->Data["Series"][$SerieName]["Data"][$i];
if ( $Value != VOID )
$Factor = $Factor + abs($Value);
}
if ( $Factor != 0 )
{
$Factor = $NormalizationFactor / $Factor;
foreach ($SelectedSeries as $Key => $SerieName )
{
$Value = $this->Data["Series"][$SerieName]["Data"][$i];
if ( $Value != VOID && $Factor != $NormalizationFactor )
$this->Data["Series"][$SerieName]["Data"][$i] = round(abs($Value)*$Factor,$Round);
elseif ( $Value == VOID || $Value == 0 )
$this->Data["Series"][$SerieName]["Data"][$i] = VOID;
elseif ( $Factor == $NormalizationFactor )
$this->Data["Series"][$SerieName]["Data"][$i] = $NormalizationFactor;
}
}
}
foreach ($SelectedSeries as $Key => $SerieName )
{
$this->Data["Series"][$SerieName]["Max"] = max($this->stripVOID($this->Data["Series"][$SerieName]["Data"]));
$this->Data["Series"][$SerieName]["Min"] = min($this->stripVOID($this->Data["Series"][$SerieName]["Data"]));
}
}
/* Load data from a CSV (or similar) data source */
function importFromCSV($FileName,$Options="")
{
$Delimiter = isset($Options["Delimiter"]) ? $Options["Delimiter"] : ",";
$GotHeader = isset($Options["GotHeader"]) ? $Options["GotHeader"] : FALSE;
$SkipColumns = isset($Options["SkipColumns"]) ? $Options["SkipColumns"] : array(-1);
$DefaultSerieName = isset($Options["DefaultSerieName"]) ? $Options["DefaultSerieName"] : "Serie";
$Handle = @fopen($FileName,"r");
if ($Handle)
{
$HeaderParsed = FALSE; $SerieNames = "";
while (!feof($Handle))
{
$Buffer = fgets($Handle, 4096);
$Buffer = str_replace(chr(10),"",$Buffer);
$Buffer = str_replace(chr(13),"",$Buffer);
$Values = preg_split("/".$Delimiter."/",$Buffer);
if ( $Buffer != "" )
{
if ( $GotHeader && !$HeaderParsed )
{
foreach($Values as $Key => $Name) { if ( !in_array($Key,$SkipColumns) ) { $SerieNames[$Key] = $Name; } }
$HeaderParsed = TRUE;
}
else
{
if ($SerieNames == "" ) { foreach($Values as $Key => $Name) { if ( !in_array($Key,$SkipColumns) ) { $SerieNames[$Key] = $DefaultSerieName.$Key; } } }
foreach($Values as $Key => $Value) { if ( !in_array($Key,$SkipColumns) ) { $this->addPoints($Value,$SerieNames[$Key]); } }
}
}
}
fclose($Handle);
}
}
/* Return the data & configuration of the series */
function getData()
{ return($this->Data); }
/* Return the palette of the series */
function getPalette()
{ return($this->Palette); }
/* Called by the scaling algorithm to save the config */
function saveAxisConfig($Axis) { $this->Data["Axis"]=$Axis; }
/* Called by the scaling algorithm to save the orientation of the scale */
function saveOrientation($Orientation) { $this->Data["Orientation"]=$Orientation; }
/* Class string wrapper */
function __toString()
{ return("pData object."); }
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,243 @@
<?php
/*
pDraw - pChart core class
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
/* The GD extension is mandatory */
if (!extension_loaded('gd') && !extension_loaded('gd2'))
{
echo "GD extension must be loaded. \r\n";
exit();
}
class pImage extends pDraw
{
/* Image settings, size, quality, .. */
var $XSize = NULL; // Width of the picture
var $YSize = NULL; // Height of the picture
var $Picture = NULL; // GD picture object
var $Antialias = TRUE; // Turn antialias on or off
var $AntialiasQuality = 0; // Quality of the antialiasing implementation (0-1)
var $Mask = ""; // Already drawn pixels mask (Filled circle implementation)
var $TransparentBackground = FALSE; // Just to know if we need to flush the alpha channels when rendering
/* Graph area settings */
var $GraphAreaX1 = NULL; // Graph area X origin
var $GraphAreaY1 = NULL; // Graph area Y origin
var $GraphAreaX2 = NULL; // Graph area bottom right X position
var $GraphAreaY2 = NULL; // Graph area bottom right Y position
/* Scale settings */
var $ScaleMinDivHeight = 20; // Minimum height for scame divs
/* Font properties */
var $FontName = "fonts/GeosansLight.ttf"; // Default font file
var $FontSize = 12; // Default font size
var $FontBox = NULL; // Return the bounding box of the last written string
var $FontColorR = 0; // Default color settings
var $FontColorG = 0; // Default color settings
var $FontColorB = 0; // Default color settings
var $FontColorA = 100; // Default transparency
/* Shadow properties */
var $Shadow = TRUE; // Turn shadows on or off
var $ShadowX = NULL; // X Offset of the shadow
var $ShadowY = NULL; // Y Offset of the shadow
var $ShadowR = NULL; // R component of the shadow
var $ShadowG = NULL; // G component of the shadow
var $ShadowB = NULL; // B component of the shadow
var $Shadowa = NULL; // Alpha level of the shadow
/* Data Set */
var $DataSet = NULL; // Attached dataset
/* Class constructor */
function pImage($XSize,$YSize,$DataSet=NULL,$TransparentBackground=FALSE)
{
$this->TransparentBackground = $TransparentBackground;
if ( $DataSet != NULL ) { $this->DataSet = $DataSet; }
$this->XSize = $XSize;
$this->YSize = $YSize;
$this->Picture = imagecreatetruecolor($XSize,$YSize);
if ( $this->TransparentBackground )
{
imagealphablending($this->Picture,FALSE);
imagefilledrectangle($this->Picture, 0,0,$XSize, $YSize, imagecolorallocatealpha($this->Picture, 255, 255, 255, 127));
imagealphablending($this->Picture,TRUE);
imagesavealpha($this->Picture,true);
}
else
{
$C_White = $this->AllocateColor($this->Picture,255,255,255);
imagefilledrectangle($this->Picture,0,0,$XSize,$YSize,$C_White);
}
}
/* Enable / Disable and set shadow properties */
function setShadow($Enabled=TRUE,$Format="")
{
$X = isset($Format["X"]) ? $Format["X"] : 2;
$Y = isset($Format["Y"]) ? $Format["Y"] : 2;
$R = isset($Format["R"]) ? $Format["R"] : 0;
$G = isset($Format["G"]) ? $Format["G"] : 0;
$B = isset($Format["B"]) ? $Format["B"] : 0;
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 10;
$this->Shadow = $Enabled;
$this->ShadowX = $X;
$this->ShadowY = $Y;
$this->ShadowR = $R;
$this->ShadowG = $G;
$this->ShadowB = $B;
$this->Shadowa = $Alpha;
}
/* Set the graph area position */
function setGraphArea($X1,$Y1,$X2,$Y2)
{
if ( $X2 < $X1 || $X1 == $X2 || $Y2 < $Y1 || $Y1 == $Y2 ) { return(-1); }
$this->GraphAreaX1 = $X1; $this->DataSet->Data["GraphArea"]["X1"] = $X1;
$this->GraphAreaY1 = $Y1; $this->DataSet->Data["GraphArea"]["Y1"] = $Y1;
$this->GraphAreaX2 = $X2; $this->DataSet->Data["GraphArea"]["X2"] = $X2;
$this->GraphAreaY2 = $Y2; $this->DataSet->Data["GraphArea"]["Y2"] = $Y2;
}
/* Return the width of the picture */
function getWidth()
{ return($this->XSize); }
/* Return the heigth of the picture */
function getHeight()
{ return($this->YSize); }
/* Render the picture to a file */
function render($FileName)
{
if ( $this->TransparentBackground ) { imagealphablending($this->Picture,false); imagesavealpha($this->Picture,true); }
imagepng($this->Picture,$FileName);
}
/* Render the picture to a web browser stream */
function stroke()
{
if ( $this->TransparentBackground ) { imagealphablending($this->Picture,false); imagesavealpha($this->Picture,true); }
header('Content-type: image/png');
imagepng($this->Picture);
}
/* Automatic output method based on the calling interface */
function autoOutput($FileName="output.png")
{
if (php_sapi_name() == "cli")
$this->Render($FileName);
else
$this->Stroke();
}
/* Return the length between two points */
function getLength($X1,$Y1,$X2,$Y2)
{ return(sqrt(pow(max($X1,$X2)-min($X1,$X2),2)+pow(max($Y1,$Y2)-min($Y1,$Y2),2))); }
/* Return the orientation of a line */
function getAngle($X1,$Y1,$X2,$Y2)
{
$Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1;$Angle = rad2deg(atan2($Opposite,$Adjacent));
if ($Angle > 0) { return($Angle); } else { return(360-abs($Angle)); }
}
/* Return the surrounding box of text area */
function getTextBox_deprecated($X,$Y,$FontName,$FontSize,$Angle,$Text)
{
$Size = imagettfbbox($FontSize,$Angle,$FontName,$Text);
$Width = $this->getLength($Size[0],$Size[1],$Size[2],$Size[3])+1;
$Height = $this->getLength($Size[2],$Size[3],$Size[4],$Size[5])+1;
$RealPos[0]["X"] = $X; $RealPos[0]["Y"] = $Y;
$RealPos[1]["X"] = cos((360-$Angle)*PI/180)*$Width + $RealPos[0]["X"]; $RealPos[1]["Y"] = sin((360-$Angle)*PI/180)*$Width + $RealPos[0]["Y"];
$RealPos[2]["X"] = cos((270-$Angle)*PI/180)*$Height + $RealPos[1]["X"]; $RealPos[2]["Y"] = sin((270-$Angle)*PI/180)*$Height + $RealPos[1]["Y"];
$RealPos[3]["X"] = cos((180-$Angle)*PI/180)*$Width + $RealPos[2]["X"]; $RealPos[3]["Y"] = sin((180-$Angle)*PI/180)*$Width + $RealPos[2]["Y"];
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["X"] = $RealPos[0]["X"]; $RealPos[TEXT_ALIGN_BOTTOMLEFT]["Y"] = $RealPos[0]["Y"];
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["X"] = $RealPos[1]["X"]; $RealPos[TEXT_ALIGN_BOTTOMRIGHT]["Y"] = $RealPos[1]["Y"];
return($RealPos);
}
/* Return the surrounding box of text area */
function getTextBox($X,$Y,$FontName,$FontSize,$Angle,$Text)
{
$coords = imagettfbbox($FontSize, 0, $FontName, $Text);
$a = deg2rad($Angle); $ca = cos($a); $sa = sin($a); $RealPos = array();
for($i = 0; $i < 7; $i += 2)
{
$RealPos[$i/2]["X"] = $X + round($coords[$i] * $ca + $coords[$i+1] * $sa);
$RealPos[$i/2]["Y"] = $Y + round($coords[$i+1] * $ca - $coords[$i] * $sa);
}
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["X"] = $RealPos[0]["X"]; $RealPos[TEXT_ALIGN_BOTTOMLEFT]["Y"] = $RealPos[0]["Y"];
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["X"] = $RealPos[1]["X"]; $RealPos[TEXT_ALIGN_BOTTOMRIGHT]["Y"] = $RealPos[1]["Y"];
$RealPos[TEXT_ALIGN_TOPLEFT]["X"] = $RealPos[3]["X"]; $RealPos[TEXT_ALIGN_TOPLEFT]["Y"] = $RealPos[3]["Y"];
$RealPos[TEXT_ALIGN_TOPRIGHT]["X"] = $RealPos[2]["X"]; $RealPos[TEXT_ALIGN_TOPRIGHT]["Y"] = $RealPos[2]["Y"];
$RealPos[TEXT_ALIGN_BOTTOMMIDDLE]["X"] = ($RealPos[1]["X"]-$RealPos[0]["X"])/2+$RealPos[0]["X"]; $RealPos[TEXT_ALIGN_BOTTOMMIDDLE]["Y"] = ($RealPos[0]["Y"]-$RealPos[1]["Y"])/2+$RealPos[1]["Y"];
$RealPos[TEXT_ALIGN_TOPMIDDLE]["X"] = ($RealPos[2]["X"]-$RealPos[3]["X"])/2+$RealPos[3]["X"]; $RealPos[TEXT_ALIGN_TOPMIDDLE]["Y"] = ($RealPos[3]["Y"]-$RealPos[2]["Y"])/2+$RealPos[2]["Y"];
$RealPos[TEXT_ALIGN_MIDDLELEFT]["X"] = ($RealPos[0]["X"]-$RealPos[3]["X"])/2+$RealPos[3]["X"]; $RealPos[TEXT_ALIGN_MIDDLELEFT]["Y"] = ($RealPos[0]["Y"]-$RealPos[3]["Y"])/2+$RealPos[3]["Y"];
$RealPos[TEXT_ALIGN_MIDDLERIGHT]["X"] = ($RealPos[1]["X"]-$RealPos[2]["X"])/2+$RealPos[2]["X"]; $RealPos[TEXT_ALIGN_MIDDLERIGHT]["Y"] = ($RealPos[1]["Y"]-$RealPos[2]["Y"])/2+$RealPos[2]["Y"];
$RealPos[TEXT_ALIGN_MIDDLEMIDDLE]["X"] = ($RealPos[1]["X"]-$RealPos[3]["X"])/2+$RealPos[3]["X"]; $RealPos[TEXT_ALIGN_MIDDLEMIDDLE]["Y"] = ($RealPos[0]["Y"]-$RealPos[2]["Y"])/2+$RealPos[2]["Y"];
return($RealPos);
}
/* Set current font properties */
function setFontProperties($Format="")
{
$R = isset($Format["R"]) ? $Format["R"] : -1;
$G = isset($Format["G"]) ? $Format["G"] : -1;
$B = isset($Format["B"]) ? $Format["B"] : -1;
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
$FontName = isset($Format["FontName"]) ? $Format["FontName"] : NULL;
$FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : NULL;
if ( $R != -1) { $this->FontColorR = $R; }
if ( $G != -1) { $this->FontColorG = $G; }
if ( $B != -1) { $this->FontColorB = $B; }
if ( $Alpha != NULL) { $this->FontColorA = $Alpha; }
if ( $FontName != NULL )
$this->FontName = $FontName;
if ( $FontSize != NULL )
$this->FontSize = $FontSize;
}
/* Returns the 1st decimal values (used to correct AA bugs) */
function getFirstDecimal($Value)
{
$Values = preg_split("/\./",$Value);
if ( isset($Values[1]) ) { return(substr($Values[1],0,1)); } else { return(0); }
}
/* Attach a dataset to your pChart Object */
function setDataSet(&$DataSet)
{ $this->DataSet = $DataSet; }
/* Print attached dataset contents to STDOUT */
function printDataSet()
{ print_r($this->DataSet); }
}
?>

View File

@ -0,0 +1,715 @@
<?php
/*
pPie - class to draw pie charts
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
/* Class return codes */
define("PIE_NO_ABSCISSA" , 140001);
define("PIE_NO_DATASERIE" , 140002);
define("PIE_SUMISNULL" , 140003);
define("PIE_RENDERED" , 140000);
define("PIE_LABEL_COLOR_AUTO" , 140010);
define("PIE_LABEL_COLOR_MANUAL", 140011);
define("PIE_VALUE_NATURAL" , 140020);
define("PIE_VALUE_PERCENTAGE" , 140021);
/* pPie class definition */
class pPie
{
var $pChartObject;
var $pDataObject;
/* Class creator */
function pPie($Object,$pDataObject)
{
/* Cache the pChart object reference */
$this->pChartObject = $Object;
/* Cache the pData object reference */
$this->pDataObject = $pDataObject;
}
/* Draw a pie chart */
function draw2DPie($X,$Y,$Format="")
{
/* Rendering layout */
$Radius = isset($Format["Radius"]) ? $Format["Radius"] : 60;
$DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0;
$DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0;
$SecondPass = isset($Format["SecondPass"]) ? $Format["SecondPass"] : TRUE;
$Border = isset($Format["Border"]) ? $Format["Border"] : FALSE;
$BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
$BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
$BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
$Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE;
$DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE;
$LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL;
$LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0;
$LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0;
$LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0;
$LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100;
/* Data Processing */
$Data = $this->pDataObject->getData();
$Palette = $this->pDataObject->getPalette();
/* Do we have an abscissa serie defined? */
if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); }
/* Try to find the data serie */
$DataSerie = "";
foreach ($Data["Series"] as $SerieName => $SerieData)
{ if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } }
/* Do we have data to compute? */
if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); }
/* Compute the pie sum */
$SerieSum = $this->pDataObject->getSum($DataSerie);
/* Do we have data to draw? */
if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); }
/* Dump the real number of data to draw */
$Values = "";
foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value)
{ if ($Value != 0) { $Values[] = $Value; } }
/* Compute the wasted angular space between series */
if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; }
/* Compute the scale */
$ScaleFactor = (360 - $WastedAngular) / $SerieSum;
$RestoreShadow = $this->pChartObject->Shadow;
if ( $this->pChartObject->Shadow )
{
$this->pChartObject->Shadow = FALSE;
$ShadowFormat = $Format; $ShadowFormat["Shadow"] = TRUE;
$this->draw2DPie($X+$this->pChartObject->ShadowX,$Y+$this->pChartObject->ShadowY,$ShadowFormat);
}
/* Draw the polygon pie elements */
$Step = 360 / (2 * PI * $Radius);
$Offset = 0; $ID = 0;
foreach($Values as $Key => $Value)
{
if ( $Shadow )
$Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa);
else
$Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);
if ( !$SecondPass && !$Shadow )
{
if ( !$Border )
$Settings["Surrounding"] = 10;
else
{ $Settings["BorderR"] = $BorderR; $Settings["BorderG"] = $BorderG; $Settings["BorderB"] = $BorderB; }
}
$Plots = "";
$EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; }
$Angle = ($EndAngle - $Offset)/2 + $Offset;
if ($DataGapAngle == 0)
{ $X0 = $X; $Y0 = $Y; }
else
{
$X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X;
$Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius + $Y;
}
$Plots[] = $X0; $Plots[] = $Y0;
for($i=$Offset;$i<=$EndAngle;$i=$i+$Step)
{
$Xc = cos(($i-90)*PI/180) * $Radius + $X;
$Yc = sin(($i-90)*PI/180) * $Radius + $Y;
if ( $SecondPass && ( $i<90 )) { $Yc++; }
if ( $SecondPass && ( $i>180 && $i<270 )) { $Xc++; }
if ( $SecondPass && ( $i>=270 )) { $Xc++; $Yc++; }
$Plots[] = $Xc; $Plots[] = $Yc;
}
$this->pChartObject->drawPolygon($Plots,$Settings);
if ( $DrawLabels && !$Shadow && !$SecondPass )
{
if ( $LabelColor == PIE_LABEL_COLOR_AUTO )
{ $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);}
else
{ $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); }
$Angle = ($EndAngle - $Offset)/2 + $Offset;
$Xc = cos(($Angle-90)*PI/180) * $Radius + $X;
$Yc = sin(($Angle-90)*PI/180) * $Radius + $Y;
$Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key];
$Settings["Angle"] = 360-$Angle;
$Settings["Length"] = 25;
$Settings["Size"] = 8;
$this->pChartObject->drawArrowLabel($Xc,$Yc," ".$Label." ",$Settings);
}
$Offset = $i + $DataGapAngle; $ID++;
}
/* Second pass to smooth the angles */
if ( $SecondPass )
{
$Step = 360 / (2 * PI * $Radius);
$Offset = 0; $ID = 0;
foreach($Values as $Key => $Value)
{
$FirstPoint = TRUE;
if ( $Shadow )
$Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa);
else
{
if ( $Border )
$Settings = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB);
else
$Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);
}
$EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; }
if ($DataGapAngle == 0)
{ $X0 = $X; $Y0 = $Y; }
else
{
$Angle = ($EndAngle - $Offset)/2 + $Offset;
$X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X;
$Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius + $Y;
}
$Plots[] = $X0; $Plots[] = $Y0;
for($i=$Offset;$i<=$EndAngle;$i=$i+$Step)
{
$Xc = cos(($i-90)*PI/180) * $Radius + $X;
$Yc = sin(($i-90)*PI/180) * $Radius + $Y;
if ( $FirstPoint ) { $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); } { $FirstPoint = FALSE; }
$this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings);
}
$this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings);
if ( $DrawLabels && !$Shadow )
{
if ( $LabelColor == PIE_LABEL_COLOR_AUTO )
{ $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);}
else
{ $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); }
$Angle = ($EndAngle - $Offset)/2 + $Offset;
$Xc = cos(($Angle-90)*PI/180) * $Radius + $X;
$Yc = sin(($Angle-90)*PI/180) * $Radius + $Y;
$Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key];
$Settings["Angle"] = 360-$Angle;
$Settings["Length"] = 25;
$Settings["Size"] = 8;
$this->pChartObject->drawArrowLabel($Xc,$Yc," ".$Label." ",$Settings);
}
$Offset = $i + $DataGapAngle; $ID++;
}
}
$this->pChartObject->Shadow = $RestoreShadow;
return(PIE_RENDERED);
}
/* Draw a 3D pie chart */
function draw3DPie($X,$Y,$Format="")
{
/* Rendering layout */
$Radius = isset($Format["Radius"]) ? $Format["Radius"] : 80;
$SkewFactor = isset($Format["SkewFactor"]) ? $Format["SkewFactor"] : .5;
$SliceHeight = isset($Format["SliceHeight"]) ? $Format["SliceHeight"] : 20;
$DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0;
$DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0;
$SecondPass = isset($Format["SecondPass"]) ? $Format["SecondPass"] : TRUE;
$Border = isset($Format["Border"]) ? $Format["Border"] : FALSE;
$Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE;
$DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE;
$LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL;
$LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0;
$LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0;
$LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0;
$LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100;
$WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : PIE_VALUE_PERCENTAGE;
$ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : "";
$ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255;
$ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255;
$ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255;
$ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100;
/* Error correction for overlaying rounded corners */
if ( $SkewFactor < .5 ) { $SkewFactor = .5; }
/* Data Processing */
$Data = $this->pDataObject->getData();
$Palette = $this->pDataObject->getPalette();
/* Do we have an abscissa serie defined? */
if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); }
/* Try to find the data serie */
$DataSerie = "";
foreach ($Data["Series"] as $SerieName => $SerieData)
{ if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } }
/* Do we have data to compute? */
if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); }
/* Compute the pie sum */
$SerieSum = $this->pDataObject->getSum($DataSerie);
/* Do we have data to draw? */
if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); }
/* Dump the real number of data to draw */
$Values = "";
foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value)
{ if ($Value != 0) { $Values[] = $Value; } }
/* Compute the wasted angular space between series */
if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; }
/* Compute the scale */
$ScaleFactor = (360 - $WastedAngular) / $SerieSum;
$RestoreShadow = $this->pChartObject->Shadow;
if ( $this->pChartObject->Shadow ) { $this->pChartObject->Shadow = FALSE; }
/* Draw the polygon pie elements */
$Step = 360 / (2 * PI * $Radius);
$Offset = 360; $ID = count($Values)-1;
$Values = array_reverse($Values);
$Slice = 0; $Slices = ""; $SliceColors = ""; $Visible = ""; $SliceAngle = "";
foreach($Values as $Key => $Value)
{
$Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);
$SliceColors[$Slice] = $Settings;
$StartAngle = $Offset;
$EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; }
if ( $StartAngle > 180 ) { $Visible[$Slice]["Start"] = TRUE; } else { $Visible[$Slice]["Start"] = TRUE; }
if ( $EndAngle < 180 ) { $Visible[$Slice]["End"] = FALSE; } else { $Visible[$Slice]["End"] = TRUE; }
if ($DataGapAngle == 0)
{ $X0 = $X; $Y0 = $Y; }
else
{
$Angle = ($EndAngle - $Offset)/2 + $Offset;
$X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X;
$Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius*$SkewFactor + $Y;
}
$Slices[$Slice][] = $X0; $Slices[$Slice][] = $Y0; $SliceAngle[$Slice][] = 0;
for($i=$Offset;$i>=$EndAngle;$i=$i-$Step)
{
$Xc = cos(($i-90)*PI/180) * $Radius + $X;
$Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y;
if ( ($SecondPass || $RestoreShadow ) && ( $i<90 )) { $Yc++; }
if ( ($SecondPass || $RestoreShadow ) && ( $i>90 && $i<180 )) { $Xc++; }
if ( ($SecondPass || $RestoreShadow ) && ( $i>180 && $i<270 )) { $Xc++; }
if ( ($SecondPass || $RestoreShadow ) && ( $i>=270 )) { $Xc++; $Yc++; }
$Slices[$Slice][] = $Xc; $Slices[$Slice][] = $Yc; $SliceAngle[$Slice][] = $i;
}
$Offset = $i - $DataGapAngle; $ID--; $Slice++;
}
/* Draw the bottom shadow if needed */
if ( $RestoreShadow && ($this->pChartObject->ShadowX != 0 || $this->pChartObject->ShadowY !=0 ))
{
foreach($Slices as $SliceID => $Plots)
{
$ShadowPie = "";
for($i=0;$i<count($Plots);$i=$i+2)
{ $ShadowPie[] = $Plots[$i]+$this->pChartObject->ShadowX; $ShadowPie[] = $Plots[$i+1]+$this->pChartObject->ShadowY; }
$Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa,"NoBorder"=>TRUE);
$this->pChartObject->drawPolygon($ShadowPie,$Settings);
}
$Step = 360 / (2 * PI * $Radius);
$Offset = 360;
foreach($Values as $Key => $Value)
{
$EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; }
for($i=$Offset;$i>=$EndAngle;$i=$i-$Step)
{
$Xc = cos(($i-90)*PI/180) * $Radius + $X + $this->pChartObject->ShadowX;
$Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y + $this->pChartObject->ShadowY;
$this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings);
}
$Offset = $i - $DataGapAngle; $ID--;
}
}
/* Draw the bottom pie splice */
foreach($Slices as $SliceID => $Plots)
{
$Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE;
$this->pChartObject->drawPolygon($Plots,$Settings);
if ( $SecondPass )
{
$Settings = $SliceColors[$SliceID];
if ( $Border )
{ $Settings["R"]+= 30; $Settings["G"]+= 30; $Settings["B"]+= 30;; }
$Angle = $SliceAngle[$SliceID][1];
$Xc = cos(($Angle-90)*PI/180) * $Radius + $X;
$Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y;
$this->pChartObject->drawLine($Plots[0],$Plots[1],$Xc,$Yc,$Settings);
$Angle = $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1];
$Xc = cos(($Angle-90)*PI/180) * $Radius + $X;
$Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y;
$this->pChartObject->drawLine($Plots[0],$Plots[1],$Xc,$Yc,$Settings);
}
}
/* Draw the two vertical edges */
$Slices = array_reverse($Slices);
$SliceColors = array_reverse($SliceColors);
foreach($Slices as $SliceID => $Plots)
{
$Settings = $SliceColors[$SliceID];
$Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE;
if ( $Visible[$SliceID]["Start"] )
{
$this->pChartObject->drawLine($Plots[2],$Plots[3],$Plots[2],$Plots[3]- $SliceHeight,array("R"=>255,"G"=>255,"B"=>255));
$Border = "";
$Border[] = $Plots[0]; $Border[] = $Plots[1]; $Border[] = $Plots[0]; $Border[] = $Plots[1] - $SliceHeight;
$Border[] = $Plots[2]; $Border[] = $Plots[3] - $SliceHeight; $Border[] = $Plots[2]; $Border[] = $Plots[3];
$this->pChartObject->drawPolygon($Border,$Settings);
}
}
$Slices = array_reverse($Slices);
$SliceColors = array_reverse($SliceColors);
foreach($Slices as $SliceID => $Plots)
{
$Settings = $SliceColors[$SliceID];
$Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE;
if ( $Visible[$SliceID]["End"] )
{
$this->pChartObject->drawLine($Plots[count($Plots)-2],$Plots[count($Plots)-1],$Plots[count($Plots)-2],$Plots[count($Plots)-1]- $SliceHeight,array("R"=>255,"G"=>255,"B"=>255));
$Border = "";
$Border[] = $Plots[0]; $Border[] = $Plots[1]; $Border[] = $Plots[0]; $Border[] = $Plots[1] - $SliceHeight;
$Border[] = $Plots[count($Plots)-2]; $Border[] = $Plots[count($Plots)-1] - $SliceHeight; $Border[] = $Plots[count($Plots)-2]; $Border[] = $Plots[count($Plots)-1];
$this->pChartObject->drawPolygon($Border,$Settings);
}
}
/* Draw the rounded edges */
foreach($Slices as $SliceID => $Plots)
{
$Settings = $SliceColors[$SliceID];
$Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE;
for ($j=2;$j<count($Plots)-2;$j=$j+2)
{
$Angle = $SliceAngle[$SliceID][$j/2];
if ( $Angle < 270 && $Angle > 90 )
{
$Border = "";
$Border[] = $Plots[$j]; $Border[] = $Plots[$j+1];
$Border[] = $Plots[$j+2]; $Border[] = $Plots[$j+3];
$Border[] = $Plots[$j+2]; $Border[] = $Plots[$j+3] - $SliceHeight;
$Border[] = $Plots[$j]; $Border[] = $Plots[$j+1] - $SliceHeight;
$this->pChartObject->drawPolygon($Border,$Settings);
}
}
if ( $SecondPass )
{
$Settings = $SliceColors[$SliceID];
if ( $Border )
{ $Settings["R"]+= 30; $Settings["G"]+= 30; $Settings["B"]+= 30; }
$Angle = $SliceAngle[$SliceID][1];
if ( $Angle < 270 && $Angle > 90 )
{
$Xc = cos(($Angle-90)*PI/180) * $Radius + $X;
$Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y;
$this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings);
}
$Angle = $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1];
if ( $Angle < 270 && $Angle > 90 )
{
$Xc = cos(($Angle-90)*PI/180) * $Radius + $X;
$Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y;
$this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings);
}
if ( $SliceAngle[$SliceID][1] > 270 && $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1] < 270 )
{
$Xc = cos((270-90)*PI/180) * $Radius + $X;
$Yc = sin((270-90)*PI/180) * $Radius*$SkewFactor + $Y;
$this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings);
}
if ( $SliceAngle[$SliceID][1] > 90 && $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1] < 90 )
{
$Xc = cos((0)*PI/180) * $Radius + $X;
$Yc = sin((0)*PI/180) * $Radius*$SkewFactor + $Y;
$this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings);
}
}
}
/* Draw the top splice */
foreach($Slices as $SliceID => $Plots)
{
$Settings = $SliceColors[$SliceID];
$Settings["R"]+= 20; $Settings["G"]+= 20; $Settings["B"]+= 20;
$Top = "";
for($j=0;$j<count($Plots);$j=$j+2) { $Top[] = $Plots[$j]; $Top[] = $Plots[$j+1]- $SliceHeight; }
$this->pChartObject->drawPolygon($Top,$Settings);
}
/* Second pass to smooth the angles */
if ( $SecondPass )
{
$Step = 360 / (2 * PI * $Radius);
$Offset = 360; $ID = count($Values)-1;
foreach($Values as $Key => $Value)
{
$FirstPoint = TRUE;
if ( $Shadow )
$Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa);
else
{
if ( $Border )
{ $Settings = array("R"=>$Palette[$ID]["R"]+30,"G"=>$Palette[$ID]["G"]+30,"B"=>$Palette[$ID]["B"]+30,"Alpha"=>$Palette[$ID]["Alpha"]); }
else
$Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);
}
$EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; }
if ($DataGapAngle == 0)
{ $X0 = $X; $Y0 = $Y- $SliceHeight; }
else
{
$Angle = ($EndAngle - $Offset)/2 + $Offset;
$X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X;
$Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius*$SkewFactor + $Y - $SliceHeight;
}
$Plots[] = $X0; $Plots[] = $Y0;
for($i=$Offset;$i>=$EndAngle;$i=$i-$Step)
{
$Xc = cos(($i-90)*PI/180) * $Radius + $X;
$Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y - $SliceHeight;
if ( $FirstPoint ) { $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); } { $FirstPoint = FALSE; }
$this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings);
if ($i < 270 && $i > 90 ) { $this->pChartObject->drawAntialiasPixel($Xc,$Yc+$SliceHeight,$Settings); }
}
$this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings);
$Offset = $i - $DataGapAngle; $ID--;
}
}
if ( $WriteValues != NULL )
{
$Step = 360 / (2 * PI * $Radius);
$Offset = 360; $ID = count($Values)-1;
$Settings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB,"Alpha"=>$ValueAlpha);
foreach($Values as $Key => $Value)
{
$EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; }
$Angle = ($EndAngle - $Offset)/2 + $Offset;
$Xc = cos(($Angle-90)*PI/180) * ($Radius)/2 + $X;
$Yc = sin(($Angle-90)*PI/180) * ($Radius*$SkewFactor)/2 + $Y - $SliceHeight;
if ( $WriteValues == PIE_VALUE_PERCENTAGE )
$Display = round(( 100 / $SerieSum ) * $Value)."%";
elseif ( $WriteValues == PIE_VALUE_NATURAL )
$Display = $Value.$ValueSuffix;
$this->pChartObject->drawText($Xc,$Yc,$Display,$Settings);
$Offset = $EndAngle - $DataGapAngle; $ID--;
}
}
if ( $DrawLabels )
{
$Step = 360 / (2 * PI * $Radius);
$Offset = 360; $ID = count($Values)-1;
foreach($Values as $Key => $Value)
{
if ( $LabelColor == PIE_LABEL_COLOR_AUTO )
{ $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);}
else
{ $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); }
$EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; }
$Angle = ($EndAngle - $Offset)/2 + $Offset;
$Xc = cos(($Angle-90)*PI/180) * $Radius + $X;
$Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y - $SliceHeight;
if ( isset($Data["Series"][$Data["Abscissa"]]["Data"][$ID]) )
{
$Label = $Data["Series"][$Data["Abscissa"]]["Data"][$ID];
$Settings["Angle"] = 360-$Angle;
$Settings["Length"] = 25;
$Settings["Size"] = 8;
$this->pChartObject->drawArrowLabel($Xc,$Yc," ".$Label." ",$Settings);
}
$Offset = $EndAngle - $DataGapAngle; $ID--;
}
}
$this->pChartObject->Shadow = $RestoreShadow;
return(PIE_RENDERED);
}
/* Draw the legend of pie chart */
function drawPieLegend($X,$Y,$Format="")
{
$FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
$FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
$FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->pChartObject->FontColorR;
$FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->pChartObject->FontColorG;
$FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->pChartObject->FontColorB;
$BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
$Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
$R = isset($Format["R"]) ? $Format["R"] : 200;
$G = isset($Format["G"]) ? $Format["G"] : 200;
$B = isset($Format["B"]) ? $Format["B"] : 200;
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
$BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
$BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
$BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
$Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
$Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
$Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
$YStep = max($this->pChartObject->FontSize,$BoxSize) + 5;
$XStep = $BoxSize + 5;
/* Data Processing */
$Data = $this->pDataObject->getData();
$Palette = $this->pDataObject->getPalette();
/* Do we have an abscissa serie defined? */
if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); }
$Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value)
{
$BoxArray = $this->pChartObject->getTextBox($vX+$BoxSize+4,$vY+$BoxSize/2,$FontName,$FontSize,0,$Value);
if ( $Mode == LEGEND_VERTICAL )
{
if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$BoxSize/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$BoxSize/2; }
if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$BoxSize/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$BoxSize/2; }
$vY=$vY+$YStep;
}
elseif ( $Mode == LEGEND_HORIZONTAL )
{
if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$BoxSize/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$BoxSize/2; }
if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$BoxSize/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$BoxSize/2; }
$vX=$Boundaries["R"]+$XStep;
}
}
$vY=$vY-$YStep; $vX=$vX-$XStep;
$TopOffset = $Y - $Boundaries["T"];
if ( $Boundaries["B"]-($vY+$BoxSize) < $TopOffset ) { $Boundaries["B"] = $vY+$BoxSize+$TopOffset; }
if ( $Style == LEGEND_ROUND )
$this->pChartObject->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
elseif ( $Style == LEGEND_BOX )
$this->pChartObject->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
$RestoreShadow = $this->pChartObject->Shadow; $this->pChartObject->Shadow = FALSE;
foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value)
{
$R = $Palette[$Key]["R"]; $G = $Palette[$Key]["G"]; $B = $Palette[$Key]["B"];
$this->pChartObject->drawFilledRectangle($X+1,$Y+1,$X+$BoxSize+1,$Y+$BoxSize+1,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
$this->pChartObject->drawFilledRectangle($X,$Y,$X+$BoxSize,$Y+$BoxSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
if ( $Mode == LEGEND_VERTICAL )
{
$this->pChartObject->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
$Y=$Y+$YStep;
}
elseif ( $Mode == LEGEND_HORIZONTAL )
{
$BoxArray = $this->pChartObject->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
$X=$BoxArray[1]["X"]+2+$XStep;
}
}
$this->Shadow = $RestoreShadow;
}
/* Set the color of the specified slice */
function setSliceColor($SliceID,$Format="")
{
$R = isset($Format["R"]) ? $Format["R"] : 0;
$G = isset($Format["G"]) ? $Format["G"] : 0;
$B = isset($Format["B"]) ? $Format["B"] : 0;
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
$this->pDataObject->Palette[$SliceID]["R"] = $R;
$this->pDataObject->Palette[$SliceID]["G"] = $G;
$this->pDataObject->Palette[$SliceID]["B"] = $B;
$this->pDataObject->Palette[$SliceID]["Alpha"] = $Alpha;
}
}
?>

View File

@ -0,0 +1,598 @@
<?php
/*
pRadar - class to draw radar charts
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
define("SEGMENT_HEIGHT_AUTO" , 690001);
define("RADAR_LAYOUT_STAR" , 690011);
define("RADAR_LAYOUT_CIRCLE" , 690012);
define("RADAR_LABELS_ROTATED" , 690021);
define("RADAR_LABELS_HORIZONTAL" , 690022);
/* pRadar class definition */
class pRadar
{
var $pChartObject;
/* Class creator */
function pRadar()
{ }
/* Draw a radar chart */
function drawRadar($Object,$Values,$Format="")
{
$this->pChartObject = $Object;
$AxisR = isset($Format["AxisR"]) ? $Format["AxisR"] : 60;
$AxisG = isset($Format["AxisG"]) ? $Format["AxisG"] : 60;
$AxisB = isset($Format["AxisB"]) ? $Format["AxisB"] : 60;
$AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 50;
$AxisRotation = isset($Format["AxisRotation"]) ? $Format["AxisRotation"] : 0;
$DrawTicks = isset($Format["DrawTicks"]) ? $Format["DrawTicks"] : TRUE;
$TicksLength = isset($Format["TicksLength"]) ? $Format["TicksLength"] : 2;
$DrawAxisValues = isset($Format["DrawAxisValues"]) ? $Format["DrawAxisValues"] : TRUE;
$AxisBoxRounded = isset($Format["AxisBoxRounded"]) ? $Format["AxisBoxRounded"] : TRUE;
$AxisFontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
$AxisFontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
$DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE;
$BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255;
$BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255;
$BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255;
$BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 50;
$BackgroundGradient= isset($Format["BackgroundGradient"]) ? $Format["BackgroundGradient"] : NULL;
$Layout = isset($Format["Layout"]) ? $Format["Layout"] : RADAR_LAYOUT_STAR;
$SegmentHeight = isset($Format["SegmentHeight"]) ? $Format["SegmentHeight"] : SEGMENT_HEIGHT_AUTO;
$Segments = isset($Format["Segments"]) ? $Format["Segments"] : 4;
$WriteLabels = isset($Format["WriteLabels"]) ? $Format["WriteLabels"] : TRUE;
$SkipLabels = isset($Format["SkipLabels"]) ? $Format["SkipLabels"] : 1;
$LabelMiddle = isset($Format["LabelMiddle"]) ? $Format["LabelMiddle"] : FALSE;
$LabelsBackground = isset($Format["LabelsBackground"]) ? $Format["LabelsBackground"] : TRUE;
$LabelsBGR = isset($Format["LabelsBGR"]) ? $Format["LabelsBGR"] : 255;
$LabelsBGG = isset($Format["LabelsBGR"]) ? $Format["LabelsBGG"] : 255;
$LabelsBGB = isset($Format["LabelsBGR"]) ? $Format["LabelsBGB"] : 255;
$LabelsBGAlpha = isset($Format["LabelsBGAlpha"]) ? $Format["LabelsBGAlpha"] : 50;
$LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : RADAR_LABELS_ROTATED;
$LabelPadding = isset($Format["LabelPadding"]) ? $Format["LabelPadding"] : 4;
$DrawPoints = isset($Format["DrawPoints"]) ? $Format["DrawPoints"] : TRUE;
$PointRadius = isset($Format["PointRadius"]) ? $Format["PointRadius"] : 4;
$PointSurrounding = isset($Format["PointRadius"]) ? $Format["PointRadius"] : -30;
$DrawLines = isset($Format["DrawLines"]) ? $Format["DrawLines"] : TRUE;
$LineLoopStart = isset($Format["LineLoopStart"]) ? $Format["LineLoopStart"] : TRUE;
$DrawPoly = isset($Format["DrawPoly"]) ? $Format["DrawPoly"] : FALSE;
$PolyAlpha = isset($Format["PolyAlpha"]) ? $Format["PolyAlpha"] : 40;
$FontSize = $Object->FontSize;
$X1 = $Object->GraphAreaX1;
$Y1 = $Object->GraphAreaY1;
$X2 = $Object->GraphAreaX2;
$Y2 = $Object->GraphAreaY2;
// if ( $AxisBoxRounded ) { $DrawAxisValues = TRUE; }
/* Cancel default tick length if ticks not enabled */
if ( $DrawTicks == FALSE ) { $TicksLength = 0; }
/* Data Processing */
$Data = $Values->getData();
$Palette = $Values->getPalette();
/* Catch the number of required axis */
$LabelSerie = $Data["Abscissa"];
if ( $LabelSerie != "" )
{ $Points = count($Data["Series"][$LabelSerie]["Data"]); }
else
{
$Points = 0;
foreach($Data["Series"] as $SerieName => $DataArray)
{ if ( count($DataArray["Data"]) > $Points ) { $Points = count($DataArray["Data"]); } }
}
/* Draw the axis */
$CenterX = ($X2-$X1)/2 + $X1;
$CenterY = ($Y2-$Y1)/2 + $Y1;
$EdgeHeight = min(($X2-$X1)/2,($Y2-$Y1)/2);
if ( $WriteLabels )
$EdgeHeight = $EdgeHeight - $FontSize - $LabelPadding - $TicksLength;
/* Determine the scale if set to automatic */
if ( $SegmentHeight == SEGMENT_HEIGHT_AUTO)
{
$Max = 0;
foreach($Data["Series"] as $SerieName => $DataArray)
{
if ( $SerieName != $LabelSerie )
{
if ( max($DataArray["Data"]) > $Max ) { $Max = max($DataArray["Data"]); }
}
}
$MaxSegments = $EdgeHeight/20;
$Scale = $Object->computeScale(0,$Max,$MaxSegments,array(1,2,5));
$Segments = $Scale["Rows"];
$SegmentHeight = $Scale["RowHeight"];
}
if ( $LabelMiddle && $SkipLabels == 1 )
{ $Axisoffset = (360/$Points)/2; }
elseif ( $LabelMiddle && $SkipLabels != 1 )
{ $Axisoffset = (360/($Points/$SkipLabels))/2; }
elseif ( !$LabelMiddle )
{ $Axisoffset = 0; }
/* Background processing */
if ( $DrawBackground )
{
$RestoreShadow = $Object->Shadow;
$Object->Shadow = FALSE;
if ($BackgroundGradient == NULL)
{
if ( $Layout == RADAR_LAYOUT_STAR )
{
$Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha);
$PointArray = "";
for($i=0;$i<=360;$i=$i+(360/$Points))
{
$PointArray[] = cos(deg2rad($i+$AxisRotation)) * $EdgeHeight + $CenterX;
$PointArray[] = sin(deg2rad($i+$AxisRotation)) * $EdgeHeight + $CenterY;
}
$Object->drawPolygon($PointArray,$Color);
}
elseif ( $Layout == RADAR_LAYOUT_CIRCLE )
{
$Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha);
$Object->drawFilledCircle($CenterX,$CenterY,$EdgeHeight,$Color);
}
}
else
{
$GradientROffset = ($BackgroundGradient["EndR"] - $BackgroundGradient["StartR"]) / $Segments;
$GradientGOffset = ($BackgroundGradient["EndG"] - $BackgroundGradient["StartG"]) / $Segments;
$GradientBOffset = ($BackgroundGradient["EndB"] - $BackgroundGradient["StartB"]) / $Segments;
$GradientAlphaOffset = ($BackgroundGradient["EndAlpha"] - $BackgroundGradient["StartAlpha"]) / $Segments;
if ( $Layout == RADAR_LAYOUT_STAR )
{
for($j=$Segments;$j>=1;$j--)
{
$Color = array("R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j,"G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j,"B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j,"Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j);
$PointArray = "";
for($i=0;$i<=360;$i=$i+(360/$Points))
{
$PointArray[] = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
$PointArray[] = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
}
$Object->drawPolygon($PointArray,$Color);
}
}
elseif ( $Layout == RADAR_LAYOUT_CIRCLE )
{
for($j=$Segments;$j>=1;$j--)
{
$Color = array("R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j,"G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j,"B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j,"Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j);
$Object->drawFilledCircle($CenterX,$CenterY,($EdgeHeight/$Segments)*$j,$Color);
}
}
}
$Object->Shadow = $RestoreShadow;
}
/* Axis to axis lines */
$Color = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha);
$ColorDotted = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha*.8, "Ticks"=>2);
if ( $Layout == RADAR_LAYOUT_STAR )
{
for($j=1;$j<=$Segments;$j++)
{
for($i=0;$i<360;$i=$i+(360/$Points))
{
$EdgeX1 = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
$EdgeY1 = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
$EdgeX2 = cos(deg2rad($i+$AxisRotation+(360/$Points))) * ($EdgeHeight/$Segments)*$j + $CenterX;
$EdgeY2 = sin(deg2rad($i+$AxisRotation+(360/$Points))) * ($EdgeHeight/$Segments)*$j + $CenterY;
$Object->drawLine($EdgeX1,$EdgeY1,$EdgeX2,$EdgeY2,$Color);
}
}
}
elseif ( $Layout == RADAR_LAYOUT_CIRCLE )
{
for($j=1;$j<=$Segments;$j++)
{
$Radius = ($EdgeHeight/$Segments)*$j;
$Object->drawCircle($CenterX,$CenterY,$Radius,$Radius,$Color);
}
}
if ( $DrawAxisValues )
{
if ( $LabelsBackground )
$Options = array("DrawBox"=>TRUE, "Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"BoxR"=>$LabelsBGR,"BoxG"=>$LabelsBGG,"BoxB"=>$LabelsBGB,"BoxAlpha"=>$LabelsBGAlpha);
else
$Options = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE);
if ( $AxisBoxRounded ) { $Options["BoxRounded"] = TRUE; }
$Options["FontName"] = $AxisFontName;
$Options["FontSize"] = $AxisFontSize;
$Angle = 360 / ($Points*2);
for($j=1;$j<=$Segments;$j++)
{
$Label = $j * $SegmentHeight;
if ( $Layout == RADAR_LAYOUT_CIRCLE )
{
$EdgeX1 = cos(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
$EdgeY1 = sin(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
}
elseif ( $Layout == RADAR_LAYOUT_STAR )
{
$EdgeX1 = cos(deg2rad($AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
$EdgeY1 = sin(deg2rad($AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
$EdgeX2 = cos(deg2rad((360 / $Points) + $AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
$EdgeY2 = sin(deg2rad((360 / $Points) + $AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
$EdgeX1 = ($EdgeX2 - $EdgeX1)/2 + $EdgeX1;
$EdgeY1 = ($EdgeY2 - $EdgeY1)/2 + $EdgeY1;
}
$Object->drawText($EdgeX1,$EdgeY1,$Label,$Options);
}
}
/* Axis lines */
$ID = 0;
for($i=0;$i<360;$i=$i+(360/$Points))
{
$EdgeX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterX;
$EdgeY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterY;
if ($ID % $SkipLabels == 0)
{ $Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$Color); }
else
{ $Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$ColorDotted); }
if ( $WriteLabels )
{
$LabelX = cos(deg2rad($i+$AxisRotation+$Axisoffset)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterX;
$LabelY = sin(deg2rad($i+$AxisRotation+$Axisoffset)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterY;
if ( $LabelSerie != "" )
{ $Label = isset($Data["Series"][$LabelSerie]["Data"][$ID]) ? $Data["Series"][$LabelSerie]["Data"][$ID] : ""; }
else
$Label = $ID;
if ($ID % $SkipLabels == 0)
{
if ( $LabelPos == RADAR_LABELS_ROTATED )
$Object->drawText($LabelX,$LabelY,$Label,array("Angle"=>(360-($i+$AxisRotation+$Axisoffset))-90,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
else
{
if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMLEFT)); }
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPLEFT)); }
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT)); }
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); }
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPRIGHT)); }
if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPMIDDLE)); }
}
}
}
$ID++;
}
/* Compute the plots position */
$ID = 0; $Plot = "";
foreach($Data["Series"] as $SerieName => $Data)
{
if ( $SerieName != $LabelSerie )
{
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
foreach($Data["Data"] as $Key => $Value)
{
$Angle = (360/$Points) * $Key;
$Length = ($EdgeHeight/($Segments*$SegmentHeight))*$Value;
$X = cos(deg2rad($Angle+$AxisRotation)) * $Length + $CenterX;
$Y = sin(deg2rad($Angle+$AxisRotation)) * $Length + $CenterY;
$Plot[$ID][] = array($X,$Y);
}
$ID++;
}
}
/* Draw all that stuff! */
foreach($Plot as $ID => $Points)
{
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
/* Draw the polygons */
if ( $DrawPoly )
{
if ($PolyAlpha != NULL)
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$PolyAlpha,"Surrounding"=>$PointSurrounding);
$PointsArray = "";
for($i=0; $i<count($Points);$i++)
{ $PointsArray[] = $Points[$i][0]; $PointsArray[] = $Points[$i][1]; }
$Object->drawPolygon($PointsArray,$Color);
}
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
/* Draw the lines & points */
for($i=0; $i<count($Points);$i++)
{
if ( $DrawLines && $i < count($Points)-1)
$Object->drawLine($Points[$i][0],$Points[$i][1],$Points[$i+1][0],$Points[$i+1][1],$Color);
if ( $DrawPoints )
$Object->drawFilledCircle($Points[$i][0],$Points[$i][1],$PointRadius,$Color);
}
/* Loop to the starting points if asked */
if ( $LineLoopStart && $DrawLines )
$Object->drawLine($Points[$i-1][0],$Points[$i-1][1],$Points[0][0],$Points[0][1],$Color);
}
}
/* Draw a radar chart */
function drawPolar($Object,$Values,$Format="")
{
$this->pChartObject = $Object;
$AxisR = isset($Format["AxisR"]) ? $Format["AxisR"] : 60;
$AxisG = isset($Format["AxisG"]) ? $Format["AxisG"] : 60;
$AxisB = isset($Format["AxisB"]) ? $Format["AxisB"] : 60;
$AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 50;
$AxisRotation = isset($Format["AxisRotation"]) ? $Format["AxisRotation"] : -90;
$DrawTicks = isset($Format["DrawTicks"]) ? $Format["DrawTicks"] : TRUE;
$TicksLength = isset($Format["TicksLength"]) ? $Format["TicksLength"] : 2;
$DrawAxisValues = isset($Format["DrawAxisValues"]) ? $Format["DrawAxisValues"] : TRUE;
$AxisBoxRounded = isset($Format["AxisBoxRounded"]) ? $Format["AxisBoxRounded"] : TRUE;
$AxisFontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
$AxisFontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
$DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE;
$BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255;
$BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255;
$BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255;
$BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 50;
$BackgroundGradient= isset($Format["BackgroundGradient"]) ? $Format["BackgroundGradient"] : NULL;
$AxisSteps = isset($Format["AxisSteps"]) ? $Format["AxisSteps"] : 20;
$SegmentHeight = isset($Format["SegmentHeight"]) ? $Format["SegmentHeight"] : SEGMENT_HEIGHT_AUTO;
$Segments = isset($Format["Segments"]) ? $Format["Segments"] : 4;
$WriteLabels = isset($Format["WriteLabels"]) ? $Format["WriteLabels"] : TRUE;
$LabelsBackground = isset($Format["LabelsBackground"]) ? $Format["LabelsBackground"] : TRUE;
$LabelsBGR = isset($Format["LabelsBGR"]) ? $Format["LabelsBGR"] : 255;
$LabelsBGG = isset($Format["LabelsBGR"]) ? $Format["LabelsBGG"] : 255;
$LabelsBGB = isset($Format["LabelsBGR"]) ? $Format["LabelsBGB"] : 255;
$LabelsBGAlpha = isset($Format["LabelsBGAlpha"]) ? $Format["LabelsBGAlpha"] : 50;
$LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : RADAR_LABELS_ROTATED;
$LabelPadding = isset($Format["LabelPadding"]) ? $Format["LabelPadding"] : 4;
$DrawPoints = isset($Format["DrawPoints"]) ? $Format["DrawPoints"] : TRUE;
$PointRadius = isset($Format["PointRadius"]) ? $Format["PointRadius"] : 4;
$PointSurrounding = isset($Format["PointRadius"]) ? $Format["PointRadius"] : -30;
$DrawLines = isset($Format["DrawLines"]) ? $Format["DrawLines"] : TRUE;
$LineLoopStart = isset($Format["LineLoopStart"]) ? $Format["LineLoopStart"] : FALSE;
$DrawPoly = isset($Format["DrawPoly"]) ? $Format["DrawPoly"] : FALSE;
$PolyAlpha = isset($Format["PolyAlpha"]) ? $Format["PolyAlpha"] : NULL;
$FontSize = $Object->FontSize;
$X1 = $Object->GraphAreaX1;
$Y1 = $Object->GraphAreaY1;
$X2 = $Object->GraphAreaX2;
$Y2 = $Object->GraphAreaY2;
if ( $AxisBoxRounded ) { $DrawAxisValues = TRUE; }
/* Cancel default tick length if ticks not enabled */
if ( $DrawTicks == FALSE ) { $TicksLength = 0; }
/* Data Processing */
$Data = $Values->getData();
$Palette = $Values->getPalette();
/* Catch the number of required axis */
$LabelSerie = $Data["Abscissa"];
if ( $LabelSerie != "" )
{ $Points = count($Data["Series"][$LabelSerie]["Data"]); }
else
{
$Points = 0;
foreach($Data["Series"] as $SerieName => $DataArray)
{ if ( count($DataArray["Data"]) > $Points ) { $Points = count($DataArray["Data"]); } }
}
/* Draw the axis */
$CenterX = ($X2-$X1)/2 + $X1;
$CenterY = ($Y2-$Y1)/2 + $Y1;
$EdgeHeight = min(($X2-$X1)/2,($Y2-$Y1)/2);
if ( $WriteLabels )
$EdgeHeight = $EdgeHeight - $FontSize - $LabelPadding - $TicksLength;
/* Determine the scale if set to automatic */
if ( $SegmentHeight == SEGMENT_HEIGHT_AUTO)
{
$Max = 0;
foreach($Data["Series"] as $SerieName => $DataArray)
{
if ( $SerieName != $LabelSerie )
{
if ( max($DataArray["Data"]) > $Max ) { $Max = max($DataArray["Data"]); }
}
}
$MaxSegments = $EdgeHeight/20;
$Scale = $Object->computeScale(0,$Max,$MaxSegments,array(1,2,5));
$Segments = $Scale["Rows"];
$SegmentHeight = $Scale["RowHeight"];
}
/* Background processing */
if ( $DrawBackground )
{
$RestoreShadow = $Object->Shadow;
$Object->Shadow = FALSE;
if ($BackgroundGradient == NULL)
{
$Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha);
$Object->drawFilledCircle($CenterX,$CenterY,$EdgeHeight,$Color);
}
else
{
$GradientROffset = ($BackgroundGradient["EndR"] - $BackgroundGradient["StartR"]) / $Segments;
$GradientGOffset = ($BackgroundGradient["EndG"] - $BackgroundGradient["StartG"]) / $Segments;
$GradientBOffset = ($BackgroundGradient["EndB"] - $BackgroundGradient["StartB"]) / $Segments;
$GradientAlphaOffset = ($BackgroundGradient["EndAlpha"] - $BackgroundGradient["StartAlpha"]) / $Segments;
for($j=$Segments;$j>=1;$j--)
{
$Color = array("R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j,"G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j,"B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j,"Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j);
$Object->drawFilledCircle($CenterX,$CenterY,($EdgeHeight/$Segments)*$j,$Color);
}
}
$Object->Shadow = $RestoreShadow;
}
/* Axis to axis lines */
$Color = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha);
for($j=1;$j<=$Segments;$j++)
{
$Radius = ($EdgeHeight/$Segments)*$j;
$Object->drawCircle($CenterX,$CenterY,$Radius,$Radius,$Color);
}
if ( $DrawAxisValues )
{
if ( $LabelsBackground )
$Options = array("DrawBox"=>TRUE, "Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"BoxR"=>$LabelsBGR,"BoxG"=>$LabelsBGG,"BoxB"=>$LabelsBGB,"BoxAlpha"=>$LabelsBGAlpha);
else
$Options = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE);
if ( $AxisBoxRounded ) { $Options["BoxRounded"] = TRUE; }
$Options["FontName"] = $AxisFontName;
$Options["FontSize"] = $AxisFontSize;
$Angle = 360 / ($Points*2);
for($j=1;$j<=$Segments;$j++)
{
$EdgeX1 = cos(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
$EdgeY1 = sin(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
$Label = $j*$SegmentHeight;
$Object->drawText($EdgeX1,$EdgeY1,$Label,$Options);
}
}
/* Axis lines */
$ID = 0;
for($i=0;$i<=359;$i=$i+$AxisSteps)
{
$EdgeX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterX;
$EdgeY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterY;
$Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$Color);
if ( $WriteLabels )
{
$LabelX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterX;
$LabelY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterY;
$Label = $i."°";
if ( $LabelPos == RADAR_LABELS_ROTATED )
$Object->drawText($LabelX,$LabelY,$Label,array("Angle"=>(360-$i),"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
else
{
if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMLEFT)); }
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPLEFT)); }
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT)); }
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); }
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPRIGHT)); }
if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPMIDDLE)); }
}
}
$ID++;
}
/* Compute the plots position */
$ID = 0; $Plot = "";
foreach($Data["Series"] as $SerieName => $DataSet)
{
if ( $SerieName != $LabelSerie )
{
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
foreach($DataSet["Data"] as $Key => $Value)
{
$Angle = $Data["Series"][$LabelSerie]["Data"][$Key];
$Length = ($EdgeHeight/($Segments*$SegmentHeight))*$Value;
$X = cos(deg2rad($Angle+$AxisRotation)) * $Length + $CenterX;
$Y = sin(deg2rad($Angle+$AxisRotation)) * $Length + $CenterY;
$Plot[$ID][] = array($X,$Y);
}
$ID++;
}
}
/* Draw all that stuff! */
foreach($Plot as $ID => $Points)
{
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
/* Draw the polygons */
if ( $DrawPoly )
{
if ($PolyAlpha != NULL)
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$PolyAlpha,"Surrounding"=>$PointSurrounding);
$PointsArray = "";
for($i=0; $i<count($Points);$i++)
{ $PointsArray[] = $Points[$i][0]; $PointsArray[] = $Points[$i][1]; }
$Object->drawPolygon($PointsArray,$Color);
}
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
/* Draw the lines & points */
for($i=0; $i<count($Points);$i++)
{
if ( $DrawLines && $i < count($Points)-1)
$Object->drawLine($Points[$i][0],$Points[$i][1],$Points[$i+1][0],$Points[$i+1][1],$Color);
if ( $DrawPoints )
$Object->drawFilledCircle($Points[$i][0],$Points[$i][1],$PointRadius,$Color);
}
/* Loop to the starting points if asked */
if ( $LineLoopStart && $DrawLines )
$Object->drawLine($Points[$i-1][0],$Points[$i-1][1],$Points[0][0],$Points[0][1],$Color);
}
}
}
?>

View File

@ -0,0 +1,828 @@
<?php
/*
pScatter - class to draw scatter charts
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
define("SCATTER_MISSING_X_SERIE" , 190001);
define("SCATTER_MISSING_Y_SERIE" , 190002);
/* pScatter class definition */
class pScatter
{
var $pChartObject;
var $pDataObject;
/* Class creator */
function pScatter($pChartObject,$pDataObject)
{
$this->pChartObject = $pChartObject;
$this->pDataObject = $pDataObject;
}
/* Prepare the scale */
function drawScatterScale($Format="")
{
$Mode = isset($Format["Mode"]) ? $Format["Mode"] : SCALE_MODE_FLOATING;
$Floating = isset($Format["Floating"]) ? $Format["Floating"] : FALSE;
$XLabelsRotation = isset($Format["XLabelsRotation"]) ? $Format["XLabelsRotation"] : 90;
$MinDivHeight = isset($Format["MinDivHeight"]) ? $Format["MinDivHeight"] : 20;
$Factors = isset($Format["Factors"]) ? $Format["Factors"] : array(1,2,5);
$ManualScale = isset($Format["ManualScale"]) ? $Format["ManualScale"] : array("0"=>array("Min"=>-100,"Max"=>100));
$XMargin = isset($Format["XMargin"]) ? $Format["XMargin"] : 0;
$YMargin = isset($Format["YMargin"]) ? $Format["YMargin"] : 0;
$ScaleSpacing = isset($Format["ScaleSpacing"]) ? $Format["ScaleSpacing"] : 15;
$InnerTickWidth = isset($Format["InnerTickWidth"]) ? $Format["InnerTickWidth"] : 2;
$OuterTickWidth = isset($Format["OuterTickWidth"]) ? $Format["OuterTickWidth"] : 2;
$DrawXLines = isset($Format["DrawXLines"]) ? $Format["DrawXLines"] : ALL;
$DrawYLines = isset($Format["DrawYLines"]) ? $Format["DrawYLines"] : ALL;
$GridTicks = isset($Format["GridTicks"]) ? $Format["GridTicks"] : 4;
$GridR = isset($Format["GridR"]) ? $Format["GridR"] : 255;
$GridG = isset($Format["GridG"]) ? $Format["GridG"] : 255;
$GridB = isset($Format["GridB"]) ? $Format["GridB"] : 255;
$GridAlpha = isset($Format["GridAlpha"]) ? $Format["GridAlpha"] : 40;
$AxisRo = isset($Format["AxisR"]) ? $Format["AxisR"] : 0;
$AxisGo = isset($Format["AxisG"]) ? $Format["AxisG"] : 0;
$AxisBo = isset($Format["AxisB"]) ? $Format["AxisB"] : 0;
$AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 100;
$TickRo = isset($Format["TickR"]) ? $Format["TickR"] : 0;
$TickGo = isset($Format["TickG"]) ? $Format["TickG"] : 0;
$TickBo = isset($Format["TickB"]) ? $Format["TickB"] : 0;
$TickAlpha = isset($Format["TickAlpha"]) ? $Format["TickAlpha"] : 100;
$DrawSubTicks = isset($Format["DrawSubTicks"]) ? $Format["DrawSubTicks"] : FALSE;
$InnerSubTickWidth = isset($Format["InnerSubTickWidth"]) ? $Format["InnerSubTickWidth"] : 0;
$OuterSubTickWidth = isset($Format["OuterSubTickWidth"]) ? $Format["OuterSubTickWidth"] : 2;
$SubTickR = isset($Format["SubTickR"]) ? $Format["SubTickR"] : 255;
$SubTickG = isset($Format["SubTickG"]) ? $Format["SubTickG"] : 0;
$SubTickB = isset($Format["SubTickB"]) ? $Format["SubTickB"] : 0;
$SubTickAlpha = isset($Format["SubTickAlpha"]) ? $Format["SubTickAlpha"] : 100;
$XReleasePercent = isset($Format["XReleasePercent"]) ? $Format["XReleasePercent"] : 1;
$DrawArrows = isset($Format["DrawArrows"]) ? $Format["DrawArrows"] : FALSE;
$ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 8;
$CycleBackground = isset($Format["CycleBackground"]) ? $Format["CycleBackground"] : FALSE;
$BackgroundR1 = isset($Format["BackgroundR1"]) ? $Format["BackgroundR1"] : 255;
$BackgroundG1 = isset($Format["BackgroundG1"]) ? $Format["BackgroundG1"] : 255;
$BackgroundB1 = isset($Format["BackgroundB1"]) ? $Format["BackgroundB1"] : 255;
$BackgroundAlpha1 = isset($Format["BackgroundAlpha1"]) ? $Format["BackgroundAlpha1"] : 10;
$BackgroundR2 = isset($Format["BackgroundR2"]) ? $Format["BackgroundR2"] : 230;
$BackgroundG2 = isset($Format["BackgroundG2"]) ? $Format["BackgroundG2"] : 230;
$BackgroundB2 = isset($Format["BackgroundB2"]) ? $Format["BackgroundB2"] : 230;
$BackgroundAlpha2 = isset($Format["BackgroundAlpha2"]) ? $Format["BackgroundAlpha2"] : 10;
/* Check if we have at least both one X and Y axis */
$GotXAxis = FALSE; $GotYAxis = FALSE;
foreach($this->pDataObject->Data["Axis"] as $AxisID => $AxisSettings)
{
if ( $AxisSettings["Identity"] == AXIS_X ) { $GotXAxis = TRUE; }
if ( $AxisSettings["Identity"] == AXIS_Y ) { $GotYAxis = TRUE; }
}
if ( !$GotXAxis ) { return(SCATTER_MISSING_X_SERIE); }
if ( !$GotYAxis ) { return(SCATTER_MISSING_Y_SERIE); }
/* Skip a NOTICE event in case of an empty array */
if ( $DrawYLines == NONE ) { $DrawYLines = array("zarma"=>"31"); }
$Data = $this->pDataObject->getData();
foreach($Data["Axis"] as $AxisID => $AxisSettings)
{
if ( $AxisSettings["Identity"] == AXIS_X)
{ $Width = $this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1 - $XMargin*2; }
else
{ $Width = $this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1 - $YMargin*2; }
$AxisMin = ABSOLUTE_MAX; $AxisMax = OUT_OF_SIGHT;
if ( $Mode == SCALE_MODE_FLOATING )
{
foreach($Data["Series"] as $SerieID => $SerieParameter)
{
if ( $SerieParameter["Axis"] == $AxisID && $Data["Series"][$SerieID]["isDrawable"] )
{
$AxisMax = max($AxisMax,$Data["Series"][$SerieID]["Max"]);
$AxisMin = min($AxisMin,$Data["Series"][$SerieID]["Min"]);
}
}
$AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
$Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
}
elseif ( $Mode == SCALE_MODE_MANUAL )
{
if ( isset($ManualScale[$AxisID]["Min"]) && isset($ManualScale[$AxisID]["Max"]) )
{
$Data["Axis"][$AxisID]["Min"] = $ManualScale[$AxisID]["Min"];
$Data["Axis"][$AxisID]["Max"] = $ManualScale[$AxisID]["Max"];
}
else
{ echo "Manual scale boundaries not set."; exit(); }
}
/* Full manual scale */
if ( isset($ManualScale[$AxisID]["Rows"]) && isset($ManualScale[$AxisID]["RowHeight"]) )
$Scale = array("Rows"=>$ManualScale[$AxisID]["Rows"],"RowHeight"=>$ManualScale[$AxisID]["RowHeight"],"XMin"=>$ManualScale[$AxisID]["Min"],"XMax"=>$ManualScale[$AxisID]["Max"]);
else
{
$MaxDivs = floor($Width/$MinDivHeight);
$Scale = $this->pChartObject->computeScale($Data["Axis"][$AxisID]["Min"],$Data["Axis"][$AxisID]["Max"],$MaxDivs,$Factors,$AxisID);
}
$Data["Axis"][$AxisID]["Margin"] = $AxisSettings["Identity"] == AXIS_X ? $XMargin : $YMargin;
$Data["Axis"][$AxisID]["ScaleMin"] = $Scale["XMin"];
$Data["Axis"][$AxisID]["ScaleMax"] = $Scale["XMax"];
$Data["Axis"][$AxisID]["Rows"] = $Scale["Rows"];
$Data["Axis"][$AxisID]["RowHeight"] = $Scale["RowHeight"];
if ( isset($Scale["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = $Scale["Format"]; }
if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
if ( !isset($Data["Axis"][$AxisID]["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = NULL; }
if ( !isset($Data["Axis"][$AxisID]["Unit"]) ) { $Data["Axis"][$AxisID]["Unit"] = NULL; }
}
/* Get the default font color */
$FontColorRo = $this->pChartObject->FontColorR; $FontColorGo = $this->pChartObject->FontColorG; $FontColorBo = $this->pChartObject->FontColorB;
/* Set the original boundaries */
$AxisPos["L"] = $this->pChartObject->GraphAreaX1; $AxisPos["R"] = $this->pChartObject->GraphAreaX2; $AxisPos["T"] = $this->pChartObject->GraphAreaY1; $AxisPos["B"] = $this->pChartObject->GraphAreaY2;
foreach($Data["Axis"] as $AxisID => $AxisSettings)
{
if ( isset($AxisSettings["Color"]) )
{
$AxisR = $AxisSettings["Color"]["R"]; $AxisG = $AxisSettings["Color"]["G"]; $AxisB = $AxisSettings["Color"]["B"];
$TickR = $AxisSettings["Color"]["R"]; $TickG = $AxisSettings["Color"]["G"]; $TickB = $AxisSettings["Color"]["B"];
$this->pChartObject->setFontProperties(array("R"=>$AxisSettings["Color"]["R"],"G"=>$AxisSettings["Color"]["G"],"B"=>$AxisSettings["Color"]["B"]));
}
else
{
$AxisR = $AxisRo; $AxisG = $AxisGo; $AxisB = $AxisBo;
$TickR = $TickRo; $TickG = $TickGo; $TickB = $TickBo;
$this->pChartObject->setFontProperties(array("R"=>$FontColorRo,"G"=>$FontColorGo,"B"=>$FontColorBo));
}
$LastValue = "w00t"; $ID = 1;
if ( $AxisSettings["Identity"] == AXIS_X )
{
if ( $AxisSettings["Position"] == AXIS_POSITION_BOTTOM )
{
if ( $XLabelsRotation == 0 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $LabelOffset = 2; }
if ( $XLabelsRotation > 0 && $XLabelsRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $LabelOffset = 5; }
if ( $XLabelsRotation == 180 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $LabelOffset = 5; }
if ( $XLabelsRotation > 180 && $XLabelsRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $LabelOffset = 2; }
if ( $Floating )
{ $FloatingOffset = $YMargin; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$AxisSettings["Margin"],$AxisPos["B"],$this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
else
{ $FloatingOffset = 0; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1,$AxisPos["B"],$this->pChartObject->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
if ( $DrawArrows ) { $this->pChartObject->drawArrow($this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["B"],$this->pChartObject->GraphAreaX2+($ArrowSize*2),$AxisPos["B"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
$Width = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) - $AxisSettings["Margin"]*2;
$Step = $Width / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MaxBottom = $AxisPos["B"];
$LastX = NULL;
for($i=0;$i<=$AxisSettings["Rows"];$i++)
{
$XPos = $this->pChartObject->GraphAreaX1 + $AxisSettings["Margin"] + $Step*$i;
$YPos = $AxisPos["B"];
$Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
if ( $LastX != NULL && $CycleBackground && ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) )) { $this->pChartObject->drawFilledRectangle($LastX,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,$BGColor); }
if ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) ) { $this->pChartObject->drawLine($XPos,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
$this->pChartObject->drawLine($XPos+$SubTicksSize,$YPos-$InnerSubTickWidth,$XPos+$SubTicksSize,$YPos+$OuterSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
$this->pChartObject->drawLine($XPos,$YPos-$InnerTickWidth,$XPos,$YPos+$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
$Bounds = $this->pChartObject->drawText($XPos,$YPos+$OuterTickWidth+$LabelOffset,$Value,array("Angle"=>$XLabelsRotation,"Align"=>$LabelAlign));
$TxtBottom = $YPos+2+$OuterTickWidth+2+($Bounds[0]["Y"]-$Bounds[2]["Y"]);
$MaxBottom = max($MaxBottom,$TxtBottom);
$LastX = $XPos;
}
if ( isset($AxisSettings["Name"]) )
{
$YPos = $MaxBottom+2;
$XPos = $this->pChartObject->GraphAreaX1+($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1)/2;
$Bounds = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
$MaxBottom = $Bounds[0]["Y"];
$this->pDataObject->Data["GraphArea"]["Y2"] = $MaxBottom + $this->pChartObject->FontSize;
}
$AxisPos["B"] = $MaxBottom + $ScaleSpacing;
}
elseif ( $AxisSettings["Position"] == AXIS_POSITION_TOP )
{
if ( $XLabelsRotation == 0 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $LabelOffset = 2; }
if ( $XLabelsRotation > 0 && $XLabelsRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $LabelOffset = 2; }
if ( $XLabelsRotation == 180 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $LabelOffset = 5; }
if ( $XLabelsRotation > 180 && $SLabelxRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $LabelOffset = 5; }
if ( $Floating )
{ $FloatingOffset = $YMargin; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$AxisSettings["Margin"],$AxisPos["T"],$this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
else
{ $FloatingOffset = 0; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1,$AxisPos["T"],$this->pChartObject->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
if ( $DrawArrows ) { $this->pChartObject->drawArrow($this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["T"],$this->pChartObject->GraphAreaX2+($ArrowSize*2),$AxisPos["T"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
$Width = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) - $AxisSettings["Margin"]*2;
$Step = $Width / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MinTop = $AxisPos["T"];
$LastX = NULL;
for($i=0;$i<=$AxisSettings["Rows"];$i++)
{
$XPos = $this->pChartObject->GraphAreaX1 + $AxisSettings["Margin"] + $Step*$i;
$YPos = $AxisPos["T"];
$Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
if ( $LastX != NULL && $CycleBackground && ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) )) { $this->pChartObject->drawFilledRectangle($LastX,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,$BGColor); }
if ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) ) { $this->pChartObject->drawLine($XPos,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
$this->pChartObject->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
$this->pChartObject->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
$Bounds = $this->pChartObject->drawText($XPos,$YPos-$OuterTickWidth-$LabelOffset,$Value,array("Angle"=>$XLabelsRotation,"Align"=>$LabelAlign));
$TxtBox = $YPos-$OuterTickWidth-4-($Bounds[0]["Y"]-$Bounds[2]["Y"]);
$MinTop = min($MinTop,$TxtBox);
$LastX = $XPos;
}
if ( isset($AxisSettings["Name"]) )
{
$YPos = $MinTop-2;
$XPos = $this->pChartObject->GraphAreaX1+($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1)/2;
$Bounds = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
$MinTop = $Bounds[2]["Y"];
$this->pDataObject->Data["GraphArea"]["Y1"] = $MinTop;
}
$AxisPos["T"] = $MinTop - $ScaleSpacing;
}
}
elseif ( $AxisSettings["Identity"] == AXIS_Y )
{
if ( $AxisSettings["Position"] == AXIS_POSITION_LEFT )
{
if ( $Floating )
{ $FloatingOffset = $XMargin; $this->pChartObject->drawLine($AxisPos["L"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["L"],$this->pChartObject->GraphAreaY2-$AxisSettings["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
else
{ $FloatingOffset = 0; $this->pChartObject->drawLine($AxisPos["L"],$this->pChartObject->GraphAreaY1,$AxisPos["L"],$this->pChartObject->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
if ( $DrawArrows ) { $this->pChartObject->drawArrow($AxisPos["L"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["L"],$this->pChartObject->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
$Height = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) - $AxisSettings["Margin"]*2;
$Step = $Height / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MinLeft = $AxisPos["L"];
$LastY = NULL;
for($i=0;$i<=$AxisSettings["Rows"];$i++)
{
$YPos = $this->pChartObject->GraphAreaY2 - $AxisSettings["Margin"] - $Step*$i;
$XPos = $AxisPos["L"];
$Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->pChartObject->drawFilledRectangle($this->pChartObject->GraphAreaX1+$FloatingOffset,$LastY,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
if ( ($YPos != $this->pChartObject->GraphAreaY1 && $YPos != $this->pChartObject->GraphAreaY2) && ($DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$FloatingOffset,$YPos,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
$this->pChartObject->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
$this->pChartObject->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
$Bounds = $this->pChartObject->drawText($XPos-$OuterTickWidth-2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLERIGHT));
$TxtLeft = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
$MinLeft = min($MinLeft,$TxtLeft);
$LastY = $YPos;
}
if ( isset($AxisSettings["Name"]) )
{
$XPos = $MinLeft-2;
$YPos = $this->pChartObject->GraphAreaY1+($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1)/2;
$Bounds = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
$MinLeft = $Bounds[2]["X"];
$this->pDataObject->Data["GraphArea"]["X1"] = $MinLeft;
}
$AxisPos["L"] = $MinLeft - $ScaleSpacing;
}
elseif ( $AxisSettings["Position"] == AXIS_POSITION_RIGHT )
{
if ( $Floating )
{ $FloatingOffset = $XMargin; $this->pChartObject->drawLine($AxisPos["R"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["R"],$this->pChartObject->GraphAreaY2-$AxisSettings["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
else
{ $FloatingOffset = 0; $this->pChartObject->drawLine($AxisPos["R"],$this->pChartObject->GraphAreaY1,$AxisPos["R"],$this->pChartObject->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
if ( $DrawArrows ) { $this->pChartObject->drawArrow($AxisPos["R"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["R"],$this->pChartObject->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
$Height = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) - $AxisSettings["Margin"]*2;
$Step = $Height / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MaxLeft = $AxisPos["R"];
$LastY = NULL;
for($i=0;$i<=$AxisSettings["Rows"];$i++)
{
$YPos = $this->pChartObject->GraphAreaY2 - $AxisSettings["Margin"] - $Step*$i;
$XPos = $AxisPos["R"];
$Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->pChartObject->drawFilledRectangle($this->pChartObject->GraphAreaX1+$FloatingOffset,$LastY,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
if ( ($YPos != $this->pChartObject->GraphAreaY1 && $YPos != $this->pChartObject->GraphAreaY2) && ($DrawYLines == ALL || in_array($AxisID,$DrawYLines)) ) { $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$FloatingOffset,$YPos,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
$this->pChartObject->drawLine($XPos-$InnerSubTickWidth,$YPos-$SubTicksSize,$XPos+$OuterSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
$this->pChartObject->drawLine($XPos-$InnerTickWidth,$YPos,$XPos+$OuterTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
$Bounds = $this->pChartObject->drawText($XPos+$OuterTickWidth+2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLELEFT));
$TxtLeft = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
$MaxLeft = max($MaxLeft,$TxtLeft);
$LastY = $YPos;
}
if ( isset($AxisSettings["Name"]) )
{
$XPos = $MaxLeft+6;
$YPos = $this->pChartObject->GraphAreaY1+($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1)/2;
$Bounds = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
$MaxLeft = $Bounds[2]["X"];
$this->pDataObject->Data["GraphArea"]["X2"] = $MaxLeft + $this->pChartObject->FontSize;
}
$AxisPos["R"] = $MaxLeft + $ScaleSpacing;
}
}
}
$this->pDataObject->saveAxisConfig($Data["Axis"]);
}
/* Draw a scatter plot chart */
function drawScatterPlotChart($Format=NULL)
{
$PlotSize = isset($Format["PlotSize"]) ? $Format["PlotSize"] : 3;
$PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : FALSE;
$BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 250;
$BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 250;
$BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 250;
$BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 30;
$BorderSize = isset($Format["BorderSize"]) ? $Format["BorderSize"] : 1;
$Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
$Data = $this->pDataObject->getData();
$Palette = $this->pDataObject->getPalette();
$BorderColor = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha);
foreach($Data["ScatterSeries"] as $Key => $Series)
{
$SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
$SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
if ( isset($Series["Picture"]) && $Series["Picture"] != "" )
{ $Picture = $Series["Picture"]; list($PicWidth,$PicHeight,$PicType) = $this->pChartObject->getPicInfo($Picture); }
else
{ $Picture = NULL; }
$PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
$PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
$Color = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
foreach($PosArrayX as $Key => $Value)
{
$X = $Value; $Y = $PosArrayY[$Key];
if ( $X != VOID && $Y != VOID )
{
if ( $Picture == NULL )
{
if ( $PlotBorder ) { $this->pChartObject->drawFilledCircle($X,$Y,$PlotSize+$BorderSize,$BorderColor); }
$this->pChartObject->drawFilledCircle($X,$Y,$PlotSize,$Color);
}
else
{ $this->pChartObject->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
}
}
}
}
/* Draw a scatter line chart */
function drawScatterLineChart($Format=NULL)
{
$Data = $this->pDataObject->getData();
$Palette = $this->pDataObject->getPalette();
/* Parse all the series to draw */
foreach($Data["ScatterSeries"] as $Key => $Series)
{
$SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
$SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
$Ticks = $Series["Ticks"];
$Weight = $Series["Weight"];
$PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
$PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
$Color = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
if ( $Ticks != 0 ) { $Color["Ticks"] = $Ticks; }
if ( $Weight != 0 ) { $Color["Weight"] = $Weight; }
$LastX = VOID; $LastY = VOID;
foreach($PosArrayX as $Key => $Value)
{
$X = $Value; $Y = $PosArrayY[$Key];
if ( $X != VOID && $Y != VOID && $LastX != VOID && $LastY != VOID)
$this->pChartObject->drawLine($LastX,$LastY,$X,$Y,$Color);
$LastX = $X; $LastY = $Y;
}
}
}
/* Draw a scatter spline chart */
function drawScatterSplineChart($Format=NULL)
{
$Data = $this->pDataObject->getData();
$Palette = $this->pDataObject->getPalette();
foreach($Data["ScatterSeries"] as $Key => $Series)
{
$SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
$SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
$Ticks = $Series["Ticks"];
$Weight = $Series["Weight"];
$PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
$PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
$SplineSettings = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
if ( $Ticks != 0 ) { $SplineSettings["Ticks"] = $Ticks; }
if ( $Weight != 0 ) { $SplineSettings["Weight"] = $Weight; }
$LastX = VOID; $LastY = VOID; $WayPoints = ""; $Forces = "";
foreach($PosArrayX as $Key => $Value)
{
$X = $Value; $Y = $PosArrayY[$Key];
$Force = $this->pChartObject->getLength($LastX,$LastY,$X,$Y)/5;
if ( $X != VOID && $Y != VOID )
{ $WayPoints[] = array($X,$Y); $Forces[] = $Force; }
if ( $Y == VOID && $LastY != NULL )
{ $SplineSettings["Forces"] = $Forces; $this->pChartObject->drawSpline($WayPoints,$SplineSettings); $WayPoints = ""; $Forces = "";}
$LastX = $X; $LastY = $Y;
}
$SplineSettings["Forces"] = $Forces;
$this->pChartObject->drawSpline($WayPoints,$SplineSettings);
}
}
/* Return the scaled plot position */
function getPosArray($Values,$AxisID)
{
$Data = $this->pDataObject->getData();
if ( !is_array($Values) ) { $Values = array($Values); }
if ( $Data["Axis"][$AxisID]["Identity"] == AXIS_X )
{
$Height = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) - $Data["Axis"][$AxisID]["Margin"]*2;
$ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
$Step = $Height / $ScaleHeight;
$Result = "";
foreach($Values as $Key => $Value)
{
if ( $Value == VOID )
$Result[] = VOID;
else
$Result[] = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"]));
}
if ( count($Result) == 1 ) { return($Result[0]); } else { return($Result); }
}
else
{
$Height = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) - $Data["Axis"][$AxisID]["Margin"]*2;
$ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
$Step = $Height / $ScaleHeight;
$Result = "";
foreach($Values as $Key => $Value)
{
if ( $Value == VOID )
$Result[] = VOID;
else
$Result[] = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"]));
}
if ( count($Result) == 1 ) { return($Result[0]); } else { return($Result); }
}
}
/* Draw the legend of the active series */
function drawScatterLegend($X,$Y,$Format="")
{
$Family = isset($Format["Family"]) ? $Format["Family"] : LEGEND_FAMILY_BOX;
$FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
$FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
$FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->pChartObject->FontColorR;
$FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->pChartObject->FontColorG;
$FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->pChartObject->FontColorB;
$BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
$BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
$IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
$IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
$XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
$Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
$R = isset($Format["R"]) ? $Format["R"] : 200;
$G = isset($Format["G"]) ? $Format["G"] : 200;
$B = isset($Format["B"]) ? $Format["B"] : 200;
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
$BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
$BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
$BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
$Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
$Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
$Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
$Data = $this->pDataObject->getData();
foreach($Data["ScatterSeries"] as $Key => $Series)
{
if ( $Series["isDrawable"] == TRUE && isset($Series["Picture"]))
{
list($PicWidth,$PicHeight) = $this->pChartObject->getPicInfo($Series["Picture"]);
if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
}
}
$YStep = max($this->pChartObject->FontSize,$IconAreaHeight) + 5;
$XStep = $IconAreaWidth + 5;
$XStep = $XSpacing;
$Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
foreach($Data["ScatterSeries"] as $Key => $Series)
{
if ( $Series["isDrawable"] == TRUE )
{
if ( $Mode == LEGEND_VERTICAL )
{
$BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Series["Description"]);
if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
$Lines = preg_split("/\n/",$Series["Description"]);
$vY = $vY + max($this->pChartObject->FontSize*count($Lines),$IconAreaHeight) + 5;
}
elseif ( $Mode == LEGEND_HORIZONTAL )
{
$Lines = preg_split("/\n/",$Series["Description"]);
$Width = "";
foreach($Lines as $Key => $Value)
{
$BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
$Width[] = $BoxArray[1]["X"];
}
$vX=max($Width)+$XStep;
}
}
}
$vY=$vY-$YStep; $vX=$vX-$XStep;
$TopOffset = $Y - $Boundaries["T"];
if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
if ( $Style == LEGEND_ROUND )
$this->pChartObject->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
elseif ( $Style == LEGEND_BOX )
$this->pChartObject->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
$RestoreShadow = $this->pChartObject->Shadow; $this->Shadow = FALSE;
foreach($Data["ScatterSeries"] as $Key => $Series)
{
if ( $Series["isDrawable"] == TRUE )
{
$R = $Series["Color"]["R"]; $G = $Series["Color"]["G"]; $B = $Series["Color"]["B"];
$Ticks = $Series["Ticks"]; $Weight = $Series["Weight"];
if ( isset($Series["Picture"]) )
{
$Picture = $Series["Picture"];
list($PicWidth,$PicHeight) = $this->pChartObject->getPicInfo($Picture);
$PicX = $X+$IconAreaWidth/2; $PicY = $Y+$IconAreaHeight/2;
$this->pChartObject->drawFromPNG($PicX-$PicWidth/2,$PicY-$PicHeight/2,$Picture);
}
else
{
if ( $Family == LEGEND_FAMILY_BOX )
{
if ( $BoxWidth != $IconAreaWidth ) { $XOffset = floor(($IconAreaWidth-$BoxWidth)/2); } else { $XOffset = 0; }
if ( $BoxHeight != $IconAreaHeight ) { $YOffset = floor(($IconAreaHeight-$BoxHeight)/2); } else { $YOffset = 0; }
$this->pChartObject->drawFilledRectangle($X+1+$XOffset,$Y+1+$YOffset,$X+$BoxWidth+$XOffset+1,$Y+$BoxHeight+1+$YOffset,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
$this->pChartObject->drawFilledRectangle($X+$XOffset,$Y+$YOffset,$X+$BoxWidth+$XOffset,$Y+$BoxHeight+$YOffset,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
}
elseif ( $Family == LEGEND_FAMILY_CIRCLE )
{
$this->pChartObject->drawFilledCircle($X+1+$IconAreaWidth/2,$Y+1+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
$this->pChartObject->drawFilledCircle($X+$IconAreaWidth/2,$Y+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
}
elseif ( $Family == LEGEND_FAMILY_LINE )
{
$this->pChartObject->drawLine($X+1,$Y+1+$IconAreaHeight/2,$X+1+$IconAreaWidth,$Y+1+$IconAreaHeight/2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20,"Ticks"=>$Ticks,"Weight"=>$Weight));
$this->pChartObject->drawLine($X,$Y+$IconAreaHeight/2,$X+$IconAreaWidth,$Y+$IconAreaHeight/2,array("R"=>$R,"G"=>$G,"B"=>$B,"Ticks"=>$Ticks,"Weight"=>$Weight));
}
}
if ( $Mode == LEGEND_VERTICAL )
{
$Lines = preg_split("/\n/",$Series["Description"]);
foreach($Lines as $Key => $Value)
$this->pChartObject->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
$Y=$Y+max($this->pChartObject->FontSize*count($Lines),$IconAreaHeight) + 5;
}
elseif ( $Mode == LEGEND_HORIZONTAL )
{
$Lines = preg_split("/\n/",$Series["Description"]);
$Width = "";
foreach($Lines as $Key => $Value)
{
$BoxArray = $this->pChartObject->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
$Width[] = $BoxArray[1]["X"];
}
$X=max($Width)+2+$XStep;
}
}
}
$this->Shadow = $RestoreShadow;
}
/* Get the legend box size */
function getScatterLegendSize($Format="")
{
$FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
$FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
$BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
$Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
$Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
$Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
$YStep = max($this->pChartObject->FontSize,$BoxSize) + 5;
$XStep = $BoxSize + 5;
$X=100; $Y=100;
$Data = $this->pDataObject->getData();
foreach($Data["ScatterSeries"] as $Key => $Series)
{
if ( $Series["isDrawable"] == TRUE && isset($Series["Picture"]))
{
list($PicWidth,$PicHeight) = $this->pChartObject->getPicInfo($Series["Picture"]);
if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
}
}
$YStep = max($this->pChartObject->FontSize,$IconAreaHeight) + 5;
$XStep = $IconAreaWidth + 5;
$XStep = $XSpacing;
$Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
foreach($Data["ScatterSeries"] as $Key => $Series)
{
if ( $Series["isDrawable"] == TRUE )
{
if ( $Mode == LEGEND_VERTICAL )
{
$BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Series["Description"]);
if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
$Lines = preg_split("/\n/",$Series["Description"]);
$vY = $vY + max($this->pChartObject->FontSize*count($Lines),$IconAreaHeight) + 5;
}
elseif ( $Mode == LEGEND_HORIZONTAL )
{
$Lines = preg_split("/\n/",$Series["Description"]);
$Width = "";
foreach($Lines as $Key => $Value)
{
$BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
$Width[] = $BoxArray[1]["X"];
}
$vX=max($Width)+$XStep;
}
}
}
$vY=$vY-$YStep; $vX=$vX-$XStep;
$TopOffset = $Y - $Boundaries["T"];
if ( $Boundaries["B"]-($vY+$BoxSize) < $TopOffset ) { $Boundaries["B"] = $vY+$BoxSize+$TopOffset; }
$Width = ($Boundaries["R"]+$Margin) - ($Boundaries["L"]-$Margin);
$Height = ($Boundaries["B"]+$Margin) - ($Boundaries["T"]-$Margin);
return(array("Width"=>$Width,"Height"=>$Height));
}
/* Draw the line of best fit */
function drawScatterBestFit($Format="")
{
$Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 0;
$Data = $this->pDataObject->getData();
foreach($Data["ScatterSeries"] as $Key => $Series)
{
$SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
$SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
$Color = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
$Color["Ticks"] = $Ticks;
$PosArrayX = $Data["Series"][$Series["X"]]["Data"];
$PosArrayY = $Data["Series"][$Series["Y"]]["Data"];
$Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
foreach($PosArrayX as $Key => $Value)
{
$X = $Value; $Y = $PosArrayY[$Key];
$Sxy = $Sxy + $X*$Y;
$Sx = $Sx + $X;
$Sy = $Sy + $Y;
$Sxx = $Sxx + $X*$X;
}
$n = count($PosArrayX);
$M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
$B = (($Sy)-($M*$Sx))/($n);
$X1 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMin"],$SerieXAxis);
$Y1 = $this->getPosArray($M * $Data["Axis"][$SerieXAxis]["ScaleMin"] + $B,$SerieYAxis);
$X2 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMax"],$SerieXAxis);
$Y2 = $this->getPosArray($M * $Data["Axis"][$SerieXAxis]["ScaleMax"] + $B,$SerieYAxis);
if ( $Y1 < $this->pChartObject->GraphAreaY1 ) { $X1 = $X1 + ($this->pChartObject->GraphAreaY1-$Y1); $Y1 = $this->pChartObject->GraphAreaY1; }
if ( $Y1 > $this->pChartObject->GraphAreaY2 ) { $X1 = $X1 + ($Y1-$this->pChartObject->GraphAreaY2); $Y1 = $this->pChartObject->GraphAreaY2; }
if ( $Y2 < $this->pChartObject->GraphAreaY1 ) { $X2 = $X2 - ($this->pChartObject->GraphAreaY1-$Y2); $Y2 = $this->pChartObject->GraphAreaY1; }
if ( $Y2 > $this->pChartObject->GraphAreaY2 ) { $X2 = $X2 - ($Y2-$this->pChartObject->GraphAreaY2); $Y2 = $this->pChartObject->GraphAreaY2; }
$this->pChartObject->drawLine($X1,$Y1,$X2,$Y2,$Color);
}
}
}
?>

View File

@ -0,0 +1,131 @@
<?php
/*
pSplit - class to draw spline splitted charts
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
define("TEXT_POS_TOP" , 690001);
define("TEXT_POS_RIGHT" , 690002);
/* pSplit class definition */
class pSplit
{
var $pChartObject;
/* Class creator */
function pSplit()
{ }
/* Create the encoded string */
function drawSplitPath($Object,$Values,$Format="")
{
$this->pChartObject = $Object;
$Spacing = isset($Format["Spacing"]) ? $Format["Spacing"] : 20;
$TextPadding = isset($Format["TextPadding"]) ? $Format["TextPadding"] : 2;
$TextPos = isset($Format["TextPos"]) ? $Format["TextPos"] : TEXT_POS_TOP;
$Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
$Force = isset($Format["Force"]) ? $Format["Force"] : 70;
$Segments = isset($Format["Segments"]) ? $Format["Segments"] : 15;
$FontSize = $Object->FontSize;
$X1 = $Object->GraphAreaX1;
$Y1 = $Object->GraphAreaY1;
$X2 = $Object->GraphAreaX2;
$Y2 = $Object->GraphAreaY2;
/* Data Processing */
$Data = $Values->getData();
$Palette = $Values->getPalette();
$LabelSerie = $Data["Abscissa"];
$DataSerie = "";
foreach($Data["Series"] as $SerieName => $Value)
{ if ( $SerieName != $LabelSerie && $DataSerie == "" ) { $DataSerie = $SerieName; } }
$DataSerieSum = array_sum($Data["Series"][$DataSerie]["Data"]);
$DataSerieCount = count($Data["Series"][$DataSerie]["Data"]);
/* Scale Processing */
if ( $TextPos == TEXT_POS_RIGHT )
$YScale = (($Y2-$Y1) - (($DataSerieCount+1)*$Spacing)) / $DataSerieSum;
else
$YScale = (($Y2-$Y1) - ($DataSerieCount*$Spacing)) / $DataSerieSum;
$LeftHeight = $DataSerieSum * $YScale;
/* Re-compute graph width depending of the text mode choosen */
if ( $TextPos == TEXT_POS_RIGHT )
{
$MaxWidth = 0;
foreach($Data["Series"][$LabelSerie]["Data"] as $Key => $Label)
{
$Boundardies = $Object->getTextBox(0,0,$Object->FontName,$Object->FontSize,0,$Label);
if ( $Boundardies[1]["X"] > $MaxWidth ) { $MaxWidth = $Boundardies[1]["X"] + $TextPadding*2; }
}
$X2 = $X2 - $MaxWidth;
}
/* Drawing */
$LeftY = ((($Y2-$Y1) / 2) + $Y1) - ($LeftHeight/2);
$RightY = $Y1;
$VectorX = (($X2-$X1) / 2);
foreach($Data["Series"][$DataSerie]["Data"] as $Key => $Value)
{
if ( isset($Data["Series"][$LabelSerie]["Data"][$Key]) )
$Label = $Data["Series"][$LabelSerie]["Data"][$Key];
else
$Label = "-";
$LeftY1 = $LeftY;
$LeftY2 = $LeftY + $Value * $YScale;
$RightY1 = $RightY + $Spacing;
$RightY2 = $RightY + $Spacing + $Value * $YScale;;
$Settings = array("R"=>$Palette[$Key]["R"],"G"=>$Palette[$Key]["G"],"B"=>$Palette[$Key]["B"],"Alpha"=>$Palette[$Key]["Alpha"],"NoDraw"=>TRUE,"Segments"=>$Segments,"Surrounding"=>$Surrounding);
$PolyGon = "";
$Angle = $Object->getAngle($X2,$RightY1,$X1,$LeftY1);
$VectorX1 = cos(deg2rad($Angle+90)) * $Force + ($X2-$X1)/2 + $X1;
$VectorY1 = sin(deg2rad($Angle+90)) * $Force + ($RightY1-$LeftY1)/2 + $LeftY1;
$VectorX2 = cos(deg2rad($Angle-90)) * $Force + ($X2-$X1)/2 + $X1;
$VectorY2 = sin(deg2rad($Angle-90)) * $Force + ($RightY1-$LeftY1)/2 + $LeftY1;
$Points = $Object->drawBezier($X1,$LeftY1,$X2,$RightY1,$VectorX1,$VectorY1,$VectorX2,$VectorY2,$Settings);
foreach($Points as $Key => $Pos) { $PolyGon[] = $Pos["X"]; $PolyGon[] = $Pos["Y"]; }
$Angle = $Object->getAngle($X2,$RightY2,$X1,$LeftY2);
$VectorX1 = cos(deg2rad($Angle+90)) * $Force + ($X2-$X1)/2 +$X1;
$VectorY1 = sin(deg2rad($Angle+90)) * $Force + ($RightY2-$LeftY2)/2 + $LeftY2;
$VectorX2 = cos(deg2rad($Angle-90)) * $Force + ($X2-$X1)/2 +$X1;
$VectorY2 = sin(deg2rad($Angle-90)) * $Force + ($RightY2-$LeftY2)/2 + $LeftY2;
$Points = $Object->drawBezier($X1,$LeftY2,$X2,$RightY2,$VectorX1,$VectorY1,$VectorX2,$VectorY2,$Settings);
$Points = array_reverse($Points);
foreach($Points as $Key => $Pos) { $PolyGon[] = $Pos["X"]; $PolyGon[] = $Pos["Y"]; }
$Object->drawPolygon($PolyGon,$Settings);
if ( $TextPos == TEXT_POS_RIGHT )
$Object->drawText($X2+$TextPadding,($RightY2-$RightY1)/2+$RightY1,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT));
else
$Object->drawText($X2,$RightY1-$TextPadding,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT));
$LeftY = $LeftY2;
$RightY = $RightY2;
}
}
}
?>

View File

@ -0,0 +1,868 @@
<?php
/*
pSpring - class to draw spring graphs
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
define("NODE_TYPE_FREE" , 690001);
define("NODE_TYPE_CENTRAL" , 690002);
define("NODE_SHAPE_CIRCLE" , 690011);
define("NODE_SHAPE_TRIANGLE" , 690012);
define("NODE_SHAPE_SQUARE" , 690013);
define("ALGORITHM_RANDOM" , 690021);
define("ALGORITHM_WEIGHTED" , 690022);
define("ALGORITHM_CIRCULAR" , 690023);
define("ALGORITHM_CENTRAL" , 690024);
define("LABEL_CLASSIC" , 690031);
define("LABEL_LIGHT" , 690032);
/* pSpring class definition */
class pSpring
{
var $History;
var $pChartObject;
var $Data;
var $Links;
var $X1;
var $Y1;
var $X2;
var $Y2;
var $AutoComputeFreeZone;
var $Labels;
/* Class creator */
function pSpring()
{
/* Initialise data arrays */
$this->Data = "";
$this->Links = "";
/* Set nodes defaults */
$this->Default["R"] = 255;
$this->Default["G"] = 255;
$this->Default["B"] = 255;
$this->Default["Alpha"] = 100;
$this->Default["BorderR"] = 0;
$this->Default["BorderG"] = 0;
$this->Default["BorderB"] = 0;
$this->Default["BorderAlpha"] = 100;
$this->Default["Surrounding"] = NULL;
$this->Default["BackgroundR"] = 255;
$this->Default["BackgroundG"] = 255;
$this->Default["BackgroundB"] = 255;
$this->Default["BackgroundAlpha"] = 0;
$this->Default["Force"] = 1;
$this->Default["NodeType"] = NODE_TYPE_FREE;
$this->Default["Size"] = 5;
$this->Default["Shape"] = NODE_SHAPE_CIRCLE;
$this->Default["FreeZone"] = 40;
$this->Default["LinkR"] = 0;
$this->Default["LinkG"] = 0;
$this->Default["LinkB"] = 0;
$this->Default["LinkAlpha"] = 0;
$this->Labels["Type"] = LABEL_CLASSIC;
$this->Labels["R"] = 0;
$this->Labels["G"] = 0;
$this->Labels["B"] = 0;
$this->Labels["Alpha"] = 100;
$this->AutoComputeFreeZone = FALSE;
}
/* Set default links options */
function setLinkDefaults($Settings="")
{
if ( isset($Settings["R"]) ) { $this->Default["LinkR"] = $Settings["R"]; }
if ( isset($Settings["G"]) ) { $this->Default["LinkG"] = $Settings["G"]; }
if ( isset($Settings["B"]) ) { $this->Default["LinkB"] = $Settings["B"]; }
if ( isset($Settings["Alpha"]) ) { $this->Default["LinkAlpha"] = $Settings["Alpha"]; }
}
/* Set default links options */
function setLabelsSettings($Settings="")
{
if ( isset($Settings["Type"]) ) { $this->Labels["Type"] = $Settings["Type"]; }
if ( isset($Settings["R"]) ) { $this->Labels["R"] = $Settings["R"]; }
if ( isset($Settings["G"]) ) { $this->Labels["G"] = $Settings["G"]; }
if ( isset($Settings["B"]) ) { $this->Labels["B"] = $Settings["B"]; }
if ( isset($Settings["Alpha"]) ) { $this->Labels["Alpha"] = $Settings["Alpha"]; }
}
/* Auto compute the FreeZone size based on the number of connections */
function autoFreeZone()
{
/* Check connections reciprocity */
foreach($this->Data as $Key => $Settings)
{
if ( isset($Settings["Connections"]) )
{ $this->Data[$Key]["FreeZone"] = count($Settings["Connections"])*10 + 20; }
else
{ $this->Data[$Key]["FreeZone"] = 20; }
}
}
/* Set link properties */
function linkProperties($FromNode,$ToNode,$Settings)
{
if ( !isset($this->Data[$FromNode]) ) { return(0); }
if ( !isset($this->Data[$ToNode]) ) { return(0); }
$R = isset($Settings["R"]) ? $Settings["R"] : 0;
$G = isset($Settings["G"]) ? $Settings["G"] : 0;
$B = isset($Settings["B"]) ? $Settings["B"] : 0;
$Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : 100;
$Name = isset($Settings["Name"]) ? $Settings["Name"] : NULL;
$Ticks = isset($Settings["Ticks"]) ? $Settings["Ticks"] : NULL;
$this->Links[$FromNode][$ToNode]["R"] = $R; $this->Links[$ToNode][$FromNode]["R"] = $R;
$this->Links[$FromNode][$ToNode]["G"] = $G; $this->Links[$ToNode][$FromNode]["G"] = $G;
$this->Links[$FromNode][$ToNode]["B"] = $B; $this->Links[$ToNode][$FromNode]["B"] = $B;
$this->Links[$FromNode][$ToNode]["Alpha"] = $Alpha; $this->Links[$ToNode][$FromNode]["Alpha"] = $Alpha;
$this->Links[$FromNode][$ToNode]["Name"] = $Name; $this->Links[$ToNode][$FromNode]["Name"] = $Name;
$this->Links[$FromNode][$ToNode]["Ticks"] = $Ticks; $this->Links[$ToNode][$FromNode]["Ticks"] = $Ticks;
}
function setNodeDefaults($Settings="")
{
if ( isset($Settings["R"]) ) { $this->Default["R"] = $Settings["R"]; }
if ( isset($Settings["G"]) ) { $this->Default["G"] = $Settings["G"]; }
if ( isset($Settings["B"]) ) { $this->Default["B"] = $Settings["B"]; }
if ( isset($Settings["Alpha"]) ) { $this->Default["Alpha"] = $Settings["Alpha"]; }
if ( isset($Settings["BorderR"]) ) { $this->Default["BorderR"] = $Settings["BorderR"]; }
if ( isset($Settings["BorderG"]) ) { $this->Default["BorderG"] = $Settings["BorderG"]; }
if ( isset($Settings["BorderB"]) ) { $this->Default["BorderB"] = $Settings["BorderB"]; }
if ( isset($Settings["BorderAlpha"]) ) { $this->Default["BorderAlpha"] = $Settings["BorderAlpha"]; }
if ( isset($Settings["Surrounding"]) ) { $this->Default["Surrounding"] = $Settings["Surrounding"]; }
if ( isset($Settings["BackgroundR"]) ) { $this->Default["BackgroundR"] = $Settings["BackgroundR"]; }
if ( isset($Settings["BackgroundG"]) ) { $this->Default["BackgroundG"] = $Settings["BackgroundG"]; }
if ( isset($Settings["BackgroundB"]) ) { $this->Default["BackgroundB"] = $Settings["BackgroundB"]; }
if ( isset($Settings["BackgroundAlpha"]) ) { $this->Default["BackgroundAlpha"] = $Settings["BackgroundAlpha"]; }
if ( isset($Settings["NodeType"]) ) { $this->Default["NodeType"] = $Settings["NodeType"]; }
if ( isset($Settings["Size"]) ) { $this->Default["Size"] = $Settings["Size"]; }
if ( isset($Settings["Shape"]) ) { $this->Default["Shape"] = $Settings["Shape"]; }
if ( isset($Settings["FreeZone"]) ) { $this->Default["FreeZone"] = $Settings["FreeZone"]; }
}
/* Add a node */
function addNode($NodeID,$Settings="")
{
/* if the node already exists, ignore */
if (isset($this->Data[$NodeID])) { return(0); }
$Name = isset($Settings["Name"]) ? $Settings["Name"] : "Node ".$NodeID;
$Connections = isset($Settings["Connections"]) ? $Settings["Connections"] : NULL;
$R = isset($Settings["R"]) ? $Settings["R"] : $this->Default["R"];
$G = isset($Settings["G"]) ? $Settings["G"] : $this->Default["G"];
$B = isset($Settings["B"]) ? $Settings["B"] : $this->Default["B"];
$Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : $this->Default["Alpha"];
$BorderR = isset($Settings["BorderR"]) ? $Settings["BorderR"] : $this->Default["BorderR"];
$BorderG = isset($Settings["BorderG"]) ? $Settings["BorderG"] : $this->Default["BorderG"];
$BorderB = isset($Settings["BorderB"]) ? $Settings["BorderB"] : $this->Default["BorderB"];
$BorderAlpha = isset($Settings["BorderAlpha"]) ? $Settings["BorderAlpha"] : $this->Default["BorderAlpha"];
$Surrounding = isset($Settings["Surrounding"]) ? $Settings["Surrounding"] : $this->Default["Surrounding"];
$BackgroundR = isset($Settings["BackgroundR"]) ? $Settings["BackgroundR"] : $this->Default["BackgroundR"];
$BackgroundG = isset($Settings["BackgroundG"]) ? $Settings["BackgroundG"] : $this->Default["BackgroundG"];
$BackgroundB = isset($Settings["BackgroundB"]) ? $Settings["BackgroundB"] : $this->Default["BackgroundB"];
$BackgroundAlpha = isset($Settings["BackgroundAlpha"]) ? $Settings["BackgroundAlpha"] : $this->Default["BackgroundAlpha"];
$Force = isset($Settings["Force"]) ? $Settings["Force"] : $this->Default["Force"];
$NodeType = isset($Settings["NodeType"]) ? $Settings["NodeType"] : $this->Default["NodeType"];
$Size = isset($Settings["Size"]) ? $Settings["Size"] : $this->Default["Size"];
$Shape = isset($Settings["Shape"]) ? $Settings["Shape"] : $this->Default["Shape"];
$FreeZone = isset($Settings["FreeZone"]) ? $Settings["FreeZone"] : $this->Default["FreeZone"];
if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
$this->Data[$NodeID]["R"] = $R; $this->Data[$NodeID]["G"] = $G; $this->Data[$NodeID]["B"] = $B; $this->Data[$NodeID]["Alpha"] = $Alpha;
$this->Data[$NodeID]["BorderR"] = $BorderR; $this->Data[$NodeID]["BorderG"] = $BorderG; $this->Data[$NodeID]["BorderB"] = $BorderB; $this->Data[$NodeID]["BorderAlpha"] = $BorderAlpha;
$this->Data[$NodeID]["BackgroundR"] = $BackgroundR; $this->Data[$NodeID]["BackgroundG"] = $BackgroundG; $this->Data[$NodeID]["BackgroundB"] = $BackgroundB; $this->Data[$NodeID]["BackgroundAlpha"] = $BackgroundAlpha;
$this->Data[$NodeID]["Name"] = $Name;
$this->Data[$NodeID]["Force"] = $Force;
$this->Data[$NodeID]["Type"] = $NodeType;
$this->Data[$NodeID]["Size"] = $Size;
$this->Data[$NodeID]["Shape"] = $Shape;
$this->Data[$NodeID]["FreeZone"] = $FreeZone;
if ( $Connections != NULL )
{
if ( is_array($Connections ) )
{
foreach($Connections as $Key => $Value)
$this->Data[$NodeID]["Connections"][] = $Value;
}
else
$this->Data[$NodeID]["Connections"][] = $Connections;
}
}
/* Set color attribute for a list of nodes */
function setNodesColor($Nodes,$Settings="")
{
if ( is_array($Nodes) )
{
foreach ($Nodes as $Key => $NodeID)
{
if (isset($this->Data[$NodeID]) )
{
if ( isset($Settings["R"]) ) { $this->Data[$NodeID]["R"] = $Settings["R"]; }
if ( isset($Settings["G"]) ) { $this->Data[$NodeID]["G"] = $Settings["G"]; }
if ( isset($Settings["B"]) ) { $this->Data[$NodeID]["B"] = $Settings["B"]; }
if ( isset($Settings["Alpha"]) ) { $this->Data[$NodeID]["Alpha"] = $Settings["Alpha"]; }
if ( isset($Settings["BorderR"]) ) { $this->Data[$NodeID]["BorderR"] = $Settings["BorderR"]; }
if ( isset($Settings["BorderG"]) ) { $this->Data[$NodeID]["BorderG"] = $Settings["BorderG"]; }
if ( isset($Settings["BorderB"]) ) { $this->Data[$NodeID]["BorderB"] = $Settings["BorderB"]; }
if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$NodeID]["BorderAlpha"] = $Settings["BorderAlpha"]; }
if ( isset($Settings["Surrounding"]) ) { $this->Data[$NodeID]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; }
}
}
}
else
{
if ( isset($Settings["R"]) ) { $this->Data[$Nodes]["R"] = $Settings["R"]; }
if ( isset($Settings["G"]) ) { $this->Data[$Nodes]["G"] = $Settings["G"]; }
if ( isset($Settings["B"]) ) { $this->Data[$Nodes]["B"] = $Settings["B"]; }
if ( isset($Settings["Alpha"]) ) { $this->Data[$Nodes]["Alpha"] = $Settings["Alpha"]; }
if ( isset($Settings["BorderR"]) ) { $this->Data[$Nodes]["BorderR"] = $Settings["BorderR"]; }
if ( isset($Settings["BorderG"]) ) { $this->Data[$Nodes]["BorderG"] = $Settings["BorderG"]; }
if ( isset($Settings["BorderB"]) ) { $this->Data[$Nodes]["BorderB"] = $Settings["BorderB"]; }
if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$Nodes]["BorderAlpha"] = $Settings["BorderAlpha"]; }
if ( isset($Settings["Surrounding"]) ) { $this->Data[$Nodes]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; }
}
}
/* Returns all the nodes details */
function dumpNodes()
{ return($this->Data); }
/* Check if a connection exists and create it if required */
function checkConnection($SourceID, $TargetID)
{
if ( isset($this->Data[$SourceID]["Connections"]) )
{
foreach ($this->Data[$SourceID]["Connections"] as $Key => $ConnectionID)
{ if ( $TargetID == $ConnectionID ) { return(TRUE); } }
}
$this->Data[$SourceID]["Connections"][] = $TargetID;
}
/* Get the median linked nodes position */
function getMedianOffset($Key,$X,$Y)
{
$Cpt = 1;
if ( isset($this->Data[$Key]["Connections"]) )
{
foreach($this->Data[$Key]["Connections"] as $ID => $NodeID)
{
if ( isset($this->Data[$NodeID]["X"]) && isset($this->Data[$NodeID]["Y"]) )
{
$X = $X + $this->Data[$NodeID]["X"];
$Y = $Y + $this->Data[$NodeID]["Y"];
$Cpt++;
}
}
}
return(array("X"=>$X/$Cpt,"Y"=>$Y/$Cpt));
}
/* Return the ID of the attached partner with the biggest weight */
function getBiggestPartner($Key)
{
if ( !isset($this->Data[$Key]["Connections"]) ) { return(""); }
$MaxWeight = 0; $Result = "";
foreach($this->Data[$Key]["Connections"] as $Key => $PeerID)
{
if ( $this->Data[$PeerID]["Weight"] > $MaxWeight )
{ $MaxWeight = $this->Data[$PeerID]["Weight"]; $Result = $PeerID; }
}
return($Result);
}
/* Do the initial node positions computing pass */
function firstPass($Algorithm)
{
$CenterX = ($this->X2 - $this->X1) / 2 + $this->X1;
$CenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1;
/* Check connections reciprocity */
foreach($this->Data as $Key => $Settings)
{
if ( isset($Settings["Connections"]) )
{
foreach($Settings["Connections"] as $ID => $ConnectionID)
$this->checkConnection($ConnectionID,$Key);
}
}
if ( $this->AutoComputeFreeZone ) { $this->autoFreeZone(); }
/* Get the max number of connections */
$MaxConnections = 0;
foreach($this->Data as $Key => $Settings)
{ if ( isset($Settings["Connections"]) ) { if ( $MaxConnections < count($Settings["Connections"] ) ) { $MaxConnections = count($Settings["Connections"]); } } }
if ( $Algorithm == ALGORITHM_WEIGHTED )
{
foreach($this->Data as $Key => $Settings)
{
if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
if ( $Settings["Type"] == NODE_TYPE_FREE )
{
if ( isset($Settings["Connections"]) )
{ $Connections = count($Settings["Connections"]); }
else
{ $Connections = 0; }
$Ring = $MaxConnections - $Connections;
$Angle = rand(0,360);
$this->Data[$Key]["X"] = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX;
$this->Data[$Key]["Y"] = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY;
}
}
}
elseif ( $Algorithm == ALGORITHM_CENTRAL )
{
/* Put a weight on each nodes */
foreach($this->Data as $Key => $Settings)
{
if ( isset($Settings["Connections"]) )
$this->Data[$Key]["Weight"] = count($Settings["Connections"]);
else
$this->Data[$Key]["Weight"] = 0;
}
$MaxConnections = $MaxConnections + 1;
for($i=$MaxConnections;$i>=0;$i--)
{
foreach($this->Data as $Key => $Settings)
{
if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
if ( $Settings["Type"] == NODE_TYPE_FREE )
{
if ( isset($Settings["Connections"]) )
{ $Connections = count($Settings["Connections"]); }
else
{ $Connections = 0; }
if ( $Connections == $i )
{
$BiggestPartner = $this->getBiggestPartner($Key);
if ( $BiggestPartner != "" )
{
$Ring = $this->Data[$BiggestPartner]["FreeZone"];
$Weight = $this->Data[$BiggestPartner]["Weight"];
$AngleDivision = 360 / $this->Data[$BiggestPartner]["Weight"];
$Done = FALSE; $Tries = 0;
while (!$Done && $Tries <= $Weight*2)
{
$Tries++;
$Angle = floor(rand(0,$Weight)*$AngleDivision);
if ( !isset($this->Data[$BiggestPartner]["Angular"][$Angle]) || !isset($this->Data[$BiggestPartner]["Angular"]) )
{
$this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle;
$Done = TRUE;
}
}
if ( !$Done )
{ $Angle = rand(0,360); $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; }
$X = cos(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["X"];
$Y = sin(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["Y"];
$this->Data[$Key]["X"] = $X;
$this->Data[$Key]["Y"] = $Y;
}
}
}
}
}
}
elseif ( $Algorithm == ALGORITHM_CIRCULAR )
{
$MaxConnections = $MaxConnections + 1;
for($i=$MaxConnections;$i>=0;$i--)
{
foreach($this->Data as $Key => $Settings)
{
if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
if ( $Settings["Type"] == NODE_TYPE_FREE )
{
if ( isset($Settings["Connections"]) )
{ $Connections = count($Settings["Connections"]); }
else
{ $Connections = 0; }
if ( $Connections == $i )
{
$Ring = $MaxConnections - $Connections;
$Angle = rand(0,360);
$X = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX;
$Y = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY;
$MedianOffset = $this->getMedianOffset($Key,$X,$Y);
$this->Data[$Key]["X"] = $MedianOffset["X"];
$this->Data[$Key]["Y"] = $MedianOffset["Y"];
}
}
}
}
}
elseif ( $Algorithm == ALGORITHM_RANDOM )
{
foreach($this->Data as $Key => $Settings)
{
if ( $Settings["Type"] == NODE_TYPE_FREE )
{
$this->Data[$Key]["X"] = $CenterX + rand(-20,20);
$this->Data[$Key]["Y"] = $CenterY + rand(-20,20);
}
if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
}
}
}
/* Compute one pass */
function doPass()
{
/* Compute vectors */
foreach($this->Data as $Key => $Settings)
{
if ( $Settings["Type"] != NODE_TYPE_CENTRAL )
{
unset($this->Data[$Key]["Vectors"]);
$X1 = $Settings["X"];
$Y1 = $Settings["Y"];
/* Repulsion vectors */
foreach($this->Data as $Key2 => $Settings2)
{
if ( $Key != $Key2 )
{
$X2 = $this->Data[$Key2]["X"];
$Y2 = $this->Data[$Key2]["Y"];
$FreeZone = $this->Data[$Key2]["FreeZone"];
$Distance = $this->getDistance($X1,$Y1,$X2,$Y2);
$Angle = $this->getAngle($X1,$Y1,$X2,$Y2) + 180;
/* Nodes too close, repulsion occurs */
if ( $Distance < $FreeZone )
{
$Force = log(pow(2,$FreeZone-$Distance));
if ( $Force > 1 )
{ $this->Data[$Key]["Vectors"][] = array("Type"=>"R","Angle"=>$Angle % 360,"Force"=>$Force); }
}
}
}
/* Attraction vectors */
if ( isset($Settings["Connections"]) )
{
foreach($Settings["Connections"] as $ID => $NodeID)
{
if ( isset($this->Data[$NodeID]) )
{
$X2 = $this->Data[$NodeID]["X"];
$Y2 = $this->Data[$NodeID]["Y"];
$FreeZone = $this->Data[$Key2]["FreeZone"];
$Distance = $this->getDistance($X1,$Y1,$X2,$Y2);
$Angle = $this->getAngle($X1,$Y1,$X2,$Y2);
if ( $Distance > $FreeZone )
$Force = log(($Distance-$FreeZone)+1);
else
{ $Force = log(($FreeZone-$Distance)+1); ($Angle = $Angle + 180); }
if ( $Force > 1 )
$this->Data[$Key]["Vectors"][] = array("Type"=>"A","Angle"=>$Angle % 360,"Force"=>$Force);
}
}
}
}
}
/* Move the nodes accoding to the vectors */
foreach($this->Data as $Key => $Settings)
{
$X = $Settings["X"];
$Y = $Settings["Y"];
if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL )
{
foreach($Settings["Vectors"] as $ID => $Vector)
{
$Type = $Vector["Type"];
$Force = $Vector["Force"];
$Angle = $Vector["Angle"];
$Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR;
$X = cos(deg2rad($Angle)) * $Force * $Factor + $X;
$Y = sin(deg2rad($Angle)) * $Force * $Factor + $Y;
}
}
$this->Data[$Key]["X"] = $X;
$this->Data[$Key]["Y"] = $Y;
}
}
function lastPass()
{
/* Put everything inside the graph area */
foreach($this->Data as $Key => $Settings)
{
$X = $Settings["X"];
$Y = $Settings["Y"];
if ( $X < $this->X1 ) { $X = $this->X1; }
if ( $X > $this->X2 ) { $X = $this->X2; }
if ( $Y < $this->Y1 ) { $Y = $this->Y1; }
if ( $Y > $this->Y2 ) { $Y = $this->Y2; }
$this->Data[$Key]["X"] = $X;
$this->Data[$Key]["Y"] = $Y;
}
/* Dump all links */
$Links = "";
foreach($this->Data as $Key => $Settings)
{
$X1 = $Settings["X"];
$Y1 = $Settings["Y"];
if ( isset($Settings["Connections"]) )
{
foreach ($Settings["Connections"] as $ID => $NodeID)
{
if ( isset($this->Data[$NodeID]) )
{
$X2 = $this->Data[$NodeID]["X"];
$Y2 = $this->Data[$NodeID]["Y"];
$Links[] = array("X1"=>$X1,"Y1"=>$Y1,"X2"=>$X2,"Y2"=>$Y2,"Source"=>$Settings["Name"],"Destination"=>$this->Data[$NodeID]["Name"]);
}
}
}
}
/* Check collisions */
$Conflicts = 0;
foreach($this->Data as $Key => $Settings)
{
$X1 = $Settings["X"];
$Y1 = $Settings["Y"];
if ( isset($Settings["Connections"]) )
{
foreach ($Settings["Connections"] as $ID => $NodeID)
{
if ( isset($this->Data[$NodeID]) )
{
$X2 = $this->Data[$NodeID]["X"];
$Y2 = $this->Data[$NodeID]["Y"];
foreach($Links as $IDLinks => $Link)
{
$X3 = $Link["X1"]; $Y3 = $Link["Y1"]; $X4 = $Link["X2"]; $Y4 = $Link["Y2"];
if ( !($X1 == $X3 && $X2 == $X4 && $Y1 == $Y3 && $Y2 == $Y4 ) )
{
if ( $this->intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4) )
{
if ( $Link["Source"] != $Settings["Name"] && $Link["Source"] != $this->Data[$NodeID]["Name"] && $Link["Destination"] != $Settings["Name"] && $Link["Destination"] != $this->Data[$NodeID]["Name"] )
{ $Conflicts++; }
}
}
}
}
}
}
}
return($Conflicts/2);
}
/* Center the graph */
function center()
{
/* Determine the real center */
$TargetCenterX = ($this->X2 - $this->X1) / 2 + $this->X1;
$TargetCenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1;
/* Get current boundaries */
$XMin = $this->X2; $XMax = $this->X1;
$YMin = $this->Y2; $YMax = $this->Y1;
foreach($this->Data as $Key => $Settings)
{
$X = $Settings["X"];
$Y = $Settings["Y"];
if ( $X < $XMin) { $XMin = $X; }
if ( $X > $XMax) { $XMax = $X; }
if ( $Y < $YMin) { $YMin = $Y; }
if ( $Y > $YMax) { $YMax = $Y; }
}
$CurrentCenterX = ($XMax - $XMin) / 2 + $XMin;
$CurrentCenterY = ($YMax - $YMin) / 2 + $YMin;
/* Compute the offset to apply */
$XOffset = $TargetCenterX - $CurrentCenterX;
$YOffset = $TargetCenterY - $CurrentCenterY;
/* Correct the points position */
foreach($this->Data as $Key => $Settings)
{
$this->Data[$Key]["X"] = $Settings["X"] + $XOffset;
$this->Data[$Key]["Y"] = $Settings["Y"] + $YOffset;
}
}
/* Create the encoded string */
function drawSpring($Object,$Settings="")
{
$this->pChartObject = $Object;
$Pass = isset($Settings["Pass"]) ? $Settings["Pass"] : 50;
$Retries = isset($Settings["Retry"]) ? $Settings["Retry"] : 10;
$this->MagneticForceA = isset($Settings["MagneticForceA"]) ? $Settings["MagneticForceA"] : 1.5;
$this->MagneticForceR = isset($Settings["MagneticForceR"]) ? $Settings["MagneticForceR"] : 2;
$this->RingSize = isset($Settings["RingSize"]) ? $Settings["RingSize"] : 40;
$DrawVectors = isset($Settings["DrawVectors"]) ? $Settings["DrawVectors"] : FALSE;
$DrawQuietZone = isset($Settings["DrawQuietZone"]) ? $Settings["DrawQuietZone"] : FALSE;
$CenterGraph = isset($Settings["CenterGraph"]) ? $Settings["CenterGraph"] : TRUE;
$TextPadding = isset($Settings["TextPadding"]) ? $Settings["TextPadding"] : 4;
$Algorithm = isset($Settings["Algorithm"]) ? $Settings["Algorithm"] : ALGORITHM_WEIGHTED;
$FontSize = $Object->FontSize;
$this->X1 = $Object->GraphAreaX1;
$this->Y1 = $Object->GraphAreaY1;
$this->X2 = $Object->GraphAreaX2;
$this->Y2 = $Object->GraphAreaY2;
$Conflicts = 1; $Jobs = 0; $this->History["MinimumConflicts"] = -1;
while ($Conflicts != 0 && $Jobs < $Retries )
{
$Jobs++;
/* Compute the initial settings */
$this->firstPass($Algorithm);
/* Apply the vectors */
if ( $Pass > 0 )
{
for ($i=0; $i<=$Pass; $i++) { $this->doPass(); }
}
$Conflicts = $this->lastPass();
if ( $this->History["MinimumConflicts"] == -1 || $Conflicts < $this->History["MinimumConflicts"] )
{ $this->History["MinimumConflicts"] = $Conflicts; $this->History["Result"] = $this->Data; }
}
$Conflicts = $this->History["MinimumConflicts"];
$this->Data = $this->History["Result"];
if ( $CenterGraph ) { $this->center(); }
/* Draw the connections */
$Drawn = "";
foreach($this->Data as $Key => $Settings)
{
$X = $Settings["X"];
$Y = $Settings["Y"];
if ( isset($Settings["Connections"]) )
{
foreach ($Settings["Connections"] as $ID => $NodeID)
{
if ( !isset($Drawn[$Key]) ) { $Drawn[$Key] = ""; }
if ( !isset($Drawn[$NodeID]) ) { $Drawn[$NodeID] = ""; }
if ( isset($this->Data[$NodeID]) && !isset($Drawn[$Key][$NodeID]) && !isset($Drawn[$NodeID][$Key]) )
{
$Color = array("R"=>$this->Default["LinkR"],"G"=>$this->Default["LinkG"],"B"=>$this->Default["LinkB"],"Alpha"=>$this->Default["Alpha"]);
if ( $this->Links != "" )
{
if ( isset($this->Links[$Key][$NodeID]["R"]) )
{ $Color = array("R"=>$this->Links[$Key][$NodeID]["R"],"G"=>$this->Links[$Key][$NodeID]["G"],"B"=>$this->Links[$Key][$NodeID]["B"],"Alpha"=>$this->Links[$Key][$NodeID]["Alpha"]); }
if ( isset($this->Links[$Key][$NodeID]["Ticks"]) )
{ $Color["Ticks"] = $this->Links[$Key][$NodeID]["Ticks"]; }
}
$X2 = $this->Data[$NodeID]["X"];
$Y2 = $this->Data[$NodeID]["Y"];
$this->pChartObject->drawLine($X,$Y,$X2,$Y2,$Color);
$Drawn[$Key][$NodeID] = TRUE;
if ( isset($this->Links) && $this->Links != "" )
{
if ( isset($this->Links[$Key][$NodeID]["Name"]) || isset($this->Links[$NodeID][$Key]["Name"]) )
{
$Name = isset($this->Links[$Key][$NodeID]["Name"]) ? $this->Links[$Key][$NodeID]["Name"] : $this->Links[$NodeID][$Key]["Name"];
$TxtX = ($X2 - $X)/2 + $X;
$TxtY = ($Y2 - $Y)/2 + $Y;
if ( $X <= $X2 )
$Angle = (360-$this->getAngle($X,$Y,$X2,$Y2)) % 360;
else
$Angle = (360-$this->getAngle($X2,$Y2,$X,$Y)) % 360;
$Settings = $Color;
$Settings["Angle"] = $Angle;
$Settings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE;
$this->pChartObject->drawText($TxtX,$TxtY,$Name,$Settings);
}
}
}
}
}
}
/* Draw the quiet zones */
if ( $DrawQuietZone )
{
foreach($this->Data as $Key => $Settings)
{
$X = $Settings["X"];
$Y = $Settings["Y"];
$FreeZone = $Settings["FreeZone"];
$this->pChartObject->drawFilledCircle($X,$Y,$FreeZone,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>2));
}
}
/* Draw the nodes */
foreach($this->Data as $Key => $Settings)
{
$X = $Settings["X"];
$Y = $Settings["Y"];
$Name = $Settings["Name"];
$FreeZone = $Settings["FreeZone"];
$Shape = $Settings["Shape"];
$Size = $Settings["Size"];
$Color = array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"],"Alpha"=>$Settings["Alpha"],"BorderR"=>$Settings["BorderR"],"BorderG"=>$Settings["BorderG"],"BorderB"=>$Settings["BorderB"],"BorderApha"=>$Settings["BorderAlpha"]);
if ( $Shape == NODE_SHAPE_CIRCLE )
{
$this->pChartObject->drawFilledCircle($X,$Y,$Size,$Color);
}
elseif ( $Shape == NODE_SHAPE_TRIANGLE )
{
$Points = "";
$Points[] = cos(deg2rad(270)) * $Size + $X; $Points[] = sin(deg2rad(270)) * $Size + $Y;
$Points[] = cos(deg2rad(45)) * $Size + $X; $Points[] = sin(deg2rad(45)) * $Size + $Y;
$Points[] = cos(deg2rad(135)) * $Size + $X; $Points[] = sin(deg2rad(135)) * $Size + $Y;
$this->pChartObject->drawPolygon($Points,$Color);
}
elseif ( $Shape == NODE_SHAPE_SQUARE )
{
$Offset = $Size/2; $Size = $Size / 2;
$this->pChartObject->drawFilledRectangle($X-$Offset,$Y-$Offset,$X+$Offset,$Y+$Offset,$Color);
}
if ( $Name != "" )
{
$LabelOptions = array("R"=>$this->Labels["R"],"G"=>$this->Labels["G"],"B"=>$this->Labels["B"],"Alpha"=>$this->Labels["Alpha"]);
if ( $this->Labels["Type"] == LABEL_LIGHT )
{
$LabelOptions["Align"] = TEXT_ALIGN_BOTTOMLEFT;
$this->pChartObject->drawText($X,$Y,$Name,$LabelOptions);
}
elseif ( $this->Labels["Type"] == LABEL_CLASSIC )
{
$LabelOptions["Align"] = TEXT_ALIGN_TOPMIDDLE;
$LabelOptions["DrawBox"] = TRUE;
$LabelOptions["BoxAlpha"] = 50;
$LabelOptions["BorderOffset"] = 4;
$LabelOptions["RoundedRadius"] = 3;
$LabelOptions["BoxRounded"] = TRUE;
$LabelOptions["NoShadow"] = TRUE;
$this->pChartObject->drawText($X,$Y+$Size+$TextPadding,$Name,$LabelOptions);
}
}
}
/* Draw the vectors */
if ( $DrawVectors )
{
foreach($this->Data as $Key => $Settings)
{
$X1 = $Settings["X"];
$Y1 = $Settings["Y"];
if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL )
{
foreach($Settings["Vectors"] as $ID => $Vector)
{
$Type = $Vector["Type"];
$Force = $Vector["Force"];
$Angle = $Vector["Angle"];
$Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR;
$Color = $Type == "A" ? array("FillR"=>255,"FillG"=>0,"FillB"=>0) : array("FillR"=>0,"FillG"=>255,"FillB"=>0);
$X2 = cos(deg2rad($Angle)) * $Force * $Factor + $X1;
$Y2 = sin(deg2rad($Angle)) * $Force * $Factor + $Y1;
$this->pChartObject->drawArrow($X1,$Y1,$X2,$Y2,$Color);
}
}
}
}
return(array("Pass"=>$Jobs,"Conflicts"=>$Conflicts));
}
/* Return the distance between two points */
function getDistance($X1,$Y1,$X2,$Y2)
{ return (sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1))); }
/* Return the angle made by a line and the X axis */
function getAngle($X1,$Y1,$X2,$Y2)
{
$Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1;$Angle = rad2deg(atan2($Opposite,$Adjacent));
if ($Angle > 0) { return($Angle); } else { return(360-abs($Angle)); }
}
function intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4)
{
$A = (($X3 * $Y4 - $X4 * $Y3) * ($X1 - $X2) - ($X1 * $Y2 - $X2 * $Y1) * ($X3 - $X4));
$B = (($Y1 - $Y2) * ($X3 - $X4) - ($Y3 - $Y4) * ($X1 - $X2));
if ( $B == 0 ) { return(FALSE); }
$Xi = $A / $B;
$C = ($X1 - $X2);
if ( $C == 0 ) { return(FALSE); }
$Yi = $Xi * (($Y1 - $Y2)/$C) + (($X1 * $Y2 - $X2 * $Y1)/$C);
if ( $Xi >= min($X1,$X2) && $Xi >= min($X3,$X4) && $Xi <= max($X1,$X2) && $Xi <= max($X3,$X4))
{
if ( $Yi >= min($Y1,$Y2) && $Yi >= min($Y3,$Y4) && $Yi <= max($Y1,$Y2) && $Yi <= max($Y3,$Y4))
{ return(TRUE); }
}
return(FALSE);
}
}
?>

View File

@ -0,0 +1,184 @@
<?php
/*
pStock - class to draw stock charts
Version : 2.1.0
Made by : Jean-Damien POGOLOTTI
Last Update : 26/01/11
This file can be distributed under the license you can find at :
http://www.pchart.net/license
You can find the whole class documentation on the pChart web site.
*/
define("STOCK_MISSING_SERIE" , 180001);
/* pStock class definition */
class pStock
{
var $pChartObject;
var $pDataObject;
/* Class creator */
function pStock($pChartObject,$pDataObject)
{
$this->pChartObject = $pChartObject;
$this->pDataObject = $pDataObject;
}
/* Draw a stock chart */
function drawStockChart($Format="")
{
$SerieOpen = isset($Format["SerieOpen"]) ? $Format["SerieOpen"] : "Open";
$SerieClose = isset($Format["SerieClose"]) ? $Format["SerieClose"] : "Close";
$SerieMin = isset($Format["SerieMin"]) ? $Format["SerieMin"] : "Min";
$SerieMax = isset($Format["SerieMax"]) ? $Format["SerieMax"] : "Max";
$LineWidth = isset($Format["LineWidth"]) ? $Format["LineWidth"] : 1;
$LineR = isset($Format["LineR"]) ? $Format["LineR"] : 0;
$LineG = isset($Format["LineG"]) ? $Format["LineG"] : 0;
$LineB = isset($Format["LineB"]) ? $Format["LineB"] : 0;
$LineAlpha = isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 100;
$ExtremityWidth = isset($Format["ExtremityWidth"]) ? $Format["ExtremityWidth"] : 1;
$ExtremityLength = isset($Format["ExtremityLength"]) ? $Format["ExtremityLength"] : 3;
$ExtremityR = isset($Format["ExtremityR"]) ? $Format["ExtremityR"] : 0;
$ExtremityG = isset($Format["ExtremityG"]) ? $Format["ExtremityG"] : 0;
$ExtremityB = isset($Format["ExtremityB"]) ? $Format["ExtremityB"] : 0;
$ExtremityAlpha = isset($Format["ExtremityAlpha"]) ? $Format["ExtremityAlpha"] : 100;
$BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 8;
$BoxUpR = isset($Format["BoxUpR"]) ? $Format["BoxUpR"] : 188;
$BoxUpG = isset($Format["BoxUpG"]) ? $Format["BoxUpG"] : 224;
$BoxUpB = isset($Format["BoxUpB"]) ? $Format["BoxUpB"] : 46;
$BoxUpAlpha = isset($Format["BoxUpAlpha"]) ? $Format["BoxUpAlpha"] : 100;
$BoxUpSurrounding = isset($Format["BoxUpSurrounding"]) ? $Format["BoxUpSurrounding"] : NULL;
$BoxUpBorderR = isset($Format["BoxUpBorderR"]) ? $Format["BoxUpBorderR"] : $BoxUpR-20;
$BoxUpBorderG = isset($Format["BoxUpBorderG"]) ? $Format["BoxUpBorderG"] : $BoxUpG-20;
$BoxUpBorderB = isset($Format["BoxUpBorderB"]) ? $Format["BoxUpBorderB"] : $BoxUpB-20;
$BoxUpBorderAlpha = isset($Format["BoxUpBorderAlpha"]) ? $Format["BoxUpBorderAlpha"] : 100;
$BoxDownR = isset($Format["BoxDownR"]) ? $Format["BoxDownR"] : 224;
$BoxDownG = isset($Format["BoxDownG"]) ? $Format["BoxDownG"] : 100;
$BoxDownB = isset($Format["BoxDownB"]) ? $Format["BoxDownB"] : 46;
$BoxDownAlpha = isset($Format["BoxDownAlpha"]) ? $Format["BoxDownAlpha"] : 100;
$BoxDownSurrounding= isset($Format["BoxDownSurrounding"]) ? $Format["BoxDownSurrounding"] : NULL;
$BoxDownBorderR = isset($Format["BoxDownBorderR"]) ? $Format["BoxDownBorderR"] : $BoxDownR-20;
$BoxDownBorderG = isset($Format["BoxDownBorderG"]) ? $Format["BoxDownBorderG"] : $BoxDownG-20;
$BoxDownBorderB = isset($Format["BoxDownBorderB"]) ? $Format["BoxDownBorderB"] : $BoxDownB-20;
$BoxDownBorderAlpha= isset($Format["BoxDownBorderAlpha"]) ? $Format["BoxDownBorderAlpha"] : 100;
$ShadowOnBoxesOnly = isset($Format["ShadowOnBoxesOnly"]) ? $Format["ShadowOnBoxesOnly"] : TRUE;
/* Data Processing */
$Data = $this->pDataObject->getData();
$Palette = $this->pDataObject->getPalette();
if ( $BoxUpSurrounding != NULL ) { $BoxUpBorderR = $BoxUpR + $BoxUpSurrounding; $BoxUpBorderG = $BoxUpG + $BoxUpSurrounding; $BoxUpBorderB = $BoxUpB + $BoxUpSurrounding; }
if ( $BoxDownSurrounding != NULL ) { $BoxDownBorderR = $BoxDownR + $BoxDownSurrounding; $BoxDownBorderG = $BoxDownG + $BoxDownSurrounding; $BoxDownBorderB = $BoxDownB + $BoxDownSurrounding; }
if ( $LineWidth != 1 ) { $LineOffset = $LineWidth / 2; }
$BoxOffset = $BoxWidth / 2;
$Data = $this->pChartObject->DataSet->getData();
list($XMargin,$XDivs) = $this->pChartObject->scaleGetXSettings();
if ( !isset($Data["Series"][$SerieOpen]) || !isset($Data["Series"][$SerieClose]) || !isset($Data["Series"][$SerieMin]) || !isset($Data["Series"][$SerieMax]) )
return(STOCK_MISSING_SERIE);
$Plots = "";
foreach($Data["Series"][$SerieOpen]["Data"] as $Key => $Value)
{
if ( isset($Data["Series"][$SerieClose]["Data"][$Key]) || isset($Data["Series"][$SerieMin]["Data"][$Key]) || isset($Data["Series"][$SerieMax]["Data"][$Key]) )
$Plots[] = array($Value,$Data["Series"][$SerieClose]["Data"][$Key],$Data["Series"][$SerieMin]["Data"][$Key],$Data["Series"][$SerieMax]["Data"][$Key]);
}
$AxisID = $Data["Series"][$SerieOpen]["Axis"];
$Mode = $Data["Axis"][$AxisID]["Display"];
$Format = $Data["Axis"][$AxisID]["Format"];
$Unit = $Data["Axis"][$AxisID]["Unit"];
$YZero = $this->pChartObject->scaleComputeY(0,array("AxisID"=>$AxisID));
$XStep = ($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1-$XMargin*2)/$XDivs;
$X = $this->pChartObject->GraphAreaX1 + $XMargin;
$Y = $this->pChartObject->GraphAreaY1 + $XMargin;
$LineSettings = array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha);
$ExtremitySettings = array("R"=>$ExtremityR,"G"=>$ExtremityG,"B"=>$ExtremityB,"Alpha"=>$ExtremityAlpha);
$BoxUpSettings = array("R"=>$BoxUpR,"G"=>$BoxUpG,"B"=>$BoxUpB,"Alpha"=>$BoxUpAlpha,"BorderR"=>$BoxUpBorderR,"BorderG"=>$BoxUpBorderG,"BorderB"=>$BoxUpBorderB,"BorderAlpha"=>$BoxUpBorderAlpha);
$BoxDownSettings = array("R"=>$BoxDownR,"G"=>$BoxDownG,"B"=>$BoxDownB,"Alpha"=>$BoxDownAlpha,"BorderR"=>$BoxDownBorderR,"BorderG"=>$BoxDownBorderG,"BorderB"=>$BoxDownBorderB,"BorderAlpha"=>$BoxDownBorderAlpha);
foreach($Plots as $Key =>$Points)
{
$PosArray = $this->pChartObject->scaleComputeY($Points,array("AxisID"=>$AxisID));
if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
{
if ( $YZero > $this->pChartObject->GraphAreaY2-1 ) { $YZero = $this->pChartObject->GraphAreaY2-1; }
if ( $YZero < $this->pChartObject->GraphAreaY1+1 ) { $YZero = $this->pChartObject->GraphAreaY1+1; }
if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1-$XMargin*2)/$XDivs; }
if ( $ShadowOnBoxesOnly ) { $RestoreShadow = $this->pChartObject->Shadow; $this->pChartObject->Shadow = FALSE; }
if ( $LineWidth == 1 )
$this->pChartObject->drawLine($X,$PosArray[2],$X,$PosArray[3],$LineSettings);
else
$this->pChartObject->drawFilledRectangle($X-$LineOffset,$PosArray[2],$X+$LineOffset,$PosArray[3],$LineSettings);
if ( $ExtremityWidth == 1 )
{
$this->pChartObject->drawLine($X-$ExtremityLength,$PosArray[2],$X+$ExtremityLength,$PosArray[2],$ExtremitySettings);
$this->pChartObject->drawLine($X-$ExtremityLength,$PosArray[3],$X+$ExtremityLength,$PosArray[3],$ExtremitySettings);
}
else
{
$this->pChartObject->drawFilledRectangle($X-$ExtremityLength,$PosArray[2],$X+$ExtremityLength,$PosArray[2]-$ExtremityWidth,$ExtremitySettings);
$this->pChartObject->drawFilledRectangle($X-$ExtremityLength,$PosArray[3],$X+$ExtremityLength,$PosArray[3]+$ExtremityWidth,$ExtremitySettings);
}
if ( $ShadowOnBoxesOnly ) { $this->pChartObject->Shadow = $RestoreShadow; }
if ( $PosArray[0] > $PosArray[1] )
$this->pChartObject->drawFilledRectangle($X-$BoxOffset,$PosArray[0],$X+$BoxOffset,$PosArray[1],$BoxUpSettings);
else
$this->pChartObject->drawFilledRectangle($X-$BoxOffset,$PosArray[0],$X+$BoxOffset,$PosArray[1],$BoxDownSettings);
$X = $X + $XStep;
}
elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
{
if ( $YZero > $this->pChartObject->GraphAreaX2-1 ) { $YZero = $this->pChartObject->GraphAreaX2-1; }
if ( $YZero < $this->pChartObject->GraphAreaX1+1 ) { $YZero = $this->pChartObject->GraphAreaX1+1; }
if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1-$XMargin*2)/$XDivs; }
if ( $LineWidth == 1 )
$this->pChartObject->drawLine($PosArray[2],$Y,$PosArray[3],$Y,$LineSettings);
else
$this->pChartObject->drawFilledRectangle($PosArray[2],$Y-$LineOffset,$PosArray[3],$Y+$LineOffset,$LineSettings);
if ( $ShadowOnBoxesOnly ) { $RestoreShadow = $this->pChartObject->Shadow; $this->pChartObject->Shadow = FALSE; }
if ( $ExtremityWidth == 1 )
{
$this->pChartObject->drawLine($PosArray[2],$Y-$ExtremityLength,$PosArray[2],$Y+$ExtremityLength,$ExtremitySettings);
$this->pChartObject->drawLine($PosArray[3],$Y-$ExtremityLength,$PosArray[3],$Y+$ExtremityLength,$ExtremitySettings);
}
else
{
$this->pChartObject->drawFilledRectangle($PosArray[2],$Y-$ExtremityLength,$PosArray[2]-$ExtremityWidth,$Y+$ExtremityLength,$ExtremitySettings);
$this->pChartObject->drawFilledRectangle($PosArray[3],$Y-$ExtremityLength,$PosArray[3]+$ExtremityWidth,$Y+$ExtremityLength,$ExtremitySettings);
}
if ( $ShadowOnBoxesOnly ) { $this->pChartObject->Shadow = $RestoreShadow; }
if ( $PosArray[0] < $PosArray[1] )
$this->pChartObject->drawFilledRectangle($PosArray[0],$Y-$BoxOffset,$PosArray[1],$Y+$BoxOffset,$BoxUpSettings);
else
$this->pChartObject->drawFilledRectangle($PosArray[0],$Y-$BoxOffset,$PosArray[1],$Y+$BoxOffset,$BoxDownSettings);
$Y = $Y + $XStep;
}
}
}
}
?>

View File

@ -0,0 +1,6 @@
185,106,154,100
216,137,184,100
156,192,137,100
216,243,201,100
253,232,215,100
255,255,255,100

View File

@ -0,0 +1,6 @@
109,152,171,100
0,39,94,100
254,183,41,100
168,177,184,100
255,255,255,100
0,0,0,100

View File

@ -0,0 +1,6 @@
242,245,237,100
255,194,0,100
255,91,0,100
184,0,40,100
132,0,46,100
74,192,242,100

View File

@ -0,0 +1,6 @@
155,225,251,100
197,239,253,100
189,32,49,100
35,31,32,100
255,255,255,100
0,98,149,100

View File

@ -0,0 +1,7 @@
239,210,121,100
149,203,233,100
2,71,105,100
175,215,117,100
44,87,0,100
222,157,127,100

View File

@ -0,0 +1,6 @@
25,78,132,100
59,107,156,100
31,36,42,100
55,65,74,100
96,187,34,100
242,186,187,100

View File

@ -0,0 +1,6 @@
117,113,22,100
174,188,33,100
217,219,86,100
0,71,127,100
76,136,190,100
141,195,233,100

View File

@ -0,0 +1,6 @@
146,123,81,100
168,145,102,100
128,195,28,100
188,221,90,100
255,121,0,100
251,179,107,100

View File

@ -0,0 +1,6 @@
253,184,19,100
246,139,31,100
241,112,34,100
98,194,204,100
228,246,248,100
238,246,108,100