3 * Pure JavaScript plotting plugin using jQuery
8 * Copyright (c) 2009-2012 Chris Leonello
9 * jqPlot is currently available for use in all personal or commercial projects
10 * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
11 * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
12 * choose the license that best suits your project and use it accordingly.
14 * Although not required, the author would appreciate an email letting him
15 * know of any substantial use of jqPlot. You can reach the author at:
16 * chris at jqplot dot com or see http://www.jqplot.com/info.php .
18 * If you are feeling kind and generous, consider supporting the project by
19 * making a donation at: http://www.jqplot.com/donate.php .
21 * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
25 * http://hexmen.com/blog/2007/03/printf-sprintf/
26 * http://hexmen.com/js/sprintf.js
27 * The author (Ash Searle) has placed this code in the public domain:
28 * "This code is unrestricted: you are free to use it however you like."
33 * Class: $.jqplot.DonutRenderer
34 * Plugin renderer to draw a donut chart.
35 * x values, if present, will be used as slice labels.
36 * y values give slice size.
38 * To use this renderer, you need to include the
39 * donut renderer plugin, for example:
41 * > <script type="text/javascript" src="plugins/jqplot.donutRenderer.js"></script>
43 * Properties described here are passed into the $.jqplot function
44 * as options on the series renderer. For example:
46 * > plot2 = $.jqplot('chart2', [s1, s2], {
48 * > renderer:$.jqplot.DonutRenderer,
51 * > innerDiameter: 110,
57 * A donut plot will trigger events on the plot target
58 * according to user interaction. All events return the event object,
59 * the series index, the point (slice) index, and the point data for
60 * the appropriate slice.
62 * 'jqplotDataMouseOver' - triggered when user mouseing over a slice.
63 * 'jqplotDataHighlight' - triggered the first time user mouses over a slice,
64 * if highlighting is enabled.
65 * 'jqplotDataUnhighlight' - triggered when a user moves the mouse out of
66 * a highlighted slice.
67 * 'jqplotDataClick' - triggered when the user clicks on a slice.
68 * 'jqplotDataRightClick' - tiggered when the user right clicks on a slice if
69 * the "captureRightClick" option is set to true on the plot.
71 $.jqplot.DonutRenderer = function(){
72 $.jqplot.LineRenderer.call(this);
75 $.jqplot.DonutRenderer.prototype = new $.jqplot.LineRenderer();
76 $.jqplot.DonutRenderer.prototype.constructor = $.jqplot.DonutRenderer;
78 // called with scope of a series
79 $.jqplot.DonutRenderer.prototype.init = function(options, plot) {
83 // Outer diameter of the donut, auto computed by default
85 // prop: innerDiameter
86 // Inner diameter of the donut, auto calculated by default.
87 // If specified will override thickness value.
88 this.innerDiameter = null;
90 // thickness of the donut, auto computed by default
91 // Overridden by if innerDiameter is specified.
92 this.thickness = null;
94 // padding between the donut and plot edges, legend, etc.
97 // angular spacing between donut slices in degrees.
100 // pixel distance between rings, or multiple series in a donut plot.
101 // null will compute ringMargin based on sliceMargin.
102 this.ringMargin = null;
104 // true or false, wether to fil the slices.
106 // prop: shadowOffset
107 // offset of the shadow from the slice and offset of
108 // each succesive stroke of the shadow from the last.
109 this.shadowOffset = 2;
111 // transparency of the shadow (0 = transparent, 1 = opaque)
112 this.shadowAlpha = 0.07;
114 // number of strokes to apply to the shadow,
115 // each stroke offset shadowOffset from the last.
116 this.shadowDepth = 5;
117 // prop: highlightMouseOver
118 // True to highlight slice when moused over.
119 // This must be false to enable highlightMouseDown to highlight when clicking on a slice.
120 this.highlightMouseOver = true;
121 // prop: highlightMouseDown
122 // True to highlight when a mouse button is pressed over a slice.
123 // This will be disabled if highlightMouseOver is true.
124 this.highlightMouseDown = false;
125 // prop: highlightColors
126 // an array of colors to use when highlighting a slice.
127 this.highlightColors = [];
129 // Either 'label', 'value', 'percent' or an array of labels to place on the pie slices.
130 // Defaults to percentage of each pie slice.
131 this.dataLabels = 'percent';
132 // prop: showDataLabels
133 // true to show data labels on slices.
134 this.showDataLabels = false;
135 // prop: dataLabelFormatString
136 // Format string for data labels. If none, '%s' is used for "label" and for arrays, '%d' for value and '%d%%' for percentage.
137 this.dataLabelFormatString = null;
138 // prop: dataLabelThreshold
139 // Threshhold in percentage (0 - 100) of pie area, below which no label will be displayed.
140 // This applies to all label types, not just to percentage labels.
141 this.dataLabelThreshold = 3;
142 // prop: dataLabelPositionFactor
143 // A Multiplier (0-1) of the pie radius which controls position of label on slice.
144 // Increasing will slide label toward edge of pie, decreasing will slide label toward center of pie.
145 this.dataLabelPositionFactor = 0.4;
146 // prop: dataLabelNudge
147 // Number of pixels to slide the label away from (+) or toward (-) the center of the pie.
148 this.dataLabelNudge = 0;
150 // Angle to start drawing donut in degrees.
151 // According to orientation of canvas coordinate system:
152 // 0 = on the positive x axis
153 // -90 = on the positive y axis.
154 // 90 = on the negaive y axis.
155 // 180 or - 180 = on the negative x axis.
157 this.tickRenderer = $.jqplot.DonutTickRenderer;
158 // Used as check for conditions where donut shouldn't be drawn.
159 this._drawData = true;
160 this._type = 'donut';
162 // if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
163 if (options.highlightMouseDown && options.highlightMouseOver == null) {
164 options.highlightMouseOver = false;
167 $.extend(true, this, options);
168 if (this.diameter != null) {
169 this.diameter = this.diameter - this.sliceMargin;
171 this._diameter = null;
172 this._innerDiameter = null;
174 this._innerRadius = null;
175 this._thickness = null;
176 // references to the previous series in the plot to properly calculate diameters
177 // and thicknesses of nested rings.
178 this._previousSeries = [];
179 this._numberSeries = 1;
180 // array of [start,end] angles arrays, one for each slice. In radians.
181 this._sliceAngles = [];
182 // index of the currenty highlighted point, if any
183 this._highlightedPoint = null;
185 // set highlight colors if none provided
186 if (this.highlightColors.length == 0) {
187 for (var i=0; i<this.seriesColors.length; i++){
188 var rgba = $.jqplot.getColorComponents(this.seriesColors[i]);
189 var newrgb = [rgba[0], rgba[1], rgba[2]];
190 var sum = newrgb[0] + newrgb[1] + newrgb[2];
191 for (var j=0; j<3; j++) {
192 // when darkening, lowest color component can be is 60.
193 newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
194 newrgb[j] = parseInt(newrgb[j], 10);
196 this.highlightColors.push('rgb('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+')');
200 plot.postParseOptionsHooks.addOnce(postParseOptions);
201 plot.postInitHooks.addOnce(postInit);
202 plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
203 plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
204 plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
205 plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
206 plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
207 plot.postDrawHooks.addOnce(postPlotDraw);
212 $.jqplot.DonutRenderer.prototype.setGridData = function(plot) {
213 // set gridData property. This will hold angle in radians of each data point.
216 var sa = this.startAngle/180*Math.PI;
218 // don't know if we have any valid data yet, so set plot to not draw.
219 this._drawData = false;
220 for (var i=0; i<this.data.length; i++){
221 if (this.data[i][1] != 0) {
222 // we have data, O.K. to draw.
223 this._drawData = true;
225 stack.push(this.data[i][1]);
226 td.push([this.data[i][0]]);
228 stack[i] += stack[i-1];
230 tot += this.data[i][1];
232 var fact = Math.PI*2/stack[stack.length - 1];
234 for (var i=0; i<stack.length; i++) {
235 td[i][1] = stack[i] * fact;
236 td[i][2] = this.data[i][1]/tot;
241 $.jqplot.DonutRenderer.prototype.makeGridData = function(data, plot) {
245 var sa = this.startAngle/180*Math.PI;
246 // don't know if we have any valid data yet, so set plot to not draw.
247 this._drawData = false;
248 for (var i=0; i<data.length; i++){
249 if (this.data[i][1] != 0) {
250 // we have data, O.K. to draw.
251 this._drawData = true;
253 stack.push(data[i][1]);
254 td.push([data[i][0]]);
256 stack[i] += stack[i-1];
260 var fact = Math.PI*2/stack[stack.length - 1];
262 for (var i=0; i<stack.length; i++) {
263 td[i][1] = stack[i] * fact;
264 td[i][2] = data[i][1]/tot;
269 $.jqplot.DonutRenderer.prototype.drawSlice = function (ctx, ang1, ang2, color, isShadow) {
270 var r = this._diameter / 2;
271 var ri = r - this._thickness;
272 var fill = this.fill;
273 // var lineWidth = this.lineWidth;
275 ctx.translate(this._center[0], this._center[1]);
276 // ctx.translate(this.sliceMargin*Math.cos((ang1+ang2)/2), this.sliceMargin*Math.sin((ang1+ang2)/2));
279 for (var i=0; i<this.shadowDepth; i++) {
281 ctx.translate(this.shadowOffset*Math.cos(this.shadowAngle/180*Math.PI), this.shadowOffset*Math.sin(this.shadowAngle/180*Math.PI));
291 // Fix for IE and Chrome that can't seem to draw circles correctly.
292 // ang2 should always be <= 2 pi since that is the way the data is converted.
293 if (ang2 > 6.282 + this.startAngle) {
294 ang2 = 6.282 + this.startAngle;
296 ang1 = 6.281 + this.startAngle;
299 // Fix for IE, where it can't seem to handle 0 degree angles. Also avoids
300 // ugly line on unfilled donuts.
305 ctx.fillStyle = color;
306 ctx.strokeStyle = color;
307 // ctx.lineWidth = lineWidth;
308 ctx.arc(0, 0, r, ang1, ang2, false);
309 ctx.lineTo(ri*Math.cos(ang2), ri*Math.sin(ang2));
310 ctx.arc(0,0, ri, ang2, ang1, true);
321 for (var i=0; i<this.shadowDepth; i++) {
329 // called with scope of series
330 $.jqplot.DonutRenderer.prototype.draw = function (ctx, gd, options, plot) {
332 var opts = (options != undefined) ? options : {};
333 // offset and direction of offset due to legend placement
337 // var colorGenerator = new this.colorGenerator(this.seriesColors);
338 if (options.legendInfo && options.legendInfo.placement == 'insideGrid') {
339 var li = options.legendInfo;
340 switch (li.location) {
342 offx = li.width + li.xoffset;
345 offx = li.width + li.xoffset;
348 offx = li.width + li.xoffset;
351 offx = li.width + li.xoffset;
355 offx = li.width + li.xoffset;
359 offx = li.width + li.xoffset;
363 offy = li.height + li.yoffset;
366 offy = li.height + li.yoffset;
374 var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
375 var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
376 var fill = (opts.fill != undefined) ? opts.fill : this.fill;
377 var cw = ctx.canvas.width;
378 var ch = ctx.canvas.height;
379 var w = cw - offx - 2 * this.padding;
380 var h = ch - offy - 2 * this.padding;
381 var mindim = Math.min(w,h);
383 var ringmargin = (this.ringMargin == null) ? this.sliceMargin * 2.0 : this.ringMargin;
385 for (var i=0; i<this._previousSeries.length; i++) {
386 d -= 2.0 * this._previousSeries[i]._thickness + 2.0 * ringmargin;
388 this._diameter = this.diameter || d;
389 if (this.innerDiameter != null) {
390 var od = (this._numberSeries > 1 && this.index > 0) ? this._previousSeries[0]._diameter : this._diameter;
391 this._thickness = this.thickness || (od - this.innerDiameter - 2.0*ringmargin*this._numberSeries) / this._numberSeries/2.0;
394 this._thickness = this.thickness || mindim / 2 / (this._numberSeries + 1) * 0.85;
397 var r = this._radius = this._diameter/2;
398 this._innerRadius = this._radius - this._thickness;
399 var sa = this.startAngle / 180 * Math.PI;
400 this._center = [(cw - trans * offx)/2 + trans * offx, (ch - trans*offy)/2 + trans * offy];
403 var shadowColor = 'rgba(0,0,0,'+this.shadowAlpha+')';
404 for (var i=0; i<gd.length; i++) {
405 var ang1 = (i == 0) ? sa : gd[i-1][1] + sa;
406 // Adjust ang1 and ang2 for sliceMargin
407 ang1 += this.sliceMargin/180*Math.PI;
408 this.renderer.drawSlice.call (this, ctx, ang1, gd[i][1]+sa, shadowColor, true);
412 for (var i=0; i<gd.length; i++) {
413 var ang1 = (i == 0) ? sa : gd[i-1][1] + sa;
414 // Adjust ang1 and ang2 for sliceMargin
415 ang1 += this.sliceMargin/180*Math.PI;
416 var ang2 = gd[i][1] + sa;
417 this._sliceAngles.push([ang1, ang2]);
418 this.renderer.drawSlice.call (this, ctx, ang1, ang2, this.seriesColors[i], false);
420 if (this.showDataLabels && gd[i][2]*100 >= this.dataLabelThreshold) {
421 var fstr, avgang = (ang1+ang2)/2, label;
423 if (this.dataLabels == 'label') {
424 fstr = this.dataLabelFormatString || '%s';
425 label = $.jqplot.sprintf(fstr, gd[i][0]);
427 else if (this.dataLabels == 'value') {
428 fstr = this.dataLabelFormatString || '%d';
429 label = $.jqplot.sprintf(fstr, this.data[i][1]);
431 else if (this.dataLabels == 'percent') {
432 fstr = this.dataLabelFormatString || '%d%%';
433 label = $.jqplot.sprintf(fstr, gd[i][2]*100);
435 else if (this.dataLabels.constructor == Array) {
436 fstr = this.dataLabelFormatString || '%s';
437 label = $.jqplot.sprintf(fstr, this.dataLabels[i]);
440 var fact = this._innerRadius + this._thickness * this.dataLabelPositionFactor + this.sliceMargin + this.dataLabelNudge;
442 var x = this._center[0] + Math.cos(avgang) * fact + this.canvas._offsets.left;
443 var y = this._center[1] + Math.sin(avgang) * fact + this.canvas._offsets.top;
445 var labelelem = $('<span class="jqplot-donut-series jqplot-data-label" style="position:absolute;">' + label + '</span>').insertBefore(plot.eventCanvas._elem);
446 x -= labelelem.width()/2;
447 y -= labelelem.height()/2;
450 labelelem.css({left: x, top: y});
456 $.jqplot.DonutAxisRenderer = function() {
457 $.jqplot.LinearAxisRenderer.call(this);
460 $.jqplot.DonutAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
461 $.jqplot.DonutAxisRenderer.prototype.constructor = $.jqplot.DonutAxisRenderer;
464 // There are no traditional axes on a donut chart. We just need to provide
465 // dummy objects with properties so the plot will render.
466 // called with scope of axis object.
467 $.jqplot.DonutAxisRenderer.prototype.init = function(options){
469 this.tickRenderer = $.jqplot.DonutTickRenderer;
470 $.extend(true, this, options);
471 // I don't think I'm going to need _dataBounds here.
472 // have to go Axis scaling in a way to fit chart onto plot area
473 // and provide u2p and p2u functionality for mouse cursor, etc.
474 // for convienence set _dataBounds to 0 and 100 and
475 // set min/max to 0 and 100.
476 this._dataBounds = {min:0, max:100};
479 this.showTicks = false;
481 this.showMark = false;
488 $.jqplot.DonutLegendRenderer = function(){
489 $.jqplot.TableLegendRenderer.call(this);
492 $.jqplot.DonutLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
493 $.jqplot.DonutLegendRenderer.prototype.constructor = $.jqplot.DonutLegendRenderer;
496 * Class: $.jqplot.DonutLegendRenderer
497 * Legend Renderer specific to donut plots. Set by default
498 * when user creates a donut plot.
500 $.jqplot.DonutLegendRenderer.prototype.init = function(options) {
504 // Maximum number of rows in the legend. 0 or null for unlimited.
505 this.numberRows = null;
506 // prop: numberColumns
507 // Maximum number of columns in the legend. 0 or null for unlimited.
508 this.numberColumns = null;
509 $.extend(true, this, options);
512 // called with context of legend
513 $.jqplot.DonutLegendRenderer.prototype.draw = function() {
516 var series = this._series;
517 var ss = 'position:absolute;';
518 ss += (this.background) ? 'background:'+this.background+';' : '';
519 ss += (this.border) ? 'border:'+this.border+';' : '';
520 ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
521 ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
522 ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
523 ss += (this.marginTop != null) ? 'margin-top:'+this.marginTop+';' : '';
524 ss += (this.marginBottom != null) ? 'margin-bottom:'+this.marginBottom+';' : '';
525 ss += (this.marginLeft != null) ? 'margin-left:'+this.marginLeft+';' : '';
526 ss += (this.marginRight != null) ? 'margin-right:'+this.marginRight+';' : '';
527 this._elem = $('<table class="jqplot-table-legend" style="'+ss+'"></table>');
528 // Donut charts legends don't go by number of series, but by number of data points
529 // in the series. Refactor things here for that.
535 var colorGenerator = new $.jqplot.ColorGenerator(s.seriesColors);
539 if (this.numberRows) {
540 nr = this.numberRows;
541 if (!this.numberColumns){
542 nc = Math.ceil(pd.length/nr);
545 nc = this.numberColumns;
548 else if (this.numberColumns) {
549 nc = this.numberColumns;
550 nr = Math.ceil(pd.length/this.numberColumns);
557 var i, j, tr, td1, td2, lt, rs, color;
560 for (i=0; i<nr; i++) {
562 tr = $('<tr class="jqplot-table-legend"></tr>').prependTo(this._elem);
565 tr = $('<tr class="jqplot-table-legend"></tr>').appendTo(this._elem);
567 for (j=0; j<nc; j++) {
568 if (idx < pd.length){
569 lt = this.labels[idx] || pd[idx][0].toString();
570 color = colorGenerator.next();
587 rs = (pad) ? this.rowSpacing : '0';
589 td1 = $('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+rs+';">'+
590 '<div><div class="jqplot-table-legend-swatch" style="border-color:'+color+';"></div>'+
592 td2 = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
593 if (this.escapeHtml){
617 // setup default renderers for axes and legend so user doesn't have to
618 // called with scope of plot
619 function preInit(target, data, options) {
620 options = options || {};
621 options.axesDefaults = options.axesDefaults || {};
622 options.legend = options.legend || {};
623 options.seriesDefaults = options.seriesDefaults || {};
624 // only set these if there is a donut series
626 if (options.seriesDefaults.renderer == $.jqplot.DonutRenderer) {
629 else if (options.series) {
630 for (var i=0; i < options.series.length; i++) {
631 if (options.series[i].renderer == $.jqplot.DonutRenderer) {
638 options.axesDefaults.renderer = $.jqplot.DonutAxisRenderer;
639 options.legend.renderer = $.jqplot.DonutLegendRenderer;
640 options.legend.preDraw = true;
641 options.seriesDefaults.pointLabels = {show: false};
645 // called with scope of plot.
646 function postInit(target, data, options) {
647 // if multiple series, add a reference to the previous one so that
648 // donut rings can nest.
649 for (var i=1; i<this.series.length; i++) {
650 if (!this.series[i]._previousSeries.length){
651 for (var j=0; j<i; j++) {
652 if (this.series[i].renderer.constructor == $.jqplot.DonutRenderer && this.series[j].renderer.constructor == $.jqplot.DonutRenderer) {
653 this.series[i]._previousSeries.push(this.series[j]);
658 for (i=0; i<this.series.length; i++) {
659 if (this.series[i].renderer.constructor == $.jqplot.DonutRenderer) {
660 this.series[i]._numberSeries = this.series.length;
661 // don't allow mouseover and mousedown at same time.
662 if (this.series[i].highlightMouseOver) {
663 this.series[i].highlightMouseDown = false;
669 var postParseOptionsRun = false;
670 // called with scope of plot
671 function postParseOptions(options) {
672 for (var i=0; i<this.series.length; i++) {
673 this.series[i].seriesColors = this.seriesColors;
674 this.series[i].colorGenerator = $.jqplot.colorGenerator;
678 function highlight (plot, sidx, pidx) {
679 var s = plot.series[sidx];
680 var canvas = plot.plugins.donutRenderer.highlightCanvas;
681 canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height);
682 s._highlightedPoint = pidx;
683 plot.plugins.donutRenderer.highlightedSeriesIndex = sidx;
684 s.renderer.drawSlice.call(s, canvas._ctx, s._sliceAngles[pidx][0], s._sliceAngles[pidx][1], s.highlightColors[pidx], false);
687 function unhighlight (plot) {
688 var canvas = plot.plugins.donutRenderer.highlightCanvas;
689 canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
690 for (var i=0; i<plot.series.length; i++) {
691 plot.series[i]._highlightedPoint = null;
693 plot.plugins.donutRenderer.highlightedSeriesIndex = null;
694 plot.target.trigger('jqplotDataUnhighlight');
697 function handleMove(ev, gridpos, datapos, neighbor, plot) {
699 var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
700 var evt1 = jQuery.Event('jqplotDataMouseOver');
701 evt1.pageX = ev.pageX;
702 evt1.pageY = ev.pageY;
703 plot.target.trigger(evt1, ins);
704 if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.donutRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
705 var evt = jQuery.Event('jqplotDataHighlight');
706 evt.which = ev.which;
707 evt.pageX = ev.pageX;
708 evt.pageY = ev.pageY;
709 plot.target.trigger(evt, ins);
710 highlight (plot, ins[0], ins[1]);
713 else if (neighbor == null) {
718 function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
720 var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
721 if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.donutRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
722 var evt = jQuery.Event('jqplotDataHighlight');
723 evt.which = ev.which;
724 evt.pageX = ev.pageX;
725 evt.pageY = ev.pageY;
726 plot.target.trigger(evt, ins);
727 highlight (plot, ins[0], ins[1]);
730 else if (neighbor == null) {
735 function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
736 var idx = plot.plugins.donutRenderer.highlightedSeriesIndex;
737 if (idx != null && plot.series[idx].highlightMouseDown) {
742 function handleClick(ev, gridpos, datapos, neighbor, plot) {
744 var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
745 var evt = jQuery.Event('jqplotDataClick');
746 evt.which = ev.which;
747 evt.pageX = ev.pageX;
748 evt.pageY = ev.pageY;
749 plot.target.trigger(evt, ins);
753 function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
755 var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
756 var idx = plot.plugins.donutRenderer.highlightedSeriesIndex;
757 if (idx != null && plot.series[idx].highlightMouseDown) {
760 var evt = jQuery.Event('jqplotDataRightClick');
761 evt.which = ev.which;
762 evt.pageX = ev.pageX;
763 evt.pageY = ev.pageY;
764 plot.target.trigger(evt, ins);
768 // called within context of plot
769 // create a canvas which we can draw on.
770 // insert it before the eventCanvas, so eventCanvas will still capture events.
771 function postPlotDraw() {
772 // Memory Leaks patch
773 if (this.plugins.donutRenderer && this.plugins.donutRenderer.highlightCanvas) {
774 this.plugins.donutRenderer.highlightCanvas.resetCanvas();
775 this.plugins.donutRenderer.highlightCanvas = null;
778 this.plugins.donutRenderer = {highlightedSeriesIndex:null};
779 this.plugins.donutRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
780 // do we have any data labels? if so, put highlight canvas before those
781 // Fix for broken jquery :first selector with canvas (VML) elements.
782 var labels = $(this.targetId+' .jqplot-data-label');
784 $(labels[0]).before(this.plugins.donutRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-donutRenderer-highlight-canvas', this._plotDimensions, this));
786 // else put highlight canvas before event canvas.
788 this.eventCanvas._elem.before(this.plugins.donutRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-donutRenderer-highlight-canvas', this._plotDimensions, this));
790 var hctx = this.plugins.donutRenderer.highlightCanvas.setContext();
791 this.eventCanvas._elem.bind('mouseleave', {plot:this}, function (ev) { unhighlight(ev.data.plot); });
794 $.jqplot.preInitHooks.push(preInit);
796 $.jqplot.DonutTickRenderer = function() {
797 $.jqplot.AxisTickRenderer.call(this);
800 $.jqplot.DonutTickRenderer.prototype = new $.jqplot.AxisTickRenderer();
801 $.jqplot.DonutTickRenderer.prototype.constructor = $.jqplot.DonutTickRenderer;