Make the graphs prettier
authorBen Klang <ben@alkaloid.net>
Sat, 5 Jul 2008 14:38:22 +0000 (14:38 +0000)
committerBen Klang <ben@alkaloid.net>
Sun, 10 Jan 2010 04:05:28 +0000 (23:05 -0500)
config/conf.xml
graphgen.php
lib/Operator.php

index 5881831..3d96910 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<!-- $Horde: incubator/operator/config/conf.xml,v 1.1 2008/04/19 01:26:06 bklang Exp $ -->
+<!-- $Horde: incubator/operator/config/conf.xml,v 1.2 2008/07/05 14:38:23 bklang Exp $ -->
 <configuration>
  <configsection name="storage">
   <configheader>Storage System Settings</configheader>
@@ -14,6 +14,8 @@
   </configswitch>
  </configsection>
 
+ <configstring name="ttf_font" desc="Full path to a True-Type font to use when rendering the graph" required="false" />
+
  <configsection name="menu">
   <configheader>Menu Settings</configheader>
   <configmultienum name="apps" desc="Select any applications that should be
index b5b8370..9562976 100644 (file)
@@ -1,6 +1,6 @@
 <?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>
  *
@@ -17,32 +17,81 @@ require_once OPERATOR_BASE . '/lib/base.php';
 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();
-
index 9dade62..e31e1a6 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * 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>
  *
@@ -125,17 +125,29 @@ class Operator {
         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;
          }
     }