jquery_cheats 5.0.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/README.md +1 -0
  2. data/app/assets/javascripts/jquery_cheats/jquery_cheats.js +1 -1
  3. data/app/assets/javascripts/jquery_cheats/replacementContextMenu.js +62 -0
  4. data/jquery_cheats.gemspec +2 -2
  5. data/lib/jquery_cheats/jquery_cheats.rb +58 -0
  6. data/vendor/assets/javascripts/jqplot/excanvas.js +1438 -0
  7. data/vendor/assets/javascripts/jqplot/jquery.jqplot.js +10901 -0
  8. data/vendor/assets/javascripts/jqplot/plugins/jqplot.BezierCurveRenderer.js +312 -0
  9. data/vendor/assets/javascripts/jqplot/plugins/jqplot.BezierCurveRenderer.min.js +57 -0
  10. data/vendor/assets/javascripts/jqplot/plugins/jqplot.barRenderer.js +747 -0
  11. data/vendor/assets/javascripts/jqplot/plugins/jqplot.barRenderer.min.js +57 -0
  12. data/vendor/assets/javascripts/jqplot/plugins/jqplot.blockRenderer.js +234 -0
  13. data/vendor/assets/javascripts/jqplot/plugins/jqplot.blockRenderer.min.js +57 -0
  14. data/vendor/assets/javascripts/jqplot/plugins/jqplot.bubbleRenderer.js +754 -0
  15. data/vendor/assets/javascripts/jqplot/plugins/jqplot.bubbleRenderer.min.js +57 -0
  16. data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasAxisLabelRenderer.js +202 -0
  17. data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasAxisLabelRenderer.min.js +57 -0
  18. data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasAxisTickRenderer.js +242 -0
  19. data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasAxisTickRenderer.min.js +57 -0
  20. data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasOverlay.js +864 -0
  21. data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasOverlay.min.js +57 -0
  22. data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasTextRenderer.js +448 -0
  23. data/vendor/assets/javascripts/jqplot/plugins/jqplot.canvasTextRenderer.min.js +57 -0
  24. data/vendor/assets/javascripts/jqplot/plugins/jqplot.categoryAxisRenderer.js +636 -0
  25. data/vendor/assets/javascripts/jqplot/plugins/jqplot.categoryAxisRenderer.min.js +57 -0
  26. data/vendor/assets/javascripts/jqplot/plugins/jqplot.ciParser.js +115 -0
  27. data/vendor/assets/javascripts/jqplot/plugins/jqplot.ciParser.min.js +57 -0
  28. data/vendor/assets/javascripts/jqplot/plugins/jqplot.cursor.js +1093 -0
  29. data/vendor/assets/javascripts/jqplot/plugins/jqplot.cursor.min.js +57 -0
  30. data/vendor/assets/javascripts/jqplot/plugins/jqplot.dateAxisRenderer.js +702 -0
  31. data/vendor/assets/javascripts/jqplot/plugins/jqplot.dateAxisRenderer.min.js +57 -0
  32. data/vendor/assets/javascripts/jqplot/plugins/jqplot.donutRenderer.js +800 -0
  33. data/vendor/assets/javascripts/jqplot/plugins/jqplot.donutRenderer.min.js +57 -0
  34. data/vendor/assets/javascripts/jqplot/plugins/jqplot.dragable.js +224 -0
  35. data/vendor/assets/javascripts/jqplot/plugins/jqplot.dragable.min.js +57 -0
  36. data/vendor/assets/javascripts/jqplot/plugins/jqplot.enhancedLegendRenderer.js +241 -0
  37. data/vendor/assets/javascripts/jqplot/plugins/jqplot.enhancedLegendRenderer.min.js +57 -0
  38. data/vendor/assets/javascripts/jqplot/plugins/jqplot.funnelRenderer.js +938 -0
  39. data/vendor/assets/javascripts/jqplot/plugins/jqplot.funnelRenderer.min.js +57 -0
  40. data/vendor/assets/javascripts/jqplot/plugins/jqplot.highlighter.js +454 -0
  41. data/vendor/assets/javascripts/jqplot/plugins/jqplot.highlighter.min.js +57 -0
  42. data/vendor/assets/javascripts/jqplot/plugins/jqplot.json2.js +475 -0
  43. data/vendor/assets/javascripts/jqplot/plugins/jqplot.json2.min.js +57 -0
  44. data/vendor/assets/javascripts/jqplot/plugins/jqplot.logAxisRenderer.js +528 -0
  45. data/vendor/assets/javascripts/jqplot/plugins/jqplot.logAxisRenderer.min.js +57 -0
  46. data/vendor/assets/javascripts/jqplot/plugins/jqplot.mekkoAxisRenderer.js +610 -0
  47. data/vendor/assets/javascripts/jqplot/plugins/jqplot.mekkoAxisRenderer.min.js +57 -0
  48. data/vendor/assets/javascripts/jqplot/plugins/jqplot.mekkoRenderer.js +436 -0
  49. data/vendor/assets/javascripts/jqplot/plugins/jqplot.mekkoRenderer.min.js +57 -0
  50. data/vendor/assets/javascripts/jqplot/plugins/jqplot.meterGaugeRenderer.js +1029 -0
  51. data/vendor/assets/javascripts/jqplot/plugins/jqplot.meterGaugeRenderer.min.js +57 -0
  52. data/vendor/assets/javascripts/jqplot/plugins/jqplot.ohlcRenderer.js +372 -0
  53. data/vendor/assets/javascripts/jqplot/plugins/jqplot.ohlcRenderer.min.js +57 -0
  54. data/vendor/assets/javascripts/jqplot/plugins/jqplot.pieRenderer.js +899 -0
  55. data/vendor/assets/javascripts/jqplot/plugins/jqplot.pieRenderer.min.js +57 -0
  56. data/vendor/assets/javascripts/jqplot/plugins/jqplot.pointLabels.js +362 -0
  57. data/vendor/assets/javascripts/jqplot/plugins/jqplot.pointLabels.min.js +57 -0
  58. data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidAxisRenderer.js +730 -0
  59. data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidAxisRenderer.min.js +57 -0
  60. data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidGridRenderer.js +423 -0
  61. data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidGridRenderer.min.js +57 -0
  62. data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidRenderer.js +490 -0
  63. data/vendor/assets/javascripts/jqplot/plugins/jqplot.pyramidRenderer.min.js +57 -0
  64. data/vendor/assets/javascripts/jqplot/plugins/jqplot.trendline.js +222 -0
  65. data/vendor/assets/javascripts/jqplot/plugins/jqplot.trendline.min.js +57 -0
  66. data/vendor/assets/javascripts/jquery_cheats/spinjs/spin.min.js +1 -1
  67. data/vendor/assets/stylesheets/jquery.jqplot.css +259 -0
  68. metadata +66 -3
