mdoc 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +2 -2
  3. data/examples/jqplot.html +62 -0
  4. data/examples/jqplot.md +8 -0
  5. data/examples/js/jquery.jqplot.css +259 -0
  6. data/examples/js/jquery.jqplot.js +11411 -0
  7. data/examples/js/jquery.jqplot.min.css +1 -0
  8. data/examples/js/jquery.jqplot.min.js +3 -0
  9. data/examples/js/jquery.js +9597 -0
  10. data/examples/js/jquery.min.js +5 -0
  11. data/examples/js/plugins/jqplot.BezierCurveRenderer.js +314 -0
  12. data/examples/js/plugins/jqplot.BezierCurveRenderer.min.js +3 -0
  13. data/examples/js/plugins/jqplot.barRenderer.js +801 -0
  14. data/examples/js/plugins/jqplot.barRenderer.min.js +3 -0
  15. data/examples/js/plugins/jqplot.blockRenderer.js +235 -0
  16. data/examples/js/plugins/jqplot.blockRenderer.min.js +3 -0
  17. data/examples/js/plugins/jqplot.bubbleRenderer.js +759 -0
  18. data/examples/js/plugins/jqplot.bubbleRenderer.min.js +3 -0
  19. data/examples/js/plugins/jqplot.canvasAxisLabelRenderer.js +203 -0
  20. data/examples/js/plugins/jqplot.canvasAxisLabelRenderer.min.js +3 -0
  21. data/examples/js/plugins/jqplot.canvasAxisTickRenderer.js +253 -0
  22. data/examples/js/plugins/jqplot.canvasAxisTickRenderer.min.js +3 -0
  23. data/examples/js/plugins/jqplot.canvasOverlay.js +1021 -0
  24. data/examples/js/plugins/jqplot.canvasOverlay.min.js +3 -0
  25. data/examples/js/plugins/jqplot.canvasTextRenderer.js +449 -0
  26. data/examples/js/plugins/jqplot.canvasTextRenderer.min.js +3 -0
  27. data/examples/js/plugins/jqplot.categoryAxisRenderer.js +679 -0
  28. data/examples/js/plugins/jqplot.categoryAxisRenderer.min.js +3 -0
  29. data/examples/js/plugins/jqplot.ciParser.js +116 -0
  30. data/examples/js/plugins/jqplot.ciParser.min.js +3 -0
  31. data/examples/js/plugins/jqplot.cursor.js +1108 -0
  32. data/examples/js/plugins/jqplot.cursor.min.js +3 -0
  33. data/examples/js/plugins/jqplot.dateAxisRenderer.js +741 -0
  34. data/examples/js/plugins/jqplot.dateAxisRenderer.min.js +3 -0
  35. data/examples/js/plugins/jqplot.donutRenderer.js +805 -0
  36. data/examples/js/plugins/jqplot.donutRenderer.min.js +3 -0
  37. data/examples/js/plugins/jqplot.dragable.js +225 -0
  38. data/examples/js/plugins/jqplot.dragable.min.js +3 -0
  39. data/examples/js/plugins/jqplot.enhancedLegendRenderer.js +305 -0
  40. data/examples/js/plugins/jqplot.enhancedLegendRenderer.min.js +3 -0
  41. data/examples/js/plugins/jqplot.funnelRenderer.js +943 -0
  42. data/examples/js/plugins/jqplot.funnelRenderer.min.js +3 -0
  43. data/examples/js/plugins/jqplot.highlighter.js +465 -0
  44. data/examples/js/plugins/jqplot.highlighter.min.js +3 -0
  45. data/examples/js/plugins/jqplot.json2.js +475 -0
  46. data/examples/js/plugins/jqplot.json2.min.js +3 -0
  47. data/examples/js/plugins/jqplot.logAxisRenderer.js +534 -0
  48. data/examples/js/plugins/jqplot.logAxisRenderer.min.js +3 -0
  49. data/examples/js/plugins/jqplot.mekkoAxisRenderer.js +611 -0
  50. data/examples/js/plugins/jqplot.mekkoAxisRenderer.min.js +3 -0
  51. data/examples/js/plugins/jqplot.mekkoRenderer.js +437 -0
  52. data/examples/js/plugins/jqplot.mekkoRenderer.min.js +3 -0
  53. data/examples/js/plugins/jqplot.meterGaugeRenderer.js +1029 -0
  54. data/examples/js/plugins/jqplot.meterGaugeRenderer.min.js +3 -0
  55. data/examples/js/plugins/jqplot.mobile.js +45 -0
  56. data/examples/js/plugins/jqplot.mobile.min.js +3 -0
  57. data/examples/js/plugins/jqplot.ohlcRenderer.js +373 -0
  58. data/examples/js/plugins/jqplot.ohlcRenderer.min.js +3 -0
  59. data/examples/js/plugins/jqplot.pieRenderer.js +904 -0
  60. data/examples/js/plugins/jqplot.pieRenderer.min.js +3 -0
  61. data/examples/js/plugins/jqplot.pointLabels.js +377 -0
  62. data/examples/js/plugins/jqplot.pointLabels.min.js +3 -0
  63. data/examples/js/plugins/jqplot.pyramidAxisRenderer.js +728 -0
  64. data/examples/js/plugins/jqplot.pyramidAxisRenderer.min.js +3 -0
  65. data/examples/js/plugins/jqplot.pyramidGridRenderer.js +429 -0
  66. data/examples/js/plugins/jqplot.pyramidGridRenderer.min.js +3 -0
  67. data/examples/js/plugins/jqplot.pyramidRenderer.js +514 -0
  68. data/examples/js/plugins/jqplot.pyramidRenderer.min.js +3 -0
  69. data/examples/js/plugins/jqplot.trendline.js +223 -0
  70. data/examples/js/plugins/jqplot.trendline.min.js +3 -0
  71. data/examples/js/raphael-min.js +11 -0
  72. data/examples/js/sequence-diagram-min.js +8 -0
  73. data/examples/js/underscore-min.js +5 -0
  74. data/lib/mdoc.rb +1 -0
  75. data/lib/mdoc/processor/jqplot.rb +48 -0
  76. data/lib/mdoc/version.rb +1 -1
  77. data/templates/default.html.erb +1 -1
  78. metadata +74 -2
