From: hickert Date: Thu, 12 Aug 2010 09:16:09 +0000 (+0000) Subject: Added pChart classes and GOsa mapping class to enable auto-include X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a3865a0133a60c9cc79f5ed5e8cc66b0cf86ee71;p=gosa.git Added pChart classes and GOsa mapping class to enable auto-include git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19382 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_pChartInclude.inc b/gosa-core/include/class_pChartInclude.inc new file mode 100644 index 000000000..90f06deba --- /dev/null +++ b/gosa-core/include/class_pChartInclude.inc @@ -0,0 +1,8 @@ + diff --git a/gosa-core/include/pChart/CO2.csv b/gosa-core/include/pChart/CO2.csv new file mode 100644 index 000000000..6bbe3d00f --- /dev/null +++ b/gosa-core/include/pChart/CO2.csv @@ -0,0 +1,37 @@ +Year,Jan.,Feb.,March,April,May,June,July,Aug.,Sept.,Oct.,Nov.,Dec.,Annual +1967,322.33,322.5,323.04,324.42,325,324.09,322.55,320.92,319.26,319.39,320.72,321.96,322.18 +1968,322.57,323.15,323.89,325.02,325.57,325.36,324.14,322.11,320.33,320.25,321.32,322.9,323.05 +1969,324,324.42,325.64,326.66,327.38,326.7,325.89,323.67,322.38,321.78,322.85,324.12,324.62 +1970,325.06,325.98,326.93,328.13,328.07,327.66,326.35,324.69,323.1,323.07,324.01,325.13,325.68 +1971,326.17,326.68,327.18,327.78,328.92,328.57,327.37,325.43,323.36,323.56,324.8,326.01,326.32 +1972,326.77,327.63,327.75,329.72,330.07,329.09,328.05,326.32,324.84,325.2,326.5,327.55,327.46 +1973,328.54,329.56,330.3,331.5,332.48,332.07,330.87,329.31,327.51,327.18,328.16,328.64,329.68 +1974,329.35,330.71,331.48,332.65,333.09,332.25,331.18,329.4,327.44,327.37,328.46,329.58,330.25 +1975,330.4,331.41,332.04,333.31,333.96,333.59,331.91,330.06,328.56,328.34,329.49,330.76,331.15 +1976,331.74,332.56,333.5,334.58,334.87,334.34,333.05,330.94,329.3,328.94,330.31,331.68,332.15 +1977,332.92,333.42,334.7,336.07,336.74,336.27,334.93,332.75,331.58,331.16,332.4,333.85,333.9 +1978,334.97,335.39,336.64,337.76,338.01,337.89,336.54,334.68,332.76,332.54,333.92,334.95,335.5 +1979,336.23,336.76,337.96,338.89,339.47,339.29,337.73,336.09,333.91,333.86,335.29,336.73,336.85 +1980,338.01,338.36,340.08,340.77,341.46,341.17,339.56,337.6,335.88,336.01,337.1,338.21,338.69 +1981,339.23,340.47,341.38,342.51,342.91,342.25,340.49,338.43,336.69,336.85,338.36,339.61,339.93 +1982,340.75,341.61,342.7,343.56,344.13,343.35,342.06,339.82,337.97,337.86,339.26,340.49,341.13 +1983,341.37,342.52,343.1,344.94,345.75,345.32,343.99,342.39,339.86,339.99,341.16,342.99,342.78 +1984,343.7,344.51,345.28,347.08,347.43,346.79,345.4,343.28,341.07,341.35,342.98,344.22,344.42 +1985,344.97,346,347.43,348.35,348.93,348.25,346.56,344.69,343.09,342.8,344.24,345.56,345.9 +1986,346.29,346.96,347.86,349.55,350.21,349.54,347.94,345.91,344.86,344.17,345.66,346.9,347.15 +1987,348.02,348.47,349.42,350.99,351.84,351.25,349.52,348.1,346.44,346.36,347.81,348.96,348.93 +1988,350.43,351.72,352.22,353.59,354.22,353.79,352.39,350.44,348.72,348.88,350.07,351.34,351.48 +1989,352.76,353.07,353.68,355.42,355.67,355.13,353.9,351.67,349.8,349.99,351.3,352.53,352.91 +1990,353.66,354.7,355.39,356.2,357.16,356.22,354.82,352.91,350.96,351.18,352.83,354.21,354.19 +1991,354.72,355.75,357.16,358.6,359.34,358.24,356.17,354.03,352.16,352.21,353.75,354.99,355.59 +1992,355.98,356.72,357.81,359.15,359.66,359.25,357.03,355,353.01,353.31,354.16,355.4,356.37 +1993,356.7,357.16,358.38,359.46,360.28,359.6,357.57,355.52,353.7,353.98,355.33,356.8,357.04 +1994,358.36,358.91,359.97,361.26,361.68,360.95,359.55,357.49,355.84,355.99,357.58,359.04,358.88 +1995,359.96,361,361.64,363.45,363.79,363.26,361.9,359.46,358.06,357.75,359.56,360.7,360.88 +1996,362.05,363.25,364.03,364.72,365.41,364.97,363.65,361.49,359.46,359.6,360.76,362.33,362.64 +1997,363.18,364,364.57,366.35,366.79,365.62,364.47,362.51,360.19,360.77,362.43,364.28,363.76 +1998,365.32,366.15,367.31,368.61,369.3,368.87,367.64,365.77,363.9,364.23,365.46,366.97,366.63 +1999,368.15,368.86,369.58,371.12,370.97,370.33,369.25,366.91,364.6,365.09,366.63,367.96,368.29 +2000,369.08,369.4,370.45,371.59,371.75,371.62,370.04,368.04,366.54,366.63,368.2,369.43,369.4 +2001,370.17,371.39,372,372.75,373.88,373.17,371.48,369.42,367.83,367.96,369.55,371.1,370.89 +2002,372.29,372.94,373.38,374.71,375.4,375.26,373.87,371.35,370.57,370.1,371.93,373.63,372.95 diff --git a/gosa-core/include/pChart/Example1.php b/gosa-core/include/pChart/Example1.php new file mode 100644 index 000000000..bc2304343 --- /dev/null +++ b/gosa-core/include/pChart/Example1.php @@ -0,0 +1,45 @@ +ImportFromCSV("Sample/bulkdata.csv",",",array(1,2,3),FALSE,0); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + $DataSet->SetSerieName("March","Serie3"); + $DataSet->SetYAxisName("Average age"); + $DataSet->SetYAxisUnit("µs"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(70,30,680,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the line graph + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(75,35,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(60,22,"example 1",50,50,50,585); + $Test->Render("example1.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example10.php b/gosa-core/include/pChart/Example10.php new file mode 100644 index 000000000..7e48d94ff --- /dev/null +++ b/gosa-core/include/pChart/Example10.php @@ -0,0 +1,34 @@ +AddPoint(array(10,2,3,5,3),"Serie1"); + $DataSet->AddPoint(array("January","February","March","April","May"),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie("Serie2"); + + // Initialise the graph + $Test = new pChart(420,250); + $Test->drawFilledRoundedRectangle(7,7,413,243,5,240,240,240); + $Test->drawRoundedRectangle(5,5,415,245,5,230,230,230); + $Test->createColorGradientPalette(195,204,56,223,110,41,5); + + // Draw the pie chart + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->AntialiasQuality = 0; + $Test->drawPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),180,130,110,PIE_PERCENTAGE_LABEL,FALSE,50,20,5); + $Test->drawPieLegend(330,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250); + + // Write the title + $Test->setFontProperties("Fonts/MankSans.ttf",10); + $Test->drawTitle(10,20,"Sales per month",100,100,100); + + $Test->Render("example10.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example11.php b/gosa-core/include/pChart/Example11.php new file mode 100644 index 000000000..be15e327c --- /dev/null +++ b/gosa-core/include/pChart/Example11.php @@ -0,0 +1,50 @@ +AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1"); + $DataSet->AddPoint(array(1,4,2,6,2,3,0,1,5,1,2,4,5,2,1,0,6,4,2),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + + // Cache definition + $Cache = new pCache(); + $Cache->GetFromCache("Graph1",$DataSet->GetData()); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(50,30,585,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the cubic curve graph + $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription()); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(50,22,"Example 1",50,50,50,585); + + // Render the graph + $Cache->WriteToCache("Graph1",$DataSet->GetData(),$Test); + $Test->Render("example1.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example12.php b/gosa-core/include/pChart/Example12.php new file mode 100644 index 000000000..dc003ab4a --- /dev/null +++ b/gosa-core/include/pChart/Example12.php @@ -0,0 +1,45 @@ +AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4),"Serie1"); + $DataSet->AddPoint(array(3,3,-4,1,-2,2,1,0,-1,6,3),"Serie2"); + $DataSet->AddPoint(array(4,1,2,-1,-4,-2,3,2,1,2,2),"Serie3"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + $DataSet->SetSerieName("March","Serie3"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(50,30,680,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the bar graph + $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE,80); + + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(596,150,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(50,22,"Example 12",50,50,50,585); + $Test->Render("example12.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example13.php b/gosa-core/include/pChart/Example13.php new file mode 100644 index 000000000..28638c81a --- /dev/null +++ b/gosa-core/include/pChart/Example13.php @@ -0,0 +1,32 @@ +AddPoint(array(10,2,3,5,3),"Serie1"); + $DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May"),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie("Serie2"); + + // Initialise the graph + $Test = new pChart(300,200); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240); + $Test->drawRoundedRectangle(5,5,295,195,5,230,230,230); + + // Draw the pie chart + $Test->AntialiasQuality = 0; + $Test->setShadowProperties(2,2,200,200,200); + $Test->drawFlatPieGraphWithShadow($DataSet->GetData(),$DataSet->GetDataDescription(),120,100,60,PIE_PERCENTAGE,8); + $Test->clearShadow(); + + $Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250); + + $Test->Render("example13.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example14.php b/gosa-core/include/pChart/Example14.php new file mode 100644 index 000000000..1b7225ea0 --- /dev/null +++ b/gosa-core/include/pChart/Example14.php @@ -0,0 +1,33 @@ +AddPoint(array(10,2,3,5,3),"Serie1"); + $DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May"),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie("Serie2"); + + // Initialise the graph + $Test = new pChart(300,200); + $Test->loadColorPalette("Sample/softtones.txt"); + $Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240); + $Test->drawRoundedRectangle(5,5,295,195,5,230,230,230); + + // This will draw a shadow under the pie chart + $Test->drawFilledCircle(122,102,70,200,200,200); + + // Draw the pie chart + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->AntialiasQuality = 0; + $Test->drawBasicPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),120,100,70,PIE_PERCENTAGE,255,255,218); + $Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250); + + $Test->Render("example14.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example15.php b/gosa-core/include/pChart/Example15.php new file mode 100644 index 000000000..57b52ce33 --- /dev/null +++ b/gosa-core/include/pChart/Example15.php @@ -0,0 +1,68 @@ +AddPoint(array(10,9.4,7.7,5,1.7,-1.7,-5,-7.7,-9.4,-10,-9.4,-7.7,-5,-1.8,1.7),"Serie1"); + $DataSet->AddPoint(array(0,3.4,6.4,8.7,9.8,9.8,8.7,6.4,3.4,0,-3.4,-6.4,-8.6,-9.8,-9.9),"Serie2"); + $DataSet->AddPoint(array(7.1,9.1,10,9.7,8.2,5.7,2.6,-0.9,-4.2,-7.1,-9.1,-10,-9.7,-8.2,-5.8),"Serie3"); + $DataSet->AddPoint(array("Jan","Jan","Jan","Feb","Feb","Feb","Mar","Mar","Mar","Apr","Apr","Apr","May","May","May"),"Serie4"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie("Serie4"); + $DataSet->SetSerieName("Max Average","Serie1"); + $DataSet->SetSerieName("Min Average","Serie2"); + $DataSet->SetSerieName("Temperature","Serie3"); + $DataSet->SetYAxisName("Temperature"); + $DataSet->SetXAxisName("Month of the year"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->reportWarnings("GD"); + $Test->setFixedScale(-12,12,5); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(65,30,570,185); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE,3); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the area + $DataSet->RemoveSerie("Serie4"); + $Test->drawArea($DataSet->GetData(),"Serie1","Serie2",239,238,227,50); + $DataSet->RemoveSerie("Serie3"); + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + + // Draw the line graph + $Test->setLineStyle(1,6); + $DataSet->RemoveAllSeries(); + $DataSet->AddSerie("Serie3"); + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + + // Write values on Serie3 + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->writeValues($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie3"); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(590,90,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(60,22,"example 15",50,50,50,585); + + // Add an image + $Test->drawFromPNG("Sample/logo.png",584,35); + + // Render the chart + $Test->Render("example15.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example16.php b/gosa-core/include/pChart/Example16.php new file mode 100644 index 000000000..8c69858e4 --- /dev/null +++ b/gosa-core/include/pChart/Example16.php @@ -0,0 +1,42 @@ +ImportFromCSV("Sample/CO2.csv",",",array(1,2,3,4),TRUE,0); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetYAxisName("CO2 concentrations"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->reportWarnings("GD"); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(60,30,680,180); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,90,2); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the line graph + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(70,40,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(60,22,"CO2 concentrations at Mauna Loa",50,50,50,585); + $Test->Render("example16.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example17.php b/gosa-core/include/pChart/Example17.php new file mode 100644 index 000000000..5b769e990 --- /dev/null +++ b/gosa-core/include/pChart/Example17.php @@ -0,0 +1,48 @@ +AddPoint(array(100,320,200,10,43),"Serie1"); + $DataSet->AddPoint(array(23,432,43,153,234),"Serie2"); + $DataSet->AddPoint(array(1217541600,1217628000,1217714400,1217800800,1217887200),"Serie3"); + $DataSet->AddSerie("Serie1"); + $DataSet->AddSerie("Serie2"); + $DataSet->SetAbsciseLabelSerie("Serie3"); + $DataSet->SetSerieName("Incoming","Serie1"); + $DataSet->SetSerieName("Outgoing","Serie2"); + $DataSet->SetYAxisName("Call duration"); + $DataSet->SetYAxisFormat("time"); + $DataSet->SetXAxisFormat("date"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(85,30,650,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the line graph + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(90,35,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(60,22,"example 17",50,50,50,585); + $Test->Render("example17.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example18.php b/gosa-core/include/pChart/Example18.php new file mode 100644 index 000000000..572889866 --- /dev/null +++ b/gosa-core/include/pChart/Example18.php @@ -0,0 +1,55 @@ +AddPoint(array(2,5,7,"","",5,6,4,8,4,"",2,5,6,4,5,6,7,6),"Serie1"); + $DataSet->AddPoint(array(-1,-3,-1,-2,-4,-1,"",-4,-5,-3,-2,-2,-3,-3,-5,-4,-3,-1,""),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("Raw #1","Serie1"); + $DataSet->SetSerieName("Raw #2","Serie2"); + $DataSet->SetYAxisName("Response time"); + $DataSet->SetXAxisName("Sample #ID"); + + //print_r($DataSet->GetData()); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(55,30,585,185); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the line graph + $DataSet->RemoveSerie("Serie2"); + $Test->drawFilledLineGraph($DataSet->GetData(),$DataSet->GetDataDescription(),60,TRUE); + + // Draw the curve graph + $DataSet->RemoveSerie("Serie1"); + $DataSet->AddSerie("Serie2"); + $Test->setShadowProperties(2,2,200,200,200,50); + $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + $Test->clearShadow(); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(50,22,"Example 18",50,50,50,585); + $Test->Render("example18.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example19.php b/gosa-core/include/pChart/Example19.php new file mode 100644 index 000000000..cc430b5ed --- /dev/null +++ b/gosa-core/include/pChart/Example19.php @@ -0,0 +1,44 @@ +AddPoint(array(10,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1"); + $DataSet->AddPoint(array(1,4,2,6,2,3,0,1,-5,1,2,4,5,2,1,0,6,4,30),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetXAxisName("Samples"); + $DataSet->SetYAxisName("Temperature"); + $DataSet->SetSerieName("January","Serie1"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->reportWarnings("GD"); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(60,30,585,185); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the cubic curve graph + $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription()); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(50,22,"Example 19",50,50,50,585); + $Test->Render("example19.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example2.php b/gosa-core/include/pChart/Example2.php new file mode 100644 index 000000000..5aa0605a9 --- /dev/null +++ b/gosa-core/include/pChart/Example2.php @@ -0,0 +1,43 @@ +AddPoint(array(1,4,3,4,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1"); + $DataSet->AddPoint(array(1,4,2,6,2,3,0,1,5,1,2,4,5,2,1,0,6,4,2),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFixedScale(-2,8); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(50,30,585,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the cubic curve graph + $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription()); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(50,22,"Example 2",50,50,50,585); + $Test->Render("example2.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example20.php b/gosa-core/include/pChart/Example20.php new file mode 100644 index 000000000..5f263219b --- /dev/null +++ b/gosa-core/include/pChart/Example20.php @@ -0,0 +1,44 @@ +AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4),"Serie1"); + $DataSet->AddPoint(array(3,3,-4,1,-2,2,1,0,-1,6,3),"Serie2"); + $DataSet->AddPoint(array(4,1,2,-1,-4,-2,3,2,1,2,2),"Serie3"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + $DataSet->SetSerieName("March","Serie3"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(50,30,680,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_ADDALL,150,150,150,TRUE,0,2,TRUE); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the bar graph + $Test->drawStackedBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),100); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(596,150,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(50,22,"Example 20",50,50,50,585); + $Test->Render("example20.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example21.php b/gosa-core/include/pChart/Example21.php new file mode 100644 index 000000000..a0c12ec30 --- /dev/null +++ b/gosa-core/include/pChart/Example21.php @@ -0,0 +1,53 @@ +AddPoint(array(9,9,9,10,10,11,12,14,16,17,18,18,19,19,18,15,12,10,9),"Serie1"); + $DataSet->AddPoint(array(10,11,11,12,12,13,14,15,17,19,22,24,23,23,22,20,18,16,14),"Serie2"); + $DataSet->AddPoint(array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22),"Serie3"); + $DataSet->AddAllSeries(); + $DataSet->RemoveSerie("Serie3"); + $DataSet->SetAbsciseLabelSerie("Serie3"); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + $DataSet->SetYAxisName("Temperature"); + $DataSet->SetYAxisUnit("°C"); + $DataSet->SetXAxisUnit("h"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->drawGraphAreaGradient(132,153,172,50,TARGET_BACKGROUND); + + // Graph area setup + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(60,20,585,180); + $Test->drawGraphArea(213,217,221,FALSE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,2); + $Test->drawGraphAreaGradient(162,183,202,50); + $Test->drawGrid(4,TRUE,230,230,230,20); + + // Draw the line chart + $Test->setShadowProperties(3,3,0,0,0,30,4); + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->clearShadow(); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),4,2,-1,-1,-1,TRUE); + + // Draw the legend + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(605,142,$DataSet->GetDataDescription(),236,238,240,52,58,82); + + // Draw the title + $Title = "Average Temperatures during the first months of 2008 "; + $Test->drawTextBox(0,210,700,230,$Title,0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30); + + // Render the picture + $Test->addBorder(2); + $Test->Render("example21.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example22.php b/gosa-core/include/pChart/Example22.php new file mode 100644 index 000000000..ea2a73515 --- /dev/null +++ b/gosa-core/include/pChart/Example22.php @@ -0,0 +1,50 @@ +AddPoint(array(60,70,90,110,100,90),"Serie1"); + $DataSet->AddPoint(array(40,50,60,80,70,60),"Serie2"); + $DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May","Jun"),"Serie3"); + $DataSet->AddSerie("Serie1"); + $DataSet->AddSerie("Serie2"); + $DataSet->SetAbsciseLabelSerie("Serie3"); + $DataSet->SetSerieName("Company A","Serie1"); + $DataSet->SetSerieName("Company B","Serie2"); + $DataSet->SetYAxisName("Product sales"); + $DataSet->SetYAxisUnit("k"); + $DataSet->SetSerieSymbol("Serie1","Sample/Point_Asterisk.gif"); + $DataSet->SetSerieSymbol("Serie2","Sample/Point_Cd.gif"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(65,30,650,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the title + $Test->setFontProperties("Fonts/pf_arma_five.ttf",6); + $Title = "Comparative product sales for company A & B "; + $Test->drawTextBox(65,30,650,45,$Title,0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30); + + // Draw the line graph + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + + // Draw the legend + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(80,60,$DataSet->GetDataDescription(),255,255,255); + + // Render the chart + $Test->Render("example22.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example23.php b/gosa-core/include/pChart/Example23.php new file mode 100644 index 000000000..778ebbb97 --- /dev/null +++ b/gosa-core/include/pChart/Example23.php @@ -0,0 +1,49 @@ +AddPoint(array(9,9,9,10,10,11,12,14,16,17,18,18,19,19,18,15,12,10,9),"Serie1"); + $DataSet->AddPoint(array(10,11,11,12,12,13,14,15,17,19,22,24,23,23,22,20,18,16,14),"Serie2"); + $DataSet->AddPoint(array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22),"Serie3"); + $DataSet->AddAllSeries(); + $DataSet->RemoveSerie("Serie3"); + $DataSet->SetAbsciseLabelSerie("Serie3"); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + $DataSet->SetYAxisName("Temperature"); + $DataSet->SetYAxisUnit("°C"); + $DataSet->SetXAxisUnit("h"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->drawGraphAreaGradient(132,173,131,50,TARGET_BACKGROUND); + + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(120,20,675,190); + $Test->drawGraphArea(213,217,221,FALSE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_ADDALL,213,217,221,TRUE,0,2,TRUE); + $Test->drawGraphAreaGradient(163,203,167,50); + $Test->drawGrid(4,TRUE,230,230,230,20); + + // Draw the bar chart + $Test->drawStackedBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),70); + + // Draw the title + $Title = " Average Temperatures during\r\n the first months of 2008 "; + $Test->drawTextBox(0,0,50,230,$Title,90,255,255,255,ALIGN_BOTTOM_CENTER,TRUE,0,0,0,30); + + // Draw the legend + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(610,10,$DataSet->GetDataDescription(),236,238,240,52,58,82); + + // Render the picture + $Test->addBorder(2); + $Test->Render("example23.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example24.php b/gosa-core/include/pChart/Example24.php new file mode 100644 index 000000000..f8946904b --- /dev/null +++ b/gosa-core/include/pChart/Example24.php @@ -0,0 +1,53 @@ +AddPoint(cos($i*3.14/180)*80+$i,"Serie1"); + $DataSet->AddPoint(sin($i*3.14/180)*80+$i,"Serie2"); + } + + $DataSet->SetSerieName("Trigonometric function","Serie1"); + $DataSet->AddSerie("Serie1"); + $DataSet->AddSerie("Serie2"); + $DataSet->SetXAxisName("X Axis"); + $DataSet->SetYAxisName("Y Axis"); + + // Initialise the graph + $Test = new pChart(300,300); + $Test->drawGraphAreaGradient(0,0,0,-100,TARGET_BACKGROUND); + + // Prepare the graph area + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(55,30,270,230); + $Test->drawXYScale($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie2",213,217,221,TRUE,45); + $Test->drawGraphArea(213,217,221,FALSE); + $Test->drawGraphAreaGradient(30,30,30,-50); + $Test->drawGrid(4,TRUE,230,230,230,20); + + // Draw the chart + $Test->setShadowProperties(2,2,0,0,0,60,4); + $Test->drawXYGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie2",0); + $Test->clearShadow(); + + // Draw the title + $Title = "Drawing X versus Y charts trigonometric functions "; + $Test->drawTextBox(0,280,300,300,$Title,0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30); + + // Draw the legend + $Test->setFontProperties("Fonts/pf_arma_five.ttf",6); + $DataSet->RemoveSerie("Serie2"); + $Test->drawLegend(160,5,$DataSet->GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE); + + $Test->Render("example24.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example25.php b/gosa-core/include/pChart/Example25.php new file mode 100644 index 000000000..1d991ba11 --- /dev/null +++ b/gosa-core/include/pChart/Example25.php @@ -0,0 +1,55 @@ +AddPoint(array(9,9,9,10,10,11,12,14,16,17,18,18,19,19,18,15,12,10,9),"Serie1"); + $DataSet->AddPoint(array(10,11,11,12,12,13,14,15,17,19,22,24,23,23,22,20,18,16,14),"Serie2"); + $DataSet->AddPoint(array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22),"Serie3"); + $DataSet->AddAllSeries(); + $DataSet->RemoveSerie("Serie3"); + $DataSet->SetAbsciseLabelSerie("Serie3"); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + $DataSet->SetYAxisName("Temperature"); + $DataSet->SetYAxisUnit("°C"); + $DataSet->SetXAxisUnit("h"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->drawGraphAreaGradient(90,90,90,90,TARGET_BACKGROUND); + $Test->setFixedScale(0,40,4); + + // Graph area setup + $Test->setFontProperties("Fonts/pf_arma_five.ttf",6); + $Test->setGraphArea(60,40,680,200); + $Test->drawGraphArea(200,200,200,FALSE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,200,200,200,TRUE,0,2); + $Test->drawGraphAreaGradient(40,40,40,-50); + $Test->drawGrid(4,TRUE,230,230,230,10); + + // Draw the line chart + $Test->setShadowProperties(3,3,0,0,0,30,4); + $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->clearShadow(); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,0,-1,-1,-1,TRUE); + + // Write the title + $Test->setFontProperties("Fonts/MankSans.ttf",18); + $Test->setShadowProperties(1,1,0,0,0); + $Test->drawTitle(0,0,"Average temperatures",255,255,255,700,30,TRUE); + $Test->clearShadow(); + + // Draw the legend + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(610,5,$DataSet->GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE); + + // Render the picture + $Test->Render("example25.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example26.php b/gosa-core/include/pChart/Example26.php new file mode 100644 index 000000000..320a2ec7d --- /dev/null +++ b/gosa-core/include/pChart/Example26.php @@ -0,0 +1,69 @@ +AddPoint(array(110,101,118,108,110,106,104),"Serie1"); + $DataSet->AddPoint(array(700,2705,2041,1712,2051,846,903),"Serie2"); + $DataSet->AddPoint(array("03 Oct","02 Oct","01 Oct","30 Sep","29 Sep","28 Sep","27 Sep"),"Serie3"); + $DataSet->AddSerie("Serie1"); + $DataSet->SetAbsciseLabelSerie("Serie3"); + $DataSet->SetSerieName("SourceForge Rank","Serie1"); + $DataSet->SetSerieName("Web Hits","Serie2"); + + // Initialise the graph + $Test = new pChart(660,230); + $Test->drawGraphAreaGradient(90,90,90,90,TARGET_BACKGROUND); + + // Prepare the graph area + $Test->setFontProperties("fonts/tahoma.ttf",8); + $Test->setGraphArea(60,40,595,190); + + // Initialise graph area + $Test->setFontProperties("fonts/tahoma.ttf",8); + + // Draw the SourceForge Rank graph + $DataSet->SetYAxisName("Sourceforge Rank"); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0); + $Test->drawGraphAreaGradient(40,40,40,-50); + $Test->drawGrid(4,TRUE,230,230,230,10); + $Test->setShadowProperties(3,3,0,0,0,30,4); + $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->clearShadow(); + $Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription(),.1,30); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + + // Clear the scale + $Test->clearScale(); + + // Draw the 2nd graph + $DataSet->RemoveSerie("Serie1"); + $DataSet->AddSerie("Serie2"); + $DataSet->SetYAxisName("Web Hits"); + $Test->drawRightScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0); + $Test->drawGrid(4,TRUE,230,230,230,10); + $Test->setShadowProperties(3,3,0,0,0,30,4); + $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->clearShadow(); + $Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription(),.1,30); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + + // Write the legend (box less) + $Test->setFontProperties("fonts/tahoma.ttf",8); + $Test->drawLegend(530,5,$DataSet->GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE); + + // Write the title + $Test->setFontProperties("fonts/MankSans.ttf",18); + $Test->setShadowProperties(1,1,0,0,0); + $Test->drawTitle(0,0,"SourceForge ranking summary",255,255,255,660,30,TRUE); + $Test->clearShadow(); + + // Render the picture + $Test->Render("example26.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example3.php b/gosa-core/include/pChart/Example3.php new file mode 100644 index 000000000..0677be22a --- /dev/null +++ b/gosa-core/include/pChart/Example3.php @@ -0,0 +1,42 @@ +AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4,-3,2,-3,3,5,1,0,7),"Serie1"); + $DataSet->AddPoint(array(0,3,-4,1,-2,2,1,0,-1,6,3,-4,1,-4,2,4,0,-1,6),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(50,30,585,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the bar graph + $Test->drawOverlayBarGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(50,22,"Example 3",50,50,50,585); + $Test->Render("example3.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example4.php b/gosa-core/include/pChart/Example4.php new file mode 100644 index 000000000..278cd2696 --- /dev/null +++ b/gosa-core/include/pChart/Example4.php @@ -0,0 +1,45 @@ +ImportFromCSV("Sample/datawithtitle.csv",",",array(1,2,3),TRUE,0); + $DataSet->AddSerie("Serie2"); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->removeSerieName("Serie1"); + $DataSet->removeSerieName("Serie3"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(60,30,680,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the area + $Test->drawArea($DataSet->GetData(),"Serie1","Serie3",239,238,227,50); + + // Draw the line graph + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(65,35,$DataSet->GetDataDescription(),250,250,250); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(60,22,"Example 4",50,50,50,585); + $Test->Render("example4.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example5.php b/gosa-core/include/pChart/Example5.php new file mode 100644 index 000000000..d643b5af8 --- /dev/null +++ b/gosa-core/include/pChart/Example5.php @@ -0,0 +1,42 @@ +AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4,-3,2,-3,3,5,1,0,7),"Serie1"); + $DataSet->AddPoint(array(2,5,7,5,1,5,6,4,8,4,0,2,5,6,4,5,6,7,6),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(50,30,585,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the limit graph + $Test->drawLimitsGraph($DataSet->GetData(),$DataSet->GetDataDescription(),180,180,180); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(50,22,"Example 5",50,50,50,585); + $Test->Render("example5.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example6.php b/gosa-core/include/pChart/Example6.php new file mode 100644 index 000000000..689f29798 --- /dev/null +++ b/gosa-core/include/pChart/Example6.php @@ -0,0 +1,39 @@ +ImportFromCSV("Sample/datawithtitle.csv",",",array(1,2,3),TRUE,0); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(60,30,680,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the filled line graph + $Test->drawFilledLineGraph($DataSet->GetData(),$DataSet->GetDataDescription(),50,TRUE); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(65,35,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(60,22,"Example 6",50,50,50,585); + $Test->Render("example6.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example7.php b/gosa-core/include/pChart/Example7.php new file mode 100644 index 000000000..d4e05ed7a --- /dev/null +++ b/gosa-core/include/pChart/Example7.php @@ -0,0 +1,42 @@ +AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1"); + $DataSet->AddPoint(array(1,4,2,6,2,3,0,1,5,1,2,4,5,2,1,0,6,4,2),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(50,30,585,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the cubic curve graph + $Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription(),.1,50); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(50,22,"Example 7",50,50,50,585); + $Test->Render("example7.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example8.php b/gosa-core/include/pChart/Example8.php new file mode 100644 index 000000000..f6cb98f4d --- /dev/null +++ b/gosa-core/include/pChart/Example8.php @@ -0,0 +1,41 @@ +AddPoint(array("Memory","Disk","Network","Slots","CPU"),"Label"); + $DataSet->AddPoint(array(1,2,3,4,3),"Serie1"); + $DataSet->AddPoint(array(1,4,2,6,2),"Serie2"); + $DataSet->AddSerie("Serie1"); + $DataSet->AddSerie("Serie2"); + $DataSet->SetAbsciseLabelSerie("Label"); + + + $DataSet->SetSerieName("Reference","Serie1"); + $DataSet->SetSerieName("Tested computer","Serie2"); + + // Initialise the graph + $Test = new pChart(400,400); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawFilledRoundedRectangle(7,7,393,393,5,240,240,240); + $Test->drawRoundedRectangle(5,5,395,395,5,230,230,230); + $Test->setGraphArea(30,30,370,370); + $Test->drawFilledRoundedRectangle(30,30,370,370,5,255,255,255); + $Test->drawRoundedRectangle(30,30,370,370,5,220,220,220); + + // Draw the radar graph + $Test->drawRadarAxis($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE,20,120,120,120,230,230,230); + $Test->drawFilledRadar($DataSet->GetData(),$DataSet->GetDataDescription(),50,20); + + // Finish the graph + $Test->drawLegend(15,15,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(0,22,"Example 8",50,50,50,400); + $Test->Render("example8.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Example9.php b/gosa-core/include/pChart/Example9.php new file mode 100644 index 000000000..aa2a6cc58 --- /dev/null +++ b/gosa-core/include/pChart/Example9.php @@ -0,0 +1,49 @@ +AddPoint(array(0,70,70,0,0,70,70,0,0,70),"Serie1"); + $DataSet->AddPoint(array(0.5,2,4.5,8,12.5,18,24.5,32,40.5,50),"Serie2"); + + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("January","Serie1"); + $DataSet->SetSerieName("February","Serie2"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(50,30,585,200); + $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the line graph + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + + // Set labels + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setLabel($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","2","Daily incomes",221,230,174); + $Test->setLabel($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie2","6","Production break",239,233,195); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(50,22,"Example 9",50,50,50,585); + $Test->Render("example9.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/GeosansLight.ttf b/gosa-core/include/pChart/GeosansLight.ttf new file mode 100644 index 000000000..055932aac Binary files /dev/null and b/gosa-core/include/pChart/GeosansLight.ttf differ diff --git a/gosa-core/include/pChart/HomePage3.php b/gosa-core/include/pChart/HomePage3.php new file mode 100644 index 000000000..e6b0fca9c --- /dev/null +++ b/gosa-core/include/pChart/HomePage3.php @@ -0,0 +1,70 @@ +AddPoint(array(1,2,5),"Serie1"); + $DataSet->AddPoint(array(3,2,2),"Serie2"); + $DataSet->AddPoint(array(3,4,1),"Serie3"); + $DataSet->AddPoint(array("A#~1","A#~2","A#~3"),"Labels"); + $DataSet->AddAllSeries(); + $DataSet->RemoveSerie("Labels"); + $DataSet->SetAbsciseLabelSerie("Labels"); + $DataSet->SetSerieName("Alpha","Serie1"); + $DataSet->SetSerieName("Beta","Serie2"); + $DataSet->SetSerieName("Gama","Serie3"); + $DataSet->SetXAxisName("Samples IDs"); + $DataSet->SetYAxisName("Test Marker"); + $DataSet->SetYAxisUnit("µm"); + + // Initialise the graph + $Test = new pChart(380,400); + $Test->drawGraphAreaGradient(90,90,90,90,TARGET_BACKGROUND); + + // Graph area setup + $Test->setFontProperties("Fonts/pf_arma_five.ttf",6); + $Test->setGraphArea(110,180,350,360); + $Test->drawGraphArea(213,217,221,FALSE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_ADDALLSTART0,213,217,221,TRUE,0,2,TRUE); + $Test->drawGraphAreaGradient(40,40,40,-50); + $Test->drawGrid(4,TRUE,230,230,230,5); + + // Draw the title + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Title = " Average growth size for selected\r\n DNA samples "; + $Test->setLineStyle(2); + $Test->drawLine(51,-2,51,402,0,0,0); + $Test->setLineStyle(1); + $Test->drawTextBox(0,0,50,400,$Title,90,255,255,255,ALIGN_BOTTOM_CENTER,TRUE,0,0,0,30); + $Test->setFontProperties("Fonts/pf_arma_five.ttf",6); + + // Draw the bar graph + $Test->drawStackedBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),70); + + // Second chart + $DataSet->SetXAxisName(""); + $Test->clearScale(); + $Test->setGraphArea(110,20,350,140); + $Test->drawGraphArea(213,217,221,FALSE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,213,217,221,TRUE,0,2); + $Test->drawGraphAreaGradient(40,40,40,-50); + $Test->drawGrid(4,TRUE,230,230,230,5); + + // Draw the line chart + $Test->setShadowProperties(0,3,0,0,0,30,4); + $Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription(),.1,40); + $Test->clearShadow(); + + // Write the legend + $Test->drawLegend(-2,3,$DataSet->GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE); + + // Finish the graph + $Test->addBorder(1); + $Test->Render("HomePage2.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/MankSans.ttf b/gosa-core/include/pChart/MankSans.ttf new file mode 100644 index 000000000..a6146a900 Binary files /dev/null and b/gosa-core/include/pChart/MankSans.ttf differ diff --git a/gosa-core/include/pChart/Naked.php b/gosa-core/include/pChart/Naked.php new file mode 100644 index 000000000..0699611b5 --- /dev/null +++ b/gosa-core/include/pChart/Naked.php @@ -0,0 +1,34 @@ +AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7)); + $DataSet->AddSerie(); + $DataSet->SetSerieName("Sample data","Serie1"); + + // Initialise the graph + $Test = new pChart(700,230); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->setGraphArea(40,30,680,200); + $Test->drawGraphArea(252,252,252,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + $Test->drawGrid(4,TRUE,230,230,230,70); + + // Draw the line graph + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(45,35,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(60,22,"My pretty graph",50,50,50,585); + $Test->Render("Naked.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/Point_Asterisk.gif b/gosa-core/include/pChart/Point_Asterisk.gif new file mode 100644 index 000000000..f75e9b84a Binary files /dev/null and b/gosa-core/include/pChart/Point_Asterisk.gif differ diff --git a/gosa-core/include/pChart/Point_Cd.gif b/gosa-core/include/pChart/Point_Cd.gif new file mode 100644 index 000000000..814c64290 Binary files /dev/null and b/gosa-core/include/pChart/Point_Cd.gif differ diff --git a/gosa-core/include/pChart/Sav143.tmp b/gosa-core/include/pChart/Sav143.tmp new file mode 100644 index 000000000..e69de29bb diff --git a/gosa-core/include/pChart/Silkscreen.ttf b/gosa-core/include/pChart/Silkscreen.ttf new file mode 100644 index 000000000..ae4425dda Binary files /dev/null and b/gosa-core/include/pChart/Silkscreen.ttf differ diff --git a/gosa-core/include/pChart/SmallGraph.php b/gosa-core/include/pChart/SmallGraph.php new file mode 100644 index 000000000..5e0aa797b --- /dev/null +++ b/gosa-core/include/pChart/SmallGraph.php @@ -0,0 +1,30 @@ +AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4,-3,2,-3,3,5,1,0,7),"Serie1"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie(); + $DataSet->SetSerieName("January","Serie1"); + + // Initialise the graph + $Test = new pChart(100,30); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawFilledRoundedRectangle(2,2,98,28,2,230,230,230); + $Test->setGraphArea(5,5,95,25); + $Test->drawGraphArea(255,255,255); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,220,220,220,FALSE); + + // Draw the line graph + $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); + + // Finish the graph + $Test->Render("SmallGraph.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/SmallStacked.php b/gosa-core/include/pChart/SmallStacked.php new file mode 100644 index 000000000..a7dedb8fe --- /dev/null +++ b/gosa-core/include/pChart/SmallStacked.php @@ -0,0 +1,48 @@ +AddPoint(1,"Serie1"); + $DataSet->AddPoint(3,"Serie2"); + $DataSet->AddPoint(3,"Serie3"); + $DataSet->AddPoint("A#~1","Labels"); + $DataSet->AddAllSeries(); + $DataSet->RemoveSerie("Labels"); + $DataSet->SetAbsciseLabelSerie("Labels"); + $DataSet->SetSerieName("Alpha","Serie1"); + $DataSet->SetSerieName("Beta","Serie2"); + $DataSet->SetSerieName("Gama","Serie3"); + $DataSet->SetYAxisName("Test Marker"); + $DataSet->SetYAxisUnit("µm"); + + // Initialise the graph + $Test = new pChart(210,230); + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->setGraphArea(65,30,125,200); + $Test->drawFilledRoundedRectangle(7,7,203,223,5,240,240,240); + $Test->drawRoundedRectangle(5,5,205,225,5,230,230,230); + $Test->drawGraphArea(255,255,255,TRUE); + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_ADDALLSTART0,150,150,150,TRUE,0,2,TRUE); + $Test->drawGrid(4,TRUE,230,230,230,50); + + // Draw the 0 line + $Test->setFontProperties("Fonts/tahoma.ttf",6); + $Test->drawTreshold(0,143,55,72,TRUE,TRUE); + + // Draw the bar graph + $Test->drawStackedBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),50); + + // Finish the graph + $Test->setFontProperties("Fonts/tahoma.ttf",8); + $Test->drawLegend(135,150,$DataSet->GetDataDescription(),255,255,255); + $Test->setFontProperties("Fonts/tahoma.ttf",10); + $Test->drawTitle(0,22,"Sample size",50,50,50,210); + $Test->Render("SmallStacked.png"); +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/buildAll.cmd b/gosa-core/include/pChart/buildAll.cmd new file mode 100644 index 000000000..f22b1f749 --- /dev/null +++ b/gosa-core/include/pChart/buildAll.cmd @@ -0,0 +1,63 @@ +ECHO OFF +CLS +ECHO Processing all examples +ECHO. +ECHO [01/28] A simple line chart + php -q %~dp0Example1.php +ECHO [02/28] A cubic curve graph + php -q %~dp0Example2.php +ECHO [03/28] An overlayed bar graph + php -q %~dp0Example3.php +ECHO [04/28] Showing how to draw area + php -q %~dp0Example4.php +ECHO [05/28] A limits graph + php -q %~dp0Example5.php +ECHO [06/28] A simple filled line graph + php -q %~dp0Example6.php +ECHO [07/28] A filled cubic curve graph + php -q %~dp0Example7.php +ECHO [08/28] A radar graph + php -q %~dp0Example8.php +ECHO [09/28] Showing how to use labels + php -q %~dp0Example9.php +ECHO [10/28] A 3D exploded pie graph + php -q %~dp0Example10.php +ECHO [11/28] A true bar graph + php -q %~dp0Example12.php +ECHO [12/28] A 2D exploded pie graph + php -q %~dp0Example13.php +ECHO [13/28] A smooth flat pie graph + php -q %~dp0Example14.php +ECHO [14/28] Playing with line style and pictures inclusion + php -q %~dp0Example15.php +ECHO [15/28] Importing CSV data + php -q %~dp0Example16.php +ECHO [16/28] Playing with axis + php -q %~dp0Example17.php +ECHO [17/28] Missing values + php -q %~dp0Example18.php +ECHO [18/28] Error reporting + php -q %~dp0Example19.php +ECHO [19/28] Stacked bar graph + php -q %~dp0Example20.php +ECHO [20/28] Playing with background + php -q %~dp0Example21.php +ECHO [21/28] Customizing plot charts + php -q %~dp0Example22.php +ECHO [22/28] Playing with background - Bis + php -q %~dp0Example23.php +ECHO [23/28] X Versus Y chart + php -q %~dp0Example24.php +ECHO [24/28] Using shadows + php -q %~dp0Example25.php +ECHO [25/28] Two Y axis / shadow demonstration + php -q %~dp0Example26.php +ECHO [26/28] Naked and easy! + php -q %~dp0Naked.php +ECHO [27/28] Let's go fast, draw small! + php -q %~dp0SmallGraph.php +ECHO [28/28] A Small stacked chart + php -q %~dp0SmallStacked.php +ECHO. +ECHO Rendering complete! +PAUSE diff --git a/gosa-core/include/pChart/bulkdata.csv b/gosa-core/include/pChart/bulkdata.csv new file mode 100644 index 000000000..867233134 --- /dev/null +++ b/gosa-core/include/pChart/bulkdata.csv @@ -0,0 +1,20 @@ +1,0,1,0.5 +2,1.204119983,4,2 +3,4.294091292,9,4.5 +4,9.632959861,16,8 +5,17.47425011,25,12.5 +6,28.01344501,36,18 +7,41.40980396,49,24.5 +8,57.79775917,64,32 +9,77.29364326,81,40.5 +10,100,100,50 +11,126.0085149,121,60.5 +12,155.4020994,144,72 +13,188.2564265,169,84.5 +14,224.641095,196,98 +15,264.6205333,225,112.5 +16,308.2547156,256,128 +17,355.5997383,289,144.5 +18,406.7082917,324,162 +19,461.6300499,361,180.5 +20,520.4119983,400,200 diff --git a/gosa-core/include/pChart/datawithtitle.csv b/gosa-core/include/pChart/datawithtitle.csv new file mode 100644 index 000000000..9761949ef --- /dev/null +++ b/gosa-core/include/pChart/datawithtitle.csv @@ -0,0 +1,21 @@ +Zob,January,February,March +1,0,1,0.5 +2,1.204119983,4,2 +3,4.294091292,9,4.5 +4,9.632959861,16,8 +5,17.47425011,25,12.5 +6,28.01344501,36,18 +7,41.40980396,49,24.5 +8,57.79775917,64,32 +9,77.29364326,81,40.5 +10,100,100,50 +11,126.0085149,121,60.5 +12,155.4020994,144,72 +13,188.2564265,169,84.5 +14,224.641095,196,98 +15,264.6205333,225,112.5 +16,308.2547156,256,128 +17,355.5997383,289,144.5 +18,406.7082917,324,162 +19,461.6300499,361,180.5 +20,520.4119983,400,200 diff --git a/gosa-core/include/pChart/logo.png b/gosa-core/include/pChart/logo.png new file mode 100644 index 000000000..8df1e4b40 Binary files /dev/null and b/gosa-core/include/pChart/logo.png differ diff --git a/gosa-core/include/pChart/pCache.class b/gosa-core/include/pChart/pCache.class new file mode 100644 index 000000000..454bbada9 --- /dev/null +++ b/gosa-core/include/pChart/pCache.class @@ -0,0 +1,119 @@ +. + + Class initialisation : + pCache($CacheFolder="Cache/") + Cache management : + IsInCache($Data) + GetFromCache($ID,$Data) + WriteToCache($ID,$Data,$Picture) + DeleteFromCache($ID,$Data) + ClearCache() + Inner functions : + GetHash($ID,$Data) + */ + + /* pCache class definition */ + class pCache + { + var $HashKey = ""; + var $CacheFolder = "Cache/"; + + /* Create the pCache object */ + function pCache($CacheFolder="Cache/") + { + $this->CacheFolder = $CacheFolder; + } + + /* This function is clearing the cache folder */ + function ClearCache() + { + if ($handle = opendir($this->CacheFolder)) + { + while (false !== ($file = readdir($handle))) + { + if ( $file != "." && $file != ".." ) + unlink($this->CacheFolder.$file); + } + closedir($handle); + } + } + + /* This function is checking if we have an offline version of this chart */ + function IsInCache($ID,$Data,$Hash="") + { + if ( $Hash == "" ) + $Hash = $this->GetHash($ID,$Data); + + if ( file_exists($this->CacheFolder.$Hash) ) + return(TRUE); + else + return(FALSE); + } + + /* This function is making a copy of drawn chart in the cache folder */ + function WriteToCache($ID,$Data,$Picture) + { + $Hash = $this->GetHash($ID,$Data); + $FileName = $this->CacheFolder.$Hash; + + imagepng($Picture->Picture,$FileName); + } + + /* This function is removing any cached copy of this chart */ + function DeleteFromCache($ID,$Data) + { + $Hash = $this->GetHash($ID,$Data); + $FileName = $this->CacheFolder.$Hash; + + if ( file_exists($FileName ) ) + unlink($FileName); + } + + /* This function is retrieving the cached picture if applicable */ + function GetFromCache($ID,$Data) + { + $Hash = $this->GetHash($ID,$Data); + if ( $this->IsInCache("","",$Hash ) ) + { + $FileName = $this->CacheFolder.$Hash; + + header('Content-type: image/png'); + @readfile($FileName); + exit(); + } + } + + /* This function is building the graph unique hash key */ + function GetHash($ID,$Data) + { + $mKey = "$ID"; + foreach($Data as $key => $Values) + { + $tKey = ""; + foreach($Values as $Serie => $Value) + $tKey = $tKey.$Serie.$Value; + $mKey = $mKey.md5($tKey); + } + return(md5($mKey)); + } + } +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/pChart.1.27d.rar b/gosa-core/include/pChart/pChart.1.27d.rar new file mode 100644 index 000000000..3fa26d449 Binary files /dev/null and b/gosa-core/include/pChart/pChart.1.27d.rar differ diff --git a/gosa-core/include/pChart/pChart.class b/gosa-core/include/pChart/pChart.class new file mode 100644 index 000000000..2b3303e43 --- /dev/null +++ b/gosa-core/include/pChart/pChart.class @@ -0,0 +1,3489 @@ +. + + Class initialisation : + pChart($XSize,$YSize) + Draw methods : + drawBackground($R,$G,$B) + drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B) + drawFilledRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B,$DrawBorder=TRUE,$Alpha=100) + drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B) + drawFilledRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B) + drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0) + drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0) + drawEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B) + drawFilledEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B) + drawLine($X1,$Y1,$X2,$Y2,$R,$G,$B,$GraphFunction=FALSE) + drawDottedLine($X1,$Y1,$X2,$Y2,$DotSize,$R,$G,$B) + drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B) + drawFromPNG($FileName,$X,$Y,$Alpha=100) + drawFromGIF($FileName,$X,$Y,$Alpha=100) + drawFromJPG($FileName,$X,$Y,$Alpha=100) + Graph setup methods : + addBorder($Width=3,$R=0,$G=0,$B=0) + clearScale() + clearShadow() + createColorGradientPalette($R1,$G1,$B1,$R2,$G2,$B2,$Shades) + drawGraphArea($R,$G,$B,$Stripe=FALSE) + drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE) + drawRightScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1) + drawXYScale($Data,$DataDescription,$YSerieName,$XSerieName,$R,$G,$B,$WithMargin=0,$Angle=0,$Decimals=1) + drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=100) + drawLegend($XPos,$YPos,$DataDescription,$R,$G,$B,$Rs=-1,$Gs=-1,$Bs=-1,$Rt=0,$Gt=0,$Bt=0,$Border=FALSE) + drawPieLegend($XPos,$YPos,$Data,$DataDescription,$R,$G,$B) + drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE) + drawTreshold($Value,$R,$G,$B,$ShowLabel=FALSE,$ShowOnRight=FALSE,$TickWidth=4,$FreeText=NULL) + drawArea($Data,$Serie1,$Serie2,$R,$G,$B,$Alpha = 50) + drawRadarAxis($Data,$DataDescription,$Mosaic=TRUE,$BorderOffset=10,$A_R=60,$A_G=60,$A_B=60,$S_R=200,$S_G=200,$S_B=200,$MaxValue=-1) + drawGraphAreaGradient($R,$G,$B,$Decay,$Target=TARGET_GRAPHAREA) + drawTextBox($X1,$Y1,$X2,$Y2,$Text,$Angle=0,$R=255,$G=255,$B=255,$Align=ALIGN_LEFT,$Shadow=TRUE,$BgR=-1,$BgG=-1,$BgB=-1,$Alpha=100) + getLegendBoxSize($DataDescription) + loadColorPalette($FileName,$Delimiter=",") + reportWarnings($Interface="CLI") + setGraphArea($X1,$Y1,$X2,$Y2) + setLabel($Data,$DataDescription,$SerieName,$ValueName,$Caption,$R=210,$G=210,$B=210) + setColorPalette($ID,$R,$G,$B) + setCurrency($Currency) + setDateFormat($Format) + setFontProperties($FontName,$FontSize) + setLineStyle($Width=1,$DotSize=0) + setFixedScale($VMin,$VMax,$Divisions=5,$VXMin=0,$VXMin=0,$XDivisions=5) + setShadowProperties($XDistance=1,$YDistance=1,$R=60,$G=60,$B=60,$Alpha) + writeValues($Data,$DataDescription,$Series) + Graphs methods : + drawPlotGraph($Data,$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=FALSE) + drawXYPlotGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1) + drawLineGraph($Data,$DataDescription,$SerieName="") + drawXYGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0) + drawFilledLineGraph($Data,$DataDescription,$Alpha=100,$AroundZero=FALSE) + drawCubicCurve($Data,$DataDescription,$Accuracy=.1,$SerieName="") + drawFilledCubicCurve($Data,$DataDescription,$Accuracy=.1,$Alpha=100,$AroundZero=FALSE) + drawOverlayBarGraph($Data,$DataDescription,$Alpha=50) + drawBarGraph($Data,$DataDescription,$Shadow=FALSE) + drawStackedBarGraph($Data,$DataDescription,$Alpha=50,$Contiguous=FALSE) + drawLimitsGraph($Data,$DataDescription,$R=0,$G=0,$B=0) + drawRadar($Data,$DataDescription,$BorderOffset=10,$MaxValue=-1) + drawFilledRadar($Data,$DataDescription,$Alpha=50,$BorderOffset=10,$MaxValue=-1) + drawBasicPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$R=255,$G=255,$B=255,$Decimals=0) + drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals = 0) + drawFlatPieGraphWithShadow($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals = 0) + drawPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$EnhanceColors=TRUE,$Skew=60,$SpliceHeight=20,$SpliceDistance=0,$Decimals=0) + Other methods : + setImageMap($Mode=TRUE,$GraphID="MyGraph") + getImageMap($MapName,$Flush=TRUE) + Render($FileName) + Stroke() + */ + + /* Declare some script wide constants */ + define("SCALE_NORMAL",1); + define("SCALE_ADDALL",2); + define("SCALE_START0",3); + define("SCALE_ADDALLSTART0",4); + define("PIE_PERCENTAGE", 1); + define("PIE_LABELS",2); + define("PIE_NOLABEL",3); + define("PIE_PERCENTAGE_LABEL", 4); + define("TARGET_GRAPHAREA",1); + define("TARGET_BACKGROUND",2); + define("ALIGN_TOP_LEFT",1); + define("ALIGN_TOP_CENTER",2); + define("ALIGN_TOP_RIGHT",3); + define("ALIGN_LEFT",4); + define("ALIGN_CENTER",5); + define("ALIGN_RIGHT",6); + define("ALIGN_BOTTOM_LEFT",7); + define("ALIGN_BOTTOM_CENTER",8); + define("ALIGN_BOTTOM_RIGHT",9); + + /* pChart class definition */ + class pChart + { + /* Palettes definition */ + var $Palette = array("0"=>array("R"=>188,"G"=>224,"B"=>46), + "1"=>array("R"=>224,"G"=>100,"B"=>46), + "2"=>array("R"=>224,"G"=>214,"B"=>46), + "3"=>array("R"=>46,"G"=>151,"B"=>224), + "4"=>array("R"=>176,"G"=>46,"B"=>224), + "5"=>array("R"=>224,"G"=>46,"B"=>117), + "6"=>array("R"=>92,"G"=>224,"B"=>46), + "7"=>array("R"=>224,"G"=>176,"B"=>46)); + + /* Some static vars used in the class */ + var $XSize = NULL; + var $YSize = NULL; + var $Picture = NULL; + var $ImageMap = NULL; + + /* Error management */ + var $ErrorReporting = FALSE; + var $ErrorInterface = "CLI"; + var $Errors = NULL; + var $ErrorFontName = "Fonts/pf_arma_five.ttf"; + var $ErrorFontSize = 6; + + /* vars related to the graphing area */ + var $GArea_X1 = NULL; + var $GArea_Y1 = NULL; + var $GArea_X2 = NULL; + var $GArea_Y2 = NULL; + var $GAreaXOffset = NULL; + var $VMax = NULL; + var $VMin = NULL; + var $VXMax = NULL; + var $VXMin = NULL; + var $Divisions = NULL; + var $XDivisions = NULL; + var $DivisionHeight = NULL; + var $XDivisionHeight = NULL; + var $DivisionCount = NULL; + var $XDivisionCount = NULL; + var $DivisionRatio = NULL; + var $XDivisionRatio = NULL; + var $DivisionWidth = NULL; + var $DataCount = NULL; + var $Currency = "\$"; + + /* Text format related vars */ + var $FontName = NULL; + var $FontSize = NULL; + var $DateFormat = "d/m/Y"; + + /* Lines format related vars */ + var $LineWidth = 1; + var $LineDotSize = 0; + + /* Layer related vars */ + var $Layers = NULL; + + /* Set antialias quality : 0 is maximum, 100 minimum*/ + var $AntialiasQuality = 0; + + /* Shadow settings */ + var $ShadowActive = FALSE; + var $ShadowXDistance = 1; + var $ShadowYDistance = 1; + var $ShadowRColor = 60; + var $ShadowGColor = 60; + var $ShadowBColor = 60; + var $ShadowAlpha = 50; + var $ShadowBlur = 0; + + /* Image Map settings */ + var $BuildMap = FALSE; + var $MapFunction = NULL; + var $tmpFolder = "tmp/"; + var $MapID = NULL; + + /* This function create the background picture */ + function pChart($XSize,$YSize) + { + $this->XSize = $XSize; + $this->YSize = $YSize; + $this->Picture = imagecreatetruecolor($XSize,$YSize); + + $C_White =$this->AllocateColor($this->Picture,255,255,255); + imagefilledrectangle($this->Picture,0,0,$XSize,$YSize,$C_White); + imagecolortransparent($this->Picture,$C_White); + + $this->setFontProperties("tahoma.ttf",8); + } + + /* Set if warnings should be reported */ + function reportWarnings($Interface="CLI") + { + $this->ErrorReporting = TRUE; + $this->ErrorInterface = $Interface; + } + + /* Set the font properties */ + function setFontProperties($FontName,$FontSize) + { + $this->FontName = $FontName; + $this->FontSize = $FontSize; + } + + /* Set the shadow properties */ + function setShadowProperties($XDistance=1,$YDistance=1,$R=60,$G=60,$B=60,$Alpha=50,$Blur=0) + { + $this->ShadowActive = TRUE; + $this->ShadowXDistance = $XDistance; + $this->ShadowYDistance = $YDistance; + $this->ShadowRColor = $R; + $this->ShadowGColor = $G; + $this->ShadowBColor = $B; + $this->ShadowAlpha = $Alpha; + $this->ShadowBlur = $Blur; + } + + /* Remove shadow option */ + function clearShadow() + { + $this->ShadowActive = FALSE; + } + + /* Set Palette color */ + function setColorPalette($ID,$R,$G,$B) + { + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $this->Palette[$ID]["R"] = $R; + $this->Palette[$ID]["G"] = $G; + $this->Palette[$ID]["B"] = $B; + } + + /* Create a color palette shading from one color to another */ + function createColorGradientPalette($R1,$G1,$B1,$R2,$G2,$B2,$Shades) + { + $RFactor = ($R2-$R1)/$Shades; + $GFactor = ($G2-$G1)/$Shades; + $BFactor = ($B2-$B1)/$Shades; + + for($i=0;$i<=$Shades-1;$i++) + { + $this->Palette[$i]["R"] = $R1+$RFactor*$i; + $this->Palette[$i]["G"] = $G1+$GFactor*$i; + $this->Palette[$i]["B"] = $B1+$BFactor*$i; + } + } + + /* Load Color Palette from file */ + function loadColorPalette($FileName,$Delimiter=",") + { + $handle = @fopen($FileName,"r"); + $ColorID = 0; + if ($handle) + { + while (!feof($handle)) + { + $buffer = fgets($handle, 4096); + $buffer = str_replace(chr(10),"",$buffer); + $buffer = str_replace(chr(13),"",$buffer); + $Values = split($Delimiter,$buffer); + if ( count($Values) == 3 ) + { + $this->Palette[$ColorID]["R"] = $Values[0]; + $this->Palette[$ColorID]["G"] = $Values[1]; + $this->Palette[$ColorID]["B"] = $Values[2]; + $ColorID++; + } + } + } + } + + /* Set line style */ + function setLineStyle($Width=1,$DotSize=0) + { + $this->LineWidth = $Width; + $this->LineDotSize = $DotSize; + } + + /* Set currency symbol */ + function setCurrency($Currency) + { + $this->Currency = $Currency; + } + + /* Set the graph area location */ + function setGraphArea($X1,$Y1,$X2,$Y2) + { + $this->GArea_X1 = $X1; + $this->GArea_Y1 = $Y1; + $this->GArea_X2 = $X2; + $this->GArea_Y2 = $Y2; + } + + /* Prepare the graph area */ + function drawGraphArea($R,$G,$B,$Stripe=FALSE) + { + $this->drawFilledRectangle($this->GArea_X1,$this->GArea_Y1,$this->GArea_X2,$this->GArea_Y2,$R,$G,$B,FALSE); + $this->drawRectangle($this->GArea_X1,$this->GArea_Y1,$this->GArea_X2,$this->GArea_Y2,$R-40,$G-40,$B-40); + + if ( $Stripe ) + { + $R2 = $R-15; if ( $R2 < 0 ) { $R2 = 0; } + $G2 = $R-15; if ( $G2 < 0 ) { $G2 = 0; } + $B2 = $R-15; if ( $B2 < 0 ) { $B2 = 0; } + + $LineColor =$this->AllocateColor($this->Picture,$R2,$G2,$B2); + $SkewWidth = $this->GArea_Y2-$this->GArea_Y1-1; + + for($i=$this->GArea_X1-$SkewWidth;$i<=$this->GArea_X2;$i=$i+4) + { + $X1 = $i; $Y1 = $this->GArea_Y2; + $X2 = $i+$SkewWidth; $Y2 = $this->GArea_Y1; + + + if ( $X1 < $this->GArea_X1 ) + { $X1 = $this->GArea_X1; $Y1 = $this->GArea_Y1 + $X2 - $this->GArea_X1 + 1; } + + if ( $X2 >= $this->GArea_X2 ) + { $Y2 = $this->GArea_Y1 + $X2 - $this->GArea_X2 +1; $X2 = $this->GArea_X2 - 1; } +// * Fixed in 1.27 * { $X2 = $this->GArea_X2 - 1; $Y2 = $this->GArea_Y2 - ($this->GArea_X2 - $X1); } + + imageline($this->Picture,$X1,$Y1,$X2,$Y2+1,$LineColor); + } + } + } + + /* Allow you to clear the scale : used if drawing multiple charts */ + function clearScale() + { + $this->VMin = NULL; + $this->VMax = NULL; + $this->VXMin = NULL; + $this->VXMax = NULL; + $this->Divisions = NULL; + $this->XDivisions = NULL; } + + /* Allow you to fix the scale, use this to bypass the automatic scaling */ + function setFixedScale($VMin,$VMax,$Divisions=5,$VXMin=0,$VXMax=0,$XDivisions=5) + { + $this->VMin = $VMin; + $this->VMax = $VMax; + $this->Divisions = $Divisions; + + if ( !$VXMin == 0 ) + { + $this->VXMin = $VXMin; + $this->VXMax = $VXMax; + $this->XDivisions = $XDivisions; + } + } + + /* Wrapper to the drawScale() function allowing a second scale to be drawn */ + function drawRightScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1) + { + $this->drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks,$Angle,$Decimals,$WithMargin,$SkipLabels,TRUE); + } + + /* Compute and draw the scale */ + function drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE) + { + /* Validate the Data and DataDescription array */ + $this->validateData("drawScale",$Data); + + $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B); + + $this->drawLine($this->GArea_X1,$this->GArea_Y1,$this->GArea_X1,$this->GArea_Y2,$R,$G,$B); + $this->drawLine($this->GArea_X1,$this->GArea_Y2,$this->GArea_X2,$this->GArea_Y2,$R,$G,$B); + + if ( $this->VMin == NULL && $this->VMax == NULL) + { + if (isset($DataDescription["Values"][0])) + { + $this->VMin = $Data[0][$DataDescription["Values"][0]]; + $this->VMax = $Data[0][$DataDescription["Values"][0]]; + } + else { $this->VMin = 2147483647; $this->VMax = -2147483647; } + + /* Compute Min and Max values */ + if ( $ScaleMode == SCALE_NORMAL || $ScaleMode == SCALE_START0 ) + { + if ( $ScaleMode == SCALE_START0 ) { $this->VMin = 0; } + + foreach ( $Data as $Key => $Values ) + { + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + if (isset($Data[$Key][$ColName])) + { + $Value = $Data[$Key][$ColName]; + + if ( is_numeric($Value) ) + { + if ( $this->VMax < $Value) { $this->VMax = $Value; } + if ( $this->VMin > $Value) { $this->VMin = $Value; } + } + } + } + } + } + elseif ( $ScaleMode == SCALE_ADDALL || $ScaleMode == SCALE_ADDALLSTART0 ) /* Experimental */ + { + if ( $ScaleMode == SCALE_ADDALLSTART0 ) { $this->VMin = 0; } + + foreach ( $Data as $Key => $Values ) + { + $Sum = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + if (isset($Data[$Key][$ColName])) + { + $Value = $Data[$Key][$ColName]; + if ( is_numeric($Value) ) + $Sum += $Value; + } + } + if ( $this->VMax < $Sum) { $this->VMax = $Sum; } + if ( $this->VMin > $Sum) { $this->VMin = $Sum; } + } + } + + if ( $this->VMax > preg_replace('/\.[0-9]+/','',$this->VMax) ) + $this->VMax = preg_replace('/\.[0-9]+/','',$this->VMax)+1; + + /* If all values are the same */ + if ( $this->VMax == $this->VMin ) + { + if ( $this->VMax >= 0 ) { $this->VMax++; } + else { $this->VMin--; } + } + + $DataRange = $this->VMax - $this->VMin; + if ( $DataRange == 0 ) { $DataRange = .1; } + + /* Compute automatic scaling */ + $ScaleOk = FALSE; $Factor = 1; + $MinDivHeight = 25; $MaxDivs = ($this->GArea_Y2 - $this->GArea_Y1) / $MinDivHeight; + + if ( $this->VMin == 0 && $this->VMax == 0 ) + { $this->VMin = 0; $this->VMax = 2; $Scale = 1; $Divisions = 2;} + elseif ($MaxDivs > 1) + { + while(!$ScaleOk) + { + $Scale1 = ( $this->VMax - $this->VMin ) / $Factor; + $Scale2 = ( $this->VMax - $this->VMin ) / $Factor / 2; + $Scale4 = ( $this->VMax - $this->VMin ) / $Factor / 4; + + if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;} + if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;} + if (!$ScaleOk) + { + if ( $Scale2 > 1 ) { $Factor = $Factor * 10; } + if ( $Scale2 < 1 ) { $Factor = $Factor / 10; } + } + } + + if ( floor($this->VMax / $Scale / $Factor) != $this->VMax / $Scale / $Factor) + { + $GridID = floor ( $this->VMax / $Scale / $Factor) + 1; + $this->VMax = $GridID * $Scale * $Factor; + $Divisions++; + } + + if ( floor($this->VMin / $Scale / $Factor) != $this->VMin / $Scale / $Factor) + { + $GridID = floor( $this->VMin / $Scale / $Factor); + $this->VMin = $GridID * $Scale * $Factor; + $Divisions++; + } + } + else /* Can occurs for small graphs */ + $Scale = 1; + + if ( !isset($Divisions) ) + $Divisions = 2; + + if ($Scale == 1 && $Divisions%2 == 1) + $Divisions--; + } + else + $Divisions = $this->Divisions; + + $this->DivisionCount = $Divisions; + + $DataRange = $this->VMax - $this->VMin; + if ( $DataRange == 0 ) { $DataRange = .1; } + + $this->DivisionHeight = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $Divisions; + $this->DivisionRatio = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $DataRange; + + $this->GAreaXOffset = 0; + if ( count($Data) > 1 ) + { + if ( $WithMargin == FALSE ) + $this->DivisionWidth = ( $this->GArea_X2 - $this->GArea_X1 ) / (count($Data)-1); + else + { + $this->DivisionWidth = ( $this->GArea_X2 - $this->GArea_X1 ) / (count($Data)); + $this->GAreaXOffset = $this->DivisionWidth / 2; + } + } + else + { + $this->DivisionWidth = $this->GArea_X2 - $this->GArea_X1; + $this->GAreaXOffset = $this->DivisionWidth / 2; + } + + $this->DataCount = count($Data); + + if ( $DrawTicks == FALSE ) + return(0); + + $YPos = $this->GArea_Y2; $XMin = NULL; + for($i=1;$i<=$Divisions+1;$i++) + { + if ( $RightScale ) + $this->drawLine($this->GArea_X2,$YPos,$this->GArea_X2+5,$YPos,$R,$G,$B); + else + $this->drawLine($this->GArea_X1,$YPos,$this->GArea_X1-5,$YPos,$R,$G,$B); + + $Value = $this->VMin + ($i-1) * (( $this->VMax - $this->VMin ) / $Divisions); + $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals); + if ( $DataDescription["Format"]["Y"] == "number" ) + $Value = $Value.$DataDescription["Unit"]["Y"]; + if ( $DataDescription["Format"]["Y"] == "time" ) + $Value = $this->ToTime($Value); + if ( $DataDescription["Format"]["Y"] == "date" ) + $Value = $this->ToDate($Value); + if ( $DataDescription["Format"]["Y"] == "metric" ) + $Value = $this->ToMetric($Value); + if ( $DataDescription["Format"]["Y"] == "currency" ) + $Value = $this->ToCurrency($Value); + + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value); + $TextWidth = $Position[2]-$Position[0]; + + if ( $RightScale ) + { + imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X2+10,$YPos+($this->FontSize/2),$C_TextColor,$this->FontName,$Value); + if ( $XMin < $this->GArea_X2+15+$TextWidth || $XMin == NULL ) { $XMin = $this->GArea_X2+15+$TextWidth; } + } + else + { + imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1-10-$TextWidth,$YPos+($this->FontSize/2),$C_TextColor,$this->FontName,$Value); + if ( $XMin > $this->GArea_X1-10-$TextWidth || $XMin == NULL ) { $XMin = $this->GArea_X1-10-$TextWidth; } + } + + $YPos = $YPos - $this->DivisionHeight; + } + + /* Write the Y Axis caption if set */ + if ( isset($DataDescription["Axis"]["Y"]) ) + { + $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["Y"]); + $TextHeight = abs($Position[1])+abs($Position[3]); + $TextTop = (($this->GArea_Y2 - $this->GArea_Y1) / 2) + $this->GArea_Y1 + ($TextHeight/2); + + if ( $RightScale ) + imagettftext($this->Picture,$this->FontSize,90,$XMin+$this->FontSize,$TextTop,$C_TextColor,$this->FontName,$DataDescription["Axis"]["Y"]); + else + imagettftext($this->Picture,$this->FontSize,90,$XMin-$this->FontSize,$TextTop,$C_TextColor,$this->FontName,$DataDescription["Axis"]["Y"]); + } + + /* Horizontal Axis */ + $XPos = $this->GArea_X1 + $this->GAreaXOffset; + $ID = 1; $YMax = NULL; + foreach ( $Data as $Key => $Values ) + { + if ( $ID % $SkipLabels == 0 ) + { + $this->drawLine(floor($XPos),$this->GArea_Y2,floor($XPos),$this->GArea_Y2+5,$R,$G,$B); + $Value = $Data[$Key][$DataDescription["Position"]]; + if ( $DataDescription["Format"]["X"] == "number" ) + $Value = $Value.$DataDescription["Unit"]["X"]; + if ( $DataDescription["Format"]["X"] == "time" ) + $Value = $this->ToTime($Value); + if ( $DataDescription["Format"]["X"] == "date" ) + $Value = $this->ToDate($Value); + if ( $DataDescription["Format"]["X"] == "metric" ) + $Value = $this->ToMetric($Value); + if ( $DataDescription["Format"]["X"] == "currency" ) + $Value = $this->ToCurrency($Value); + + $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Value); + $TextWidth = abs($Position[2])+abs($Position[0]); + $TextHeight = abs($Position[1])+abs($Position[3]); + + if ( $Angle == 0 ) + { + $YPos = $this->GArea_Y2+18; + imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-floor($TextWidth/2),$YPos,$C_TextColor,$this->FontName,$Value); + } + else + { + $YPos = $this->GArea_Y2+10+$TextHeight; + if ( $Angle <= 90 ) + imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value); + else + imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)+$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value); + } + if ( $YMax < $YPos || $YMax == NULL ) { $YMax = $YPos; } + } + + $XPos = $XPos + $this->DivisionWidth; + $ID++; + } + + /* Write the X Axis caption if set */ + if ( isset($DataDescription["Axis"]["X"]) ) + { + $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["X"]); + $TextWidth = abs($Position[2])+abs($Position[0]); + $TextLeft = (($this->GArea_X2 - $this->GArea_X1) / 2) + $this->GArea_X1 + ($TextWidth/2); + imagettftext($this->Picture,$this->FontSize,0,$TextLeft,$YMax+$this->FontSize+5,$C_TextColor,$this->FontName,$DataDescription["Axis"]["X"]); + } + } + + /* Compute and draw the scale for X/Y charts */ + function drawXYScale($Data,$DataDescription,$YSerieName,$XSerieName,$R,$G,$B,$WithMargin=0,$Angle=0,$Decimals=1) + { + /* Validate the Data and DataDescription array */ + $this->validateData("drawScale",$Data); + + $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B); + + $this->drawLine($this->GArea_X1,$this->GArea_Y1,$this->GArea_X1,$this->GArea_Y2,$R,$G,$B); + $this->drawLine($this->GArea_X1,$this->GArea_Y2,$this->GArea_X2,$this->GArea_Y2,$R,$G,$B); + + /* Process Y scale */ + if ( $this->VMin == NULL && $this->VMax == NULL) + { + $this->VMin = $Data[0][$YSerieName]; + $this->VMax = $Data[0][$YSerieName]; + + foreach ( $Data as $Key => $Values ) + { + if (isset($Data[$Key][$YSerieName])) + { + $Value = $Data[$Key][$YSerieName]; + if ( $this->VMax < $Value) { $this->VMax = $Value; } + if ( $this->VMin > $Value) { $this->VMin = $Value; } + } + } + + if ( $this->VMax > preg_replace('/\.[0-9]+/','',$this->VMax) ) + $this->VMax = preg_replace('/\.[0-9]+/','',$this->VMax)+1; + + $DataRange = $this->VMax - $this->VMin; + if ( $DataRange == 0 ) { $DataRange = .1; } + + /* Compute automatic scaling */ + $ScaleOk = FALSE; $Factor = 1; + $MinDivHeight = 25; $MaxDivs = ($this->GArea_Y2 - $this->GArea_Y1) / $MinDivHeight; + + if ( $this->VMin == 0 && $this->VMax == 0 ) + { $this->VMin = 0; $this->VMax = 2; $Scale = 1; $Divisions = 2;} + elseif ($MaxDivs > 1) + { + while(!$ScaleOk) + { + $Scale1 = ( $this->VMax - $this->VMin ) / $Factor; + $Scale2 = ( $this->VMax - $this->VMin ) / $Factor / 2; + $Scale4 = ( $this->VMax - $this->VMin ) / $Factor / 4; + + if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;} + if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;} + if (!$ScaleOk) + { + if ( $Scale2 > 1 ) { $Factor = $Factor * 10; } + if ( $Scale2 < 1 ) { $Factor = $Factor / 10; } + } + } + + if ( floor($this->VMax / $Scale / $Factor) != $this->VMax / $Scale / $Factor) + { + $GridID = floor ( $this->VMax / $Scale / $Factor) + 1; + $this->VMax = $GridID * $Scale * $Factor; + $Divisions++; + } + + if ( floor($this->VMin / $Scale / $Factor) != $this->VMin / $Scale / $Factor) + { + $GridID = floor( $this->VMin / $Scale / $Factor); + $this->VMin = $GridID * $Scale * $Factor; + $Divisions++; + } + } + else /* Can occurs for small graphs */ + $Scale = 1; + + if ( !isset($Divisions) ) + $Divisions = 2; + + if ( $this->isRealInt(($this->VMax-$this->VMin)/($Divisions-1))) + $Divisions--; + elseif ( $this->isRealInt(($this->VMax-$this->VMin)/($Divisions+1))) + $Divisions++; + } + else + $Divisions = $this->Divisions; + + $this->DivisionCount = $Divisions; + + $DataRange = $this->VMax - $this->VMin; + if ( $DataRange == 0 ) { $DataRange = .1; } + + $this->DivisionHeight = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $Divisions; + $this->DivisionRatio = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $DataRange; + + $YPos = $this->GArea_Y2; $XMin = NULL; + for($i=1;$i<=$Divisions+1;$i++) + { + $this->drawLine($this->GArea_X1,$YPos,$this->GArea_X1-5,$YPos,$R,$G,$B); + $Value = $this->VMin + ($i-1) * (( $this->VMax - $this->VMin ) / $Divisions); + $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals); + if ( $DataDescription["Format"]["Y"] == "number" ) + $Value = $Value.$DataDescription["Unit"]["Y"]; + if ( $DataDescription["Format"]["Y"] == "time" ) + $Value = $this->ToTime($Value); + if ( $DataDescription["Format"]["Y"] == "date" ) + $Value = $this->ToDate($Value); + if ( $DataDescription["Format"]["Y"] == "metric" ) + $Value = $this->ToMetric($Value); + if ( $DataDescription["Format"]["Y"] == "currency" ) + $Value = $this->ToCurrency($Value); + + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value); + $TextWidth = $Position[2]-$Position[0]; + imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1-10-$TextWidth,$YPos+($this->FontSize/2),$C_TextColor,$this->FontName,$Value); + + if ( $XMin > $this->GArea_X1-10-$TextWidth || $XMin == NULL ) { $XMin = $this->GArea_X1-10-$TextWidth; } + + $YPos = $YPos - $this->DivisionHeight; + } + + /* Process X scale */ + if ( $this->VXMin == NULL && $this->VXMax == NULL) + { + $this->VXMin = $Data[0][$XSerieName]; + $this->VXMax = $Data[0][$XSerieName]; + + foreach ( $Data as $Key => $Values ) + { + if (isset($Data[$Key][$XSerieName])) + { + $Value = $Data[$Key][$XSerieName]; + if ( $this->VXMax < $Value) { $this->VXMax = $Value; } + if ( $this->VXMin > $Value) { $this->VXMin = $Value; } + } + } + + if ( $this->VXMax > preg_replace('/\.[0-9]+/','',$this->VXMax) ) + $this->VXMax = preg_replace('/\.[0-9]+/','',$this->VXMax)+1; + + $DataRange = $this->VMax - $this->VMin; + if ( $DataRange == 0 ) { $DataRange = .1; } + + /* Compute automatic scaling */ + $ScaleOk = FALSE; $Factor = 1; + $MinDivWidth = 25; $MaxDivs = ($this->GArea_X2 - $this->GArea_X1) / $MinDivWidth; + + if ( $this->VXMin == 0 && $this->VXMax == 0 ) + { $this->VXMin = 0; $this->VXMax = 2; $Scale = 1; $XDivisions = 2;} + elseif ($MaxDivs > 1) + { + while(!$ScaleOk) + { + $Scale1 = ( $this->VXMax - $this->VXMin ) / $Factor; + $Scale2 = ( $this->VXMax - $this->VXMin ) / $Factor / 2; + $Scale4 = ( $this->VXMax - $this->VXMin ) / $Factor / 4; + + if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $XDivisions = floor($Scale1); $Scale = 1;} + if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $XDivisions = floor($Scale2); $Scale = 2;} + if (!$ScaleOk) + { + if ( $Scale2 > 1 ) { $Factor = $Factor * 10; } + if ( $Scale2 < 1 ) { $Factor = $Factor / 10; } + } + } + + if ( floor($this->VXMax / $Scale / $Factor) != $this->VXMax / $Scale / $Factor) + { + $GridID = floor ( $this->VXMax / $Scale / $Factor) + 1; + $this->VXMax = $GridID * $Scale * $Factor; + $XDivisions++; + } + + if ( floor($this->VXMin / $Scale / $Factor) != $this->VXMin / $Scale / $Factor) + { + $GridID = floor( $this->VXMin / $Scale / $Factor); + $this->VXMin = $GridID * $Scale * $Factor; + $XDivisions++; + } + } + else /* Can occurs for small graphs */ + $Scale = 1; + + if ( !isset($XDivisions) ) + $XDivisions = 2; + + if ( $this->isRealInt(($this->VXMax-$this->VXMin)/($XDivisions-1))) + $XDivisions--; + elseif ( $this->isRealInt(($this->VXMax-$this->VXMin)/($XDivisions+1))) + $XDivisions++; + } + else + $XDivisions = $this->XDivisions; + + $this->XDivisionCount = $Divisions; + $this->DataCount = $Divisions + 2; + + $XDataRange = $this->VXMax - $this->VXMin; + if ( $XDataRange == 0 ) { $XDataRange = .1; } + + $this->DivisionWidth = ( $this->GArea_X2 - $this->GArea_X1 ) / $XDivisions; + $this->XDivisionRatio = ( $this->GArea_X2 - $this->GArea_X1 ) / $XDataRange; + + $XPos = $this->GArea_X1; $YMax = NULL; + for($i=1;$i<=$XDivisions+1;$i++) + { + $this->drawLine($XPos,$this->GArea_Y2,$XPos,$this->GArea_Y2+5,$R,$G,$B); + + $Value = $this->VXMin + ($i-1) * (( $this->VXMax - $this->VXMin ) / $XDivisions); + $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals); + if ( $DataDescription["Format"]["Y"] == "number" ) + $Value = $Value.$DataDescription["Unit"]["Y"]; + if ( $DataDescription["Format"]["Y"] == "time" ) + $Value = $this->ToTime($Value); + if ( $DataDescription["Format"]["Y"] == "date" ) + $Value = $this->ToDate($Value); + if ( $DataDescription["Format"]["Y"] == "metric" ) + $Value = $this->ToMetric($Value); + if ( $DataDescription["Format"]["Y"] == "currency" ) + $Value = $this->ToCurrency($Value); + + $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Value); + $TextWidth = abs($Position[2])+abs($Position[0]); + $TextHeight = abs($Position[1])+abs($Position[3]); + + if ( $Angle == 0 ) + { + $YPos = $this->GArea_Y2+18; + imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-floor($TextWidth/2),$YPos,$C_TextColor,$this->FontName,$Value); + } + else + { + $YPos = $this->GArea_Y2+10+$TextHeight; + if ( $Angle <= 90 ) + imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value); + else + imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)+$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value); + } + + if ( $YMax < $YPos || $YMax == NULL ) { $YMax = $YPos; } + + $XPos = $XPos + $this->DivisionWidth; + } + + /* Write the Y Axis caption if set */ + if ( isset($DataDescription["Axis"]["Y"]) ) + { + $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["Y"]); + $TextHeight = abs($Position[1])+abs($Position[3]); + $TextTop = (($this->GArea_Y2 - $this->GArea_Y1) / 2) + $this->GArea_Y1 + ($TextHeight/2); + imagettftext($this->Picture,$this->FontSize,90,$XMin-$this->FontSize,$TextTop,$C_TextColor,$this->FontName,$DataDescription["Axis"]["Y"]); + } + + /* Write the X Axis caption if set */ + if ( isset($DataDescription["Axis"]["X"]) ) + { + $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["X"]); + $TextWidth = abs($Position[2])+abs($Position[0]); + $TextLeft = (($this->GArea_X2 - $this->GArea_X1) / 2) + $this->GArea_X1 + ($TextWidth/2); + imagettftext($this->Picture,$this->FontSize,0,$TextLeft,$YMax+$this->FontSize+5,$C_TextColor,$this->FontName,$DataDescription["Axis"]["X"]); + } + } + + /* Compute and draw the scale */ + function drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=100) + { + /* Draw mosaic */ + if ( $Mosaic ) + { + $LayerWidth = $this->GArea_X2-$this->GArea_X1; + $LayerHeight = $this->GArea_Y2-$this->GArea_Y1; + + $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight); + $C_White =$this->AllocateColor($this->Layers[0],255,255,255); + imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White); + imagecolortransparent($this->Layers[0],$C_White); + + $C_Rectangle =$this->AllocateColor($this->Layers[0],250,250,250); + + $YPos = $LayerHeight; //$this->GArea_Y2-1; + $LastY = $YPos; + for($i=0;$i<=$this->DivisionCount;$i++) + { + $LastY = $YPos; + $YPos = $YPos - $this->DivisionHeight; + + if ( $YPos <= 0 ) { $YPos = 1; } + + if ( $i % 2 == 0 ) + { + imagefilledrectangle($this->Layers[0],1,$YPos,$LayerWidth-1,$LastY,$C_Rectangle); + } + } + imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha); + imagedestroy($this->Layers[0]); + } + + /* Horizontal lines */ + $YPos = $this->GArea_Y2 - $this->DivisionHeight; + for($i=1;$i<=$this->DivisionCount;$i++) + { + if ( $YPos > $this->GArea_Y1 && $YPos < $this->GArea_Y2 ) + $this->drawDottedLine($this->GArea_X1,$YPos,$this->GArea_X2,$YPos,$LineWidth,$R,$G,$B); + + $YPos = $YPos - $this->DivisionHeight; + } + + /* Vertical lines */ + if ( $this->GAreaXOffset == 0 ) + { $XPos = $this->GArea_X1 + $this->DivisionWidth + $this->GAreaXOffset; $ColCount = $this->DataCount-2; } + else + { $XPos = $this->GArea_X1 + $this->GAreaXOffset; $ColCount = floor( ($this->GArea_X2 - $this->GArea_X1) / $this->DivisionWidth ); } + + for($i=1;$i<=$ColCount;$i++) + { + if ( $XPos > $this->GArea_X1 && $XPos < $this->GArea_X2 ) + $this->drawDottedLine(floor($XPos),$this->GArea_Y1,floor($XPos),$this->GArea_Y2,$LineWidth,$R,$G,$B); + $XPos = $XPos + $this->DivisionWidth; + } + } + + /* retrieve the legends size */ + function getLegendBoxSize($DataDescription) + { + if ( !isset($DataDescription["Description"]) ) + return(-1); + + /* <-10->[8]<-4->Text<-10-> */ + $MaxWidth = 0; $MaxHeight = 8; + foreach($DataDescription["Description"] as $Key => $Value) + { + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value); + $TextWidth = $Position[2]-$Position[0]; + $TextHeight = $Position[1]-$Position[7]; + if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; } + $MaxHeight = $MaxHeight + $TextHeight + 4; + } + $MaxHeight = $MaxHeight - 3; + $MaxWidth = $MaxWidth + 32; + + return(array($MaxWidth,$MaxHeight)); + } + + /* Draw the data legends */ + function drawLegend($XPos,$YPos,$DataDescription,$R,$G,$B,$Rs=-1,$Gs=-1,$Bs=-1,$Rt=0,$Gt=0,$Bt=0,$Border=TRUE) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawLegend",$DataDescription); + + if ( !isset($DataDescription["Description"]) ) + return(-1); + + $C_TextColor =$this->AllocateColor($this->Picture,$Rt,$Gt,$Bt); + + /* <-10->[8]<-4->Text<-10-> */ + $MaxWidth = 0; $MaxHeight = 8; + foreach($DataDescription["Description"] as $Key => $Value) + { + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value); + $TextWidth = $Position[2]-$Position[0]; + $TextHeight = $Position[1]-$Position[7]; + if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; } + $MaxHeight = $MaxHeight + $TextHeight + 4; + } + $MaxHeight = $MaxHeight - 5; + $MaxWidth = $MaxWidth + 32; + + if ( $Rs == -1 || $Gs == -1 || $Bs == -1 ) + { $Rs = $R-30; $Gs = $G-30; $Bs = $B-30; } + + if ( $Border ) + { + $this->drawFilledRoundedRectangle($XPos+1,$YPos+1,$XPos+$MaxWidth+1,$YPos+$MaxHeight+1,5,$Rs,$Gs,$Bs); + $this->drawFilledRoundedRectangle($XPos,$YPos,$XPos+$MaxWidth,$YPos+$MaxHeight,5,$R,$G,$B); + } + + $YOffset = 4 + $this->FontSize; $ID = 0; + foreach($DataDescription["Description"] as $Key => $Value) + { + $this->drawFilledRoundedRectangle($XPos+10,$YPos+$YOffset-4,$XPos+14,$YPos+$YOffset-4,2,$this->Palette[$ID]["R"],$this->Palette[$ID]["G"],$this->Palette[$ID]["B"]); + imagettftext($this->Picture,$this->FontSize,0,$XPos+22,$YPos+$YOffset,$C_TextColor,$this->FontName,$Value); + + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value); + $TextHeight = $Position[1]-$Position[7]; + + $YOffset = $YOffset + $TextHeight + 4; + $ID++; + } + } + + /* Draw the data legends */ + function drawPieLegend($XPos,$YPos,$Data,$DataDescription,$R,$G,$B) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawPieLegend",$DataDescription,FALSE); + $this->validateData("drawPieLegend",$Data); + + if ( !isset($DataDescription["Position"]) ) + return(-1); + + $C_TextColor =$this->AllocateColor($this->Picture,0,0,0); + + /* <-10->[8]<-4->Text<-10-> */ + $MaxWidth = 0; $MaxHeight = 8; + foreach($Data as $Key => $Value) + { + $Value2 = $Value[$DataDescription["Position"]]; + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value2); + $TextWidth = $Position[2]-$Position[0]; + $TextHeight = $Position[1]-$Position[7]; + if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; } + + $MaxHeight = $MaxHeight + $TextHeight + 4; + } + $MaxHeight = $MaxHeight - 3; + $MaxWidth = $MaxWidth + 32; + + $this->drawFilledRoundedRectangle($XPos+1,$YPos+1,$XPos+$MaxWidth+1,$YPos+$MaxHeight+1,5,$R-30,$G-30,$B-30); + $this->drawFilledRoundedRectangle($XPos,$YPos,$XPos+$MaxWidth,$YPos+$MaxHeight,5,$R,$G,$B); + + $YOffset = 4 + $this->FontSize; $ID = 0; + foreach($Data as $Key => $Value) + { + $Value2 = $Value[$DataDescription["Position"]]; + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value2); + $TextHeight = $Position[1]-$Position[7]; + $this->drawFilledRectangle($XPos+10,$YPos+$YOffset-6,$XPos+14,$YPos+$YOffset-2,$this->Palette[$ID]["R"],$this->Palette[$ID]["G"],$this->Palette[$ID]["B"]); + + imagettftext($this->Picture,$this->FontSize,0,$XPos+22,$YPos+$YOffset,$C_TextColor,$this->FontName,$Value2); + $YOffset = $YOffset + $TextHeight + 4; + $ID++; + } + } + + /* Draw the graph title */ + function drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE) + { + $C_TextColor = $this->AllocateColor($this->Picture,$R,$G,$B); + + if ( $XPos2 != -1 ) + { + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value); + $TextWidth = $Position[2]-$Position[0]; + $XPos = floor(( $XPos2 - $XPos - $TextWidth ) / 2 ) + $XPos; + } + + if ( $YPos2 != -1 ) + { + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value); + $TextHeight = $Position[5]-$Position[3]; + $YPos = floor(( $YPos2 - $YPos - $TextHeight ) / 2 ) + $YPos; + } + + if ( $Shadow ) + { + $C_ShadowColor = $this->AllocateColor($this->Picture,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor); + imagettftext($this->Picture,$this->FontSize,0,$XPos+$this->ShadowXDistance,$YPos+$this->ShadowYDistance,$C_ShadowColor,$this->FontName,$Value); + } + + imagettftext($this->Picture,$this->FontSize,0,$XPos,$YPos,$C_TextColor,$this->FontName,$Value); + } + + /* Draw a text box with text align & alpha properties */ + function drawTextBox($X1,$Y1,$X2,$Y2,$Text,$Angle=0,$R=255,$G=255,$B=255,$Align=ALIGN_LEFT,$Shadow=TRUE,$BgR=-1,$BgG=-1,$BgB=-1,$Alpha=100) + { + $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Text); + $TextWidth = $Position[2]-$Position[0]; + $TextHeight = $Position[5]-$Position[3]; + $AreaWidth = $X2 - $X1; + $AreaHeight = $Y2 - $Y1; + + if ( $BgR != -1 && $BgG != -1 && $BgB != -1 ) + $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$BgR,$BgG,$BgB,FALSE,$Alpha); + + if ( $Align == ALIGN_TOP_LEFT ) { $X = $X1+1; $Y = $Y1+$this->FontSize+1; } + if ( $Align == ALIGN_TOP_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y1+$this->FontSize+1; } + if ( $Align == ALIGN_TOP_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y1+$this->FontSize+1; } + if ( $Align == ALIGN_LEFT ) { $X = $X1+1; $Y = $Y1+($AreaHeight/2)-($TextHeight/2); } + if ( $Align == ALIGN_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y1+($AreaHeight/2)-($TextHeight/2); } + if ( $Align == ALIGN_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y1+($AreaHeight/2)-($TextHeight/2); } + if ( $Align == ALIGN_BOTTOM_LEFT ) { $X = $X1+1; $Y = $Y2-1; } + if ( $Align == ALIGN_BOTTOM_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y2-1; } + if ( $Align == ALIGN_BOTTOM_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y2-1; } + + $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B); + $C_ShadowColor =$this->AllocateColor($this->Picture,0,0,0); + if ( $Shadow ) + imagettftext($this->Picture,$this->FontSize,$Angle,$X+1,$Y+1,$C_ShadowColor,$this->FontName,$Text); + + imagettftext($this->Picture,$this->FontSize,$Angle,$X,$Y,$C_TextColor,$this->FontName,$Text); + } + + /* Compute and draw the scale */ + function drawTreshold($Value,$R,$G,$B,$ShowLabel=FALSE,$ShowOnRight=FALSE,$TickWidth=4,$FreeText=NULL) + { + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B); + $Y = $this->GArea_Y2 - ($Value - $this->VMin) * $this->DivisionRatio; + + if ( $Y <= $this->GArea_Y1 || $Y >= $this->GArea_Y2 ) + return(-1); + + if ( $TickWidth == 0 ) + $this->drawLine($this->GArea_X1,$Y,$this->GArea_X2,$Y,$R,$G,$B); + else + $this->drawDottedLine($this->GArea_X1,$Y,$this->GArea_X2,$Y,$TickWidth,$R,$G,$B); + + if ( $ShowLabel ) + { + if ( $FreeText == NULL ) + { $Label = $Value; } else { $Label = $FreeText; } + + if ( $ShowOnRight ) + imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X2+2,$Y+($this->FontSize/2),$C_TextColor,$this->FontName,$Label); + else + imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1+2,$Y-($this->FontSize/2),$C_TextColor,$this->FontName,$Label); + } + } + + /* This function put a label on a specific point */ + function setLabel($Data,$DataDescription,$SerieName,$ValueName,$Caption,$R=210,$G=210,$B=210) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("setLabel",$DataDescription); + $this->validateData("setLabel",$Data); + $ShadowFactor = 100; + $C_Label =$this->AllocateColor($this->Picture,$R,$G,$B); + $C_Shadow =$this->AllocateColor($this->Picture,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor); + $C_TextColor =$this->AllocateColor($this->Picture,0,0,0); + + $Cp = 0; $Found = FALSE; + foreach ( $Data as $Key => $Value ) + { + if ( $Data[$Key][$DataDescription["Position"]] == $ValueName ) + { $NumericalValue = $Data[$Key][$SerieName]; $Found = TRUE; } + if ( !$Found ) + $Cp++; + } + + $XPos = $this->GArea_X1 + $this->GAreaXOffset + ( $this->DivisionWidth * $Cp ) + 2; + $YPos = $this->GArea_Y2 - ($NumericalValue - $this->VMin) * $this->DivisionRatio; + + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption); + $TextHeight = $Position[3] - $Position[5]; + $TextWidth = $Position[2]-$Position[0] + 2; + $TextOffset = floor($TextHeight/2); + + // Shadow + $Poly = array($XPos+1,$YPos+1,$XPos + 9,$YPos - $TextOffset,$XPos + 8,$YPos + $TextOffset + 2); + imagefilledpolygon($this->Picture,$Poly,3,$C_Shadow); + $this->drawLine($XPos,$YPos+1,$XPos + 9,$YPos - $TextOffset - .2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor); + $this->drawLine($XPos,$YPos+1,$XPos + 9,$YPos + $TextOffset + 2.2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor); + $this->drawFilledRectangle($XPos + 9,$YPos - $TextOffset-.2,$XPos + 13 + $TextWidth,$YPos + $TextOffset + 2.2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor); + + // Label background + $Poly = array($XPos,$YPos,$XPos + 8,$YPos - $TextOffset - 1,$XPos + 8,$YPos + $TextOffset + 1); + imagefilledpolygon($this->Picture,$Poly,3,$C_Label); + $this->drawLine($XPos-1,$YPos,$XPos + 8,$YPos - $TextOffset - 1.2,$R,$G,$B); + $this->drawLine($XPos-1,$YPos,$XPos + 8,$YPos + $TextOffset + 1.2,$R,$G,$B); + $this->drawFilledRectangle($XPos + 8,$YPos - $TextOffset - 1.2,$XPos + 12 + $TextWidth,$YPos + $TextOffset + 1.2,$R,$G,$B); + + imagettftext($this->Picture,$this->FontSize,0,$XPos + 10,$YPos + $TextOffset,$C_TextColor,$this->FontName,$Caption); + } + + /* This function draw a plot graph */ + function drawPlotGraph($Data,$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=FALSE) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawPlotGraph",$DataDescription); + $this->validateData("drawPlotGraph",$Data); + + $GraphID = 0; + $Ro = $R2; $Go = $G2; $Bo = $B2; + + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; } + + $R = $this->Palette[$ColorID]["R"]; + $G = $this->Palette[$ColorID]["G"]; + $B = $this->Palette[$ColorID]["B"]; + $R2 = $Ro; $G2 = $Go; $B2 = $Bo; + + if ( isset($DataDescription["Symbol"][$ColName]) ) + { + $Is_Alpha = ((ord ( file_get_contents ($DataDescription["Symbol"][$ColName], false, null, 25, 1)) & 6) & 4) == 4; + + $Infos = getimagesize($DataDescription["Symbol"][$ColName]); + $ImageWidth = $Infos[0]; + $ImageHeight = $Infos[1]; + $Symbol = imagecreatefromgif($DataDescription["Symbol"][$ColName]); + } + + $XPos = $this->GArea_X1 + $this->GAreaXOffset; + $Hsize = round($BigRadius/2); + $R3 = -1; $G3 = -1; $B3 = -1; + foreach ( $Data as $Key => $Values ) + { + $Value = $Data[$Key][$ColName]; + $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio); + + /* Save point into the image map if option activated */ + if ( $this->BuildMap ) + $this->addToImageMap($XPos-$Hsize,$YPos-$Hsize,$XPos+1+$Hsize,$YPos+$Hsize+1,$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Plot"); + + if ( is_numeric($Value) ) + { + if ( !isset($DataDescription["Symbol"][$ColName]) ) + { + + if ( $Shadow ) + { + if ( $R3 !=-1 && $G3 !=-1 && $B3 !=-1 ) + $this->drawFilledCircle($XPos+2,$YPos+2,$BigRadius,$R3,$G3,$B3); + else + { + $R3 = $this->Palette[$ColorID]["R"]-20; if ( $R3 < 0 ) { $R3 = 0; } + $G3 = $this->Palette[$ColorID]["G"]-20; if ( $G3 < 0 ) { $G3 = 0; } + $B3 = $this->Palette[$ColorID]["B"]-20; if ( $B3 < 0 ) { $B3 = 0; } + $this->drawFilledCircle($XPos+2,$YPos+2,$BigRadius,$R3,$G3,$B3); + } + } + + $this->drawFilledCircle($XPos+1,$YPos+1,$BigRadius,$R,$G,$B); + + if ( $SmallRadius != 0 ) + { + if ( $R2 !=-1 && $G2 !=-1 && $B2 !=-1 ) + $this->drawFilledCircle($XPos+1,$YPos+1,$SmallRadius,$R2,$G2,$B2); + else + { + $R2 = $this->Palette[$ColorID]["R"]-15; if ( $R2 < 0 ) { $R2 = 0; } + $G2 = $this->Palette[$ColorID]["G"]-15; if ( $G2 < 0 ) { $G2 = 0; } + $B2 = $this->Palette[$ColorID]["B"]-15; if ( $B2 < 0 ) { $B2 = 0; } + + $this->drawFilledCircle($XPos+1,$YPos+1,$SmallRadius,$R2,$G2,$B2); + } + } + } + else + { + imagecopymerge($this->Picture,$Symbol,$XPos+1-$ImageWidth/2,$YPos+1-$ImageHeight/2,0,0,$ImageWidth,$ImageHeight,100); + } + } + + $XPos = $XPos + $this->DivisionWidth; + } + $GraphID++; + } + } + + /* This function draw a plot graph in an X/Y space */ + function drawXYPlotGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=TRUE) + { + $R = $this->Palette[$PaletteID]["R"]; + $G = $this->Palette[$PaletteID]["G"]; + $B = $this->Palette[$PaletteID]["B"]; + $R3 = -1; $G3 = -1; $B3 = -1; + + $YLast = -1; $XLast = -1; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$YSerieName]) && isset($Data[$Key][$XSerieName]) ) + { + $X = $Data[$Key][$XSerieName]; + $Y = $Data[$Key][$YSerieName]; + + $Y = $this->GArea_Y2 - (($Y-$this->VMin) * $this->DivisionRatio); + $X = $this->GArea_X1 + (($X-$this->VXMin) * $this->XDivisionRatio); + + + if ( $Shadow ) + { + if ( $R3 !=-1 && $G3 !=-1 && $B3 !=-1 ) + $this->drawFilledCircle($X+2,$Y+2,$BigRadius,$R3,$G3,$B3); + else + { + $R3 = $this->Palette[$PaletteID]["R"]-20; if ( $R < 0 ) { $R = 0; } + $G3 = $this->Palette[$PaletteID]["G"]-20; if ( $G < 0 ) { $G = 0; } + $B3 = $this->Palette[$PaletteID]["B"]-20; if ( $B < 0 ) { $B = 0; } + $this->drawFilledCircle($X+2,$Y+2,$BigRadius,$R3,$G3,$B3); + } + } + + $this->drawFilledCircle($X+1,$Y+1,$BigRadius,$R,$G,$B); + + if ( $R2 !=-1 && $G2 !=-1 && $B2 !=-1 ) + $this->drawFilledCircle($X+1,$Y+1,$SmallRadius,$R2,$G2,$B2); + else + { + $R2 = $this->Palette[$PaletteID]["R"]+20; if ( $R > 255 ) { $R = 255; } + $G2 = $this->Palette[$PaletteID]["G"]+20; if ( $G > 255 ) { $G = 255; } + $B2 = $this->Palette[$PaletteID]["B"]+20; if ( $B > 255 ) { $B = 255; } + $this->drawFilledCircle($X+1,$Y+1,$SmallRadius,$R2,$G2,$B2); + } + } + } + + } + + /* This function draw an area between two series */ + function drawArea($Data,$Serie1,$Serie2,$R,$G,$B,$Alpha = 50) + { + /* Validate the Data and DataDescription array */ + $this->validateData("drawArea",$Data); + + $LayerWidth = $this->GArea_X2-$this->GArea_X1; + $LayerHeight = $this->GArea_Y2-$this->GArea_Y1; + + $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight); + $C_White =$this->AllocateColor($this->Layers[0],255,255,255); + imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White); + imagecolortransparent($this->Layers[0],$C_White); + + $C_Graph =$this->AllocateColor($this->Layers[0],$R,$G,$B); + + $XPos = $this->GAreaXOffset; + $LastXPos = -1; + foreach ( $Data as $Key => $Values ) + { + $Value1 = $Data[$Key][$Serie1]; + $Value2 = $Data[$Key][$Serie2]; + $YPos1 = $LayerHeight - (($Value1-$this->VMin) * $this->DivisionRatio); + $YPos2 = $LayerHeight - (($Value2-$this->VMin) * $this->DivisionRatio); + + if ( $LastXPos != -1 ) + { + $Points = ""; + $Points[] = $LastXPos; $Points[] = $LastYPos1; + $Points[] = $LastXPos; $Points[] = $LastYPos2; + $Points[] = $XPos; $Points[] = $YPos2; + $Points[] = $XPos; $Points[] = $YPos1; + + imagefilledpolygon($this->Layers[0],$Points,4,$C_Graph); + } + + $LastYPos1 = $YPos1; + $LastYPos2 = $YPos2; + $LastXPos = $XPos; + + $XPos = $XPos + $this->DivisionWidth; + } + + imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha); + imagedestroy($this->Layers[0]); + } + + + /* This function write the values of the specified series */ + function writeValues($Data,$DataDescription,$Series) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("writeValues",$DataDescription); + $this->validateData("writeValues",$Data); + + if ( !is_array($Series) ) { $Series = array($Series); } + + foreach($Series as $Key => $Serie) + { + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $Serie ) { $ColorID = $ID; }; $ID++; } + + $XPos = $this->GArea_X1 + $this->GAreaXOffset; + $XLast = -1; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$Serie]) && is_numeric($Data[$Key][$Serie])) + { + $Value = $Data[$Key][$Serie]; + $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio); + + $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$Value); + $Width = $Positions[2] - $Positions[6]; $XOffset = $XPos - ($Width/2); + $Height = $Positions[3] - $Positions[7]; $YOffset = $YPos - 4; + + $C_TextColor =$this->AllocateColor($this->Picture,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]); + imagettftext($this->Picture,$this->FontSize,0,$XOffset,$YOffset,$C_TextColor,$this->FontName,$Value); + } + $XPos = $XPos + $this->DivisionWidth; + } + + } + } + + /* This function draw a line graph */ + function drawLineGraph($Data,$DataDescription,$SerieName="") + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawLineGraph",$DataDescription); + $this->validateData("drawLineGraph",$Data); + + $GraphID = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; } + + if ( $SerieName == "" || $SerieName == $ColName ) + { + $XPos = $this->GArea_X1 + $this->GAreaXOffset; + $XLast = -1; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName])) + { + $Value = $Data[$Key][$ColName]; + $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio); + + /* Save point into the image map if option activated */ + if ( $this->BuildMap ) + $this->addToImageMap($XPos-3,$YPos-3,$XPos+3,$YPos+3,$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Line"); + + if (!is_numeric($Value)) { $XLast = -1; } + if ( $XLast != -1 ) + $this->drawLine($XLast,$YLast,$XPos,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE); + + $XLast = $XPos; + $YLast = $YPos; + if (!is_numeric($Value)) { $XLast = -1; } + } + $XPos = $XPos + $this->DivisionWidth; + } + $GraphID++; + } + } + } + + /* This function draw a line graph */ + function drawXYGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0) + { + $YLast = -1; $XLast = -1; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$YSerieName]) && isset($Data[$Key][$XSerieName]) ) + { + $X = $Data[$Key][$XSerieName]; + $Y = $Data[$Key][$YSerieName]; + + $Y = $this->GArea_Y2 - (($Y-$this->VMin) * $this->DivisionRatio); + $X = $this->GArea_X1 + (($X-$this->VXMin) * $this->XDivisionRatio); + + if ($XLast != -1 && $YLast != -1) + { + $this->drawLine($XLast,$YLast,$X,$Y,$this->Palette[$PaletteID]["R"],$this->Palette[$PaletteID]["G"],$this->Palette[$PaletteID]["B"],TRUE); + } + + $XLast = $X; + $YLast = $Y; + } + } + } + + /* This function draw a cubic curve */ + function drawCubicCurve($Data,$DataDescription,$Accuracy=.1,$SerieName="") + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawCubicCurve",$DataDescription); + $this->validateData("drawCubicCurve",$Data); + + $GraphID = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + if ( $SerieName == "" || $SerieName == $ColName ) + { + $XIn = ""; $Yin = ""; $Yt = ""; $U = ""; + $XIn[0] = 0; $YIn[0] = 0; + + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; } + + $Index = 1; + $XLast = -1; $Missing = ""; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName]) ) + { + $Value = $Data[$Key][$ColName]; + $XIn[$Index] = $Index; + $YIn[$Index] = $Value; + if ( !is_numeric($Value) ) { $Missing[$Index] = TRUE; } + $Index++; + } + } + $Index--; + + $Yt[0] = 0; + $Yt[1] = 0; + $U[1] = 0; + for($i=2;$i<=$Index-1;$i++) + { + $Sig = ($XIn[$i] - $XIn[$i-1]) / ($XIn[$i+1] - $XIn[$i-1]); + $p = $Sig * $Yt[$i-1] + 2; + $Yt[$i] = ($Sig - 1) / $p; + $U[$i] = ($YIn[$i+1] - $YIn[$i]) / ($XIn[$i+1] - $XIn[$i]) - ($YIn[$i] - $YIn[$i-1]) / ($XIn[$i] - $XIn[$i-1]); + $U[$i] = (6 * $U[$i] / ($XIn[$i+1] - $XIn[$i-1]) - $Sig * $U[$i-1]) / $p; + } + + $qn = 0; + $un = 0; + $Yt[$Index] = ($un - $qn * $U[$Index-1]) / ($qn * $Yt[$Index-1] + 1); + + for($k=$Index-1;$k>=1;$k--) + $Yt[$k] = $Yt[$k] * $Yt[$k+1] + $U[$k]; + + $XPos = $this->GArea_X1 + $this->GAreaXOffset; + for($X=1;$X<=$Index;$X=$X+$Accuracy) + { + $klo = 1; + $khi = $Index; + $k = $khi - $klo; + while($k > 1) + { + $k = $khi - $klo; + If ( $XIn[$k] >= $X ) + $khi = $k; + else + $klo = $k; + } + $klo = $khi - 1; + + $h = $XIn[$khi] - $XIn[$klo]; + $a = ($XIn[$khi] - $X) / $h; + $b = ($X - $XIn[$klo]) / $h; + $Value = $a * $YIn[$klo] + $b * $YIn[$khi] + (($a*$a*$a - $a) * $Yt[$klo] + ($b*$b*$b - $b) * $Yt[$khi]) * ($h*$h) / 6; + + $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio); + + if ( $XLast != -1 && !isset($Missing[floor($X)]) && !isset($Missing[floor($X+1)]) ) + $this->drawLine($XLast,$YLast,$XPos,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE); + + $XLast = $XPos; + $YLast = $YPos; + $XPos = $XPos + $this->DivisionWidth * $Accuracy; + } + + // Add potentialy missing values + $XPos = $XPos - $this->DivisionWidth * $Accuracy; + if ( $XPos < ($this->GArea_X2 - $this->GAreaXOffset) ) + { + $YPos = $this->GArea_Y2 - (($YIn[$Index]-$this->VMin) * $this->DivisionRatio); + $this->drawLine($XLast,$YLast,$this->GArea_X2-$this->GAreaXOffset,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE); + } + + $GraphID++; + } + } + } + + /* This function draw a filled cubic curve */ + function drawFilledCubicCurve($Data,$DataDescription,$Accuracy=.1,$Alpha=100,$AroundZero=FALSE) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawFilledCubicCurve",$DataDescription); + $this->validateData("drawFilledCubicCurve",$Data); + + $LayerWidth = $this->GArea_X2-$this->GArea_X1; + $LayerHeight = $this->GArea_Y2-$this->GArea_Y1; + $YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio); + if ( $YZero > $LayerHeight ) { $YZero = $LayerHeight; } + + $GraphID = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + $XIn = ""; $Yin = ""; $Yt = ""; $U = ""; + $XIn[0] = 0; $YIn[0] = 0; + + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; } + + $Index = 1; + $XLast = -1; $Missing = ""; + foreach ( $Data as $Key => $Values ) + { + $Value = $Data[$Key][$ColName]; + $XIn[$Index] = $Index; + $YIn[$Index] = $Value; + if ( !is_numeric($Value) ) { $Missing[$Index] = TRUE; } + $Index++; + } + $Index--; + + $Yt[0] = 0; + $Yt[1] = 0; + $U[1] = 0; + for($i=2;$i<=$Index-1;$i++) + { + $Sig = ($XIn[$i] - $XIn[$i-1]) / ($XIn[$i+1] - $XIn[$i-1]); + $p = $Sig * $Yt[$i-1] + 2; + $Yt[$i] = ($Sig - 1) / $p; + $U[$i] = ($YIn[$i+1] - $YIn[$i]) / ($XIn[$i+1] - $XIn[$i]) - ($YIn[$i] - $YIn[$i-1]) / ($XIn[$i] - $XIn[$i-1]); + $U[$i] = (6 * $U[$i] / ($XIn[$i+1] - $XIn[$i-1]) - $Sig * $U[$i-1]) / $p; + } + + $qn = 0; + $un = 0; + $Yt[$Index] = ($un - $qn * $U[$Index-1]) / ($qn * $Yt[$Index-1] + 1); + + for($k=$Index-1;$k>=1;$k--) + $Yt[$k] = $Yt[$k] * $Yt[$k+1] + $U[$k]; + + $Points = ""; + $Points[] = $this->GAreaXOffset; + $Points[] = $LayerHeight; + + $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight); + $C_White =$this->AllocateColor($this->Layers[0],255,255,255); + imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White); + imagecolortransparent($this->Layers[0],$C_White); + + $YLast = NULL; + $XPos = $this->GAreaXOffset; $PointsCount = 2; + for($X=1;$X<=$Index;$X=$X+$Accuracy) + { + $klo = 1; + $khi = $Index; + $k = $khi - $klo; + while($k > 1) + { + $k = $khi - $klo; + If ( $XIn[$k] >= $X ) + $khi = $k; + else + $klo = $k; + } + $klo = $khi - 1; + + $h = $XIn[$khi] - $XIn[$klo]; + $a = ($XIn[$khi] - $X) / $h; + $b = ($X - $XIn[$klo]) / $h; + $Value = $a * $YIn[$klo] + $b * $YIn[$khi] + (($a*$a*$a - $a) * $Yt[$klo] + ($b*$b*$b - $b) * $Yt[$khi]) * ($h*$h) / 6; + + $YPos = $LayerHeight - (($Value-$this->VMin) * $this->DivisionRatio); + + if ( $YLast != NULL && $AroundZero && !isset($Missing[floor($X)]) && !isset($Missing[floor($X+1)])) + { + $aPoints = ""; + $aPoints[] = $XLast; + $aPoints[] = $YLast; + $aPoints[] = $XPos; + $aPoints[] = $YPos; + $aPoints[] = $XPos; + $aPoints[] = $YZero; + $aPoints[] = $XLast; + $aPoints[] = $YZero; + + $C_Graph =$this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]); + imagefilledpolygon($this->Layers[0],$aPoints,4,$C_Graph); + } + + if ( !isset($Missing[floor($X)]) || $YLast == NULL ) + { + $PointsCount++; + $Points[] = $XPos; + $Points[] = $YPos; + } + else + { + $PointsCount++; $Points[] = $XLast; $Points[] = $LayerHeight; + } + + $YLast = $YPos; $XLast = $XPos; + $XPos = $XPos + $this->DivisionWidth * $Accuracy; + } + + // Add potentialy missing values + $XPos = $XPos - $this->DivisionWidth * $Accuracy; + if ( $XPos < ($LayerWidth-$this->GAreaXOffset) ) + { + $YPos = $LayerHeight - (($YIn[$Index]-$this->VMin) * $this->DivisionRatio); + + if ( $YLast != NULL && $AroundZero ) + { + $aPoints = ""; + $aPoints[] = $XLast; + $aPoints[] = $YLast; + $aPoints[] = $LayerWidth-$this->GAreaXOffset; + $aPoints[] = $YPos; + $aPoints[] = $LayerWidth-$this->GAreaXOffset; + $aPoints[] = $YZero; + $aPoints[] = $XLast; + $aPoints[] = $YZero; + + $C_Graph =$this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]); + imagefilledpolygon($this->Layers[0],$aPoints,4,$C_Graph); + } + + if ( $YIn[$klo] != "" && $YIn[$khi] != "" || $YLast == NULL ) + { + $PointsCount++; + $Points[] = $LayerWidth-$this->GAreaXOffset; + $Points[] = $YPos; + } + } + + $Points[] = $LayerWidth-$this->GAreaXOffset; + $Points[] = $LayerHeight; + + if ( !$AroundZero ) + { + $C_Graph =$this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]); + imagefilledpolygon($this->Layers[0],$Points,$PointsCount,$C_Graph); + } + + imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha); + imagedestroy($this->Layers[0]); + + $this->drawCubicCurve($Data,$DataDescription,$Accuracy,$ColName); + + $GraphID++; + } + } + + /* This function draw a filled line graph */ + function drawFilledLineGraph($Data,$DataDescription,$Alpha=100,$AroundZero=FALSE) + { + $Empty = -2147483647; + + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawFilledLineGraph",$DataDescription); + $this->validateData("drawFilledLineGraph",$Data); + + $LayerWidth = $this->GArea_X2-$this->GArea_X1; + $LayerHeight = $this->GArea_Y2-$this->GArea_Y1; + + $GraphID = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; } + + $aPoints = ""; + $aPoints[] = $this->GAreaXOffset; + $aPoints[] = $LayerHeight; + + $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight); + $C_White = $this->AllocateColor($this->Layers[0],255,255,255); + imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White); + imagecolortransparent($this->Layers[0],$C_White); + + $XPos = $this->GAreaXOffset; + $XLast = -1; $PointsCount = 2; + $YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio); + if ( $YZero > $LayerHeight ) { $YZero = $LayerHeight; } + + $YLast = $Empty; + foreach ( $Data as $Key => $Values ) + { + $Value = $Data[$Key][$ColName]; + $YPos = $LayerHeight - (($Value-$this->VMin) * $this->DivisionRatio); + + /* Save point into the image map if option activated */ + if ( $this->BuildMap ) + $this->addToImageMap($XPos-3,$YPos-3,$XPos+3,$YPos+3,$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"FLine"); + + if ( !is_numeric($Value) ) + { + $PointsCount++; + $aPoints[] = $XLast; + $aPoints[] = $LayerHeight; + + $YLast = $Empty; + } + else + { + $PointsCount++; + if ( $YLast <> $Empty ) + { $aPoints[] = $XPos; $aPoints[] = $YPos; } + else + { $PointsCount++; $aPoints[] = $XPos; $aPoints[] = $LayerHeight; $aPoints[] = $XPos; $aPoints[] = $YPos; } + + if ($YLast <> $Empty && $AroundZero) + { + $Points = ""; + $Points[] = $XLast; $Points[] = $YLast; + $Points[] = $XPos; + $Points[] = $YPos; + $Points[] = $XPos; + $Points[] = $YZero; + $Points[] = $XLast; + $Points[] = $YZero; + + $C_Graph = $this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]); + imagefilledpolygon($this->Layers[0],$Points,4,$C_Graph); + } + $YLast = $YPos; + } + + $XLast = $XPos; + $XPos = $XPos + $this->DivisionWidth; + } + $aPoints[] = $LayerWidth - $this->GAreaXOffset; + $aPoints[] = $LayerHeight; + + if ( $AroundZero == FALSE ) + { + $C_Graph = $this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]); + imagefilledpolygon($this->Layers[0],$aPoints,$PointsCount,$C_Graph); + } + + imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha); + imagedestroy($this->Layers[0]); + $GraphID++; + $this->drawLineGraph($Data,$DataDescription,$ColName); + } + } + + /* This function draw a bar graph */ + function drawOverlayBarGraph($Data,$DataDescription,$Alpha=50) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawOverlayBarGraph",$DataDescription); + $this->validateData("drawOverlayBarGraph",$Data); + + $LayerWidth = $this->GArea_X2-$this->GArea_X1; + $LayerHeight = $this->GArea_Y2-$this->GArea_Y1; + + $GraphID = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; } + + $this->Layers[$GraphID] = imagecreatetruecolor($LayerWidth,$LayerHeight); + $C_White = $this->AllocateColor($this->Layers[$GraphID],255,255,255); + $C_Graph = $this->AllocateColor($this->Layers[$GraphID],$this->Palette[$GraphID]["R"],$this->Palette[$GraphID]["G"],$this->Palette[$GraphID]["B"]); + imagefilledrectangle($this->Layers[$GraphID],0,0,$LayerWidth,$LayerHeight,$C_White); + imagecolortransparent($this->Layers[$GraphID],$C_White); + + $XWidth = $this->DivisionWidth / 4; + $XPos = $this->GAreaXOffset; + $YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio); + $XLast = -1; $PointsCount = 2; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName]) ) + { + $Value = $Data[$Key][$ColName]; + if ( is_numeric($Value) ) + { + $YPos = $LayerHeight - (($Value-$this->VMin) * $this->DivisionRatio); + + imagefilledrectangle($this->Layers[$GraphID],$XPos-$XWidth,$YPos,$XPos+$XWidth,$YZero,$C_Graph); + + $X1 = floor($XPos - $XWidth + $this->GArea_X1); $Y1 = floor($YPos+$this->GArea_Y1) + .2; + $X2 = floor($XPos + $XWidth + $this->GArea_X1); $Y2 = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio); + if ( $X1 <= $this->GArea_X1 ) { $X1 = $this->GArea_X1 + 1; } + if ( $X2 >= $this->GArea_X2 ) { $X2 = $this->GArea_X2 - 1; } + + /* Save point into the image map if option activated */ + if ( $this->BuildMap ) + $this->addToImageMap($X1,min($Y1,$Y2),$X2,max($Y1,$Y2),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"oBar"); + + $this->drawLine($X1,$Y1,$X2,$Y1,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE); + } + } + $XPos = $XPos + $this->DivisionWidth; + } + + $GraphID++; + } + + for($i=0;$i<=($GraphID-1);$i++) + { + imagecopymerge($this->Picture,$this->Layers[$i],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha); + imagedestroy($this->Layers[$i]); + } + } + + /* This function draw a bar graph */ + function drawBarGraph($Data,$DataDescription,$Shadow=FALSE,$Alpha=100) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawBarGraph",$DataDescription); + $this->validateData("drawBarGraph",$Data); + + $GraphID = 0; + $Series = count($DataDescription["Values"]); + $SeriesWidth = $this->DivisionWidth / ($Series+1); + $SerieXOffset = $this->DivisionWidth / 2 - $SeriesWidth / 2; + + $YZero = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio); + if ( $YZero > $this->GArea_Y2 ) { $YZero = $this->GArea_Y2; } + + $SerieID = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; } + + $XPos = $this->GArea_X1 + $this->GAreaXOffset - $SerieXOffset + $SeriesWidth * $SerieID; + $XLast = -1; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName])) + { + if ( is_numeric($Data[$Key][$ColName]) ) + { + $Value = $Data[$Key][$ColName]; + $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio); + + /* Save point into the image map if option activated */ + if ( $this->BuildMap ) + { + $this->addToImageMap($XPos+1,min($YZero,$YPos),$XPos+$SeriesWidth-1,max($YZero,$YPos),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Bar"); + } + + if ( $Shadow && $Alpha == 100 ) + $this->drawRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,25,25,25,TRUE,$Alpha); + + $this->drawFilledRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha); + } + } + $XPos = $XPos + $this->DivisionWidth; + } + $SerieID++; + } + } + + /* This function draw a stacked bar graph */ + function drawStackedBarGraph($Data,$DataDescription,$Alpha=50,$Contiguous=FALSE) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawBarGraph",$DataDescription); + $this->validateData("drawBarGraph",$Data); + + $GraphID = 0; + $Series = count($DataDescription["Values"]); + if ( $Contiguous ) + $SeriesWidth = $this->DivisionWidth; + else + $SeriesWidth = $this->DivisionWidth * .8; + + $YZero = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio); + if ( $YZero > $this->GArea_Y2 ) { $YZero = $this->GArea_Y2; } + + $SerieID = 0; $LastValue = ""; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; } + + $XPos = $this->GArea_X1 + $this->GAreaXOffset - $SeriesWidth / 2; + $XLast = -1; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName])) + { + if ( is_numeric($Data[$Key][$ColName]) ) + { + $Value = $Data[$Key][$ColName]; + + if ( isset($LastValue[$Key]) ) + { + $YPos = $this->GArea_Y2 - ((($Value+$LastValue[$Key])-$this->VMin) * $this->DivisionRatio); + $YBottom = $this->GArea_Y2 - (($LastValue[$Key]-$this->VMin) * $this->DivisionRatio); + $LastValue[$Key] += $Value; + } + else + { + $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio); + $YBottom = $YZero; + $LastValue[$Key] = $Value; + } + + /* Save point into the image map if option activated */ + if ( $this->BuildMap ) + $this->addToImageMap($XPos+1,min($YBottom,$YPos),$XPos+$SeriesWidth-1,max($YBottom,$YPos),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"sBar"); + + $this->drawFilledRectangle($XPos+1,$YBottom,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha); + } + } + $XPos = $XPos + $this->DivisionWidth; + } + $SerieID++; + } + } + + /* This function draw a limits bar graphs */ + function drawLimitsGraph($Data,$DataDescription,$R=0,$G=0,$B=0) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawLimitsGraph",$DataDescription); + $this->validateData("drawLimitsGraph",$Data); + + $XWidth = $this->DivisionWidth / 4; + $XPos = $this->GArea_X1 + $this->GAreaXOffset; + + foreach ( $Data as $Key => $Values ) + { + $Min = $Data[$Key][$DataDescription["Values"][0]]; + $Max = $Data[$Key][$DataDescription["Values"][0]]; + $GraphID = 0; $MaxID = 0; $MinID = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + if ( isset($Data[$Key][$ColName]) ) + { + if ( $Data[$Key][$ColName] > $Max && is_numeric($Data[$Key][$ColName])) + { $Max = $Data[$Key][$ColName]; $MaxID = $GraphID; } + } + if ( isset($Data[$Key][$ColName]) && is_numeric($Data[$Key][$ColName])) + { + if ( $Data[$Key][$ColName] < $Min ) + { $Min = $Data[$Key][$ColName]; $MinID = $GraphID; } + $GraphID++; + } + } + + $YPos = $this->GArea_Y2 - (($Max-$this->VMin) * $this->DivisionRatio); + $X1 = floor($XPos - $XWidth); $Y1 = floor($YPos) - .2; + $X2 = floor($XPos + $XWidth); + if ( $X1 <= $this->GArea_X1 ) { $X1 = $this->GArea_X1 + 1; } + if ( $X2 >= $this->GArea_X2 ) { $X2 = $this->GArea_X2 - 1; } + + $YPos = $this->GArea_Y2 - (($Min-$this->VMin) * $this->DivisionRatio); + $Y2 = floor($YPos) + .2; + + $this->drawLine(floor($XPos)-.2,$Y1+1,floor($XPos)-.2,$Y2-1,$R,$G,$B,TRUE); + $this->drawLine(floor($XPos)+.2,$Y1+1,floor($XPos)+.2,$Y2-1,$R,$G,$B,TRUE); + $this->drawLine($X1,$Y1,$X2,$Y1,$this->Palette[$MaxID]["R"],$this->Palette[$MaxID]["G"],$this->Palette[$MaxID]["B"],FALSE); + $this->drawLine($X1,$Y2,$X2,$Y2,$this->Palette[$MinID]["R"],$this->Palette[$MinID]["G"],$this->Palette[$MinID]["B"],FALSE); + + $XPos = $XPos + $this->DivisionWidth; + } + } + + /* This function draw radar axis centered on the graph area */ + function drawRadarAxis($Data,$DataDescription,$Mosaic=TRUE,$BorderOffset=10,$A_R=60,$A_G=60,$A_B=60,$S_R=200,$S_G=200,$S_B=200,$MaxValue=-1) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawRadarAxis",$DataDescription); + $this->validateData("drawRadarAxis",$Data); + + $C_TextColor = $this->AllocateColor($this->Picture,$A_R,$A_G,$A_B); + + /* Draw radar axis */ + $Points = count($Data); + $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset; + $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2 + $this->GArea_X1; + $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 + $this->GArea_Y1; + + /* Search for the max value */ + if ( $MaxValue == -1 ) + { + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName])) + if ( $Data[$Key][$ColName] > $MaxValue ) { $MaxValue = $Data[$Key][$ColName]; } + } + } + } + + /* Draw the mosaic */ + if ( $Mosaic ) + { + $RadiusScale = $Radius / $MaxValue; + for ( $t=1; $t<=$MaxValue-1; $t++) + { + $TRadius = $RadiusScale * $t; + $LastX1 = -1; + + for ( $i=0; $i<=$Points; $i++) + { + $Angle = -90 + $i * 360/$Points; + $X1 = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter; + $Y1 = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter; + $X2 = cos($Angle * 3.1418 / 180 ) * ($TRadius+$RadiusScale) + $XCenter; + $Y2 = sin($Angle * 3.1418 / 180 ) * ($TRadius+$RadiusScale) + $YCenter; + + if ( $t % 2 == 1 && $LastX1 != -1) + { + $Plots = ""; + $Plots[] = $X1; $Plots[] = $Y1; + $Plots[] = $X2; $Plots[] = $Y2; + $Plots[] = $LastX2; $Plots[] = $LastY2; + $Plots[] = $LastX1; $Plots[] = $LastY1; + + $C_Graph = $this->AllocateColor($this->Picture,250,250,250); + imagefilledpolygon($this->Picture,$Plots,(count($Plots)+1)/2,$C_Graph); + } + + $LastX1 = $X1; $LastY1= $Y1; + $LastX2 = $X2; $LastY2= $Y2; + } + } + } + + + /* Draw the spider web */ + for ( $t=1; $t<=$MaxValue; $t++) + { + $TRadius = ( $Radius / $MaxValue ) * $t; + $LastX = -1; + + for ( $i=0; $i<=$Points; $i++) + { + $Angle = -90 + $i * 360/$Points; + $X = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter; + $Y = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter; + + if ( $LastX != -1 ) + $this->drawDottedLine($LastX,$LastY,$X,$Y,4,$S_R,$S_G,$S_B); + + $LastX = $X; $LastY= $Y; + } + } + + /* Draw the axis */ + for ( $i=0; $i<=$Points; $i++) + { + $Angle = -90 + $i * 360/$Points; + $X = cos($Angle * 3.1418 / 180 ) * $Radius + $XCenter; + $Y = sin($Angle * 3.1418 / 180 ) * $Radius + $YCenter; + + $this->drawLine($XCenter,$YCenter,$X,$Y,$A_R,$A_G,$A_B); + + $XOffset = 0; $YOffset = 0; + if (isset($Data[$i][$DataDescription["Position"]])) + { + $Label = $Data[$i][$DataDescription["Position"]]; + + $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$Label); + $Width = $Positions[2] - $Positions[6]; + $Height = $Positions[3] - $Positions[7]; + + if ( $Angle >= 0 && $Angle <= 90 ) + $YOffset = $Height; + + if ( $Angle > 90 && $Angle <= 180 ) + { $YOffset = $Height; $XOffset = -$Width; } + + if ( $Angle > 180 && $Angle <= 270 ) + { $XOffset = -$Width; } + + imagettftext($this->Picture,$this->FontSize,0,$X+$XOffset,$Y+$YOffset,$C_TextColor,$this->FontName,$Label); + } + } + + /* Write the values */ + for ( $t=1; $t<=$MaxValue; $t++) + { + $TRadius = ( $Radius / $MaxValue ) * $t; + + $Angle = -90 + 360 / $Points; + $X1 = $XCenter; + $Y1 = $YCenter - $TRadius; + $X2 = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter; + $Y2 = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter; + + $XPos = floor(($X2-$X1)/2) + $X1; + $YPos = floor(($Y2-$Y1)/2) + $Y1; + + $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$t); + $X = $XPos - ( $X+$Positions[2] - $X+$Positions[6] ) / 2; + $Y = $YPos + $this->FontSize; + + $this->drawFilledRoundedRectangle($X+$Positions[6]-2,$Y+$Positions[7]-1,$X+$Positions[2]+4,$Y+$Positions[3]+1,2,240,240,240); + $this->drawRoundedRectangle($X+$Positions[6]-2,$Y+$Positions[7]-1,$X+$Positions[2]+4,$Y+$Positions[3]+1,2,220,220,220); + imagettftext($this->Picture,$this->FontSize,0,$X,$Y,$C_TextColor,$this->FontName,$t); + } + } + + /* This function draw a radar graph centered on the graph area */ + function drawRadar($Data,$DataDescription,$BorderOffset=10,$MaxValue=-1) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawRadar",$DataDescription); + $this->validateData("drawRadar",$Data); + + $Points = count($Data); + $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset; + $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2 + $this->GArea_X1; + $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 + $this->GArea_Y1; + + /* Search for the max value */ + if ( $MaxValue == -1 ) + { + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName])) + if ( $Data[$Key][$ColName] > $MaxValue ) { $MaxValue = $Data[$Key][$ColName]; } + } + } + } + + $GraphID = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; } + + $Angle = -90; + $XLast = -1; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName])) + { + $Value = $Data[$Key][$ColName]; + $Strength = ( $Radius / $MaxValue ) * $Value; + + $XPos = cos($Angle * 3.1418 / 180 ) * $Strength + $XCenter; + $YPos = sin($Angle * 3.1418 / 180 ) * $Strength + $YCenter; + + if ( $XLast != -1 ) + $this->drawLine($XLast,$YLast,$XPos,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]); + + if ( $XLast == -1 ) + { $FirstX = $XPos; $FirstY = $YPos; } + + $Angle = $Angle + (360/$Points); + $XLast = $XPos; + $YLast = $YPos; + } + } + $this->drawLine($XPos,$YPos,$FirstX,$FirstY,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]); + $GraphID++; + } + } + + /* This function draw a radar graph centered on the graph area */ + function drawFilledRadar($Data,$DataDescription,$Alpha=50,$BorderOffset=10,$MaxValue=-1) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawFilledRadar",$DataDescription); + $this->validateData("drawFilledRadar",$Data); + + $Points = count($Data); + $LayerWidth = $this->GArea_X2-$this->GArea_X1; + $LayerHeight = $this->GArea_Y2-$this->GArea_Y1; + $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset; + $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2; + $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2; + + /* Search for the max value */ + if ( $MaxValue == -1 ) + { + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName])) + if ( $Data[$Key][$ColName] > $MaxValue && is_numeric($Data[$Key][$ColName])) { $MaxValue = $Data[$Key][$ColName]; } + } + } + } + + $GraphID = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + $ID = 0; + foreach ( $DataDescription["Description"] as $keyI => $ValueI ) + { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; } + + $Angle = -90; + $XLast = -1; + $Plots = ""; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName])) + { + $Value = $Data[$Key][$ColName]; + if ( !is_numeric($Value) ) { $Value = 0; } + $Strength = ( $Radius / $MaxValue ) * $Value; + + $XPos = cos($Angle * 3.1418 / 180 ) * $Strength + $XCenter; + $YPos = sin($Angle * 3.1418 / 180 ) * $Strength + $YCenter; + + $Plots[] = $XPos; + $Plots[] = $YPos; + + $Angle = $Angle + (360/$Points); + $XLast = $XPos; + $YLast = $YPos; + } + } + + if (isset($Plots[0])) + { + $Plots[] = $Plots[0]; + $Plots[] = $Plots[1]; + + $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight); + $C_White = $this->AllocateColor($this->Layers[0],255,255,255); + imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White); + imagecolortransparent($this->Layers[0],$C_White); + + $C_Graph = $this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]); + imagefilledpolygon($this->Layers[0],$Plots,(count($Plots)+1)/2,$C_Graph); + + imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha); + imagedestroy($this->Layers[0]); + + for($i=0;$i<=count($Plots)-4;$i=$i+2) + $this->drawLine($Plots[$i]+$this->GArea_X1,$Plots[$i+1]+$this->GArea_Y1,$Plots[$i+2]+$this->GArea_X1,$Plots[$i+3]+$this->GArea_Y1,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]); + } + + $GraphID++; + } + } + + /* This function draw a flat pie chart */ + function drawBasicPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$R=255,$G=255,$B=255,$Decimals=0) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawBasicPieGraph",$DataDescription,FALSE); + $this->validateData("drawBasicPieGraph",$Data); + + /* Determine pie sum */ + $Series = 0; $PieSum = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + if ( $ColName != $DataDescription["Position"] ) + { + $Series++; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName])) + $PieSum = $PieSum + $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]]; + } + } + } + + /* Validate serie */ + if ( $Series != 1 ) + RaiseFatal("Pie chart can only accept one serie of data."); + + $SpliceRatio = 360 / $PieSum; + $SplicePercent = 100 / $PieSum; + + /* Calculate all polygons */ + $Angle = 0; $TopPlots = ""; + foreach($iValues as $Key => $Value) + { + $TopPlots[$Key][] = $XPos; + $TopPlots[$Key][] = $YPos; + + /* Process labels position & size */ + $Caption = ""; + if ( !($DrawLabels == PIE_NOLABEL) ) + { + $TAngle = $Angle+($Value*$SpliceRatio/2); + if ($DrawLabels == PIE_PERCENTAGE) + $Caption = (round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%"; + elseif ($DrawLabels == PIE_LABELS) + $Caption = $iLabels[$Key]; + elseif ($DrawLabels == PIE_PERCENTAGE_LABEL) + $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%"; + elseif ($DrawLabels == PIE_PERCENTAGE_LABEL) + $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%"; + + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption); + $TextWidth = $Position[2]-$Position[0]; + $TextHeight = abs($Position[1])+abs($Position[3]); + + $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius+10) + $XPos; + + if ( $TAngle > 0 && $TAngle < 180 ) + $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+10) + $YPos + 4; + else + $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+4) + $YPos - ($TextHeight/2); + + if ( $TAngle > 90 && $TAngle < 270 ) + $TX = $TX - $TextWidth; + + $C_TextColor = $this->AllocateColor($this->Picture,70,70,70); + imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption); + } + + /* Process pie slices */ + for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5) + { + $TopX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos; + $TopY = sin($iAngle * 3.1418 / 180 ) * $Radius + $YPos; + + $TopPlots[$Key][] = $TopX; + $TopPlots[$Key][] = $TopY; + } + + $TopPlots[$Key][] = $XPos; + $TopPlots[$Key][] = $YPos; + + $Angle = $iAngle; + } + $PolyPlots = $TopPlots; + + /* Set array values type to float --- PHP Bug with imagefilledpolygon casting to integer */ + foreach ($TopPlots as $Key => $Value) + { foreach ($TopPlots[$Key] as $Key2 => $Value2) { settype($TopPlots[$Key][$Key2],"float"); } } + + /* Draw Top polygons */ + foreach ($PolyPlots as $Key => $Value) + { + $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]); + imagefilledpolygon($this->Picture,$PolyPlots[$Key],(count($PolyPlots[$Key])+1)/2,$C_GraphLo); + } + + $this->drawCircle($XPos-.5,$YPos-.5,$Radius,$R,$G,$B); + $this->drawCircle($XPos-.5,$YPos-.5,$Radius+.5,$R,$G,$B); + + /* Draw Top polygons */ + foreach ($TopPlots as $Key => $Value) + { + for($j=0;$j<=count($TopPlots[$Key])-4;$j=$j+2) + $this->drawLine($TopPlots[$Key][$j],$TopPlots[$Key][$j+1],$TopPlots[$Key][$j+2],$TopPlots[$Key][$j+3],$R,$G,$B); + } + } + + function drawFlatPieGraphWithShadow($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals=0) + { + $this->drawFlatPieGraph($Data,$DataDescription,$XPos+$this->ShadowXDistance,$YPos+$this->ShadowYDistance,$Radius,PIE_NOLABEL,$SpliceDistance,$Decimals,TRUE); + $this->drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius,$DrawLabels,$SpliceDistance,$Decimals,FALSE); + } + + /* This function draw a flat pie chart */ + function drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals=0,$AllBlack=FALSE) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawFlatPieGraph",$DataDescription,FALSE); + $this->validateData("drawFlatPieGraph",$Data); + + $ShadowStatus = $this->ShadowActive ; $this->ShadowActive = FALSE; + + /* Determine pie sum */ + $Series = 0; $PieSum = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + if ( $ColName != $DataDescription["Position"] ) + { + $Series++; + foreach ( $Data as $Key => $Values ) + { + if ( isset($Data[$Key][$ColName])) + $PieSum = $PieSum + $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]]; + } + } + } + + /* Validate serie */ + if ( $Series != 1 ) + { + RaiseFatal("Pie chart can only accept one serie of data."); + return(0); + } + + $SpliceRatio = 360 / $PieSum; + $SplicePercent = 100 / $PieSum; + + /* Calculate all polygons */ + $Angle = 0; $TopPlots = ""; + foreach($iValues as $Key => $Value) + { + $XOffset = cos(($Angle+($Value/2*$SpliceRatio)) * 3.1418 / 180 ) * $SpliceDistance; + $YOffset = sin(($Angle+($Value/2*$SpliceRatio)) * 3.1418 / 180 ) * $SpliceDistance; + + $TopPlots[$Key][] = round($XPos + $XOffset); + $TopPlots[$Key][] = round($YPos + $YOffset); + + if ( $AllBlack ) + { $Rc = $this->ShadowRColor; $Gc = $this->ShadowGColor; $Bc = $this->ShadowBColor; } + else + { $Rc = $this->Palette[$Key]["R"]; $Gc = $this->Palette[$Key]["G"]; $Bc = $this->Palette[$Key]["B"]; } + + $XLineLast = ""; $YLineLast = ""; + + /* Process labels position & size */ + $Caption = ""; + if ( !($DrawLabels == PIE_NOLABEL) ) + { + $TAngle = $Angle+($Value*$SpliceRatio/2); + if ($DrawLabels == PIE_PERCENTAGE) + $Caption = (round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%"; + elseif ($DrawLabels == PIE_LABELS) + $Caption = $iLabels[$Key]; + elseif ($DrawLabels == PIE_PERCENTAGE_LABEL) + $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%"; + elseif ($DrawLabels == PIE_PERCENTAGE_LABEL) + $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%"; + + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption); + $TextWidth = $Position[2]-$Position[0]; + $TextHeight = abs($Position[1])+abs($Position[3]); + + $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius+10+$SpliceDistance) + $XPos; + + if ( $TAngle > 0 && $TAngle < 180 ) + $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+10+$SpliceDistance) + $YPos + 4; + else + $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+$SpliceDistance+4) + $YPos - ($TextHeight/2); + + if ( $TAngle > 90 && $TAngle < 270 ) + $TX = $TX - $TextWidth; + + $C_TextColor = $this->AllocateColor($this->Picture,70,70,70); + imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption); + } + + /* Process pie slices */ + if ( !$AllBlack ) + $LineColor = $this->AllocateColor($this->Picture,$Rc,$Gc,$Bc); + else + $LineColor = $this->AllocateColor($this->Picture,$Rc,$Gc,$Bc); + + $XLineLast = ""; $YLineLast = ""; + for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5) + { + $PosX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos + $XOffset; + $PosY = sin($iAngle * 3.1418 / 180 ) * $Radius + $YPos + $YOffset; + + $TopPlots[$Key][] = round($PosX); $TopPlots[$Key][] = round($PosY); + + if ( $iAngle == $Angle || $iAngle == $Angle+$Value*$SpliceRatio || $iAngle +.5 > $Angle+$Value*$SpliceRatio) + $this->drawLine($XPos+$XOffset,$YPos+$YOffset,$PosX,$PosY,$Rc,$Gc,$Bc); + + if ( $XLineLast != "" ) + $this->drawLine($XLineLast,$YLineLast,$PosX,$PosY,$Rc,$Gc,$Bc); + + $XLineLast = $PosX; $YLineLast = $PosY; + } + + $TopPlots[$Key][] = round($XPos + $XOffset); $TopPlots[$Key][] = round($YPos + $YOffset); + + $Angle = $iAngle; + } + $PolyPlots = $TopPlots; + + /* Draw Top polygons */ + foreach ($PolyPlots as $Key => $Value) + { + if ( !$AllBlack ) + $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]); + else + $C_GraphLo = $this->AllocateColor($this->Picture,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor); + + imagefilledpolygon($this->Picture,$PolyPlots[$Key],(count($PolyPlots[$Key])+1)/2,$C_GraphLo); + } + $this->ShadowActive = $ShadowStatus; + } + + /* This function draw a pseudo-3D pie chart */ + function drawPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$EnhanceColors=TRUE,$Skew=60,$SpliceHeight=20,$SpliceDistance=0,$Decimals=0) + { + /* Validate the Data and DataDescription array */ + $this->validateDataDescription("drawPieGraph",$DataDescription,FALSE); + $this->validateData("drawPieGraph",$Data); + + /* Determine pie sum */ + $Series = 0; $PieSum = 0; $rPieSum = 0; + foreach ( $DataDescription["Values"] as $Key2 => $ColName ) + { + if ( $ColName != $DataDescription["Position"] ) + { + $Series++; + foreach ( $Data as $Key => $Values ) + if ( isset($Data[$Key][$ColName])) + { + if ( $Data[$Key][$ColName] == 0 ) + { $iValues[] = 0; $rValues[] = 0; $iLabels[] = $Data[$Key][$DataDescription["Position"]]; } + // Removed : $PieSum++; $rValues[] = 1; + else + { $PieSum += $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]]; $rValues[] = $Data[$Key][$ColName]; $rPieSum += $Data[$Key][$ColName];} + } + } + } + + /* Validate serie */ + if ( $Series != 1 ) + RaiseFatal("Pie chart can only accept one serie of data."); + + $SpliceDistanceRatio = $SpliceDistance; + $SkewHeight = ($Radius * $Skew) / 100; + $SpliceRatio = (360 - $SpliceDistanceRatio * count($iValues) ) / $PieSum; + $SplicePercent = 100 / $PieSum; + $rSplicePercent = 100 / $rPieSum; + + /* Calculate all polygons */ + $Angle = 0; $CDev = 5; + $TopPlots = ""; $BotPlots = ""; + $aTopPlots = ""; $aBotPlots = ""; + foreach($iValues as $Key => $Value) + { + $XCenterPos = cos(($Angle-$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $XPos; + $YCenterPos = sin(($Angle-$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $YPos; + $XCenterPos2 = cos(($Angle+$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $XPos; + $YCenterPos2 = sin(($Angle+$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $YPos; + + $TopPlots[$Key][] = round($XCenterPos); $BotPlots[$Key][] = round($XCenterPos); + $TopPlots[$Key][] = round($YCenterPos); $BotPlots[$Key][] = round($YCenterPos + $SpliceHeight); + $aTopPlots[$Key][] = $XCenterPos; $aBotPlots[$Key][] = $XCenterPos; + $aTopPlots[$Key][] = $YCenterPos; $aBotPlots[$Key][] = $YCenterPos + $SpliceHeight; + + /* Process labels position & size */ + $Caption = ""; + if ( !($DrawLabels == PIE_NOLABEL) ) + { + $TAngle = $Angle+($Value*$SpliceRatio/2); + if ($DrawLabels == PIE_PERCENTAGE) + $Caption = (round($rValues[$Key] * pow(10,$Decimals) * $rSplicePercent)/pow(10,$Decimals))."%"; + elseif ($DrawLabels == PIE_LABELS) + $Caption = $iLabels[$Key]; + elseif ($DrawLabels == PIE_PERCENTAGE_LABEL) + $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%"; + + $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption); + $TextWidth = $Position[2]-$Position[0]; + $TextHeight = abs($Position[1])+abs($Position[3]); + + $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius + 10)+ $XPos; + + if ( $TAngle > 0 && $TAngle < 180 ) + $TY = sin(($TAngle) * 3.1418 / 180 ) * ($SkewHeight + 10) + $YPos + $SpliceHeight + 4; + else + $TY = sin(($TAngle) * 3.1418 / 180 ) * ($SkewHeight + 4) + $YPos - ($TextHeight/2); + + if ( $TAngle > 90 && $TAngle < 270 ) + $TX = $TX - $TextWidth; + + $C_TextColor = $this->AllocateColor($this->Picture,70,70,70); + imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption); + } + + /* Process pie slices */ + for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5) + { + $TopX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos; + $TopY = sin($iAngle * 3.1418 / 180 ) * $SkewHeight + $YPos; + + $TopPlots[$Key][] = round($TopX); $BotPlots[$Key][] = round($TopX); + $TopPlots[$Key][] = round($TopY); $BotPlots[$Key][] = round($TopY + $SpliceHeight); + $aTopPlots[$Key][] = $TopX; $aBotPlots[$Key][] = $TopX; + $aTopPlots[$Key][] = $TopY; $aBotPlots[$Key][] = $TopY + $SpliceHeight; + } + + $TopPlots[$Key][] = round($XCenterPos2); $BotPlots[$Key][] = round($XCenterPos2); + $TopPlots[$Key][] = round($YCenterPos2); $BotPlots[$Key][] = round($YCenterPos2 + $SpliceHeight); + $aTopPlots[$Key][] = $XCenterPos2; $aBotPlots[$Key][] = $XCenterPos2; + $aTopPlots[$Key][] = $YCenterPos2; $aBotPlots[$Key][] = $YCenterPos2 + $SpliceHeight; + + $Angle = $iAngle + $SpliceDistanceRatio; + } + + /* Draw Bottom polygons */ + foreach($iValues as $Key => $Value) + { + $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"],-20); + imagefilledpolygon($this->Picture,$BotPlots[$Key],(count($BotPlots[$Key])+1)/2,$C_GraphLo); + + if ( $EnhanceColors ) { $En = -10; } else { $En = 0; } + + for($j=0;$j<=count($aBotPlots[$Key])-4;$j=$j+2) + $this->drawLine($aBotPlots[$Key][$j],$aBotPlots[$Key][$j+1],$aBotPlots[$Key][$j+2],$aBotPlots[$Key][$j+3],$this->Palette[$Key]["R"]+$En,$this->Palette[$Key]["G"]+$En,$this->Palette[$Key]["B"]+$En); + } + + /* Draw pie layers */ + if ( $EnhanceColors ) { $ColorRatio = 30 / $SpliceHeight; } else { $ColorRatio = 25 / $SpliceHeight; } + for($i=$SpliceHeight-1;$i>=1;$i--) + { + foreach($iValues as $Key => $Value) + { + $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"],-10); + $Plots = ""; $Plot = 0; + foreach($TopPlots[$Key] as $Key2 => $Value2) + { + $Plot++; + if ( $Plot % 2 == 1 ) + $Plots[] = $Value2; + else + $Plots[] = $Value2+$i; + } + imagefilledpolygon($this->Picture,$Plots,(count($Plots)+1)/2,$C_GraphLo); + + $Index = count($Plots); + if ($EnhanceColors ) {$ColorFactor = -20 + ($SpliceHeight - $i) * $ColorRatio; } else { $ColorFactor = 0; } + + $this->drawAntialiasPixel($Plots[0],$Plots[1],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor); + $this->drawAntialiasPixel($Plots[2],$Plots[3],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor); + $this->drawAntialiasPixel($Plots[$Index-4],$Plots[$Index-3],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor); + } + } + + /* Draw Top polygons */ + for($Key=count($iValues)-1;$Key>=0;$Key--) + { + $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]); + imagefilledpolygon($this->Picture,$TopPlots[$Key],(count($TopPlots[$Key])+1)/2,$C_GraphLo); + + if ( $EnhanceColors ) { $En = 10; } else { $En = 0; } + for($j=0;$j<=count($aTopPlots[$Key])-4;$j=$j+2) + $this->drawLine($aTopPlots[$Key][$j],$aTopPlots[$Key][$j+1],$aTopPlots[$Key][$j+2],$aTopPlots[$Key][$j+3],$this->Palette[$Key]["R"]+$En,$this->Palette[$Key]["G"]+$En,$this->Palette[$Key]["B"]+$En); + } + } + + /* This function can be used to set the background color */ + function drawBackground($R,$G,$B) + { + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B); + imagefilledrectangle($this->Picture,0,0,$this->XSize,$this->YSize,$C_Background); + } + + /* This function can be used to set the background color */ + function drawGraphAreaGradient($R,$G,$B,$Decay,$Target=TARGET_GRAPHAREA) + { + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + if ( $Target == TARGET_GRAPHAREA ) { $X1 = $this->GArea_X1+1; $X2 = $this->GArea_X2-1; $Y1 = $this->GArea_Y1+1; $Y2 = $this->GArea_Y2; } + if ( $Target == TARGET_BACKGROUND ) { $X1 = 0; $X2 = $this->XSize; $Y1 = 0; $Y2 = $this->YSize; } + + /* Positive gradient */ + if ( $Decay > 0 ) + { + $YStep = ($Y2 - $Y1 - 2) / $Decay; + for($i=0;$i<=$Decay;$i++) + { + $R-=1;$G-=1;$B-=1; + $Yi1 = $Y1 + ( $i * $YStep ); + $Yi2 = ceil( $Yi1 + ( $i * $YStep ) + $YStep ); + if ( $Yi2 >= $Yi2 ) { $Yi2 = $Y2-1; } + + $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B); + imagefilledrectangle($this->Picture,$X1,$Yi1,$X2,$Yi2,$C_Background); + } + } + + /* Negative gradient */ + if ( $Decay < 0 ) + { + $YStep = ($Y2 - $Y1 - 2) / -$Decay; + $Yi1 = $Y1; $Yi2 = $Y1+$YStep; + for($i=-$Decay;$i>=0;$i--) + { + $R+=1;$G+=1;$B+=1; + $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B); + imagefilledrectangle($this->Picture,$X1,$Yi1,$X2,$Yi2,$C_Background); + + $Yi1+= $YStep; + $Yi2+= $YStep; + if ( $Yi2 >= $Yi2 ) { $Yi2 = $Y2-1; } + } + } + } + + /* This function create a rectangle with antialias */ + function drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B) + { + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B); + + $X1=$X1-.2;$Y1=$Y1-.2; + $X2=$X2+.2;$Y2=$Y2+.2; + $this->drawLine($X1,$Y1,$X2,$Y1,$R,$G,$B); + $this->drawLine($X2,$Y1,$X2,$Y2,$R,$G,$B); + $this->drawLine($X2,$Y2,$X1,$Y2,$R,$G,$B); + $this->drawLine($X1,$Y2,$X1,$Y1,$R,$G,$B); + } + + /* This function create a filled rectangle with antialias */ + function drawFilledRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B,$DrawBorder=TRUE,$Alpha=100,$NoFallBack=FALSE) + { + if ( $X2 < $X1 ) { list($X1, $X2) = array($X2, $X1); } + if ( $Y2 < $Y1 ) { list($Y1, $Y2) = array($Y2, $Y1); } + + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + if ( $Alpha == 100 ) + { + /* Process shadows */ + if ( $this->ShadowActive && !$NoFallBack ) + { + $this->drawFilledRectangle($X1+$this->ShadowXDistance,$Y1+$this->ShadowYDistance,$X2+$this->ShadowXDistance,$Y2+$this->ShadowYDistance,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,FALSE,$this->ShadowAlpha,TRUE); + if ( $this->ShadowBlur != 0 ) + { + $AlphaDecay = ($this->ShadowAlpha / $this->ShadowBlur); + + for($i=1; $i<=$this->ShadowBlur; $i++) + $this->drawFilledRectangle($X1+$this->ShadowXDistance-$i/2,$Y1+$this->ShadowYDistance-$i/2,$X2+$this->ShadowXDistance-$i/2,$Y2+$this->ShadowYDistance-$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,FALSE,$this->ShadowAlpha-$AlphaDecay*$i,TRUE); + for($i=1; $i<=$this->ShadowBlur; $i++) + $this->drawFilledRectangle($X1+$this->ShadowXDistance+$i/2,$Y1+$this->ShadowYDistance+$i/2,$X2+$this->ShadowXDistance+$i/2,$Y2+$this->ShadowYDistance+$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,FALSE,$this->ShadowAlpha-$AlphaDecay*$i,TRUE); + } + } + + $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B); + imagefilledrectangle($this->Picture,round($X1),round($Y1),round($X2),round($Y2),$C_Rectangle); + } + else + { + $LayerWidth = abs($X2-$X1)+2; + $LayerHeight = abs($Y2-$Y1)+2; + + $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight); + $C_White = $this->AllocateColor($this->Layers[0],255,255,255); + imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White); + imagecolortransparent($this->Layers[0],$C_White); + + $C_Rectangle = $this->AllocateColor($this->Layers[0],$R,$G,$B); + imagefilledrectangle($this->Layers[0],round(1),round(1),round($LayerWidth-1),round($LayerHeight-1),$C_Rectangle); + + imagecopymerge($this->Picture,$this->Layers[0],round(min($X1,$X2)-1),round(min($Y1,$Y2)-1),0,0,$LayerWidth,$LayerHeight,$Alpha); + imagedestroy($this->Layers[0]); + } + + if ( $DrawBorder ) + { + $ShadowSettings = $this->ShadowActive; $this->ShadowActive = FALSE; + $this->drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B); + $this->ShadowActive = $ShadowSettings; + } + } + + /* This function create a rectangle with rounded corners and antialias */ + function drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B) + { + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B); + + $Step = 90 / ((3.1418 * $Radius)/2); + + for($i=0;$i<=90;$i=$i+$Step) + { + $X = cos(($i+180)*3.1418/180) * $Radius + $X1 + $Radius; + $Y = sin(($i+180)*3.1418/180) * $Radius + $Y1 + $Radius; + $this->drawAntialiasPixel($X,$Y,$R,$G,$B); + + $X = cos(($i-90)*3.1418/180) * $Radius + $X2 - $Radius; + $Y = sin(($i-90)*3.1418/180) * $Radius + $Y1 + $Radius; + $this->drawAntialiasPixel($X,$Y,$R,$G,$B); + + $X = cos(($i)*3.1418/180) * $Radius + $X2 - $Radius; + $Y = sin(($i)*3.1418/180) * $Radius + $Y2 - $Radius; + $this->drawAntialiasPixel($X,$Y,$R,$G,$B); + + $X = cos(($i+90)*3.1418/180) * $Radius + $X1 + $Radius; + $Y = sin(($i+90)*3.1418/180) * $Radius + $Y2 - $Radius; + $this->drawAntialiasPixel($X,$Y,$R,$G,$B); + } + + $X1=$X1-.2;$Y1=$Y1-.2; + $X2=$X2+.2;$Y2=$Y2+.2; + $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$R,$G,$B); + $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$R,$G,$B); + $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$R,$G,$B); + $this->drawLine($X1,$Y2-$Radius,$X1,$Y1+$Radius,$R,$G,$B); + } + + /* This function create a filled rectangle with rounded corners and antialias */ + function drawFilledRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B) + { + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B); + + $Step = 90 / ((3.1418 * $Radius)/2); + + for($i=0;$i<=90;$i=$i+$Step) + { + $Xi1 = cos(($i+180)*3.1418/180) * $Radius + $X1 + $Radius; + $Yi1 = sin(($i+180)*3.1418/180) * $Radius + $Y1 + $Radius; + + $Xi2 = cos(($i-90)*3.1418/180) * $Radius + $X2 - $Radius; + $Yi2 = sin(($i-90)*3.1418/180) * $Radius + $Y1 + $Radius; + + $Xi3 = cos(($i)*3.1418/180) * $Radius + $X2 - $Radius; + $Yi3 = sin(($i)*3.1418/180) * $Radius + $Y2 - $Radius; + + $Xi4 = cos(($i+90)*3.1418/180) * $Radius + $X1 + $Radius; + $Yi4 = sin(($i+90)*3.1418/180) * $Radius + $Y2 - $Radius; + + imageline($this->Picture,$Xi1,$Yi1,$X1+$Radius,$Yi1,$C_Rectangle); + imageline($this->Picture,$X2-$Radius,$Yi2,$Xi2,$Yi2,$C_Rectangle); + imageline($this->Picture,$X2-$Radius,$Yi3,$Xi3,$Yi3,$C_Rectangle); + imageline($this->Picture,$Xi4,$Yi4,$X1+$Radius,$Yi4,$C_Rectangle); + + $this->drawAntialiasPixel($Xi1,$Yi1,$R,$G,$B); + $this->drawAntialiasPixel($Xi2,$Yi2,$R,$G,$B); + $this->drawAntialiasPixel($Xi3,$Yi3,$R,$G,$B); + $this->drawAntialiasPixel($Xi4,$Yi4,$R,$G,$B); + } + + imagefilledrectangle($this->Picture,$X1,$Y1+$Radius,$X2,$Y2-$Radius,$C_Rectangle); + imagefilledrectangle($this->Picture,$X1+$Radius,$Y1,$X2-$Radius,$Y2,$C_Rectangle); + + $X1=$X1-.2;$Y1=$Y1-.2; + $X2=$X2+.2;$Y2=$Y2+.2; + $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$R,$G,$B); + $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$R,$G,$B); + $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$R,$G,$B); + $this->drawLine($X1,$Y2-$Radius,$X1,$Y1+$Radius,$R,$G,$B); + } + + /* This function create a circle with antialias */ + function drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0) + { + if ( $Width == 0 ) { $Width = $Height; } + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $C_Circle = $this->AllocateColor($this->Picture,$R,$G,$B); + $Step = 360 / (2 * 3.1418 * max($Width,$Height)); + + for($i=0;$i<=360;$i=$i+$Step) + { + $X = cos($i*3.1418/180) * $Height + $Xc; + $Y = sin($i*3.1418/180) * $Width + $Yc; + $this->drawAntialiasPixel($X,$Y,$R,$G,$B); + } + } + + /* This function create a filled circle/ellipse with antialias */ + function drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0) + { + if ( $Width == 0 ) { $Width = $Height; } + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $C_Circle = $this->AllocateColor($this->Picture,$R,$G,$B); + $Step = 360 / (2 * 3.1418 * max($Width,$Height)); + + for($i=90;$i<=270;$i=$i+$Step) + { + $X1 = cos($i*3.1418/180) * $Height + $Xc; + $Y1 = sin($i*3.1418/180) * $Width + $Yc; + $X2 = cos((180-$i)*3.1418/180) * $Height + $Xc; + $Y2 = sin((180-$i)*3.1418/180) * $Width + $Yc; + + $this->drawAntialiasPixel($X1-1,$Y1-1,$R,$G,$B); + $this->drawAntialiasPixel($X2-1,$Y2-1,$R,$G,$B); + + if ( ($Y1-1) > $Yc - max($Width,$Height) ) + imageline($this->Picture,$X1,$Y1-1,$X2-1,$Y2-1,$C_Circle); + } + } + + /* This function will draw a filled ellipse */ + function drawEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B) + { $this->drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width); } + + /* This function will draw an ellipse */ + function drawFilledEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B) + { $this->drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width); } + + /* This function create a line with antialias */ + function drawLine($X1,$Y1,$X2,$Y2,$R,$G,$B,$GraphFunction=FALSE) + { + if ( $this->LineDotSize > 1 ) { $this->drawDottedLine($X1,$Y1,$X2,$Y2,$this->LineDotSize,$R,$G,$B,$GraphFunction); return(0); } + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1)); + if ( $Distance == 0 ) + return(-1); + $XStep = ($X2-$X1) / $Distance; + $YStep = ($Y2-$Y1) / $Distance; + + for($i=0;$i<=$Distance;$i++) + { + $X = $i * $XStep + $X1; + $Y = $i * $YStep + $Y1; + + if ( ($X >= $this->GArea_X1 && $X <= $this->GArea_X2 && $Y >= $this->GArea_Y1 && $Y <= $this->GArea_Y2) || !$GraphFunction ) + { + if ( $this->LineWidth == 1 ) + $this->drawAntialiasPixel($X,$Y,$R,$G,$B); + else + { + $StartOffset = -($this->LineWidth/2); $EndOffset = ($this->LineWidth/2); + for($j=$StartOffset;$j<=$EndOffset;$j++) + $this->drawAntialiasPixel($X+$j,$Y+$j,$R,$G,$B); + } + } + } + } + + /* This function create a line with antialias */ + function drawDottedLine($X1,$Y1,$X2,$Y2,$DotSize,$R,$G,$B,$GraphFunction=FALSE) + { + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1)); + + $XStep = ($X2-$X1) / $Distance; + $YStep = ($Y2-$Y1) / $Distance; + + $DotIndex = 0; + for($i=0;$i<=$Distance;$i++) + { + $X = $i * $XStep + $X1; + $Y = $i * $YStep + $Y1; + + if ( $DotIndex <= $DotSize) + { + if ( ($X >= $this->GArea_X1 && $X <= $this->GArea_X2 && $Y >= $this->GArea_Y1 && $Y <= $this->GArea_Y2) || !$GraphFunction ) + { + if ( $this->LineWidth == 1 ) + $this->drawAntialiasPixel($X,$Y,$R,$G,$B); + else + { + $StartOffset = -($this->LineWidth/2); $EndOffset = ($this->LineWidth/2); + for($j=$StartOffset;$j<=$EndOffset;$j++) + $this->drawAntialiasPixel($X+$j,$Y+$j,$R,$G,$B); + } + } + } + + $DotIndex++; + if ( $DotIndex == $DotSize * 2 ) + $DotIndex = 0; + } + } + + /* Load a PNG file and draw it over the chart */ + function drawFromPNG($FileName,$X,$Y,$Alpha=100) + { $this->drawFromPicture(1,$FileName,$X,$Y,$Alpha); } + + /* Load a GIF file and draw it over the chart */ + function drawFromGIF($FileName,$X,$Y,$Alpha=100) + { $this->drawFromPicture(2,$FileName,$X,$Y,$Alpha); } + + /* Load a JPEG file and draw it over the chart */ + function drawFromJPG($FileName,$X,$Y,$Alpha=100) + { $this->drawFromPicture(3,$FileName,$X,$Y,$Alpha); } + + /* Generic loader function for external pictures */ + function drawFromPicture($PicType,$FileName,$X,$Y,$Alpha=100) + { + if ( file_exists($FileName)) + { + $Infos = getimagesize($FileName); + $Width = $Infos[0]; + $Height = $Infos[1]; + if ( $PicType == 1 ) { $Raster = imagecreatefrompng($FileName); } + if ( $PicType == 2 ) { $Raster = imagecreatefromgif($FileName); } + if ( $PicType == 3 ) { $Raster = imagecreatefromjpeg($FileName); } + + imagecopymerge($this->Picture,$Raster,$X,$Y,0,0,$Width,$Height,$Alpha); + imagedestroy($Raster); + } + } + + /* Draw an alpha pixel */ + function drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B) + { + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize ) + return(-1); + + $RGB2 = imagecolorat($this->Picture, $X, $Y); + $R2 = ($RGB2 >> 16) & 0xFF; + $G2 = ($RGB2 >> 8) & 0xFF; + $B2 = $RGB2 & 0xFF; + + $iAlpha = (100 - $Alpha)/100; + $Alpha = $Alpha / 100; + + $Ra = floor($R*$Alpha+$R2*$iAlpha); + $Ga = floor($G*$Alpha+$G2*$iAlpha); + $Ba = floor($B*$Alpha+$B2*$iAlpha); + + $C_Aliased = $this->AllocateColor($this->Picture,$Ra,$Ga,$Ba); + imagesetpixel($this->Picture,$X,$Y,$C_Aliased); + } + + /* Color helper */ + function AllocateColor($Picture,$R,$G,$B,$Factor=0) + { + $R = $R + $Factor; + $G = $G + $Factor; + $B = $B + $Factor; + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + return(imagecolorallocate($Picture,$R,$G,$B)); + } + + /* Add a border to the picture */ + function addBorder($Size=3,$R=0,$G=0,$B=0) + { + $Width = $this->XSize+2*$Size; + $Height = $this->YSize+2*$Size; + + $Resampled = imagecreatetruecolor($Width,$Height); + $C_Background = $this->AllocateColor($Resampled,$R,$G,$B); + imagefilledrectangle($Resampled,0,0,$Width,$Height,$C_Background); + + imagecopy($Resampled,$this->Picture,$Size,$Size,0,0,$this->XSize,$this->YSize); + imagedestroy($this->Picture); + + $this->XSize = $Width; + $this->YSize = $Height; + + $this->Picture = imagecreatetruecolor($this->XSize,$this->YSize); + $C_White = $this->AllocateColor($this->Picture,255,255,255); + imagefilledrectangle($this->Picture,0,0,$this->XSize,$this->YSize,$C_White); + imagecolortransparent($this->Picture,$C_White); + imagecopy($this->Picture,$Resampled,0,0,0,0,$this->XSize,$this->YSize); + } + + /* Render the current picture to a file */ + function Render($FileName) + { + if ( $this->ErrorReporting ) + $this->printErrors($this->ErrorInterface); + + /* Save image map if requested */ + if ( $this->BuildMap ) + $this->SaveImageMap(); + + imagepng($this->Picture,$FileName); + } + + /* Render the current picture to STDOUT */ + function Stroke() + { + if ( $this->ErrorReporting ) + $this->printErrors("GD"); + + /* Save image map if requested */ + if ( $this->BuildMap ) + $this->SaveImageMap(); + + header('Content-type: image/png'); + imagepng($this->Picture); + } + + /* Private functions for internal processing */ + function drawAntialiasPixel($X,$Y,$R,$G,$B,$Alpha=100,$NoFallBack=FALSE) + { + /* Process shadows */ + if ( $this->ShadowActive && !$NoFallBack ) + { + $this->drawAntialiasPixel($X+$this->ShadowXDistance,$Y+$this->ShadowYDistance,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha,TRUE); + if ( $this->ShadowBlur != 0 ) + { + $AlphaDecay = ($this->ShadowAlpha / $this->ShadowBlur); + + for($i=1; $i<=$this->ShadowBlur; $i++) + $this->drawAntialiasPixel($X+$this->ShadowXDistance-$i/2,$Y+$this->ShadowYDistance-$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha-$AlphaDecay*$i,TRUE); + for($i=1; $i<=$this->ShadowBlur; $i++) + $this->drawAntialiasPixel($X+$this->ShadowXDistance+$i/2,$Y+$this->ShadowYDistance+$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha-$AlphaDecay*$i,TRUE); + } + } + + if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; } + if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; } + if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; } + + $Plot = ""; + $Xi = floor($X); + $Yi = floor($Y); + + if ( $Xi == $X && $Yi == $Y) + { + if ( $Alpha == 100 ) + { + $C_Aliased = $this->AllocateColor($this->Picture,$R,$G,$B); + imagesetpixel($this->Picture,$X,$Y,$C_Aliased); + } + else + $this->drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B); + } + else + { + $Alpha1 = (((1 - ($X - floor($X))) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha; + if ( $Alpha1 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi,$Alpha1,$R,$G,$B); } + + $Alpha2 = ((($X - floor($X)) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha; + if ( $Alpha2 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi,$Alpha2,$R,$G,$B); } + + $Alpha3 = (((1 - ($X - floor($X))) * ($Y - floor($Y)) * 100) / 100) * $Alpha; + if ( $Alpha3 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi+1,$Alpha3,$R,$G,$B); } + + $Alpha4 = ((($X - floor($X)) * ($Y - floor($Y)) * 100) / 100) * $Alpha; + if ( $Alpha4 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi+1,$Alpha4,$R,$G,$B); } + } + } + + /* Validate data contained in the description array */ + function validateDataDescription($FunctionName,&$DataDescription,$DescriptionRequired=TRUE) + { + if (!isset($DataDescription["Position"])) + { + $this->Errors[] = "[Warning] ".$FunctionName." - Y Labels are not set."; + $DataDescription["Position"] = "Name"; + } + + if ( $DescriptionRequired ) + { + if (!isset($DataDescription["Description"])) + { + $this->Errors[] = "[Warning] ".$FunctionName." - Series descriptions are not set."; + foreach($DataDescription["Values"] as $key => $Value) + { + $DataDescription["Description"][$Value] = $Value; + } + } + + if (count($DataDescription["Description"]) < count($DataDescription["Values"])) + { + $this->Errors[] = "[Warning] ".$FunctionName." - Some series descriptions are not set."; + foreach($DataDescription["Values"] as $key => $Value) + { + if ( !isset($DataDescription["Description"][$Value])) + $DataDescription["Description"][$Value] = $Value; + } + } + } + } + + /* Validate data contained in the data array */ + function validateData($FunctionName,&$Data) + { + $DataSummary = array(); + + foreach($Data as $key => $Values) + { + foreach($Values as $key2 => $Value) + { + if (!isset($DataSummary[$key2])) + $DataSummary[$key2] = 1; + else + $DataSummary[$key2]++; + } + } + + if ( max($DataSummary) == 0 ) + $this->Errors[] = "[Warning] ".$FunctionName." - No data set."; + + foreach($DataSummary as $key => $Value) + { + if ($Value < max($DataSummary)) + { + $this->Errors[] = "[Warning] ".$FunctionName." - Missing data in serie ".$key."."; + } + } + } + + /* Print all error messages on the CLI or graphically */ + function printErrors($Mode="CLI") + { + if (count($this->Errors) == 0) + return(0); + + if ( $Mode == "CLI" ) + { + foreach($this->Errors as $key => $Value) + echo $Value."\r\n"; + } + elseif ( $Mode == "GD" ) + { + $this->setLineStyle($Width=1); + $MaxWidth = 0; + foreach($this->Errors as $key => $Value) + { + $Position = imageftbbox($this->ErrorFontSize,0,$this->ErrorFontName,$Value); + $TextWidth = $Position[2]-$Position[0]; + if ( $TextWidth > $MaxWidth ) { $MaxWidth = $TextWidth; } + } + $this->drawFilledRoundedRectangle($this->XSize-($MaxWidth+20),$this->YSize-(20+(($this->ErrorFontSize+4)*count($this->Errors))),$this->XSize-10,$this->YSize-10,6,233,185,185); + $this->drawRoundedRectangle($this->XSize-($MaxWidth+20),$this->YSize-(20+(($this->ErrorFontSize+4)*count($this->Errors))),$this->XSize-10,$this->YSize-10,6,193,145,145); + + $C_TextColor = $this->AllocateColor($this->Picture,133,85,85); + $YPos = $this->YSize - (18 + (count($this->Errors)-1) * ($this->ErrorFontSize + 4)); + foreach($this->Errors as $key => $Value) + { + imagettftext($this->Picture,$this->ErrorFontSize,0,$this->XSize-($MaxWidth+15),$YPos,$C_TextColor,$this->ErrorFontName,$Value); + $YPos = $YPos + ($this->ErrorFontSize + 4); + } + } + } + + /* Activate the image map creation process */ + function setImageMap($Mode=TRUE,$GraphID="MyGraph") + { + $this->BuildMap = $Mode; + $this->MapID = $GraphID; + } + + /* Add a box into the image map */ + function addToImageMap($X1,$Y1,$X2,$Y2,$SerieName,$Value,$CallerFunction) + { + if ( $this->MapFunction == NULL || $this->MapFunction == $CallerFunction ) + { + $this->ImageMap[] = round($X1).",".round($Y1).",".round($X2).",".round($Y2).",".$SerieName.",".$Value; + $this->MapFunction = $CallerFunction; + } + } + + /* Load and cleanup the image map from disk */ + function getImageMap($MapName,$Flush=TRUE) + { + /* Strip HTML query strings */ + $Values = $this->tmpFolder.$MapName; + $Value = split("\?",$Values); + $FileName = $Value[0]; + + if ( file_exists($FileName) ) + { + $Handle = fopen($FileName, "r"); + $MapContent = fread($Handle, filesize($FileName)); + fclose($Handle); + echo $MapContent; + + if ( $Flush ) + unlink($FileName); + + exit(); + } + else + { + header("HTTP/1.0 404 Not Found"); + exit(); + } + } + + /* Save the image map to the disk */ + function SaveImageMap() + { + if ( !$this->BuildMap ) { return(-1); } + + if ( $this->ImageMap == NULL ) + { + $this->Errors[] = "[Warning] SaveImageMap - Image map is empty."; + return(-1); + } + + $Handle = fopen($this->tmpFolder.$this->MapID, 'w'); + if ( !$Handle ) + { + $this->Errors[] = "[Warning] SaveImageMap - Cannot save the image map."; + return(-1); + } + else + { + foreach($this->ImageMap as $Key => $Value) + fwrite($Handle, htmlentities($Value)."\r"); + } + fclose ($Handle); + } + + /* Convert seconds to a time format string */ + function ToTime($Value) + { + $Hour = floor($Value/3600); + $Minute = floor(($Value - $Hour*3600)/60); + $Second = floor($Value - $Hour*3600 - $Minute*60); + + if (strlen($Hour) == 1 ) { $Hour = "0".$Hour; } + if (strlen($Minute) == 1 ) { $Minute = "0".$Minute; } + if (strlen($Second) == 1 ) { $Second = "0".$Second; } + + return($Hour.":".$Minute.":".$Second); + } + + /* Convert to metric system */ + function ToMetric($Value) + { + $Go = floor($Value/1000000000); + $Mo = floor(($Value - $Go*1000000000)/1000000); + $Ko = floor(($Value - $Go*1000000000 - $Mo*1000000)/1000); + $o = floor($Value - $Go*1000000000 - $Mo*1000000 - $Ko*1000); + + if ($Go != 0) { return($Go.".".$Mo."g"); } + if ($Mo != 0) { return($Mo.".".$ko."m"); } + if ($Ko != 0) { return($Ko.".".$o)."k"; } + return($o); + } + + /* Convert to curency */ + function ToCurrency($Value) + { + $Go = floor($Value/1000000000); + $Mo = floor(($Value - $Go*1000000000)/1000000); + $Ko = floor(($Value - $Go*1000000000 - $Mo*1000000)/1000); + $o = floor($Value - $Go*1000000000 - $Mo*1000000 - $Ko*1000); + + if ( strlen($o) == 1 ) { $o = "00".$o; } + if ( strlen($o) == 2 ) { $o = "0".$o; } + + $ResultString = $o; + if ( $Ko != 0 ) { $ResultString = $Ko.".".$ResultString; } + if ( $Mo != 0 ) { $ResultString = $Mo.".".$ResultString; } + if ( $Go != 0 ) { $ResultString = $Go.".".$ResultString; } + + $ResultString = $this->Currency.$ResultString; + return($ResultString); + } + + /* Set date format for axis labels */ + function setDateFormat($Format) + { + $this->DateFormat = $Format; + } + + /* Convert TS to a date format string */ + function ToDate($Value) + { + return(date($this->DateFormat,$Value)); + } + + /* Check if a number is a full integer (for scaling) */ + function isRealInt($Value) + { + if ($Value == floor($Value)) + return(TRUE); + return(FALSE); + } + } + + function RaiseFatal($Message) + { + echo "[FATAL] ".$Message."\r\n"; + exit(); + } +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/pData.class b/gosa-core/include/pChart/pData.class new file mode 100644 index 000000000..8e1938d36 --- /dev/null +++ b/gosa-core/include/pChart/pData.class @@ -0,0 +1,260 @@ +. + + Class initialisation : + pData() + Data populating methods : + ImportFromCSV($FileName,$Delimiter=",",$DataColumns=-1,$HasHeader=FALSE,$DataName=-1) + AddPoint($Value,$Serie="Serie1",$Description="") + Series manipulation methods : + AddSerie($SerieName="Serie1") + AddAllSeries() + RemoveSerie($SerieName="Serie1") + SetAbsciseLabelSerie($SerieName = "Name") + SetSerieName($Name,$SerieName="Serie1") + + SetSerieSymbol($Name,$Symbol) + SetXAxisName($Name="X Axis") + SetYAxisName($Name="Y Axis") + SetXAxisFormat($Format="number") + SetYAxisFormat($Format="number") + SetXAxisUnit($Unit="") + SetYAxisUnit($Unit="") + removeSerieName($SerieName) + removeAllSeries() + Data retrieval methods : + GetData() + GetDataDescription() + */ + + /* pData class definition */ + class pData + { + var $Data; + var $DataDescription; + + function pData() + { + $this->Data = ""; + $this->DataDescription = ""; + $this->DataDescription["Position"] = "Name"; + $this->DataDescription["Format"]["X"] = "number"; + $this->DataDescription["Format"]["Y"] = "number"; + $this->DataDescription["Unit"]["X"] = NULL; + $this->DataDescription["Unit"]["Y"] = NULL; + } + + function ImportFromCSV($FileName,$Delimiter=",",$DataColumns=-1,$HasHeader=FALSE,$DataName=-1) + { + $handle = @fopen($FileName,"r"); + if ($handle) + { + $HeaderParsed = FALSE; + while (!feof($handle)) + { + $buffer = fgets($handle, 4096); + $buffer = str_replace(chr(10),"",$buffer); + $buffer = str_replace(chr(13),"",$buffer); + $Values = split($Delimiter,$buffer); + + if ( $buffer != "" ) + { + if ( $HasHeader == TRUE && $HeaderParsed == FALSE ) + { + if ( $DataColumns == -1 ) + { + $ID = 1; + foreach($Values as $key => $Value) + { $this->SetSerieName($Value,"Serie".$ID); $ID++; } + } + else + { + $SerieName = ""; + + foreach($DataColumns as $key => $Value) + $this->SetSerieName($Values[$Value],"Serie".$Value); + } + $HeaderParsed = TRUE; + } + else + { + if ( $DataColumns == -1 ) + { + $ID = 1; + foreach($Values as $key => $Value) + { $this->AddPoint(intval($Value),"Serie".$ID); $ID++; } + } + else + { + $SerieName = ""; + if ( $DataName != -1 ) + $SerieName = $Values[$DataName]; + + foreach($DataColumns as $key => $Value) + $this->AddPoint($Values[$Value],"Serie".$Value,$SerieName); + } + } + } + } + fclose($handle); + } + } + + function AddPoint($Value,$Serie="Serie1",$Description="") + { + if (is_array($Value) && count($Value) == 1) + $Value = $Value[0]; + + $ID = 0; + for($i=0;$i<=count($this->Data);$i++) + { if(isset($this->Data[$i][$Serie])) { $ID = $i+1; } } + + if ( count($Value) == 1 ) + { + $this->Data[$ID][$Serie] = $Value; + if ( $Description != "" ) + $this->Data[$ID]["Name"] = $Description; + elseif (!isset($this->Data[$ID]["Name"])) + $this->Data[$ID]["Name"] = $ID; + } + else + { + foreach($Value as $key => $Val) + { + $this->Data[$ID][$Serie] = $Val; + if (!isset($this->Data[$ID]["Name"])) + $this->Data[$ID]["Name"] = $ID; + $ID++; + } + } + } + + function AddSerie($SerieName="Serie1") + { + if ( !isset($this->DataDescription["Values"]) ) + { + $this->DataDescription["Values"][] = $SerieName; + } + else + { + $Found = FALSE; + foreach($this->DataDescription["Values"] as $key => $Value ) + if ( $Value == $SerieName ) { $Found = TRUE; } + + if ( !$Found ) + $this->DataDescription["Values"][] = $SerieName; + } + } + + function AddAllSeries() + { + unset($this->DataDescription["Values"]); + + if ( isset($this->Data[0]) ) + { + foreach($this->Data[0] as $Key => $Value) + { + if ( $Key != "Name" ) + $this->DataDescription["Values"][] = $Key; + } + } + } + + function RemoveSerie($SerieName="Serie1") + { + if ( !isset($this->DataDescription["Values"]) ) + return(0); + + $Found = FALSE; + foreach($this->DataDescription["Values"] as $key => $Value ) + { + if ( $Value == $SerieName ) + unset($this->DataDescription["Values"][$key]); + } + } + + function SetAbsciseLabelSerie($SerieName = "Name") + { + $this->DataDescription["Position"] = $SerieName; + } + + function SetSerieName($Name,$SerieName="Serie1") + { + $this->DataDescription["Description"][$SerieName] = $Name; + } + + function SetXAxisName($Name="X Axis") + { + $this->DataDescription["Axis"]["X"] = $Name; + } + + function SetYAxisName($Name="Y Axis") + { + $this->DataDescription["Axis"]["Y"] = $Name; + } + + function SetXAxisFormat($Format="number") + { + $this->DataDescription["Format"]["X"] = $Format; + } + + function SetYAxisFormat($Format="number") + { + $this->DataDescription["Format"]["Y"] = $Format; + } + + function SetXAxisUnit($Unit="") + { + $this->DataDescription["Unit"]["X"] = $Unit; + } + + function SetYAxisUnit($Unit="") + { + $this->DataDescription["Unit"]["Y"] = $Unit; + } + + function SetSerieSymbol($Name,$Symbol) + { + $this->DataDescription["Symbol"][$Name] = $Symbol; + } + + function removeSerieName($SerieName) + { + if ( isset($this->DataDescription["Description"][$SerieName]) ) + unset($this->DataDescription["Description"][$SerieName]); + } + + function removeAllSeries() + { + foreach($this->DataDescription["Values"] as $Key => $Value) + unset($this->DataDescription["Values"][$Key]); + } + + function GetData() + { + return($this->Data); + } + + function GetDataDescription() + { + return($this->DataDescription); + } + } +?> \ No newline at end of file diff --git a/gosa-core/include/pChart/pf_arma_five.ttf b/gosa-core/include/pChart/pf_arma_five.ttf new file mode 100644 index 000000000..db04ec3b0 Binary files /dev/null and b/gosa-core/include/pChart/pf_arma_five.ttf differ diff --git a/gosa-core/include/pChart/softtones.txt b/gosa-core/include/pChart/softtones.txt new file mode 100644 index 000000000..ca941cac2 --- /dev/null +++ b/gosa-core/include/pChart/softtones.txt @@ -0,0 +1,5 @@ +168,188,56 +188,208,76 +208,228,96 +228,245,116 +248,255,136 diff --git a/gosa-core/include/pChart/tahoma.ttf b/gosa-core/include/pChart/tahoma.ttf new file mode 100644 index 000000000..59b14a2d2 Binary files /dev/null and b/gosa-core/include/pChart/tahoma.ttf differ diff --git a/gosa-core/include/pChart/tones.txt b/gosa-core/include/pChart/tones.txt new file mode 100644 index 000000000..5016263de --- /dev/null +++ b/gosa-core/include/pChart/tones.txt @@ -0,0 +1,5 @@ +94,48,0 +201,34,0 +247,143,1 +255,238,208 +90,181,110