--- jquery.flot.js~	2009-01-29 22:18:46.000000000 -0800
+++ jquery.flot.js	2009-01-29 22:18:18.000000000 -0800
@@ -1,7 +1,7 @@
 /* Javascript plotting library for jQuery, v. 0.5.
  *
  * Released under the MIT license by IOLA, December 2007.
- *
+ * PIE modifications by Sergey Nosenko http://javascript.cooldev.com
  */
 
 (function($) {
@@ -92,6 +92,18 @@
                     mode: null, // one of null, "x", "y" or "xy"
                     color: "#e8cfac"
                 },
+		pie: {
+                    show: false,
+                    pieStrokeColor: '#FFF',
+                    pieStrokeLineWidth: 1,
+                    centerOffsetTop:0,
+                    centerOffsetLeft:0,
+                    showLabel: true,
+                    labelFormatter: function(serie){return serie.label},
+                    labelOffsetFactor: 5/6, //as part of radius
+                    labelBackgroundOpacity: 0.85,
+                    labelOffset: 0
+                },
                 shadowSize: 4
             },
         canvas = null,      // the canvas for the plot itself
@@ -103,6 +115,16 @@
         plotOffset = { left: 0, right: 0, top: 0, bottom: 0},
         canvasWidth = 0, canvasHeight = 0,
         plotWidth = 0, plotHeight = 0,
+        //PIE: variables
+        pieChartRadius, pieChartDiameter,
+        pieVertices = 12,
+        arcIncrementMultiplier,
+        pieIndex = 0,
+        pieArcIndex = 0,
+        pieTotal = 0,
+        legendWidth = 0,
+        pieCenterLeft, pieCenterTop,
+
         // dedicated to storing data for buggy standard compliance cases
         workarounds = {};
         
@@ -232,6 +254,7 @@
                 s.lines = $.extend(true, {}, options.lines, s.lines);
                 s.points = $.extend(true, {}, options.points, s.points);
                 s.bars = $.extend(true, {}, options.bars, s.bars);
+                s.pie = $.extend(true, {}, options.pie, s.pie);
                 if (s.shadowSize == null)
                     s.shadowSize = options.shadowSize;
                 if (s.xaxis && s.xaxis == 2)
