Author: f1gm3nt
Date: 2010-03-26 21:35:33 +0100 (Fri, 26 Mar 2010)
New Revision: 28817

Added:
   plugins/sfSvgPlugin/lib/sfSvgPie.class.php
   plugins/sfSvgPlugin/web/sfSvgPluginSandbox.php
Log:
forgot to add these two files during las commit

Added: plugins/sfSvgPlugin/lib/sfSvgPie.class.php
===================================================================
--- plugins/sfSvgPlugin/lib/sfSvgPie.class.php                          (rev 0)
+++ plugins/sfSvgPlugin/lib/sfSvgPie.class.php  2010-03-26 20:35:33 UTC (rev 
28817)
@@ -0,0 +1,81 @@
+<?php
+/**
+ * This is used to create pie charts
+ *
+ * @author Joshua Estes <[email protected]>
+ * @package sfSvgPlugin
+ * @subpackage Pie Chart
+ */
+class sfSvgPie extends sfSvgPlugin
+{
+  protected $dataSets = array();
+  protected $colors   = array('red','blue','black','purple','yellow');
+  protected $radius   = 150;
+
+  function  __construct()
+  {
+  }
+
+  function addDataSet($data=array())
+  {
+    if (!empty($data))
+    {
+      $this->dataSets = (array)$data;
+    }
+  }
+
+  function addColor($color)
+  {
+    if (is_array($color))
+    {
+      $this->colors = $color;
+    }
+    else
+    {
+      $this->colors[] = $color;
+    }
+  }
+
+  function setRadius($radius)
+  {
+    $this->radius = $radius;
+  }
+
+  function renderPie()
+  {
+    $total = 0;
+    $seg = 0;
+    $sx = $this->getWidth(); // start x
+    $sy = $this->getHeight(); // start y
+    $lx = $this->radius; // last x
+    $ly = 0; // last y
+
+    foreach ($this->dataSets as $v)
+    {
+      $total += $v;
+    }
+
+    for($i=0;$i<=count($this->dataSets);$i++)
+    {
+      $seg = $this->dataSets[$i]/$total * 360 + $seg;
+      $arc = ($this->dataSets[$i]/$total > 50) ? 1 : 0;
+      $radSeg = $seg;
+      $nx = cos($radSeg) * $this->radius;
+      $ny = sin($radSeg) * $this->radius;
+      $output .= '<path d="';
+      $output .= ' M'.$sx.','.$sy;
+      $output .= ' l '.$lx.','.-($ly);
+      $output .= ' a'.$this->radius.','.$this->radius.' 0 '.$arc.',0 '.($nx - 
$lx).','.-($ny - $ly);
+      $output .= ' z" fill="'.$this->colors[$i].'"';
+      $output .= "/>\n";
+      $lx = $nx;
+      $ly = $ny;
+    }
+
+
+
+
+    return $output;
+  }
+}
+?>


Property changes on: plugins/sfSvgPlugin/lib/sfSvgPie.class.php
___________________________________________________________________
Added: svn:executable
   + *

Added: plugins/sfSvgPlugin/web/sfSvgPluginSandbox.php
===================================================================
--- plugins/sfSvgPlugin/web/sfSvgPluginSandbox.php                              
(rev 0)
+++ plugins/sfSvgPlugin/web/sfSvgPluginSandbox.php      2010-03-26 20:35:33 UTC 
(rev 28817)
@@ -0,0 +1,21 @@
+<?php
+/**
+ * sandbox used for testing
+ * 
+ */
+include('../lib/sfSvgPlugin.class.php');
+include('../lib/sfSvgPie.class.php');
+$pieChart = new sfSvgPie();
+header('content-type: image/svg+xml');
+
+echo <<<END
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg width="500" height="500" xmlns:svg="http://www.w3.org/2000/svg"; 
xmlns="http://www.w3.org/2000/svg";>
+END;
+
+
+$pieChart->addDataSet(array('123','300'));
+echo $pieChart->renderPie();
+
+?>
+</svg>
\ No newline at end of file


Property changes on: plugins/sfSvgPlugin/web/sfSvgPluginSandbox.php
___________________________________________________________________
Added: svn:executable
   + *

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to