<?php
/**
- * $Horde: incubator/operator/graphgen.php,v 1.2 2008/07/04 04:23:16 bklang Exp $
+ * $Horde: incubator/operator/graphgen.php,v 1.3 2008/07/05 14:38:22 bklang Exp $
*
* Copyright 2008 Alkaloid Networks LLC <http://projects.alkaloid.net>
*
require_once 'Image/Graph.php';
$graphtype = Util::getFormData('graph');
-$graphname = Operator::getGraphName(Util::getFormData('name'));
+$graphInfo = Operator::getGraphInfo($graphtype);
$cachekey = Util::getFormData('key');
$stats = unserialize($cache->get($cachekey, 0));
-Horde::logMessage(print_r($stats, true), __FILE__, __LINE__, PEAR_LOG_ERR);
-$graph = Image_Graph::factory('graph', array(600, 400));
-$plotarea = $graph->addNew('plotarea');
-#$graph->add(Image_Graph::vertical(
-# Image_Graph::factory('title', array($graphname, 11)),
-# Image_Graph::vertical(
-# $plotarea = $graph->addNew('plotarea'),
-# $legend = Image_Graph::factory('legend'),
-# 90
-# ),
-# 5
-#));
-#$legend->setPlotArea($plotarea);
-$grid =& $plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY);
-$grid->setFillStyle(Image_Graph::factory(
- 'gradient',
- array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', 'lightgrey')
-));
-$dataset = Image_Graph::factory('dataset');
+
+
+
+
+
+
+// Create the graph image base.
+$graph =& Image_Graph::factory('graph', array(700, 500));
+
+if (!empty($conf['ttf_font'])) {
+ // add a TrueType font
+ $Font =& $graph->addNew('ttf_font', $conf['ttf_font']);
+ // set the font size to 11 pixels
+ $Font->setSize(8);
+ $graph->setFont($Font);
+}
+
+
+// create the plotarea layout
+$graph->add(
+ Image_Graph::vertical(
+ Image_Graph::factory('title', array($graphInfo['title'], 11)),
+ #Image_Graph::vertical(
+ $plotarea = Image_Graph::factory('plotarea'),
+ # $legend = Image_Graph::factory('legend'),
+ # 90
+ #),
+ 5
+ )
+);
+
+// make the legend use the plotarea (or implicitly it's plots)
+#$legend->setPlotarea($plotarea);
+
+// create a grid and assign it to the secondary Y axis
+$gridY2 =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY);
+$gridY2->setLineColor('black');
+#$gridY2->setFillStyle(
+# Image_Graph::factory(
+# 'gradient',
+# array(IMAGE_GRAPH_GRAD_HORIZONTAL, 'white', 'lightgrey')
+# )
+#);
+
+$dataset1 = Image_Graph::factory('dataset');
foreach ($stats as $month => $stats) {
- $dataset->addPoint($month, $stats[$graphtype]);
+ $dataset1->addPoint($month, $stats[$graphtype]);
}
-$plot = $plotarea->addNew('bar', $dataset);
+$plot1 =& $plotarea->addNew('bar', $dataset1);
+$plot1->setLineColor('black@0.5');
+$plot1->setFillColor('blue@0.2');
+$plot1->setTitle('Primary Axis');
+
+// create an area plot using a random dataset
+#$dataset2 =& Image_Graph::factory('random', array(8, 1, 10, true));
+#$plot2 =& $plotarea->addNew(
+# 'Image_Graph_Plot_Area',
+# $dataset2,
+# IMAGE_GRAPH_AXIS_Y_SECONDARY
+#);
+
+#$plot2->setLineColor('gray');
+#$plot2->setFillColor('blue@0.2');
+#$plot2->setTitle('Secondary Axis');
+
+$axisX =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
+$axisX->setTitle($graphInfo['axisX']);
+$axisY =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
+$axisY->setTitle($graphInfo['axisY'], 'vertical');
+#$axisYsecondary =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY);
+#$axisYsecondary->setTitle('Pears', 'vertical2');
+
+// output the Graph
$graph->done();
-
/**
* Operator Base Class.
*
- * $Horde: incubator/operator/lib/Operator.php,v 1.5 2008/07/04 04:23:16 bklang Exp $
+ * $Horde: incubator/operator/lib/Operator.php,v 1.6 2008/07/05 14:38:23 bklang Exp $
*
* Copyright 2008 Alkaloid Networks LLC <http://projects.alkaloid.net>
*
return $accountcodes;
}
- function getGraphName($graphid)
+ function getGraphInfo($graphid)
{
switch($graphid) {
case 'numcalls':
- return _("Number of Calls");
+ return array(
+ 'title' => _("Number of Calls by Month"),
+ 'axisX' => _("Month"),
+ 'axisY' => _("Number of Calls"),
+ );
break;
case 'minutes':
- return _("Total Minutes Used");
+ return array(
+ 'title' => _("Total Minutes Used by Month"),
+ 'axisX' => _("Month"),
+ 'axisY' => _("Minute"),
+ );
break;
case 'failed':
- return _("Number of Failed Calls");
+ return array(
+ 'title' => _("Number of Failed Calls by Month"),
+ 'axisX' => _("Month"),
+ 'axisY' => _("Failed Calls"),
+ );
break;
}
}