@@ -0,0 +1,3 @@
1
+ /* jqPlot 1.0.8r1250 | (c) 2009-2013 Chris Leonello | jplot.com
2
+ jsDate | (c) 2010-2013 Chris Leonello
3
+ */(function(e){e.jqplot.FunnelRenderer=function(){e.jqplot.LineRenderer.call(this)};e.jqplot.FunnelRenderer.prototype=new e.jqplot.LineRenderer();e.jqplot.FunnelRenderer.prototype.constructor=e.jqplot.FunnelRenderer;e.jqplot.FunnelRenderer.prototype.init=function(p,t){this.padding={top:20,right:20,bottom:20,left:20};this.sectionMargin=6;this.fill=true;this.shadowOffset=2;this.shadowAlpha=0.07;this.shadowDepth=5;this.highlightMouseOver=true;this.highlightMouseDown=false;this.highlightColors=[];this.widthRatio=0.2;this.lineWidth=2;this.dataLabels="percent";this.showDataLabels=false;this.dataLabelFormatString=null;this.dataLabelThreshold=3;this._type="funnel";this.tickRenderer=e.jqplot.FunnelTickRenderer;if(p.highlightMouseDown&&p.highlightMouseOver==null){p.highlightMouseOver=false}e.extend(true,this,p);this._highlightedPoint=null;this._bases=[];this._atot;this._areas=[];this._lengths=[];this._angle;this._dataIndices=[];this._unorderedData=e.extend(true,[],this.data);var o=e.extend(true,[],this.data);for(var r=0;r<o.length;r++){o[r].push(r)}this.data.sort(function(v,u){return u[1]-v[1]});o.sort(function(v,u){return u[1]-v[1]});for(var r=0;r<o.length;r++){this._dataIndices.push(o[r][2])}if(this.highlightColors.length==0){for(var r=0;r<this.seriesColors.length;r++){var q=e.jqplot.getColorComponents(this.seriesColors[r]);var m=[q[0],q[1],q[2]];var s=m[0]+m[1]+m[2];for(var n=0;n<3;n++){m[n]=(s>570)?m[n]*0.8:m[n]+0.4*(255-m[n]);m[n]=parseInt(m[n],10)}this.highlightColors.push("rgb("+m[0]+","+m[1]+","+m[2]+")")}}t.postParseOptionsHooks.addOnce(k);t.postInitHooks.addOnce(g);t.eventListenerHooks.addOnce("jqplotMouseMove",a);t.eventListenerHooks.addOnce("jqplotMouseDown",b);t.eventListenerHooks.addOnce("jqplotMouseUp",j);t.eventListenerHooks.addOnce("jqplotClick",f);t.eventListenerHooks.addOnce("jqplotRightClick",l);t.postDrawHooks.addOnce(h)};e.jqplot.FunnelRenderer.prototype.setGridData=function(o){var n=0;var p=[];for(var m=0;m<this.data.length;m++){n+=this.data[m][1];p.push([this.data[m][0],this.data[m][1]])}for(var m=0;m<p.length;m++){p[m][1]=p[m][1]/n}this._bases=new Array(p.length+1);this._lengths=new Array(p.length);this.gridData=p};e.jqplot.FunnelRenderer.prototype.makeGridData=function(o,p){var n=0;var q=[];for(var m=0;m<this.data.length;m++){n+=this.data[m][1];q.push([this.data[m][0],this.data[m][1]])}for(var m=0;m<q.length;m++){q[m][1]=q[m][1]/n}this._bases=new Array(q.length+1);this._lengths=new Array(q.length);return q};e.jqplot.FunnelRenderer.prototype.drawSection=function(n,p,o,s){var t=this.fill;var m=this.lineWidth;n.save();if(s){for(var r=0;r<this.shadowDepth;r++){n.save();n.translate(this.shadowOffset*Math.cos(this.shadowAngle/180*Math.PI),this.shadowOffset*Math.sin(this.shadowAngle/180*Math.PI));q()}}else{q()}function q(){n.beginPath();n.fillStyle=o;n.strokeStyle=o;n.lineWidth=m;n.moveTo(p[0][0],p[0][1]);for(var u=1;u<4;u++){n.lineTo(p[u][0],p[u][1])}n.closePath();if(t){n.fill()}else{n.stroke()}}if(s){for(var r=0;r<this.shadowDepth;r++){n.restore()}}n.restore()};e.jqplot.FunnelRenderer.prototype.draw=function(G,B,J,p){var Y;var L=(J!=undefined)?J:{};var w=0;var u=0;var R=1;this._areas=[];if(J.legendInfo&&J.legendInfo.placement=="insideGrid"){var O=J.legendInfo;switch(O.location){case"nw":w=O.width+O.xoffset;break;case"w":w=O.width+O.xoffset;break;case"sw":w=O.width+O.xoffset;break;case"ne":w=O.width+O.xoffset;R=-1;break;case"e":w=O.width+O.xoffset;R=-1;break;case"se":w=O.width+O.xoffset;R=-1;break;case"n":u=O.height+O.yoffset;break;case"s":u=O.height+O.yoffset;R=-1;break;default:break}}var t=(R==1)?this.padding.left+w:this.padding.left;var F=(R==1)?this.padding.top+u:this.padding.top;var M=(R==-1)?this.padding.right+w:this.padding.right;var o=(R==-1)?this.padding.bottom+u:this.padding.bottom;var P=(L.shadow!=undefined)?L.shadow:this.shadow;var q=(L.showLine!=undefined)?L.showLine:this.showLine;var C=(L.fill!=undefined)?L.fill:this.fill;var H=G.canvas.width;var N=G.canvas.height;this._bases[0]=H-t-M;var I=this._length=N-F-o;var r=this._bases[0]*this.widthRatio;this._atot=I/2*(this._bases[0]+this._bases[0]*this.widthRatio);this._angle=Math.atan((this._bases[0]-r)/2/I);for(Y=0;Y<B.length;Y++){this._areas.push(B[Y][1]*this._atot)}var E,aa,W,Q=0;var n=0.0001;for(Y=0;Y<this._areas.length;Y++){E=this._areas[Y]/this._bases[Y];aa=999999;this._lengths[Y]=E;W=0;while(aa>this._lengths[Y]*n&&W<100){this._lengths[Y]=this._areas[Y]/(this._bases[Y]-this._lengths[Y]*Math.tan(this._angle));aa=Math.abs(this._lengths[Y]-E);this._bases[Y+1]=this._bases[Y]-(2*this._lengths[Y]*Math.tan(this._angle));E=this._lengths[Y];W++}Q+=this._lengths[Y]}this._vertices=new Array(B.length);var ae=[t,F],ad=[t+this._bases[0],F],ac=[t+(this._bases[0]-this._bases[this._bases.length-1])/2,F+this._length],ab=[ac[0]+this._bases[this._bases.length-1],ac[1]];function V(ag){var x=(ae[1]-ac[1])/(ae[0]-ac[0]);var v=ae[1]-x*ae[0];var ah=ag+ae[1];return[(ah-v)/x,ah]}function D(ag){var x=(ad[1]-ab[1])/(ad[0]-ab[0]);var v=ad[1]-x*ad[0];var ah=ag+ad[1];return[(ah-v)/x,ah]}var T=w,S=u;var Z=0,m=0;for(Y=0;Y<B.length;Y++){this._vertices[Y]=new Array();var U=this._vertices[Y];var A=this.sectionMargin;if(Y==0){m=0}if(Y==1){m=A/3}else{if(Y>0&&Y<B.length-1){m=A/2}else{if(Y==B.length-1){m=2*A/3}}}U.push(V(Z+m));U.push(D(Z+m));Z+=this._lengths[Y];if(Y==0){m=-2*A/3}else{if(Y>0&&Y<B.length-1){m=-A/2}else{if(Y==B.length-1){m=0}}}U.push(D(Z+m));U.push(V(Z+m))}if(this.shadow){var af="rgba(0,0,0,"+this.shadowAlpha+")";for(var Y=0;Y<B.length;Y++){this.renderer.drawSection.call(this,G,this._vertices[Y],af,true)}}for(var Y=0;Y<B.length;Y++){var U=this._vertices[Y];this.renderer.drawSection.call(this,G,U,this.seriesColors[Y]);if(this.showDataLabels&&B[Y][1]*100>=this.dataLabelThreshold){var K,X;if(this.dataLabels=="label"){K=this.dataLabelFormatString||"%s";X=e.jqplot.sprintf(K,B[Y][0])}else{if(this.dataLabels=="value"){K=this.dataLabelFormatString||"%d";X=e.jqplot.sprintf(K,this.data[Y][1])}else{if(this.dataLabels=="percent"){K=this.dataLabelFormatString||"%d%%";X=e.jqplot.sprintf(K,B[Y][1]*100)}else{if(this.dataLabels.constructor==Array){K=this.dataLabelFormatString||"%s";X=e.jqplot.sprintf(K,this.dataLabels[this._dataIndices[Y]])}}}}var s=(this._radius)*this.dataLabelPositionFactor+this.sliceMargin+this.dataLabelNudge;var T=(U[0][0]+U[1][0])/2+this.canvas._offsets.left;var S=(U[1][1]+U[2][1])/2+this.canvas._offsets.top;var z=e('<span class="jqplot-funnel-series jqplot-data-label" style="position:absolute;">'+X+"</span>").insertBefore(p.eventCanvas._elem);T-=z.width()/2;S-=z.height()/2;T=Math.round(T);S=Math.round(S);z.css({left:T,top:S})}}};e.jqplot.FunnelAxisRenderer=function(){e.jqplot.LinearAxisRenderer.call(this)};e.jqplot.FunnelAxisRenderer.prototype=new e.jqplot.LinearAxisRenderer();e.jqplot.FunnelAxisRenderer.prototype.constructor=e.jqplot.FunnelAxisRenderer;e.jqplot.FunnelAxisRenderer.prototype.init=function(m){this.tickRenderer=e.jqplot.FunnelTickRenderer;e.extend(true,this,m);this._dataBounds={min:0,max:100};this.min=0;this.max=100;this.showTicks=false;this.ticks=[];this.showMark=false;this.show=false};e.jqplot.FunnelLegendRenderer=function(){e.jqplot.TableLegendRenderer.call(this)};e.jqplot.FunnelLegendRenderer.prototype=new e.jqplot.TableLegendRenderer();e.jqplot.FunnelLegendRenderer.prototype.constructor=e.jqplot.FunnelLegendRenderer;e.jqplot.FunnelLegendRenderer.prototype.init=function(m){this.numberRows=null;this.numberColumns=null;e.extend(true,this,m)};e.jqplot.FunnelLegendRenderer.prototype.draw=function(){var p=this;if(this.show){var x=this._series;var A="position:absolute;";A+=(this.background)?"background:"+this.background+";":"";A+=(this.border)?"border:"+this.border+";":"";A+=(this.fontSize)?"font-size:"+this.fontSize+";":"";A+=(this.fontFamily)?"font-family:"+this.fontFamily+";":"";A+=(this.textColor)?"color:"+this.textColor+";":"";A+=(this.marginTop!=null)?"margin-top:"+this.marginTop+";":"";A+=(this.marginBottom!=null)?"margin-bottom:"+this.marginBottom+";":"";A+=(this.marginLeft!=null)?"margin-left:"+this.marginLeft+";":"";A+=(this.marginRight!=null)?"margin-right:"+this.marginRight+";":"";this._elem=e('<table class="jqplot-table-legend" style="'+A+'"></table>');var E=false,w=false,m,u;var y=x[0];var n=new e.jqplot.ColorGenerator(y.seriesColors);if(y.show){var F=y.data;if(this.numberRows){m=this.numberRows;if(!this.numberColumns){u=Math.ceil(F.length/m)}else{u=this.numberColumns}}else{if(this.numberColumns){u=this.numberColumns;m=Math.ceil(F.length/this.numberColumns)}else{m=F.length;u=1}}var D,C,o,r,q,t,v,B;var z=0;for(D=0;D<m;D++){if(w){o=e('<tr class="jqplot-table-legend"></tr>').prependTo(this._elem)}else{o=e('<tr class="jqplot-table-legend"></tr>').appendTo(this._elem)}for(C=0;C<u;C++){if(z<F.length){t=this.labels[z]||F[z][0].toString();B=n.next();if(!w){if(D>0){E=true}else{E=false}}else{if(D==m-1){E=false}else{E=true}}v=(E)?this.rowSpacing:"0";r=e('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+v+';"><div><div class="jqplot-table-legend-swatch" style="border-color:'+B+';"></div></div></td>');q=e('<td class="jqplot-table-legend" style="padding-top:'+v+';"></td>');if(this.escapeHtml){q.text(t)}else{q.html(t)}if(w){q.prependTo(o);r.prependTo(o)}else{r.appendTo(o);q.appendTo(o)}E=true}z++}}}}return this._elem};function c(q,p,n){n=n||{};n.axesDefaults=n.axesDefaults||{};n.legend=n.legend||{};n.seriesDefaults=n.seriesDefaults||{};var m=false;if(n.seriesDefaults.renderer==e.jqplot.FunnelRenderer){m=true}else{if(n.series){for(var o=0;o<n.series.length;o++){if(n.series[o].renderer==e.jqplot.FunnelRenderer){m=true}}}}if(m){n.axesDefaults.renderer=e.jqplot.FunnelAxisRenderer;n.legend.renderer=e.jqplot.FunnelLegendRenderer;n.legend.preDraw=true;n.sortData=false;n.seriesDefaults.pointLabels={show:false}}}function g(p,o,m){for(var n=0;n<this.series.length;n++){if(this.series[n].renderer.constructor==e.jqplot.FunnelRenderer){if(this.series[n].highlightMouseOver){this.series[n].highlightMouseDown=false}}}}function k(m){for(var n=0;n<this.series.length;n++){this.series[n].seriesColors=this.seriesColors;this.series[n].colorGenerator=e.jqplot.colorGenerator}}function d(q,p,o){var n=q.series[p];var m=q.plugins.funnelRenderer.highlightCanvas;m._ctx.clearRect(0,0,m._ctx.canvas.width,m._ctx.canvas.height);n._highlightedPoint=o;q.plugins.funnelRenderer.highlightedSeriesIndex=p;n.renderer.drawSection.call(n,m._ctx,n._vertices[o],n.highlightColors[o],false)}function i(o){var m=o.plugins.funnelRenderer.highlightCanvas;m._ctx.clearRect(0,0,m._ctx.canvas.width,m._ctx.canvas.height);for(var n=0;n<o.series.length;n++){o.series[n]._highlightedPoint=null}o.plugins.funnelRenderer.highlightedSeriesIndex=null;o.target.trigger("jqplotDataUnhighlight")}function a(q,p,t,s,r){if(s){var o=[s.seriesIndex,s.pointIndex,s.data];var n=jQuery.Event("jqplotDataMouseOver");n.pageX=q.pageX;n.pageY=q.pageY;r.target.trigger(n,o);if(r.series[o[0]].highlightMouseOver&&!(o[0]==r.plugins.funnelRenderer.highlightedSeriesIndex&&o[1]==r.series[o[0]]._highlightedPoint)){var m=jQuery.Event("jqplotDataHighlight");m.which=q.which;m.pageX=q.pageX;m.pageY=q.pageY;r.target.trigger(m,o);d(r,o[0],o[1])}}else{if(s==null){i(r)}}}function b(p,o,s,r,q){if(r){var n=[r.seriesIndex,r.pointIndex,r.data];if(q.series[n[0]].highlightMouseDown&&!(n[0]==q.plugins.funnelRenderer.highlightedSeriesIndex&&n[1]==q.series[n[0]]._highlightedPoint)){var m=jQuery.Event("jqplotDataHighlight");m.which=p.which;m.pageX=p.pageX;m.pageY=p.pageY;q.target.trigger(m,n);d(q,n[0],n[1])}}else{if(r==null){i(q)}}}function j(o,n,r,q,p){var m=p.plugins.funnelRenderer.highlightedSeriesIndex;if(m!=null&&p.series[m].highlightMouseDown){i(p)}}function f(p,o,s,r,q){if(r){var n=[r.seriesIndex,r.pointIndex,r.data];var m=jQuery.Event("jqplotDataClick");m.which=p.which;m.pageX=p.pageX;m.pageY=p.pageY;q.target.trigger(m,n)}}function l(q,p,t,s,r){if(s){var o=[s.seriesIndex,s.pointIndex,s.data];var m=r.plugins.funnelRenderer.highlightedSeriesIndex;if(m!=null&&r.series[m].highlightMouseDown){i(r)}var n=jQuery.Event("jqplotDataRightClick");n.which=q.which;n.pageX=q.pageX;n.pageY=q.pageY;r.target.trigger(n,o)}}function h(){if(this.plugins.funnelRenderer&&this.plugins.funnelRenderer.highlightCanvas){this.plugins.funnelRenderer.highlightCanvas.resetCanvas();this.plugins.funnelRenderer.highlightCanvas=null}this.plugins.funnelRenderer={};this.plugins.funnelRenderer.highlightCanvas=new e.jqplot.GenericCanvas();var n=e(this.targetId+" .jqplot-data-label");if(n.length){e(n[0]).before(this.plugins.funnelRenderer.highlightCanvas.createElement(this._gridPadding,"jqplot-funnelRenderer-highlight-canvas",this._plotDimensions,this))}else{this.eventCanvas._elem.before(this.plugins.funnelRenderer.highlightCanvas.createElement(this._gridPadding,"jqplot-funnelRenderer-highlight-canvas",this._plotDimensions,this))}var m=this.plugins.funnelRenderer.highlightCanvas.setContext();this.eventCanvas._elem.bind("mouseleave",{plot:this},function(o){i(o.data.plot)})}e.jqplot.preInitHooks.push(c);e.jqplot.FunnelTickRenderer=function(){e.jqplot.AxisTickRenderer.call(this)};e.jqplot.FunnelTickRenderer.prototype=new e.jqplot.AxisTickRenderer();e.jqplot.FunnelTickRenderer.prototype.constructor=e.jqplot.FunnelTickRenderer})(jQuery);
@@ -0,0 +1,465 @@
1
+ /**
2
+ * jqPlot
3
+ * Pure JavaScript plotting plugin using jQuery
4
+ *
5
+ * Version: 1.0.8
6
+ * Revision: 1250
7
+ *
8
+ * Copyright (c) 2009-2013 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.
13
+ *
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 .
17
+ *
18
+ * If you are feeling kind and generous, consider supporting the project by
19
+ * making a donation at: http://www.jqplot.com/donate.php .
20
+ *
21
+ * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
22
+ *
23
+ * version 2007.04.27
24
+ * author 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."
29
+ *
30
+ */
31
+ (function($) {
32
+ $.jqplot.eventListenerHooks.push(['jqplotMouseMove', handleMove]);
33
+
34
+ /**
35
+ * Class: $.jqplot.Highlighter
36
+ * Plugin which will highlight data points when they are moused over.
37
+ *
38
+ * To use this plugin, include the js
39
+ * file in your source:
40
+ *
41
+ * > <script type="text/javascript" src="plugins/jqplot.highlighter.js"></script>
42
+ *
43
+ * A tooltip providing information about the data point is enabled by default.
44
+ * To disable the tooltip, set "showTooltip" to false.
45
+ *
46
+ * You can control what data is displayed in the tooltip with various
47
+ * options. The "tooltipAxes" option controls whether the x, y or both
48
+ * data values are displayed.
49
+ *
50
+ * Some chart types (e.g. hi-low-close) have more than one y value per
51
+ * data point. To display the additional values in the tooltip, set the
52
+ * "yvalues" option to the desired number of y values present (3 for a hlc chart).
53
+ *
54
+ * By default, data values will be formatted with the same formatting
55
+ * specifiers as used to format the axis ticks. A custom format code
56
+ * can be supplied with the tooltipFormatString option. This will apply
57
+ * to all values in the tooltip.
58
+ *
59
+ * For more complete control, the "formatString" option can be set. This
60
+ * Allows conplete control over tooltip formatting. Values are passed to
61
+ * the format string in an order determined by the "tooltipAxes" and "yvalues"
62
+ * options. So, if you have a hi-low-close chart and you just want to display
63
+ * the hi-low-close values in the tooltip, you could set a formatString like:
64
+ *
65
+ * > highlighter: {
66
+ * > tooltipAxes: 'y',
67
+ * > yvalues: 3,
68
+ * > formatString:'<table class="jqplot-highlighter">
69
+ * > <tr><td>hi:</td><td>%s</td></tr>
70
+ * > <tr><td>low:</td><td>%s</td></tr>
71
+ * > <tr><td>close:</td><td>%s</td></tr></table>'
72
+ * > }
73
+ *
74
+ */
75
+ $.jqplot.Highlighter = function(options) {
76
+ // Group: Properties
77
+ //
78
+ //prop: show
79
+ // true to show the highlight.
80
+ this.show = $.jqplot.config.enablePlugins;
81
+ // prop: markerRenderer
82
+ // Renderer used to draw the marker of the highlighted point.
83
+ // Renderer will assimilate attributes from the data point being highlighted,
84
+ // so no attributes need set on the renderer directly.
85
+ // Default is to turn off shadow drawing on the highlighted point.
86
+ this.markerRenderer = new $.jqplot.MarkerRenderer({shadow:false});
87
+ // prop: showMarker
88
+ // true to show the marker
89
+ this.showMarker = true;
90
+ // prop: lineWidthAdjust
91
+ // Pixels to add to the lineWidth of the highlight.
92
+ this.lineWidthAdjust = 2.5;
93
+ // prop: sizeAdjust
94
+ // Pixels to add to the overall size of the highlight.
95
+ this.sizeAdjust = 5;
96
+ // prop: showTooltip
97
+ // Show a tooltip with data point values.
98
+ this.showTooltip = true;
99
+ // prop: tooltipLocation
100
+ // Where to position tooltip, 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'
101
+ this.tooltipLocation = 'nw';
102
+ // prop: fadeTooltip
103
+ // true = fade in/out tooltip, flase = show/hide tooltip
104
+ this.fadeTooltip = true;
105
+ // prop: tooltipFadeSpeed
106
+ // 'slow', 'def', 'fast', or number of milliseconds.
107
+ this.tooltipFadeSpeed = "fast";
108
+ // prop: tooltipOffset
109
+ // Pixel offset of tooltip from the highlight.
110
+ this.tooltipOffset = 2;
111
+ // prop: tooltipAxes
112
+ // Which axes to display in tooltip, 'x', 'y' or 'both', 'xy' or 'yx'
113
+ // 'both' and 'xy' are equivalent, 'yx' reverses order of labels.
114
+ this.tooltipAxes = 'both';
115
+ // prop; tooltipSeparator
116
+ // String to use to separate x and y axes in tooltip.
117
+ this.tooltipSeparator = ', ';
118
+ // prop; tooltipContentEditor
119
+ // Function used to edit/augment/replace the formatted tooltip contents.
120
+ // Called as str = tooltipContentEditor(str, seriesIndex, pointIndex)
121
+ // where str is the generated tooltip html and seriesIndex and pointIndex identify
122
+ // the data point being highlighted. Should return the html for the tooltip contents.
123
+ this.tooltipContentEditor = null;
124
+ // prop: useAxesFormatters
125
+ // Use the x and y axes formatters to format the text in the tooltip.
126
+ this.useAxesFormatters = true;
127
+ // prop: tooltipFormatString
128
+ // sprintf format string for the tooltip.
129
+ // Uses Ash Searle's javascript sprintf implementation
130
+ // found here: http://hexmen.com/blog/2007/03/printf-sprintf/
131
+ // See http://perldoc.perl.org/functions/sprintf.html for reference.
132
+ // Additional "p" and "P" format specifiers added by Chris Leonello.
133
+ this.tooltipFormatString = '%.5P';
134
+ // prop: formatString
135
+ // alternative to tooltipFormatString
136
+ // will format the whole tooltip text, populating with x, y values as
137
+ // indicated by tooltipAxes option. So, you could have a tooltip like:
138
+ // 'Date: %s, number of cats: %d' to format the whole tooltip at one go.
139
+ // If useAxesFormatters is true, values will be formatted according to
140
+ // Axes formatters and you can populate your tooltip string with
141
+ // %s placeholders.
142
+ this.formatString = null;
143
+ // prop: yvalues
144
+ // Number of y values to expect in the data point array.
145
+ // Typically this is 1. Certain plots, like OHLC, will
146
+ // have more y values in each data point array.
147
+ this.yvalues = 1;
148
+ // prop: bringSeriesToFront
149
+ // This option requires jQuery 1.4+
150
+ // True to bring the series of the highlighted point to the front
151
+ // of other series.
152
+ this.bringSeriesToFront = false;
153
+ this._tooltipElem;
154
+ this.isHighlighting = false;
155
+ this.currentNeighbor = null;
156
+
157
+ $.extend(true, this, options);
158
+ };
159
+
160
+ var locations = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w'];
161
+ var locationIndicies = {'nw':0, 'n':1, 'ne':2, 'e':3, 'se':4, 's':5, 'sw':6, 'w':7};
162
+ var oppositeLocations = ['se', 's', 'sw', 'w', 'nw', 'n', 'ne', 'e'];
163
+
164
+ // axis.renderer.tickrenderer.formatter
165
+
166
+ // called with scope of plot
167
+ $.jqplot.Highlighter.init = function (target, data, opts){
168
+ var options = opts || {};
169
+ // add a highlighter attribute to the plot
170
+ this.plugins.highlighter = new $.jqplot.Highlighter(options.highlighter);
171
+ };
172
+
173
+ // called within scope of series
174
+ $.jqplot.Highlighter.parseOptions = function (defaults, options) {
175
+ // Add a showHighlight option to the series
176
+ // and set it to true by default.
177
+ this.showHighlight = true;
178
+ };
179
+
180
+ // called within context of plot
181
+ // create a canvas which we can draw on.
182
+ // insert it before the eventCanvas, so eventCanvas will still capture events.
183
+ $.jqplot.Highlighter.postPlotDraw = function() {
184
+ // Memory Leaks patch
185
+ if (this.plugins.highlighter && this.plugins.highlighter.highlightCanvas) {
186
+ this.plugins.highlighter.highlightCanvas.resetCanvas();
187
+ this.plugins.highlighter.highlightCanvas = null;
188
+ }
189
+
190
+ if (this.plugins.highlighter && this.plugins.highlighter._tooltipElem) {
191
+ this.plugins.highlighter._tooltipElem.emptyForce();
192
+ this.plugins.highlighter._tooltipElem = null;
193
+ }
194
+
195
+ this.plugins.highlighter.highlightCanvas = new $.jqplot.GenericCanvas();
196
+
197
+ this.eventCanvas._elem.before(this.plugins.highlighter.highlightCanvas.createElement(this._gridPadding, 'jqplot-highlight-canvas', this._plotDimensions, this));
198
+ this.plugins.highlighter.highlightCanvas.setContext();
199
+
200
+ var elem = document.createElement('div');
201
+ this.plugins.highlighter._tooltipElem = $(elem);
202
+ elem = null;
203
+ this.plugins.highlighter._tooltipElem.addClass('jqplot-highlighter-tooltip');
204
+ this.plugins.highlighter._tooltipElem.css({position:'absolute', display:'none'});
205
+
206
+ this.eventCanvas._elem.before(this.plugins.highlighter._tooltipElem);
207
+ };
208
+
209
+ $.jqplot.preInitHooks.push($.jqplot.Highlighter.init);
210
+ $.jqplot.preParseSeriesOptionsHooks.push($.jqplot.Highlighter.parseOptions);
211
+ $.jqplot.postDrawHooks.push($.jqplot.Highlighter.postPlotDraw);
212
+
213
+ function draw(plot, neighbor) {
214
+ var hl = plot.plugins.highlighter;
215
+ var s = plot.series[neighbor.seriesIndex];
216
+ var smr = s.markerRenderer;
217
+ var mr = hl.markerRenderer;
218
+ mr.style = smr.style;
219
+ mr.lineWidth = smr.lineWidth + hl.lineWidthAdjust;
220
+ mr.size = smr.size + hl.sizeAdjust;
221
+ var rgba = $.jqplot.getColorComponents(smr.color);
222
+ var newrgb = [rgba[0], rgba[1], rgba[2]];
223
+ var alpha = (rgba[3] >= 0.6) ? rgba[3]*0.6 : rgba[3]*(2-rgba[3]);
224
+ mr.color = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+alpha+')';
225
+ mr.init();
226
+ mr.draw(s.gridData[neighbor.pointIndex][0], s.gridData[neighbor.pointIndex][1], hl.highlightCanvas._ctx);
227
+ }
228
+
229
+ function showTooltip(plot, series, neighbor) {
230
+ // neighbor looks like: {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]}
231
+ // gridData should be x,y pixel coords on the grid.
232
+ // add the plot._gridPadding to that to get x,y in the target.
233
+ var hl = plot.plugins.highlighter;
234
+ var elem = hl._tooltipElem;
235
+ var serieshl = series.highlighter || {};
236
+
237
+ var opts = $.extend(true, {}, hl, serieshl);
238
+
239
+ if (opts.useAxesFormatters) {
240
+ var xf = series._xaxis._ticks[0].formatter;
241
+ var yf = series._yaxis._ticks[0].formatter;
242
+ var xfstr = series._xaxis._ticks[0].formatString;
243
+ var yfstr = series._yaxis._ticks[0].formatString;
244
+ var str;
245
+ var xstr = xf(xfstr, neighbor.data[0]);
246
+ var ystrs = [];
247
+ for (var i=1; i<opts.yvalues+1; i++) {
248
+ ystrs.push(yf(yfstr, neighbor.data[i]));
249
+ }
250
+ if (typeof opts.formatString === 'string') {
251
+ switch (opts.tooltipAxes) {
252
+ case 'both':
253
+ case 'xy':
254
+ ystrs.unshift(xstr);
255
+ ystrs.unshift(opts.formatString);
256
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
257
+ break;
258
+ case 'yx':
259
+ ystrs.push(xstr);
260
+ ystrs.unshift(opts.formatString);
261
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
262
+ break;
263
+ case 'x':
264
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, [opts.formatString, xstr]);
265
+ break;
266
+ case 'y':
267
+ ystrs.unshift(opts.formatString);
268
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
269
+ break;
270
+ default: // same as xy
271
+ ystrs.unshift(xstr);
272
+ ystrs.unshift(opts.formatString);
273
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, ystrs);
274
+ break;
275
+ }
276
+ }
277
+ else {
278
+ switch (opts.tooltipAxes) {
279
+ case 'both':
280
+ case 'xy':
281
+ str = xstr;
282
+ for (var i=0; i<ystrs.length; i++) {
283
+ str += opts.tooltipSeparator + ystrs[i];
284
+ }
285
+ break;
286
+ case 'yx':
287
+ str = '';
288
+ for (var i=0; i<ystrs.length; i++) {
289
+ str += ystrs[i] + opts.tooltipSeparator;
290
+ }
291
+ str += xstr;
292
+ break;
293
+ case 'x':
294
+ str = xstr;
295
+ break;
296
+ case 'y':
297
+ str = ystrs.join(opts.tooltipSeparator);
298
+ break;
299
+ default: // same as 'xy'
300
+ str = xstr;
301
+ for (var i=0; i<ystrs.length; i++) {
302
+ str += opts.tooltipSeparator + ystrs[i];
303
+ }
304
+ break;
305
+
306
+ }
307
+ }
308
+ }
309
+ else {
310
+ var str;
311
+ if (typeof opts.formatString === 'string') {
312
+ str = $.jqplot.sprintf.apply($.jqplot.sprintf, [opts.formatString].concat(neighbor.data));
313
+ }
314
+
315
+ else {
316
+ if (opts.tooltipAxes == 'both' || opts.tooltipAxes == 'xy') {
317
+ str = $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[0]) + opts.tooltipSeparator + $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[1]);
318
+ }
319
+ else if (opts.tooltipAxes == 'yx') {
320
+ str = $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[1]) + opts.tooltipSeparator + $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[0]);
321
+ }
322
+ else if (opts.tooltipAxes == 'x') {
323
+ str = $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[0]);
324
+ }
325
+ else if (opts.tooltipAxes == 'y') {
326
+ str = $.jqplot.sprintf(opts.tooltipFormatString, neighbor.data[1]);
327
+ }
328
+ }
329
+ }
330
+ if ($.isFunction(opts.tooltipContentEditor)) {
331
+ // args str, seriesIndex, pointIndex are essential so the hook can look up
332
+ // extra data for the point.
333
+ str = opts.tooltipContentEditor(str, neighbor.seriesIndex, neighbor.pointIndex, plot);
334
+ }
335
+ elem.html(str);
336
+ var gridpos = {x:neighbor.gridData[0], y:neighbor.gridData[1]};
337
+ var ms = 0;
338
+ var fact = 0.707;
339
+ if (series.markerRenderer.show == true) {
340
+ ms = (series.markerRenderer.size + opts.sizeAdjust)/2;
341
+ }
342
+
343
+ var loc = locations;
344
+ if (series.fillToZero && series.fill && neighbor.data[1] < 0) {
345
+ loc = oppositeLocations;
346
+ }
347
+
348
+ switch (loc[locationIndicies[opts.tooltipLocation]]) {
349
+ case 'nw':
350
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset - fact * ms;
351
+ var y = gridpos.y + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true) - fact * ms;
352
+ break;
353
+ case 'n':
354
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
355
+ var y = gridpos.y + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true) - ms;
356
+ break;
357
+ case 'ne':
358
+ var x = gridpos.x + plot._gridPadding.left + opts.tooltipOffset + fact * ms;
359
+ var y = gridpos.y + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true) - fact * ms;
360
+ break;
361
+ case 'e':
362
+ var x = gridpos.x + plot._gridPadding.left + opts.tooltipOffset + ms;
363
+ var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
364
+ break;
365
+ case 'se':
366
+ var x = gridpos.x + plot._gridPadding.left + opts.tooltipOffset + fact * ms;
367
+ var y = gridpos.y + plot._gridPadding.top + opts.tooltipOffset + fact * ms;
368
+ break;
369
+ case 's':
370
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true)/2;
371
+ var y = gridpos.y + plot._gridPadding.top + opts.tooltipOffset + ms;
372
+ break;
373
+ case 'sw':
374
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset - fact * ms;
375
+ var y = gridpos.y + plot._gridPadding.top + opts.tooltipOffset + fact * ms;
376
+ break;
377
+ case 'w':
378
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset - ms;
379
+ var y = gridpos.y + plot._gridPadding.top - elem.outerHeight(true)/2;
380
+ break;
381
+ default: // same as 'nw'
382
+ var x = gridpos.x + plot._gridPadding.left - elem.outerWidth(true) - opts.tooltipOffset - fact * ms;
383
+ var y = gridpos.y + plot._gridPadding.top - opts.tooltipOffset - elem.outerHeight(true) - fact * ms;
384
+ break;
385
+ }
386
+ elem.css('left', x);
387
+ elem.css('top', y);
388
+ if (opts.fadeTooltip) {
389
+ // Fix for stacked up animations. Thnanks Trevor!
390
+ elem.stop(true,true).fadeIn(opts.tooltipFadeSpeed);
391
+ }
392
+ else {
393
+ elem.show();
394
+ }
395
+ elem = null;
396
+
397
+ }
398
+
399
+ function handleMove(ev, gridpos, datapos, neighbor, plot) {
400
+ var hl = plot.plugins.highlighter;
401
+ var c = plot.plugins.cursor;
402
+ if (hl.show) {
403
+ if (neighbor == null && hl.isHighlighting) {
404
+ var evt = jQuery.Event('jqplotHighlighterUnhighlight');
405
+ plot.target.trigger(evt);
406
+
407
+ var ctx = hl.highlightCanvas._ctx;
408
+ ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
409
+ if (hl.fadeTooltip) {
410
+ hl._tooltipElem.fadeOut(hl.tooltipFadeSpeed);
411
+ }
412
+ else {
413
+ hl._tooltipElem.hide();
414
+ }
415
+ if (hl.bringSeriesToFront) {
416
+ plot.restorePreviousSeriesOrder();
417
+ }
418
+ hl.isHighlighting = false;
419
+ hl.currentNeighbor = null;
420
+ ctx = null;
421
+ }
422
+ else if (neighbor != null && plot.series[neighbor.seriesIndex].showHighlight && !hl.isHighlighting) {
423
+ var evt = jQuery.Event('jqplotHighlighterHighlight');
424
+ evt.which = ev.which;
425
+ evt.pageX = ev.pageX;
426
+ evt.pageY = ev.pageY;
427
+ var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data, plot];
428
+ plot.target.trigger(evt, ins);
429
+
430
+ hl.isHighlighting = true;
431
+ hl.currentNeighbor = neighbor;
432
+ if (hl.showMarker) {
433
+ draw(plot, neighbor);
434
+ }
435
+ if (plot.series[neighbor.seriesIndex].show && hl.showTooltip && (!c || !c._zoom.started)) {
436
+ showTooltip(plot, plot.series[neighbor.seriesIndex], neighbor);
437
+ }
438
+ if (hl.bringSeriesToFront) {
439
+ plot.moveSeriesToFront(neighbor.seriesIndex);
440
+ }
441
+ }
442
+ // check to see if we're highlighting the wrong point.
443
+ else if (neighbor != null && hl.isHighlighting && hl.currentNeighbor != neighbor) {
444
+ // highlighting the wrong point.
445
+
446
+ // if new series allows highlighting, highlight new point.
447
+ if (plot.series[neighbor.seriesIndex].showHighlight) {
448
+ var ctx = hl.highlightCanvas._ctx;
449
+ ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
450
+ hl.isHighlighting = true;
451
+ hl.currentNeighbor = neighbor;
452
+ if (hl.showMarker) {
453
+ draw(plot, neighbor);
454
+ }
455
+ if (plot.series[neighbor.seriesIndex].show && hl.showTooltip && (!c || !c._zoom.started)) {
456
+ showTooltip(plot, plot.series[neighbor.seriesIndex], neighbor);
457
+ }
458
+ if (hl.bringSeriesToFront) {
459
+ plot.moveSeriesToFront(neighbor.seriesIndex);
460
+ }
461
+ }
462
+ }
463
+ }
464
+ }
465
+ })(jQuery);