@@ -246,6 +269,21 @@
         }
         
         function processData() {
+            if (options.pie.show) {
+                // Initialize variables
+                pieVertices = 12; // Does not include the center vertex
+                arcIncrementMultiplier = 1 / pieVertices;
+                pieIndex = 0;
+                pieTotal = 0;
+                for (var i=0;i<series.length;i++) {
+                    pieTotal += series[i].data;
+                }
+                for (var i=0;i<series.length;i++) {
+                    series[i].percent = (series[i].data/pieTotal)*100;
+                }
+                return;
+            }
+
             var topSentry = Number.POSITIVE_INFINITY,
                 bottomSentry = Number.NEGATIVE_INFINITY,
                 axis;
@@ -344,6 +382,16 @@
         }
 
         function setupGrid() {
+            //PIE: cvalculate radius and exit;
+            if (options.pie.show) {
+                pieChartRadius = options.pie.pieChartRadius || Math.min(canvasWidth,canvasHeight)/2;
+                pieChartDiameter = pieChartRadius * 2;
+                insertLegend();
+                pieCenterLeft = options.pie.centerOffsetLeft == 'auto'?options.legend.position.match('w')?pieChartRadius+legendWidth:pieChartRadius:pieChartRadius+options.pie.centerOffsetLeft;
+                pieCenterTop = pieChartRadius+ options.pie.centerOffsetTop;
+                return;
+            }
+
             function setupAxis(axis, options) {
                 setRange(axis, options);
                 prepareTickGeneration(axis, options);
@@ -869,6 +917,9 @@
                 ctx.fillRect(0, 0, plotWidth, plotHeight);
             }
 
+            //PIE: skip any data processing
+            if (options.pie.show) return;
+
             // draw markings
             if (options.grid.markings) {
                 var markings = options.grid.markings;
@@ -1023,6 +1074,11 @@
         }
 
         function drawSeries(series) {
+            //PIE: if pie draw it and stop
+            if (series.pie.show) {
+                drawSeriesPie(series);
+                return;
+            }
             if (series.lines.show || (!series.bars.show && !series.points.show))
                 drawSeriesLines(series);
             if (series.bars.show)
@@ -1030,6 +1086,64 @@
             if (series.points.show)
                 drawSeriesPoints(series);
         }
+
+        //PIE: draw series pie
+        function drawSeriesPie(serie){
+            var thisvalue = serie.data / pieTotal;		
+            var arcStartAngle = Math.PI * (- 0.5 + 2 * pieIndex); // -0.5 sets set the start to be top
+            var arcEndAngle = Math.PI * (- 0.5 + 2 * (pieIndex + thisvalue));		
+
+            ctx.beginPath();
+            ctx.lineWidth = 0;
+            ctx.moveTo(pieCenterLeft,pieCenterTop); // Center of the pie
+            ctx.arc(  // draw next arc
+                    pieCenterLeft,
+                    pieCenterTop,
+                    pieChartRadius,
+                    arcStartAngle,
+                    arcEndAngle,
+                    false
+                      );
+            ctx.closePath();		
+            ctx.fillStyle = serie.color; // Color
+            ctx.fill();
+
+            // Draw the same thing again to draw stroke properly in IE
+            if (serie.pie.pieStrokeLineWidth > 0) {
+                ctx.strokeStyle = serie.pie.pieStrokeColor;
+                ctx.lineWidth = serie.pie.pieStrokeLineWidth;
+                ctx.beginPath();
+                ctx.moveTo(pieCenterLeft,pieCenterTop); // Center of the pie
+                ctx.arc(  // draw next arc
+                        pieCenterLeft,
+                        pieCenterTop,
+                        pieChartRadius,
+                        arcStartAngle, 
+                        arcEndAngle,
+                        false
+                          );
+                ctx.closePath();		
+                ctx.strokeStyle = serie.pie.pieStrokeColor;
+                ctx.stroke();
+            }
+
+            ///// STEP 4 - Draw pie labels
+            if (options.pie.showLabel && typeof(options.pie.labelFormatter) == 'function') {
+                var text = options.pie.labelFormatter(serie);
+                var halfAngle = (arcEndAngle + arcStartAngle)/2;
+                var lo = serie.pie.labelOffset?serie.pie.labelOffset:pieChartRadius*serie.pie.labelOffsetFactor;
+                var xh = pieCenterLeft + Math.round(Math.cos(halfAngle) * lo);
+                var yh = pieCenterTop + Math.round(Math.sin(halfAngle) * lo);
+                var html = '<span  class="pieLabel" id="pieLabel'+pieArcIndex+'" style="position:absolute;top:' + (plotOffset.top + yh) + 'px;left:' + (plotOffset.left + xh) + 'px;"><div>' + text + "</div></span>";
+                target.append(html);
+                var label = $('#pieLabel'+pieArcIndex);
+                label.css('opacity', serie.pie.labelBackgroundOpacity);
+                label.css('top', (plotOffset.top + yh - label.height()/2));
+                label.css('left', (plotOffset.left + xh - label.width()/2));
+            }
+            pieIndex += thisvalue; // increment progress tracker
+            pieArcIndex++;
+        }
         
         function drawSeriesLines(series) {
             function plotLine(data, offset, axisx, axisy) {
@@ -1515,6 +1629,8 @@
                 else if (p.charAt(1) == "w")
                     pos += 'left:' + (m + plotOffset.left) + 'px;';
                 var legend = $('<div class="legend">' + table.replace('style="', 'style="position:absolute;' + pos +';') + '</div>').appendTo(target);
+                //PIE: need global variable legendWidth
+                legendWidth = legend.children().width();
                 if (options.legend.backgroundOpacity != 0.0) {
                     // put in the transparent background
                     // separately to avoid blended labels and