@@ -0,0 +1,57 @@
1
+ /**
2
+ * jqPlot
3
+ * Pure JavaScript plotting plugin using jQuery
4
+ *
5
+ * Version: 1.0.0b2_r1012
6
+ *
7
+ * Copyright (c) 2009-2011 Chris Leonello
8
+ * jqPlot is currently available for use in all personal or commercial projects
9
+ * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
10
+ * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
11
+ * choose the license that best suits your project and use it accordingly.
12
+ *
13
+ * Although not required, the author would appreciate an email letting him
14
+ * know of any substantial use of jqPlot. You can reach the author at:
15
+ * chris at jqplot dot com or see http://www.jqplot.com/info.php .
16
+ *
17
+ * If you are feeling kind and generous, consider supporting the project by
18
+ * making a donation at: http://www.jqplot.com/donate.php .
19
+ *
20
+ * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
21
+ *
22
+ * version 2007.04.27
23
+ * author Ash Searle
24
+ * http://hexmen.com/blog/2007/03/printf-sprintf/
25
+ * http://hexmen.com/js/sprintf.js
26
+ * The author (Ash Searle) has placed this code in the public domain:
27
+ * "This code is unrestricted: you are free to use it however you like."
28
+ *
29
+ * included jsDate library by Chris Leonello:
30
+ *
31
+ * Copyright (c) 2010-2011 Chris Leonello
32
+ *
33
+ * jsDate is currently available for use in all personal or commercial projects
34
+ * under both the MIT and GPL version 2.0 licenses. This means that you can
35
+ * choose the license that best suits your project and use it accordingly.
36
+ *
37
+ * jsDate borrows many concepts and ideas from the Date Instance
38
+ * Methods by Ken Snyder along with some parts of Ken's actual code.
39
+ *
40
+ * Ken's origianl Date Instance Methods and copyright notice:
41
+ *
42
+ * Ken Snyder (ken d snyder at gmail dot com)
43
+ * 2008-09-10
44
+ * version 2.0.2 (http://kendsnyder.com/sandbox/date/)
45
+ * Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
46
+ *
47
+ * jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
48
+ * Larry has generously given permission to adapt his code for inclusion
49
+ * into jqPlot.
50
+ *
51
+ * Larry's original code can be found here:
52
+ *
53
+ * https://github.com/lsiden/export-jqplot-to-png
54
+ *
55
+ *
56
+ */
57
+ (function(h){h.jqplot.DateAxisRenderer=function(){h.jqplot.LinearAxisRenderer.call(this);this.date=new h.jsDate()};var c=1000;var e=60*c;var f=60*e;var l=24*f;var b=7*l;var j=30.4368499*l;var k=365.242199*l;var g=[31,28,31,30,31,30,31,30,31,30,31,30];var i=["%M:%S.%#N","%M:%S.%#N","%M:%S.%#N","%M:%S","%M:%S","%M:%S","%M:%S","%H:%M:%S","%H:%M:%S","%H:%M","%H:%M","%H:%M","%H:%M","%H:%M","%H:%M","%a %H:%M","%a %H:%M","%b %e %H:%M","%b %e %H:%M","%b %e %H:%M","%b %e %H:%M","%v","%v","%v","%v","%v","%v","%v"];var m=[0.1*c,0.2*c,0.5*c,c,2*c,5*c,10*c,15*c,30*c,e,2*e,5*e,10*e,15*e,30*e,f,2*f,4*f,6*f,8*f,12*f,l,2*l,3*l,4*l,5*l,b,2*b];var d=[];function a(p,s,t){var o=Number.MAX_VALUE;var u,r,v;for(var q=0,n=m.length;q<n;q++){u=Math.abs(t-m[q]);if(u<o){o=u;r=m[q];v=i[q]}}return[r,v]}h.jqplot.DateAxisRenderer.prototype=new h.jqplot.LinearAxisRenderer();h.jqplot.DateAxisRenderer.prototype.constructor=h.jqplot.DateAxisRenderer;h.jqplot.DateTickFormatter=function(n,o){if(!n){n="%Y/%m/%d"}return h.jsDate.strftime(o,n)};h.jqplot.DateAxisRenderer.prototype.init=function(E){this.tickOptions.formatter=h.jqplot.DateTickFormatter;this.tickInset=0;this.drawBaseline=true;this.baselineWidth=null;this.baselineColor=null;this.daTickInterval=null;this._daTickInterval=null;h.extend(true,this,E);var C=this._dataBounds,u,x,D,y,A,z,o;for(var t=0;t<this._series.length;t++){u={intervals:[],frequencies:{},sortedIntervals:[],min:null,max:null,mean:null};x=0;D=this._series[t];y=D.data;A=D._plotData;z=D._stackData;o=0;for(var r=0;r<y.length;r++){if(this.name=="xaxis"||this.name=="x2axis"){y[r][0]=new h.jsDate(y[r][0]).getTime();A[r][0]=new h.jsDate(y[r][0]).getTime();z[r][0]=new h.jsDate(y[r][0]).getTime();if((y[r][0]!=null&&y[r][0]<C.min)||C.min==null){C.min=y[r][0]}if((y[r][0]!=null&&y[r][0]>C.max)||C.max==null){C.max=y[r][0]}if(r>0){o=Math.abs(y[r][0]-y[r-1][0]);u.intervals.push(o);if(u.frequencies.hasOwnProperty(o)){u.frequencies[o]+=1}else{u.frequencies[o]=1}}x+=o}else{y[r][1]=new h.jsDate(y[r][1]).getTime();A[r][1]=new h.jsDate(y[r][1]).getTime();z[r][1]=new h.jsDate(y[r][1]).getTime();if((y[r][1]!=null&&y[r][1]<C.min)||C.min==null){C.min=y[r][1]}if((y[r][1]!=null&&y[r][1]>C.max)||C.max==null){C.max=y[r][1]}if(r>0){o=Math.abs(y[r][1]-y[r-1][1]);u.intervals.push(o);if(u.frequencies.hasOwnProperty(o)){u.frequencies[o]+=1}else{u.frequencies[o]=1}}}x+=o}if(D.renderer.bands){if(D.renderer.bands.hiData.length){var w=D.renderer.bands.hiData;for(var r=0,q=w.length;r<q;r++){if(this.name==="xaxis"||this.name==="x2axis"){w[r][0]=new h.jsDate(w[r][0]).getTime();if((w[r][0]!=null&&w[r][0]>C.max)||C.max==null){C.max=w[r][0]}}else{w[r][1]=new h.jsDate(w[r][1]).getTime();if((w[r][1]!=null&&w[r][1]>C.max)||C.max==null){C.max=w[r][1]}}}}if(D.renderer.bands.lowData.length){var w=D.renderer.bands.lowData;for(var r=0,q=w.length;r<q;r++){if(this.name==="xaxis"||this.name==="x2axis"){w[r][0]=new h.jsDate(w[r][0]).getTime();if((w[r][0]!=null&&w[r][0]<C.min)||C.min==null){C.min=w[r][0]}}else{w[r][1]=new h.jsDate(w[r][1]).getTime();if((w[r][1]!=null&&w[r][1]<C.min)||C.min==null){C.min=w[r][1]}}}}}var B=0,v=0;for(var p in u.frequencies){u.sortedIntervals.push({interval:p,frequency:u.frequencies[p]})}u.sortedIntervals.sort(function(s,n){return n.frequency-s.frequency});u.min=h.jqplot.arrayMin(u.intervals);u.max=h.jqplot.arrayMax(u.intervals);u.mean=x/y.length;this._intervalStats.push(u);u=x=D=y=A=z=null}C=null};h.jqplot.DateAxisRenderer.prototype.reset=function(){this.min=this._options.min;this.max=this._options.max;this.tickInterval=this._options.tickInterval;this.numberTicks=this._options.numberTicks;this._autoFormatString="";if(this._overrideFormatString&&this.tickOptions&&this.tickOptions.formatString){this.tickOptions.formatString=""}this.daTickInterval=this._daTickInterval};h.jqplot.DateAxisRenderer.prototype.createTicks=function(p){var U=this._ticks;var J=this.ticks;var E=this.name;var G=this._dataBounds;var L=this._intervalStats;var n=(this.name.charAt(0)==="x")?this._plotDimensions.width:this._plotDimensions.height;var w;var ab,I;var y,x;var aa,X;var s=30;var N=1;var v=this.tickInterval;ab=((this.min!=null)?new h.jsDate(this.min).getTime():G.min);I=((this.max!=null)?new h.jsDate(this.max).getTime():G.max);var A=p.plugins.cursor;if(A&&A._zoom&&A._zoom.zooming){this.min=null;this.max=null}var B=I-ab;if(this.tickOptions==null||!this.tickOptions.formatString){this._overrideFormatString=true}if(J.length){for(X=0;X<J.length;X++){var O=J[X];var V=new this.tickRenderer(this.tickOptions);if(O.constructor==Array){V.value=new h.jsDate(O[0]).getTime();V.label=O[1];if(!this.showTicks){V.showLabel=false;V.showMark=false}else{if(!this.showTickMarks){V.showMark=false}}V.setTick(V.value,this.name);this._ticks.push(V)}else{V.value=new h.jsDate(O).getTime();if(!this.showTicks){V.showLabel=false;V.showMark=false}else{if(!this.showTickMarks){V.showMark=false}}V.setTick(V.value,this.name);this._ticks.push(V)}}this.numberTicks=J.length;this.min=this._ticks[0].value;this.max=this._ticks[this.numberTicks-1].value;this.daTickInterval=[(this.max-this.min)/(this.numberTicks-1)/1000,"seconds"]}else{if(this.min==null&&this.max==null){var M=h.extend(true,{},this.tickOptions,{name:this.name,value:null});var Y,H;if(!this.tickInterval&&!this.numberTicks){var Q=Math.max(n,s+1);var W=115;if(this.tickRenderer===h.jqplot.CanvasAxisTickRenderer&&this.tickOptions.angle){W=115-40*Math.abs(Math.sin(this.tickOptions.angle/180*Math.PI))}Y=Math.ceil((Q-s)/W+1);H=(I-ab)/(Y-1)}else{if(this.tickInterval){H=this.tickInterval}else{if(this.numberTicks){Y=this.numberTicks;H=(I-ab)/(Y-1)}}}if(H<=19*l){var P=a(ab,I,H);var r=P[0];this._autoFormatString=P[1];ab=Math.floor(ab/r)*r;ab=new h.jsDate(ab);ab=ab.getTime()+ab.getUtcOffset();Y=Math.ceil((I-ab)/r)+1;this.min=ab;this.max=ab+(Y-1)*r;if(this.max<I){this.max+=r;Y+=1}this.tickInterval=r;this.numberTicks=Y;for(var X=0;X<Y;X++){M.value=this.min+X*r;V=new this.tickRenderer(M);if(this._overrideFormatString&&this._autoFormatString!=""){V.formatString=this._autoFormatString}if(!this.showTicks){V.showLabel=false;V.showMark=false}else{if(!this.showTickMarks){V.showMark=false}}this._ticks.push(V)}N=this.tickInterval}else{if(H<=9*j){this._autoFormatString="%v";var D=Math.round(H/j);if(D<1){D=1}else{if(D>6){D=6}}var S=new h.jsDate(ab).setDate(1).setHours(0,0,0,0);var q=new h.jsDate(I);var z=new h.jsDate(I).setDate(1).setHours(0,0,0,0);if(q.getTime()!==z.getTime()){z=z.add(1,"month")}var R=z.diff(S,"month");Y=Math.ceil(R/D)+1;this.min=S.getTime();this.max=S.clone().add((Y-1)*D,"month").getTime();this.numberTicks=Y;for(var X=0;X<Y;X++){if(X===0){M.value=S.getTime()}else{M.value=S.add(D,"month").getTime()}V=new this.tickRenderer(M);if(this._overrideFormatString&&this._autoFormatString!=""){V.formatString=this._autoFormatString}if(!this.showTicks){V.showLabel=false;V.showMark=false}else{if(!this.showTickMarks){V.showMark=false}}this._ticks.push(V)}N=D*j}else{this._autoFormatString="%v";var D=Math.round(H/k);if(D<1){D=1}var S=new h.jsDate(ab).setMonth(0,1).setHours(0,0,0,0);var z=new h.jsDate(I).add(1,"year").setMonth(0,1).setHours(0,0,0,0);var K=z.diff(S,"year");Y=Math.ceil(K/D)+1;this.min=S.getTime();this.max=S.clone().add((Y-1)*D,"year").getTime();this.numberTicks=Y;for(var X=0;X<Y;X++){if(X===0){M.value=S.getTime()}else{M.value=S.add(D,"year").getTime()}V=new this.tickRenderer(M);if(this._overrideFormatString&&this._autoFormatString!=""){V.formatString=this._autoFormatString}if(!this.showTicks){V.showLabel=false;V.showMark=false}else{if(!this.showTickMarks){V.showMark=false}}this._ticks.push(V)}N=D*k}}}else{if(E=="xaxis"||E=="x2axis"){n=this._plotDimensions.width}else{n=this._plotDimensions.height}if(this.min!=null&&this.max!=null&&this.numberTicks!=null){this.tickInterval=null}if(this.tickInterval!=null){if(Number(this.tickInterval)){this.daTickInterval=[Number(this.tickInterval),"seconds"]}else{if(typeof this.tickInterval=="string"){var Z=this.tickInterval.split(" ");if(Z.length==1){this.daTickInterval=[1,Z[0]]}else{if(Z.length==2){this.daTickInterval=[Z[0],Z[1]]}}}}}if(ab==I){var o=24*60*60*500;ab-=o;I+=o}B=I-ab;var F=2+parseInt(Math.max(0,n-100)/100,10);var T,C;T=(this.min!=null)?new h.jsDate(this.min).getTime():ab-B/2*(this.padMin-1);C=(this.max!=null)?new h.jsDate(this.max).getTime():I+B/2*(this.padMax-1);this.min=T;this.max=C;B=this.max-this.min;if(this.numberTicks==null){if(this.daTickInterval!=null){var u=new h.jsDate(this.max).diff(this.min,this.daTickInterval[1],true);this.numberTicks=Math.ceil(u/this.daTickInterval[0])+1;this.max=new h.jsDate(this.min).add((this.numberTicks-1)*this.daTickInterval[0],this.daTickInterval[1]).getTime()}else{if(n>200){this.numberTicks=parseInt(3+(n-200)/100,10)}else{this.numberTicks=2}}}N=B/(this.numberTicks-1)/1000;if(this.daTickInterval==null){this.daTickInterval=[N,"seconds"]}for(var X=0;X<this.numberTicks;X++){var ab=new h.jsDate(this.min);aa=ab.add(X*this.daTickInterval[0],this.daTickInterval[1]).getTime();var V=new this.tickRenderer(this.tickOptions);if(!this.showTicks){V.showLabel=false;V.showMark=false}else{if(!this.showTickMarks){V.showMark=false}}V.setTick(aa,this.name);this._ticks.push(V)}}}if(this.tickInset){this.min=this.min-this.tickInset*N;this.max=this.max+this.tickInset*N}if(this._daTickInterval==null){this._daTickInterval=this.daTickInterval}U=null}})(jQuery);
@@ -0,0 +1,800 @@
1
+ /**
2
+ * jqPlot
3
+ * Pure JavaScript plotting plugin using jQuery
4
+ *
5
+ * Version: 1.0.0b2_r1012
6
+ *
7
+ * Copyright (c) 2009-2011 Chris Leonello
8
+ * jqPlot is currently available for use in all personal or commercial projects
9
+ * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
10
+ * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
11
+ * choose the license that best suits your project and use it accordingly.
12
+ *
13
+ * Although not required, the author would appreciate an email letting him
14
+ * know of any substantial use of jqPlot. You can reach the author at:
15
+ * chris at jqplot dot com or see http://www.jqplot.com/info.php .
16
+ *
17
+ * If you are feeling kind and generous, consider supporting the project by
18
+ * making a donation at: http://www.jqplot.com/donate.php .
19
+ *
20
+ * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
21
+ *
22
+ * version 2007.04.27
23
+ * author Ash Searle
24
+ * http://hexmen.com/blog/2007/03/printf-sprintf/
25
+ * http://hexmen.com/js/sprintf.js
26
+ * The author (Ash Searle) has placed this code in the public domain:
27
+ * "This code is unrestricted: you are free to use it however you like."
28
+ *
29
+ */
30
+ (function($) {
31
+ /**
32
+ * Class: $.jqplot.DonutRenderer
33
+ * Plugin renderer to draw a donut chart.
34
+ * x values, if present, will be used as slice labels.
35
+ * y values give slice size.
36
+ *
37
+ * To use this renderer, you need to include the
38
+ * donut renderer plugin, for example:
39
+ *
40
+ * > <script type="text/javascript" src="plugins/jqplot.donutRenderer.js"></script>
41
+ *
42
+ * Properties described here are passed into the $.jqplot function
43
+ * as options on the series renderer. For example:
44
+ *
45
+ * > plot2 = $.jqplot('chart2', [s1, s2], {
46
+ * > seriesDefaults: {
47
+ * > renderer:$.jqplot.DonutRenderer,
48
+ * > rendererOptions:{
49
+ * > sliceMargin: 2,
50
+ * > innerDiameter: 110,
51
+ * > startAngle: -90
52
+ * > }
53
+ * > }
54
+ * > });
55
+ *
56
+ * A donut plot will trigger events on the plot target
57
+ * according to user interaction. All events return the event object,
58
+ * the series index, the point (slice) index, and the point data for
59
+ * the appropriate slice.
60
+ *
61
+ * 'jqplotDataMouseOver' - triggered when user mouseing over a slice.
62
+ * 'jqplotDataHighlight' - triggered the first time user mouses over a slice,
63
+ * if highlighting is enabled.
64
+ * 'jqplotDataUnhighlight' - triggered when a user moves the mouse out of
65
+ * a highlighted slice.
66
+ * 'jqplotDataClick' - triggered when the user clicks on a slice.
67
+ * 'jqplotDataRightClick' - tiggered when the user right clicks on a slice if
68
+ * the "captureRightClick" option is set to true on the plot.
69
+ */
70
+ $.jqplot.DonutRenderer = function(){
71
+ $.jqplot.LineRenderer.call(this);
72
+ };
73
+
74
+ $.jqplot.DonutRenderer.prototype = new $.jqplot.LineRenderer();
75
+ $.jqplot.DonutRenderer.prototype.constructor = $.jqplot.DonutRenderer;
76
+
77
+ // called with scope of a series
78
+ $.jqplot.DonutRenderer.prototype.init = function(options, plot) {
79
+ // Group: Properties
80
+ //
81
+ // prop: diameter
82
+ // Outer diameter of the donut, auto computed by default
83
+ this.diameter = null;
84
+ // prop: innerDiameter
85
+ // Inner diameter of the donut, auto calculated by default.
86
+ // If specified will override thickness value.
87
+ this.innerDiameter = null;
88
+ // prop: thickness
89
+ // thickness of the donut, auto computed by default
90
+ // Overridden by if innerDiameter is specified.
91
+ this.thickness = null;
92
+ // prop: padding
93
+ // padding between the donut and plot edges, legend, etc.
94
+ this.padding = 20;
95
+ // prop: sliceMargin
96
+ // angular spacing between donut slices in degrees.
97
+ this.sliceMargin = 0;
98
+ // prop: ringMargin
99
+ // pixel distance between rings, or multiple series in a donut plot.
100
+ // null will compute ringMargin based on sliceMargin.
101
+ this.ringMargin = null;
102
+ // prop: fill
103
+ // true or false, wether to fil the slices.
104
+ this.fill = true;
105
+ // prop: shadowOffset
106
+ // offset of the shadow from the slice and offset of
107
+ // each succesive stroke of the shadow from the last.
108
+ this.shadowOffset = 2;
109
+ // prop: shadowAlpha
110
+ // transparency of the shadow (0 = transparent, 1 = opaque)
111
+ this.shadowAlpha = 0.07;
112
+ // prop: shadowDepth
113
+ // number of strokes to apply to the shadow,
114
+ // each stroke offset shadowOffset from the last.
115
+ this.shadowDepth = 5;
116
+ // prop: highlightMouseOver
117
+ // True to highlight slice when moused over.
118
+ // This must be false to enable highlightMouseDown to highlight when clicking on a slice.
119
+ this.highlightMouseOver = true;
120
+ // prop: highlightMouseDown
121
+ // True to highlight when a mouse button is pressed over a slice.
122
+ // This will be disabled if highlightMouseOver is true.
123
+ this.highlightMouseDown = false;
124
+ // prop: highlightColors
125
+ // an array of colors to use when highlighting a slice.
126
+ this.highlightColors = [];
127
+ // prop: dataLabels
128
+ // Either 'label', 'value', 'percent' or an array of labels to place on the pie slices.
129
+ // Defaults to percentage of each pie slice.
130
+ this.dataLabels = 'percent';
131
+ // prop: showDataLabels
132
+ // true to show data labels on slices.
133
+ this.showDataLabels = false;
134
+ // prop: dataLabelFormatString
135
+ // Format string for data labels. If none, '%s' is used for "label" and for arrays, '%d' for value and '%d%%' for percentage.
136
+ this.dataLabelFormatString = null;
137
+ // prop: dataLabelThreshold
138
+ // Threshhold in percentage (0 - 100) of pie area, below which no label will be displayed.
139
+ // This applies to all label types, not just to percentage labels.
140
+ this.dataLabelThreshold = 3;
141
+ // prop: dataLabelPositionFactor
142
+ // A Multiplier (0-1) of the pie radius which controls position of label on slice.
143
+ // Increasing will slide label toward edge of pie, decreasing will slide label toward center of pie.
144
+ this.dataLabelPositionFactor = 0.4;
145
+ // prop: dataLabelNudge
146
+ // Number of pixels to slide the label away from (+) or toward (-) the center of the pie.
147
+ this.dataLabelNudge = 0;
148
+ // prop: startAngle
149
+ // Angle to start drawing donut in degrees.
150
+ // According to orientation of canvas coordinate system:
151
+ // 0 = on the positive x axis
152
+ // -90 = on the positive y axis.
153
+ // 90 = on the negaive y axis.
154
+ // 180 or - 180 = on the negative x axis.
155
+ this.startAngle = 0;
156
+ this.tickRenderer = $.jqplot.DonutTickRenderer;
157
+ // Used as check for conditions where donut shouldn't be drawn.
158
+ this._drawData = true;
159
+ this._type = 'donut';
160
+
161
+ // if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
162
+ if (options.highlightMouseDown && options.highlightMouseOver == null) {
163
+ options.highlightMouseOver = false;
164
+ }
165
+
166
+ $.extend(true, this, options);
167
+ if (this.diameter != null) {
168
+ this.diameter = this.diameter - this.sliceMargin;
169
+ }
170
+ this._diameter = null;
171
+ this._innerDiameter = null;
172
+ this._radius = null;
173
+ this._innerRadius = null;
174
+ this._thickness = null;
175
+ // references to the previous series in the plot to properly calculate diameters
176
+ // and thicknesses of nested rings.
177
+ this._previousSeries = [];
178
+ this._numberSeries = 1;
179
+ // array of [start,end] angles arrays, one for each slice. In radians.
180
+ this._sliceAngles = [];
181
+ // index of the currenty highlighted point, if any
182
+ this._highlightedPoint = null;
183
+
184
+ // set highlight colors if none provided
185
+ if (this.highlightColors.length == 0) {
186
+ for (var i=0; i<this.seriesColors.length; i++){
187
+ var rgba = $.jqplot.getColorComponents(this.seriesColors[i]);
188
+ var newrgb = [rgba[0], rgba[1], rgba[2]];
189
+ var sum = newrgb[0] + newrgb[1] + newrgb[2];
190
+ for (var j=0; j<3; j++) {
191
+ // when darkening, lowest color component can be is 60.
192
+ newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
193
+ newrgb[j] = parseInt(newrgb[j], 10);
194
+ }
195
+ this.highlightColors.push('rgb('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+')');
196
+ }
197
+ }
198
+
199
+ plot.postParseOptionsHooks.addOnce(postParseOptions);
200
+ plot.postInitHooks.addOnce(postInit);
201
+ plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
202
+ plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
203
+ plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
204
+ plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
205
+ plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
206
+ plot.postDrawHooks.addOnce(postPlotDraw);
207
+
208
+
209
+ };
210
+
211
+ $.jqplot.DonutRenderer.prototype.setGridData = function(plot) {
212
+ // set gridData property. This will hold angle in radians of each data point.
213
+ var stack = [];
214
+ var td = [];
215
+ var sa = this.startAngle/180*Math.PI;
216
+ var tot = 0;
217
+ // don't know if we have any valid data yet, so set plot to not draw.
218
+ this._drawData = false;
219
+ for (var i=0; i<this.data.length; i++){
220
+ if (this.data[i][1] != 0) {
221
+ // we have data, O.K. to draw.
222
+ this._drawData = true;
223
+ }
224
+ stack.push(this.data[i][1]);
225
+ td.push([this.data[i][0]]);
226
+ if (i>0) {
227
+ stack[i] += stack[i-1];
228
+ }
229
+ tot += this.data[i][1];
230
+ }
231
+ var fact = Math.PI*2/stack[stack.length - 1];
232
+
233
+ for (var i=0; i<stack.length; i++) {
234
+ td[i][1] = stack[i] * fact;
235
+ td[i][2] = this.data[i][1]/tot;
236
+ }
237
+ this.gridData = td;
238
+ };
239
+
240
+ $.jqplot.DonutRenderer.prototype.makeGridData = function(data, plot) {
241
+ var stack = [];
242
+ var td = [];
243
+ var tot = 0;
244
+ var sa = this.startAngle/180*Math.PI;
245
+ // don't know if we have any valid data yet, so set plot to not draw.
246
+ this._drawData = false;
247
+ for (var i=0; i<data.length; i++){
248
+ if (this.data[i][1] != 0) {
249
+ // we have data, O.K. to draw.
250
+ this._drawData = true;
251
+ }
252
+ stack.push(data[i][1]);
253
+ td.push([data[i][0]]);
254
+ if (i>0) {
255
+ stack[i] += stack[i-1];
256
+ }
257
+ tot += data[i][1];
258
+ }
259
+ var fact = Math.PI*2/stack[stack.length - 1];
260
+
261
+ for (var i=0; i<stack.length; i++) {
262
+ td[i][1] = stack[i] * fact;
263
+ td[i][2] = data[i][1]/tot;
264
+ }
265
+ return td;
266
+ };
267
+
268
+ $.jqplot.DonutRenderer.prototype.drawSlice = function (ctx, ang1, ang2, color, isShadow) {
269
+ var r = this._diameter / 2;
270
+ var ri = r - this._thickness;
271
+ var fill = this.fill;
272
+ // var lineWidth = this.lineWidth;
273
+ ctx.save();
274
+ ctx.translate(this._center[0], this._center[1]);
275
+ // ctx.translate(this.sliceMargin*Math.cos((ang1+ang2)/2), this.sliceMargin*Math.sin((ang1+ang2)/2));
276
+
277
+ if (isShadow) {
278
+ for (var i=0; i<this.shadowDepth; i++) {
279
+ ctx.save();
280
+ ctx.translate(this.shadowOffset*Math.cos(this.shadowAngle/180*Math.PI), this.shadowOffset*Math.sin(this.shadowAngle/180*Math.PI));
281
+ doDraw();
282
+ }
283
+ }
284
+
285
+ else {
286
+ doDraw();
287
+ }
288
+
289
+ function doDraw () {
290
+ // Fix for IE and Chrome that can't seem to draw circles correctly.
291
+ // ang2 should always be <= 2 pi since that is the way the data is converted.
292
+ if (ang2 > 6.282 + this.startAngle) {
293
+ ang2 = 6.282 + this.startAngle;
294
+ if (ang1 > ang2) {
295
+ ang1 = 6.281 + this.startAngle;
296
+ }
297
+ }
298
+ // Fix for IE, where it can't seem to handle 0 degree angles. Also avoids
299
+ // ugly line on unfilled donuts.
300
+ if (ang1 >= ang2) {
301
+ return;
302
+ }
303
+ ctx.beginPath();
304
+ ctx.fillStyle = color;
305
+ ctx.strokeStyle = color;
306
+ // ctx.lineWidth = lineWidth;
307
+ ctx.arc(0, 0, r, ang1, ang2, false);
308
+ ctx.lineTo(ri*Math.cos(ang2), ri*Math.sin(ang2));
309
+ ctx.arc(0,0, ri, ang2, ang1, true);
310
+ ctx.closePath();
311
+ if (fill) {
312
+ ctx.fill();
313
+ }
314
+ else {
315
+ ctx.stroke();
316
+ }
317
+ }
318
+
319
+ if (isShadow) {
320
+ for (var i=0; i<this.shadowDepth; i++) {
321
+ ctx.restore();
322
+ }
323
+ }
324
+
325
+ ctx.restore();
326
+ };
327
+
328
+ // called with scope of series
329
+ $.jqplot.DonutRenderer.prototype.draw = function (ctx, gd, options, plot) {
330
+ var i;
331
+ var opts = (options != undefined) ? options : {};
332
+ // offset and direction of offset due to legend placement
333
+ var offx = 0;
334
+ var offy = 0;
335
+ var trans = 1;
336
+ // var colorGenerator = new this.colorGenerator(this.seriesColors);
337
+ if (options.legendInfo && options.legendInfo.placement == 'insideGrid') {
338
+ var li = options.legendInfo;
339
+ switch (li.location) {
340
+ case 'nw':
341
+ offx = li.width + li.xoffset;
342
+ break;
343
+ case 'w':
344
+ offx = li.width + li.xoffset;
345
+ break;
346
+ case 'sw':
347
+ offx = li.width + li.xoffset;
348
+ break;
349
+ case 'ne':
350
+ offx = li.width + li.xoffset;
351
+ trans = -1;
352
+ break;
353
+ case 'e':
354
+ offx = li.width + li.xoffset;
355
+ trans = -1;
356
+ break;
357
+ case 'se':
358
+ offx = li.width + li.xoffset;
359
+ trans = -1;
360
+ break;
361
+ case 'n':
362
+ offy = li.height + li.yoffset;
363
+ break;
364
+ case 's':
365
+ offy = li.height + li.yoffset;
366
+ trans = -1;
367
+ break;
368
+ default:
369
+ break;
370
+ }
371
+ }
372
+
373
+ var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
374
+ var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
375
+ var fill = (opts.fill != undefined) ? opts.fill : this.fill;
376
+ var cw = ctx.canvas.width;
377
+ var ch = ctx.canvas.height;
378
+ var w = cw - offx - 2 * this.padding;
379
+ var h = ch - offy - 2 * this.padding;
380
+ var mindim = Math.min(w,h);
381
+ var d = mindim;
382
+ var ringmargin = (this.ringMargin == null) ? this.sliceMargin * 2.0 : this.ringMargin;
383
+
384
+ for (var i=0; i<this._previousSeries.length; i++) {
385
+ d -= 2.0 * this._previousSeries[i]._thickness + 2.0 * ringmargin;
386
+ }
387
+ this._diameter = this.diameter || d;
388
+ if (this.innerDiameter != null) {
389
+ var od = (this._numberSeries > 1 && this.index > 0) ? this._previousSeries[0]._diameter : this._diameter;
390
+ this._thickness = this.thickness || (od - this.innerDiameter - 2.0*ringmargin*this._numberSeries) / this._numberSeries/2.0;
391
+ }
392
+ else {
393
+ this._thickness = this.thickness || mindim / 2 / (this._numberSeries + 1) * 0.85;
394
+ }
395
+
396
+ var r = this._radius = this._diameter/2;
397
+ this._innerRadius = this._radius - this._thickness;
398
+ var sa = this.startAngle / 180 * Math.PI;
399
+ this._center = [(cw - trans * offx)/2 + trans * offx, (ch - trans*offy)/2 + trans * offy];
400
+
401
+ if (this.shadow) {
402
+ var shadowColor = 'rgba(0,0,0,'+this.shadowAlpha+')';
403
+ for (var i=0; i<gd.length; i++) {
404
+ var ang1 = (i == 0) ? sa : gd[i-1][1] + sa;
405
+ // Adjust ang1 and ang2 for sliceMargin
406
+ ang1 += this.sliceMargin/180*Math.PI;
407
+ this.renderer.drawSlice.call (this, ctx, ang1, gd[i][1]+sa, shadowColor, true);
408
+ }
409
+
410
+ }
411
+ for (var i=0; i<gd.length; i++) {
412
+ var ang1 = (i == 0) ? sa : gd[i-1][1] + sa;
413
+ // Adjust ang1 and ang2 for sliceMargin
414
+ ang1 += this.sliceMargin/180*Math.PI;
415
+ var ang2 = gd[i][1] + sa;
416
+ this._sliceAngles.push([ang1, ang2]);
417
+ this.renderer.drawSlice.call (this, ctx, ang1, ang2, this.seriesColors[i], false);
418
+
419
+ if (this.showDataLabels && gd[i][2]*100 >= this.dataLabelThreshold) {
420
+ var fstr, avgang = (ang1+ang2)/2, label;
421
+
422
+ if (this.dataLabels == 'label') {
423
+ fstr = this.dataLabelFormatString || '%s';
424
+ label = $.jqplot.sprintf(fstr, gd[i][0]);
425
+ }
426
+ else if (this.dataLabels == 'value') {
427
+ fstr = this.dataLabelFormatString || '%d';
428
+ label = $.jqplot.sprintf(fstr, this.data[i][1]);
429
+ }
430
+ else if (this.dataLabels == 'percent') {
431
+ fstr = this.dataLabelFormatString || '%d%%';
432
+ label = $.jqplot.sprintf(fstr, gd[i][2]*100);
433
+ }
434
+ else if (this.dataLabels.constructor == Array) {
435
+ fstr = this.dataLabelFormatString || '%s';
436
+ label = $.jqplot.sprintf(fstr, this.dataLabels[i]);
437
+ }
438
+
439
+ var fact = this._innerRadius + this._thickness * this.dataLabelPositionFactor + this.sliceMargin + this.dataLabelNudge;
440
+
441
+ var x = this._center[0] + Math.cos(avgang) * fact + this.canvas._offsets.left;
442
+ var y = this._center[1] + Math.sin(avgang) * fact + this.canvas._offsets.top;
443
+
444
+ var labelelem = $('<span class="jqplot-donut-series jqplot-data-label" style="position:absolute;">' + label + '</span>').insertBefore(plot.eventCanvas._elem);
445
+ x -= labelelem.width()/2;
446
+ y -= labelelem.height()/2;
447
+ x = Math.round(x);
448
+ y = Math.round(y);
449
+ labelelem.css({left: x, top: y});
450
+ }
451
+ }
452
+
453
+ };
454
+
455
+ $.jqplot.DonutAxisRenderer = function() {
456
+ $.jqplot.LinearAxisRenderer.call(this);
457
+ };
458
+
459
+ $.jqplot.DonutAxisRenderer.prototype = new $.jqplot.LinearAxisRenderer();
460
+ $.jqplot.DonutAxisRenderer.prototype.constructor = $.jqplot.DonutAxisRenderer;
461
+
462
+
463
+ // There are no traditional axes on a donut chart. We just need to provide
464
+ // dummy objects with properties so the plot will render.
465
+ // called with scope of axis object.
466
+ $.jqplot.DonutAxisRenderer.prototype.init = function(options){
467
+ //
468
+ this.tickRenderer = $.jqplot.DonutTickRenderer;
469
+ $.extend(true, this, options);
470
+ // I don't think I'm going to need _dataBounds here.
471
+ // have to go Axis scaling in a way to fit chart onto plot area
472
+ // and provide u2p and p2u functionality for mouse cursor, etc.
473
+ // for convienence set _dataBounds to 0 and 100 and
474
+ // set min/max to 0 and 100.
475
+ this._dataBounds = {min:0, max:100};
476
+ this.min = 0;
477
+ this.max = 100;
478
+ this.showTicks = false;
479
+ this.ticks = [];
480
+ this.showMark = false;
481
+ this.show = false;
482
+ };
483
+
484
+
485
+
486
+
487
+ $.jqplot.DonutLegendRenderer = function(){
488
+ $.jqplot.TableLegendRenderer.call(this);
489
+ };
490
+
491
+ $.jqplot.DonutLegendRenderer.prototype = new $.jqplot.TableLegendRenderer();
492
+ $.jqplot.DonutLegendRenderer.prototype.constructor = $.jqplot.DonutLegendRenderer;
493
+
494
+ /**
495
+ * Class: $.jqplot.DonutLegendRenderer
496
+ * Legend Renderer specific to donut plots. Set by default
497
+ * when user creates a donut plot.
498
+ */
499
+ $.jqplot.DonutLegendRenderer.prototype.init = function(options) {
500
+ // Group: Properties
501
+ //
502
+ // prop: numberRows
503
+ // Maximum number of rows in the legend. 0 or null for unlimited.
504
+ this.numberRows = null;
505
+ // prop: numberColumns
506
+ // Maximum number of columns in the legend. 0 or null for unlimited.
507
+ this.numberColumns = null;
508
+ $.extend(true, this, options);
509
+ };
510
+
511
+ // called with context of legend
512
+ $.jqplot.DonutLegendRenderer.prototype.draw = function() {
513
+ var legend = this;
514
+ if (this.show) {
515
+ var series = this._series;
516
+ var ss = 'position:absolute;';
517
+ ss += (this.background) ? 'background:'+this.background+';' : '';
518
+ ss += (this.border) ? 'border:'+this.border+';' : '';
519
+ ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
520
+ ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
521
+ ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
522
+ ss += (this.marginTop != null) ? 'margin-top:'+this.marginTop+';' : '';
523
+ ss += (this.marginBottom != null) ? 'margin-bottom:'+this.marginBottom+';' : '';
524
+ ss += (this.marginLeft != null) ? 'margin-left:'+this.marginLeft+';' : '';
525
+ ss += (this.marginRight != null) ? 'margin-right:'+this.marginRight+';' : '';
526
+ this._elem = $('<table class="jqplot-table-legend" style="'+ss+'"></table>');
527
+ // Donut charts legends don't go by number of series, but by number of data points
528
+ // in the series. Refactor things here for that.
529
+
530
+ var pad = false,
531
+ reverse = false,
532
+ nr, nc;
533
+ var s = series[0];
534
+ var colorGenerator = new $.jqplot.ColorGenerator(s.seriesColors);
535
+
536
+ if (s.show) {
537
+ var pd = s.data;
538
+ if (this.numberRows) {
539
+ nr = this.numberRows;
540
+ if (!this.numberColumns){
541
+ nc = Math.ceil(pd.length/nr);
542
+ }
543
+ else{
544
+ nc = this.numberColumns;
545
+ }
546
+ }
547
+ else if (this.numberColumns) {
548
+ nc = this.numberColumns;
549
+ nr = Math.ceil(pd.length/this.numberColumns);
550
+ }
551
+ else {
552
+ nr = pd.length;
553
+ nc = 1;
554
+ }
555
+
556
+ var i, j, tr, td1, td2, lt, rs, color;
557
+ var idx = 0;
558
+
559
+ for (i=0; i<nr; i++) {
560
+ if (reverse){
561
+ tr = $('<tr class="jqplot-table-legend"></tr>').prependTo(this._elem);
562
+ }
563
+ else{
564
+ tr = $('<tr class="jqplot-table-legend"></tr>').appendTo(this._elem);
565
+ }
566
+ for (j=0; j<nc; j++) {
567
+ if (idx < pd.length){
568
+ lt = this.labels[idx] || pd[idx][0].toString();
569
+ color = colorGenerator.next();
570
+ if (!reverse){
571
+ if (i>0){
572
+ pad = true;
573
+ }
574
+ else{
575
+ pad = false;
576
+ }
577
+ }
578
+ else{
579
+ if (i == nr -1){
580
+ pad = false;
581
+ }
582
+ else{
583
+ pad = true;
584
+ }
585
+ }
586
+ rs = (pad) ? this.rowSpacing : '0';
587
+
588
+ td1 = $('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+rs+';">'+
589
+ '<div><div class="jqplot-table-legend-swatch" style="border-color:'+color+';"></div>'+
590
+ '</div></td>');
591
+ td2 = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
592
+ if (this.escapeHtml){
593
+ td2.text(lt);
594
+ }
595
+ else {
596
+ td2.html(lt);
597
+ }
598
+ if (reverse) {
599
+ td2.prependTo(tr);
600
+ td1.prependTo(tr);
601
+ }
602
+ else {
603
+ td1.appendTo(tr);
604
+ td2.appendTo(tr);
605
+ }
606
+ pad = true;
607
+ }
608
+ idx++;
609
+ }
610
+ }
611
+ }
612
+ }
613
+ return this._elem;
614
+ };
615
+
616
+ // setup default renderers for axes and legend so user doesn't have to
617
+ // called with scope of plot
618
+ function preInit(target, data, options) {
619
+ options = options || {};
620
+ options.axesDefaults = options.axesDefaults || {};
621
+ options.legend = options.legend || {};
622
+ options.seriesDefaults = options.seriesDefaults || {};
623
+ // only set these if there is a donut series
624
+ var setopts = false;
625
+ if (options.seriesDefaults.renderer == $.jqplot.DonutRenderer) {
626
+ setopts = true;
627
+ }
628
+ else if (options.series) {
629
+ for (var i=0; i < options.series.length; i++) {
630
+ if (options.series[i].renderer == $.jqplot.DonutRenderer) {
631
+ setopts = true;
632
+ }
633
+ }
634
+ }
635
+
636
+ if (setopts) {
637
+ options.axesDefaults.renderer = $.jqplot.DonutAxisRenderer;
638
+ options.legend.renderer = $.jqplot.DonutLegendRenderer;
639
+ options.legend.preDraw = true;
640
+ options.seriesDefaults.pointLabels = {show: false};
641
+ }
642
+ }
643
+
644
+ // called with scope of plot.
645
+ function postInit(target, data, options) {
646
+ // if multiple series, add a reference to the previous one so that
647
+ // donut rings can nest.
648
+ for (var i=1; i<this.series.length; i++) {
649
+ if (!this.series[i]._previousSeries.length){
650
+ for (var j=0; j<i; j++) {
651
+ if (this.series[i].renderer.constructor == $.jqplot.DonutRenderer && this.series[j].renderer.constructor == $.jqplot.DonutRenderer) {
652
+ this.series[i]._previousSeries.push(this.series[j]);
653
+ }
654
+ }
655
+ }
656
+ }
657
+ for (i=0; i<this.series.length; i++) {
658
+ if (this.series[i].renderer.constructor == $.jqplot.DonutRenderer) {
659
+ this.series[i]._numberSeries = this.series.length;
660
+ // don't allow mouseover and mousedown at same time.
661
+ if (this.series[i].highlightMouseOver) {
662
+ this.series[i].highlightMouseDown = false;
663
+ }
664
+ }
665
+ }
666
+ }
667
+
668
+ var postParseOptionsRun = false;
669
+ // called with scope of plot
670
+ function postParseOptions(options) {
671
+ for (var i=0; i<this.series.length; i++) {
672
+ this.series[i].seriesColors = this.seriesColors;
673
+ this.series[i].colorGenerator = $.jqplot.colorGenerator;
674
+ }
675
+ }
676
+
677
+ function highlight (plot, sidx, pidx) {
678
+ var s = plot.series[sidx];
679
+ var canvas = plot.plugins.donutRenderer.highlightCanvas;
680
+ canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height);
681
+ s._highlightedPoint = pidx;
682
+ plot.plugins.donutRenderer.highlightedSeriesIndex = sidx;
683
+ s.renderer.drawSlice.call(s, canvas._ctx, s._sliceAngles[pidx][0], s._sliceAngles[pidx][1], s.highlightColors[pidx], false);
684
+ }
685
+
686
+ function unhighlight (plot) {
687
+ var canvas = plot.plugins.donutRenderer.highlightCanvas;
688
+ canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
689
+ for (var i=0; i<plot.series.length; i++) {
690
+ plot.series[i]._highlightedPoint = null;
691
+ }
692
+ plot.plugins.donutRenderer.highlightedSeriesIndex = null;
693
+ plot.target.trigger('jqplotDataUnhighlight');
694
+ }
695
+
696
+ function handleMove(ev, gridpos, datapos, neighbor, plot) {
697
+ if (neighbor) {
698
+ var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
699
+ var evt1 = jQuery.Event('jqplotDataMouseOver');
700
+ evt1.pageX = ev.pageX;
701
+ evt1.pageY = ev.pageY;
702
+ plot.target.trigger(evt1, ins);
703
+ if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.donutRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
704
+ var evt = jQuery.Event('jqplotDataHighlight');
705
+ evt.pageX = ev.pageX;
706
+ evt.pageY = ev.pageY;
707
+ plot.target.trigger(evt, ins);
708
+ highlight (plot, ins[0], ins[1]);
709
+ }
710
+ }
711
+ else if (neighbor == null) {
712
+ unhighlight (plot);
713
+ }
714
+ }
715
+
716
+ function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
717
+ if (neighbor) {
718
+ var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
719
+ if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.donutRenderer.highlightedSeriesIndex && ins[1] == plot.series[ins[0]]._highlightedPoint)) {
720
+ var evt = jQuery.Event('jqplotDataHighlight');
721
+ evt.pageX = ev.pageX;
722
+ evt.pageY = ev.pageY;
723
+ plot.target.trigger(evt, ins);
724
+ highlight (plot, ins[0], ins[1]);
725
+ }
726
+ }
727
+ else if (neighbor == null) {
728
+ unhighlight (plot);
729
+ }
730
+ }
731
+
732
+ function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
733
+ var idx = plot.plugins.donutRenderer.highlightedSeriesIndex;
734
+ if (idx != null && plot.series[idx].highlightMouseDown) {
735
+ unhighlight(plot);
736
+ }
737
+ }
738
+
739
+ function handleClick(ev, gridpos, datapos, neighbor, plot) {
740
+ if (neighbor) {
741
+ var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
742
+ var evt = jQuery.Event('jqplotDataClick');
743
+ evt.pageX = ev.pageX;
744
+ evt.pageY = ev.pageY;
745
+ plot.target.trigger(evt, ins);
746
+ }
747
+ }
748
+
749
+ function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
750
+ if (neighbor) {
751
+ var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
752
+ var idx = plot.plugins.donutRenderer.highlightedSeriesIndex;
753
+ if (idx != null && plot.series[idx].highlightMouseDown) {
754
+ unhighlight(plot);
755
+ }
756
+ var evt = jQuery.Event('jqplotDataRightClick');
757
+ evt.pageX = ev.pageX;
758
+ evt.pageY = ev.pageY;
759
+ plot.target.trigger(evt, ins);
760
+ }
761
+ }
762
+
763
+ // called within context of plot
764
+ // create a canvas which we can draw on.
765
+ // insert it before the eventCanvas, so eventCanvas will still capture events.
766
+ function postPlotDraw() {
767
+ // Memory Leaks patch
768
+ if (this.plugins.donutRenderer && this.plugins.donutRenderer.highlightCanvas) {
769
+ this.plugins.donutRenderer.highlightCanvas.resetCanvas();
770
+ this.plugins.donutRenderer.highlightCanvas = null;
771
+ }
772
+
773
+ this.plugins.donutRenderer = {highlightedSeriesIndex:null};
774
+ this.plugins.donutRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
775
+ // do we have any data labels? if so, put highlight canvas before those
776
+ // Fix for broken jquery :first selector with canvas (VML) elements.
777
+ var labels = $(this.targetId+' .jqplot-data-label');
778
+ if (labels.length) {
779
+ $(labels[0]).before(this.plugins.donutRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-donutRenderer-highlight-canvas', this._plotDimensions, this));
780
+ }
781
+ // else put highlight canvas before event canvas.
782
+ else {
783
+ this.eventCanvas._elem.before(this.plugins.donutRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-donutRenderer-highlight-canvas', this._plotDimensions, this));
784
+ }
785
+ var hctx = this.plugins.donutRenderer.highlightCanvas.setContext();
786
+ this.eventCanvas._elem.bind('mouseleave', {plot:this}, function (ev) { unhighlight(ev.data.plot); });
787
+ }
788
+
789
+ $.jqplot.preInitHooks.push(preInit);
790
+
791
+ $.jqplot.DonutTickRenderer = function() {
792
+ $.jqplot.AxisTickRenderer.call(this);
793
+ };
794
+
795
+ $.jqplot.DonutTickRenderer.prototype = new $.jqplot.AxisTickRenderer();
796
+ $.jqplot.DonutTickRenderer.prototype.constructor = $.jqplot.DonutTickRenderer;
797
+
798
+ })(jQuery);
799
+
800
+