jquery_cheats 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -2
- data/app/assets/javascripts/jqueryCheats.js +36 -1
- data/jquery_cheats.gemspec +2 -2
- data/lib/jquery_cheats.rb +4 -0
- data/vendor/assets/excanvas.js +1438 -0
- data/vendor/assets/jquery.jqplot.css +259 -0
- data/vendor/assets/jquery.jqplot.js +10901 -0
- data/vendor/assets/plugins/jqplot.BezierCurveRenderer.js +312 -0
- data/vendor/assets/plugins/jqplot.BezierCurveRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.barRenderer.js +747 -0
- data/vendor/assets/plugins/jqplot.barRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.blockRenderer.js +234 -0
- data/vendor/assets/plugins/jqplot.blockRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.bubbleRenderer.js +754 -0
- data/vendor/assets/plugins/jqplot.bubbleRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.canvasAxisLabelRenderer.js +202 -0
- data/vendor/assets/plugins/jqplot.canvasAxisLabelRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.canvasAxisTickRenderer.js +242 -0
- data/vendor/assets/plugins/jqplot.canvasAxisTickRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.canvasOverlay.js +864 -0
- data/vendor/assets/plugins/jqplot.canvasOverlay.min.js +57 -0
- data/vendor/assets/plugins/jqplot.canvasTextRenderer.js +448 -0
- data/vendor/assets/plugins/jqplot.canvasTextRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.categoryAxisRenderer.js +636 -0
- data/vendor/assets/plugins/jqplot.categoryAxisRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.ciParser.js +115 -0
- data/vendor/assets/plugins/jqplot.ciParser.min.js +57 -0
- data/vendor/assets/plugins/jqplot.cursor.js +1093 -0
- data/vendor/assets/plugins/jqplot.cursor.min.js +57 -0
- data/vendor/assets/plugins/jqplot.dateAxisRenderer.js +702 -0
- data/vendor/assets/plugins/jqplot.dateAxisRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.donutRenderer.js +800 -0
- data/vendor/assets/plugins/jqplot.donutRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.dragable.js +224 -0
- data/vendor/assets/plugins/jqplot.dragable.min.js +57 -0
- data/vendor/assets/plugins/jqplot.enhancedLegendRenderer.js +241 -0
- data/vendor/assets/plugins/jqplot.enhancedLegendRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.funnelRenderer.js +938 -0
- data/vendor/assets/plugins/jqplot.funnelRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.highlighter.js +454 -0
- data/vendor/assets/plugins/jqplot.highlighter.min.js +57 -0
- data/vendor/assets/plugins/jqplot.json2.js +475 -0
- data/vendor/assets/plugins/jqplot.json2.min.js +57 -0
- data/vendor/assets/plugins/jqplot.logAxisRenderer.js +528 -0
- data/vendor/assets/plugins/jqplot.logAxisRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.mekkoAxisRenderer.js +610 -0
- data/vendor/assets/plugins/jqplot.mekkoAxisRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.mekkoRenderer.js +436 -0
- data/vendor/assets/plugins/jqplot.mekkoRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.meterGaugeRenderer.js +1029 -0
- data/vendor/assets/plugins/jqplot.meterGaugeRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.ohlcRenderer.js +372 -0
- data/vendor/assets/plugins/jqplot.ohlcRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.pieRenderer.js +899 -0
- data/vendor/assets/plugins/jqplot.pieRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.pointLabels.js +362 -0
- data/vendor/assets/plugins/jqplot.pointLabels.min.js +57 -0
- data/vendor/assets/plugins/jqplot.pyramidAxisRenderer.js +730 -0
- data/vendor/assets/plugins/jqplot.pyramidAxisRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.pyramidGridRenderer.js +423 -0
- data/vendor/assets/plugins/jqplot.pyramidGridRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.pyramidRenderer.js +490 -0
- data/vendor/assets/plugins/jqplot.pyramidRenderer.min.js +57 -0
- data/vendor/assets/plugins/jqplot.trendline.js +222 -0
- data/vendor/assets/plugins/jqplot.trendline.min.js +57 -0
- metadata +64 -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(c){c.jqplot.MeterGaugeRenderer=function(){c.jqplot.LineRenderer.call(this)};c.jqplot.MeterGaugeRenderer.prototype=new c.jqplot.LineRenderer();c.jqplot.MeterGaugeRenderer.prototype.constructor=c.jqplot.MeterGaugeRenderer;c.jqplot.MeterGaugeRenderer.prototype.init=function(e){this.diameter=null;this.padding=null;this.shadowOffset=2;this.shadowAlpha=0.07;this.shadowDepth=4;this.background="#efefef";this.ringColor="#BBC6D0";this.needleColor="#C3D3E5";this.tickColor="989898";this.ringWidth=null;this.min;this.max;this.ticks=[];this.showTicks=true;this.showTickLabels=true;this.label=null;this.labelHeightAdjust=0;this.labelPosition="inside";this.intervals=[];this.intervalColors=["#4bb2c5","#EAA228","#c5b47f","#579575","#839557","#958c12","#953579","#4b5de4","#d8b83f","#ff5800","#0085cc","#c747a3","#cddf54","#FBD178","#26B4E3","#bd70c7"];this.intervalInnerRadius=null;this.intervalOuterRadius=null;this.tickRenderer=c.jqplot.MeterGaugeTickRenderer;this.tickPositions=[1,2,2.5,5,10];this.tickSpacing=30;this.numberMinorTicks=null;this.hubRadius=null;this.tickPadding=null;this.needleThickness=null;this.needlePad=6;this.pegNeedle=true;this._type="meterGauge";c.extend(true,this,e);this.type=null;this.numberTicks=null;this.tickInterval=null;this.span=180;if(this.type=="circular"){this.semiCircular=false}else{if(this.type!="circular"){this.semiCircular=true}else{this.semiCircular=(this.span<=180)?true:false}}this._tickPoints=[];this._labelElem=null;this.startAngle=(90+(360-this.span)/2)*Math.PI/180;this.endAngle=(90-(360-this.span)/2)*Math.PI/180;this.setmin=!!(this.min==null);this.setmax=!!(this.max==null);if(this.intervals.length){if(this.intervals[0].length==null||this.intervals.length==1){for(var f=0;f<this.intervals.length;f++){this.intervals[f]=[this.intervals[f],this.intervals[f],this.intervalColors[f]]}}else{if(this.intervals[0].length==2){for(f=0;f<this.intervals.length;f++){this.intervals[f]=[this.intervals[f][0],this.intervals[f][1],this.intervalColors[f]]}}}}if(this.ticks.length){if(this.ticks[0].length==null||this.ticks[0].length==1){for(var f=0;f<this.ticks.length;f++){this.ticks[f]=[this.ticks[f],this.ticks[f]]}}this.min=(this.min==null)?this.ticks[0][0]:this.min;this.max=(this.max==null)?this.ticks[this.ticks.length-1][0]:this.max;this.setmin=false;this.setmax=false;this.numberTicks=this.ticks.length;this.tickInterval=this.ticks[1][0]-this.ticks[0][0];this.tickFactor=Math.floor(parseFloat((Math.log(this.tickInterval)/Math.log(10)).toFixed(11)));this.numberMinorTicks=b(this.tickPositions,this.tickInterval,this.tickFactor);if(!this.numberMinorTicks){this.numberMinorTicks=b(this.tickPositions,this.tickInterval,this.tickFactor-1)}if(!this.numberMinorTicks){this.numberMinorTicks=1}}else{if(this.intervals.length){this.min=(this.min==null)?0:this.min;this.setmin=false;if(this.max==null){if(this.intervals[this.intervals.length-1][0]>=this.data[0][1]){this.max=this.intervals[this.intervals.length-1][0];this.setmax=false}}else{this.setmax=false}}else{this.min=(this.min==null)?0:this.min;this.setmin=false;if(this.max==null){this.max=this.data[0][1]*1.25;this.setmax=true}else{this.setmax=false}}}};c.jqplot.MeterGaugeRenderer.prototype.setGridData=function(j){var f=[];var k=[];var e=this.startAngle;for(var h=0;h<this.data.length;h++){f.push(this.data[h][1]);k.push([this.data[h][0]]);if(h>0){f[h]+=f[h-1]}}var g=Math.PI*2/f[f.length-1];for(var h=0;h<f.length;h++){k[h][1]=f[h]*g}this.gridData=k};c.jqplot.MeterGaugeRenderer.prototype.makeGridData=function(j,k){var f=[];var l=[];var e=this.startAngle;for(var h=0;h<j.length;h++){f.push(j[h][1]);l.push([j[h][0]]);if(h>0){f[h]+=f[h-1]}}var g=Math.PI*2/f[f.length-1];for(var h=0;h<f.length;h++){l[h][1]=f[h]*g}return l};function b(j,f,g){var e;for(var h=j.length-1;h>=0;h--){e=f/(j[h]*Math.pow(10,g));if(e==4||e==5){return e-1}}return null}c.jqplot.MeterGaugeRenderer.prototype.draw=function(X,aC,ap){var aa;var aM=(ap!=undefined)?ap:{};var ai=0;var ah=0;var at=1;if(ap.legendInfo&&ap.legendInfo.placement=="inside"){var aI=ap.legendInfo;switch(aI.location){case"nw":ai=aI.width+aI.xoffset;break;case"w":ai=aI.width+aI.xoffset;break;case"sw":ai=aI.width+aI.xoffset;break;case"ne":ai=aI.width+aI.xoffset;at=-1;break;case"e":ai=aI.width+aI.xoffset;at=-1;break;case"se":ai=aI.width+aI.xoffset;at=-1;break;case"n":ah=aI.height+aI.yoffset;break;case"s":ah=aI.height+aI.yoffset;at=-1;break;default:break}}if(this.label){this._labelElem=c('<div class="jqplot-meterGauge-label" style="position:absolute;">'+this.label+"</div>");this.canvas._elem.after(this._labelElem)}var m=(aM.shadow!=undefined)?aM.shadow:this.shadow;var N=(aM.showLine!=undefined)?aM.showLine:this.showLine;var I=(aM.fill!=undefined)?aM.fill:this.fill;var K=X.canvas.width;var S=X.canvas.height;if(this.padding==null){this.padding=Math.round(Math.min(K,S)/30)}var Q=K-ai-2*this.padding;var ab=S-ah-2*this.padding;if(this.labelPosition=="bottom"&&this.label){ab-=this._labelElem.outerHeight(true)}var L=Math.min(Q,ab);var ad=L;if(!this.diameter){if(this.semiCircular){if(Q>=2*ab){if(!this.ringWidth){this.ringWidth=2*ab/35}this.needleThickness=this.needleThickness||2+Math.pow(this.ringWidth,0.8);this.innerPad=this.ringWidth/2+this.needleThickness/2+this.needlePad;this.diameter=2*(ab-2*this.innerPad)}else{if(!this.ringWidth){this.ringWidth=Q/35}this.needleThickness=this.needleThickness||2+Math.pow(this.ringWidth,0.8);this.innerPad=this.ringWidth/2+this.needleThickness/2+this.needlePad;this.diameter=Q-2*this.innerPad-this.ringWidth-this.padding}this._center=[(K-at*ai)/2+at*ai,(S+at*ah-this.padding-this.ringWidth-this.innerPad)]}else{if(!this.ringWidth){this.ringWidth=ad/35}this.needleThickness=this.needleThickness||2+Math.pow(this.ringWidth,0.8);this.innerPad=0;this.diameter=ad-this.ringWidth;this._center=[(K-at*ai)/2+at*ai,(S-at*ah)/2+at*ah]}}if(this._labelElem&&this.labelPosition=="bottom"){this._center[1]-=this._labelElem.outerHeight(true)}this._radius=this.diameter/2;this.tickSpacing=6000/this.diameter;if(!this.hubRadius){this.hubRadius=this.diameter/18}this.shadowOffset=0.5+this.ringWidth/9;this.shadowWidth=this.ringWidth*1;this.tickPadding=3+Math.pow(this.diameter/20,0.7);this.tickOuterRadius=this._radius-this.ringWidth/2-this.tickPadding;this.tickLength=(this.showTicks)?this._radius/13:0;if(this.ticks.length==0){var A=this.max,aL=this.min,q=this.setmax,aG=this.setmin,au=(A-aL)*this.tickSpacing/this.span;var aw=Math.floor(parseFloat((Math.log(au)/Math.log(10)).toFixed(11)));var an=(au/Math.pow(10,aw));(an>2&&an<=2.5)?an=2.5:an=Math.ceil(an);var T=this.tickPositions;var aA,ak;for(aa=0;aa<T.length;aa++){if(an==T[aa]||aa&&T[aa-1]<an&&an<T[aa]){au=T[aa]*Math.pow(10,aw);aA=aa}}for(aa=0;aa<T.length;aa++){if(an==T[aa]||aa&&T[aa-1]<an&&an<T[aa]){au=T[aa]*Math.pow(10,aw);ak=Math.ceil((A-aL)/au)}}if(q&&aG){var aP=(aL>0)?aL-aL%au:aL-aL%au-au;if(!this.forceZero){var D=Math.min(aL-aP,0.8*au);var o=Math.floor(D/T[aA]);if(o>1){aP=aP+T[aA]*(o-1);if(parseInt(aP,10)!=aP&&parseInt(aP-T[aA],10)==aP-T[aA]){aP=aP-T[aA]}}}if(aL==aP){aL-=au}else{if(aL-aP>0.23*au){aL=aP}else{aL=aP-au;ak+=1}}ak+=1;var E=aL+(ak-1)*au;if(A>=E){E+=au;ak+=1}if(E-A<0.23*au){E+=au;ak+=1}this.max=A=E;this.min=aL;this.tickInterval=au;this.numberTicks=ak;var O;for(aa=0;aa<ak;aa++){O=parseFloat((aL+aa*au).toFixed(11));this.ticks.push([O,O])}this.max=this.ticks[ak-1][1];this.tickFactor=aw;this.numberMinorTicks=b(this.tickPositions,this.tickInterval,this.tickFactor);if(!this.numberMinorTicks){this.numberMinorTicks=b(this.tickPositions,this.tickInterval,this.tickFactor-1)}}else{if(q){var E=aL+(ak-1)*au;if(A>=E){A=E+au;ak+=1}else{A=E}this.tickInterval=this.tickInterval||au;this.numberTicks=this.numberTicks||ak;var O;for(aa=0;aa<this.numberTicks;aa++){O=parseFloat((aL+aa*this.tickInterval).toFixed(11));this.ticks.push([O,O])}this.max=this.ticks[this.numberTicks-1][1];this.tickFactor=aw;this.numberMinorTicks=b(this.tickPositions,this.tickInterval,this.tickFactor);if(!this.numberMinorTicks){this.numberMinorTicks=b(this.tickPositions,this.tickInterval,this.tickFactor-1)}}}if(!q&&!aG){var P=this.max-this.min;aw=Math.floor(parseFloat((Math.log(P)/Math.log(10)).toFixed(11)))-1;var aN=[5,6,4,7,3,8,9,10,2],V,C,av=0,M;if(P>1){var aJ=String(P);if(aJ.search(/\./)==-1){var aF=aJ.search(/0+$/);av=(aF>0)?aJ.length-aF-1:0}}M=P/Math.pow(10,av);for(aa=0;aa<aN.length;aa++){V=M/(aN[aa]-1);if(V==parseInt(V,10)){this.numberTicks=aN[aa];this.tickInterval=P/(this.numberTicks-1);this.tickFactor=aw+1;break}}var O;for(aa=0;aa<this.numberTicks;aa++){O=parseFloat((this.min+aa*this.tickInterval).toFixed(11));this.ticks.push([O,O])}this.numberMinorTicks=b(this.tickPositions,this.tickInterval,this.tickFactor);if(!this.numberMinorTicks){this.numberMinorTicks=b(this.tickPositions,this.tickInterval,this.tickFactor-1)}if(!this.numberMinorTicks){this.numberMinorTicks=1;var aH=[4,5,3,6,2];for(aa=0;aa<5;aa++){var ao=this.tickInterval/aH[aa];if(ao==parseInt(ao,10)){this.numberMinorTicks=aH[aa]-1;break}}}}}var U=this._radius,aE=this.startAngle,k=this.endAngle,H=Math.PI,e=Math.PI/2;if(this.semiCircular){var z=Math.atan(this.innerPad/U),ac=this.outerStartAngle=aE-z,aB=this.outerEndAngle=k+z,B=this.hubStartAngle=aE-Math.atan(this.innerPad/this.hubRadius*2),af=this.hubEndAngle=k+Math.atan(this.innerPad/this.hubRadius*2);X.save();X.translate(this._center[0],this._center[1]);X.lineJoin="round";X.lineCap="round";X.save();X.beginPath();X.fillStyle=this.background;X.arc(0,0,U,ac,aB,false);X.closePath();X.fill();X.restore();var aj="rgba(0,0,0,"+this.shadowAlpha+")";X.save();for(var aa=0;aa<this.shadowDepth;aa++){X.translate(this.shadowOffset*Math.cos(this.shadowAngle/180*Math.PI),this.shadowOffset*Math.sin(this.shadowAngle/180*Math.PI));X.beginPath();X.strokeStyle=aj;X.lineWidth=this.shadowWidth;X.arc(0,0,U,ac,aB,false);X.closePath();X.stroke()}X.restore();X.save();var az=parseInt((this.shadowDepth+1)/2,10);for(var aa=0;aa<az;aa++){X.translate(this.shadowOffset*Math.cos(this.shadowAngle/180*Math.PI),this.shadowOffset*Math.sin(this.shadowAngle/180*Math.PI));X.beginPath();X.fillStyle=aj;X.arc(0,0,this.hubRadius,B,af,false);X.closePath();X.fill()}X.restore();X.save();X.beginPath();X.strokeStyle=this.ringColor;X.lineWidth=this.ringWidth;X.arc(0,0,U,ac,aB,false);X.closePath();X.stroke();X.restore();X.save();X.beginPath();X.fillStyle=this.ringColor;X.arc(0,0,this.hubRadius,B,af,false);X.closePath();X.fill();X.restore();if(this.showTicks){X.save();var f=this.tickOuterRadius,aq=this.tickLength,v=aq/2,F=this.numberMinorTicks,am=this.span*Math.PI/180/(this.ticks.length-1),p=am/(F+1);for(aa=0;aa<this.ticks.length;aa++){X.beginPath();X.lineWidth=1.5+this.diameter/360;X.strokeStyle=this.ringColor;var ae=am*aa+aE;X.moveTo(-f*Math.cos(am*aa+aE),f*Math.sin(am*aa+aE));X.lineTo(-(f-aq)*Math.cos(am*aa+aE),(f-aq)*Math.sin(am*aa+aE));this._tickPoints.push([(f-aq)*Math.cos(am*aa+aE)+this._center[0]+this.canvas._offsets.left,(f-aq)*Math.sin(am*aa+aE)+this._center[1]+this.canvas._offsets.top,am*aa+aE]);X.stroke();X.lineWidth=1+this.diameter/440;if(aa<this.ticks.length-1){for(var Y=1;Y<=F;Y++){X.beginPath();X.moveTo(-f*Math.cos(am*aa+p*Y+aE),f*Math.sin(am*aa+p*Y+aE));X.lineTo(-(f-v)*Math.cos(am*aa+p*Y+aE),(f-v)*Math.sin(am*aa+p*Y+aE));X.stroke()}}}X.restore()}if(this.showTickLabels){var J,W,T,aO,g,G,n=0;var an=this.tickPadding*(1-1/(this.diameter/80+1));for(aa=0;aa<this.ticks.length;aa++){J=c('<div class="jqplot-meterGauge-tick" style="position:absolute;">'+this.ticks[aa][1]+"</div>");this.canvas._elem.after(J);aO=J.outerWidth(true);g=J.outerHeight(true);W=this._tickPoints[aa][0]-aO*(this._tickPoints[aa][2]-Math.PI)/Math.PI-an*Math.cos(this._tickPoints[aa][2]);T=this._tickPoints[aa][1]-g/2+g/2*Math.pow(Math.abs((Math.sin(this._tickPoints[aa][2]))),0.5)+an/3*Math.pow(Math.abs((Math.sin(this._tickPoints[aa][2]))),0.5);J.css({left:W,top:T});G=aO*Math.cos(this._tickPoints[aa][2])+g*Math.sin(Math.PI/2+this._tickPoints[aa][2]/2);n=(G>n)?G:n}}if(this.label&&this.labelPosition=="inside"){var W=this._center[0]+this.canvas._offsets.left;var an=this.tickPadding*(1-1/(this.diameter/80+1));var T=0.5*(this._center[1]+this.canvas._offsets.top-this.hubRadius)+0.5*(this._center[1]+this.canvas._offsets.top-this.tickOuterRadius+this.tickLength+an)+this.labelHeightAdjust;W-=this._labelElem.outerWidth(true)/2;T-=this._labelElem.outerHeight(true)/2;this._labelElem.css({left:W,top:T})}else{if(this.label&&this.labelPosition=="bottom"){var W=this._center[0]+this.canvas._offsets.left-this._labelElem.outerWidth(true)/2;var T=this._center[1]+this.canvas._offsets.top+this.innerPad+ +this.ringWidth+this.padding+this.labelHeightAdjust;this._labelElem.css({left:W,top:T})}}X.save();var ax=this.intervalInnerRadius||this.hubRadius*1.5;if(this.intervalOuterRadius==null){if(this.showTickLabels){var ag=(this.tickOuterRadius-this.tickLength-this.tickPadding-this.diameter/8)}else{var ag=(this.tickOuterRadius-this.tickLength-this.diameter/16)}}else{var ag=this.intervalOuterRadius}var P=this.max-this.min;var aD=this.intervals[this.intervals.length-1]-this.min;var y,Z,u=this.span*Math.PI/180;for(aa=0;aa<this.intervals.length;aa++){y=(aa==0)?aE:aE+(this.intervals[aa-1][0]-this.min)*u/P;if(y<0){y=0}Z=aE+(this.intervals[aa][0]-this.min)*u/P;if(Z<0){Z=0}X.beginPath();X.fillStyle=this.intervals[aa][2];X.arc(0,0,ax,y,Z,false);X.lineTo(ag*Math.cos(Z),ag*Math.sin(Z));X.arc(0,0,ag,Z,y,true);X.lineTo(ax*Math.cos(y),ax*Math.sin(y));X.closePath();X.fill()}X.restore();var ay=this.data[0][1];var R=this.max-this.min;if(this.pegNeedle){if(this.data[0][1]>this.max+R*3/this.span){ay=this.max+R*3/this.span}if(this.data[0][1]<this.min-R*3/this.span){ay=this.min-R*3/this.span}}var al=(ay-this.min)/R*this.span*Math.PI/180+this.startAngle;X.save();X.beginPath();X.fillStyle=this.ringColor;X.strokeStyle=this.ringColor;this.needleLength=(this.tickOuterRadius-this.tickLength)*0.85;this.needleThickness=(this.needleThickness<2)?2:this.needleThickness;var aK=this.needleThickness*0.4;var x=this.needleLength/10;var s=(this.needleThickness-aK)/10;var ar;for(var aa=0;aa<10;aa++){ar=this.needleThickness-aa*s;X.moveTo(x*aa*Math.cos(al),x*aa*Math.sin(al));X.lineWidth=ar;X.lineTo(x*(aa+1)*Math.cos(al),x*(aa+1)*Math.sin(al));X.stroke()}X.restore()}else{this._center=[(K-at*ai)/2+at*ai,(S-at*ah)/2+at*ah]}};c.jqplot.MeterGaugeAxisRenderer=function(){c.jqplot.LinearAxisRenderer.call(this)};c.jqplot.MeterGaugeAxisRenderer.prototype=new c.jqplot.LinearAxisRenderer();c.jqplot.MeterGaugeAxisRenderer.prototype.constructor=c.jqplot.MeterGaugeAxisRenderer;c.jqplot.MeterGaugeAxisRenderer.prototype.init=function(e){this.tickRenderer=c.jqplot.MeterGaugeTickRenderer;c.extend(true,this,e);this._dataBounds={min:0,max:100};this.min=0;this.max=100;this.showTicks=false;this.ticks=[];this.showMark=false;this.show=false};c.jqplot.MeterGaugeLegendRenderer=function(){c.jqplot.TableLegendRenderer.call(this)};c.jqplot.MeterGaugeLegendRenderer.prototype=new c.jqplot.TableLegendRenderer();c.jqplot.MeterGaugeLegendRenderer.prototype.constructor=c.jqplot.MeterGaugeLegendRenderer;c.jqplot.MeterGaugeLegendRenderer.prototype.init=function(e){this.numberRows=null;this.numberColumns=null;c.extend(true,this,e)};c.jqplot.MeterGaugeLegendRenderer.prototype.draw=function(){if(this.show){var p=this._series;var x="position:absolute;";x+=(this.background)?"background:"+this.background+";":"";x+=(this.border)?"border:"+this.border+";":"";x+=(this.fontSize)?"font-size:"+this.fontSize+";":"";x+=(this.fontFamily)?"font-family:"+this.fontFamily+";":"";x+=(this.textColor)?"color:"+this.textColor+";":"";x+=(this.marginTop!=null)?"margin-top:"+this.marginTop+";":"";x+=(this.marginBottom!=null)?"margin-bottom:"+this.marginBottom+";":"";x+=(this.marginLeft!=null)?"margin-left:"+this.marginLeft+";":"";x+=(this.marginRight!=null)?"margin-right:"+this.marginRight+";":"";this._elem=c('<table class="jqplot-table-legend" style="'+x+'"></table>');var f=false,q=false,u,o;var w=p[0];if(w.show){var t=w.data;if(this.numberRows){u=this.numberRows;if(!this.numberColumns){o=Math.ceil(t.length/u)}else{o=this.numberColumns}}else{if(this.numberColumns){o=this.numberColumns;u=Math.ceil(t.length/this.numberColumns)}else{u=t.length;o=1}}var n,m,r,g,e,l,k,h;var v=0;for(n=0;n<u;n++){if(q){r=c('<tr class="jqplot-table-legend"></tr>').prependTo(this._elem)}else{r=c('<tr class="jqplot-table-legend"></tr>').appendTo(this._elem)}for(m=0;m<o;m++){if(v<t.length){l=this.labels[v]||t[v][0].toString();h=w.color;if(!q){if(n>0){f=true}else{f=false}}else{if(n==u-1){f=false}else{f=true}}k=(f)?this.rowSpacing:"0";g=c('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+k+';"><div><div class="jqplot-table-legend-swatch" style="border-color:'+h+';"></div></div></td>');e=c('<td class="jqplot-table-legend" style="padding-top:'+k+';"></td>');if(this.escapeHtml){e.text(l)}else{e.html(l)}if(q){e.prependTo(r);g.prependTo(r)}else{g.appendTo(r);e.appendTo(r)}f=true}v++}}}}return this._elem};function a(j,h,f){f=f||{};f.axesDefaults=f.axesDefaults||{};f.legend=f.legend||{};f.seriesDefaults=f.seriesDefaults||{};f.grid=f.grid||{};var e=false;if(f.seriesDefaults.renderer==c.jqplot.MeterGaugeRenderer){e=true}else{if(f.series){for(var g=0;g<f.series.length;g++){if(f.series[g].renderer==c.jqplot.MeterGaugeRenderer){e=true}}}}if(e){f.axesDefaults.renderer=c.jqplot.MeterGaugeAxisRenderer;f.legend.renderer=c.jqplot.MeterGaugeLegendRenderer;f.legend.preDraw=true;f.grid.background=f.grid.background||"white";f.grid.drawGridlines=false;f.grid.borderWidth=(f.grid.borderWidth!=null)?f.grid.borderWidth:0;f.grid.shadow=(f.grid.shadow!=null)?f.grid.shadow:false}}function d(e){}c.jqplot.preInitHooks.push(a);c.jqplot.postParseOptionsHooks.push(d);c.jqplot.MeterGaugeTickRenderer=function(){c.jqplot.AxisTickRenderer.call(this)};c.jqplot.MeterGaugeTickRenderer.prototype=new c.jqplot.AxisTickRenderer();c.jqplot.MeterGaugeTickRenderer.prototype.constructor=c.jqplot.MeterGaugeTickRenderer})(jQuery);
|
@@ -0,0 +1,372 @@
|
|
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.OHLCRenderer
|
33
|
+
* jqPlot Plugin to draw Open Hi Low Close, Candlestick and Hi Low Close charts.
|
34
|
+
*
|
35
|
+
* To use this plugin, include the renderer js file in
|
36
|
+
* your source:
|
37
|
+
*
|
38
|
+
* > <script type="text/javascript" src="plugins/jqplot.ohlcRenderer.js"></script>
|
39
|
+
*
|
40
|
+
* You will most likely want to use a date axis renderer
|
41
|
+
* for the x axis also, so include the date axis render js file also:
|
42
|
+
*
|
43
|
+
* > <script type="text/javascript" src="plugins/jqplot.dateAxisRenderer.js"></script>
|
44
|
+
*
|
45
|
+
* Then you set the renderer in the series options on your plot:
|
46
|
+
*
|
47
|
+
* > series: [{renderer:$.jqplot.OHLCRenderer}]
|
48
|
+
*
|
49
|
+
* For OHLC and candlestick charts, data should be specified
|
50
|
+
* like so:
|
51
|
+
*
|
52
|
+
* > dat = [['07/06/2009',138.7,139.68,135.18,135.4], ['06/29/2009',143.46,144.66,139.79,140.02], ...]
|
53
|
+
*
|
54
|
+
* If the data array has only 4 values per point instead of 5,
|
55
|
+
* the renderer will create a Hi Low Close chart instead. In that case,
|
56
|
+
* data should be supplied like:
|
57
|
+
*
|
58
|
+
* > dat = [['07/06/2009',139.68,135.18,135.4], ['06/29/2009',144.66,139.79,140.02], ...]
|
59
|
+
*
|
60
|
+
* To generate a candlestick chart instead of an OHLC chart,
|
61
|
+
* set the "candlestick" option to true:
|
62
|
+
*
|
63
|
+
* > series: [{renderer:$.jqplot.OHLCRenderer, rendererOptions:{candleStick:true}}],
|
64
|
+
*
|
65
|
+
*/
|
66
|
+
$.jqplot.OHLCRenderer = function(){
|
67
|
+
// subclass line renderer to make use of some of it's methods.
|
68
|
+
$.jqplot.LineRenderer.call(this);
|
69
|
+
// prop: candleStick
|
70
|
+
// true to render chart as candleStick.
|
71
|
+
// Must have an open price, cannot be a hlc chart.
|
72
|
+
this.candleStick = false;
|
73
|
+
// prop: tickLength
|
74
|
+
// length of the line in pixels indicating open and close price.
|
75
|
+
// Default will auto calculate based on plot width and
|
76
|
+
// number of points displayed.
|
77
|
+
this.tickLength = 'auto';
|
78
|
+
// prop: bodyWidth
|
79
|
+
// width of the candlestick body in pixels. Default will auto calculate
|
80
|
+
// based on plot width and number of candlesticks displayed.
|
81
|
+
this.bodyWidth = 'auto';
|
82
|
+
// prop: openColor
|
83
|
+
// color of the open price tick mark. Default is series color.
|
84
|
+
this.openColor = null;
|
85
|
+
// prop: closeColor
|
86
|
+
// color of the close price tick mark. Default is series color.
|
87
|
+
this.closeColor = null;
|
88
|
+
// prop: wickColor
|
89
|
+
// color of the hi-lo line thorugh the candlestick body.
|
90
|
+
// Default is the series color.
|
91
|
+
this.wickColor = null;
|
92
|
+
// prop: fillUpBody
|
93
|
+
// true to render an "up" day (close price greater than open price)
|
94
|
+
// with a filled candlestick body.
|
95
|
+
this.fillUpBody = false;
|
96
|
+
// prop: fillDownBody
|
97
|
+
// true to render a "down" day (close price lower than open price)
|
98
|
+
// with a filled candlestick body.
|
99
|
+
this.fillDownBody = true;
|
100
|
+
// prop: upBodyColor
|
101
|
+
// Color of candlestick body of an "up" day. Default is series color.
|
102
|
+
this.upBodyColor = null;
|
103
|
+
// prop: downBodyColor
|
104
|
+
// Color of candlestick body on a "down" day. Default is series color.
|
105
|
+
this.downBodyColor = null;
|
106
|
+
// prop: hlc
|
107
|
+
// true if is a hi-low-close chart (no open price).
|
108
|
+
// This is determined automatically from the series data.
|
109
|
+
this.hlc = false;
|
110
|
+
// prop: lineWidth
|
111
|
+
// Width of the hi-low line and open/close ticks.
|
112
|
+
// Must be set in the rendererOptions for the series.
|
113
|
+
this.lineWidth = 1.5;
|
114
|
+
this._tickLength;
|
115
|
+
this._bodyWidth;
|
116
|
+
};
|
117
|
+
|
118
|
+
$.jqplot.OHLCRenderer.prototype = new $.jqplot.LineRenderer();
|
119
|
+
$.jqplot.OHLCRenderer.prototype.constructor = $.jqplot.OHLCRenderer;
|
120
|
+
|
121
|
+
// called with scope of series.
|
122
|
+
$.jqplot.OHLCRenderer.prototype.init = function(options) {
|
123
|
+
options = options || {};
|
124
|
+
// lineWidth has to be set on the series, changes in renderer
|
125
|
+
// constructor have no effect. set the default here
|
126
|
+
// if no renderer option for lineWidth is specified.
|
127
|
+
this.lineWidth = options.lineWidth || 1.5;
|
128
|
+
$.jqplot.LineRenderer.prototype.init.call(this, options);
|
129
|
+
this._type = 'ohlc';
|
130
|
+
// set the yaxis data bounds here to account for hi and low values
|
131
|
+
var db = this._yaxis._dataBounds;
|
132
|
+
var d = this._plotData;
|
133
|
+
// if data points have less than 5 values, force a hlc chart.
|
134
|
+
if (d[0].length < 5) {
|
135
|
+
this.renderer.hlc = true;
|
136
|
+
|
137
|
+
for (var j=0; j<d.length; j++) {
|
138
|
+
if (d[j][2] < db.min || db.min == null) {
|
139
|
+
db.min = d[j][2];
|
140
|
+
}
|
141
|
+
if (d[j][1] > db.max || db.max == null) {
|
142
|
+
db.max = d[j][1];
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
else {
|
147
|
+
for (var j=0; j<d.length; j++) {
|
148
|
+
if (d[j][3] < db.min || db.min == null) {
|
149
|
+
db.min = d[j][3];
|
150
|
+
}
|
151
|
+
if (d[j][2] > db.max || db.max == null) {
|
152
|
+
db.max = d[j][2];
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
};
|
158
|
+
|
159
|
+
// called within scope of series.
|
160
|
+
$.jqplot.OHLCRenderer.prototype.draw = function(ctx, gd, options) {
|
161
|
+
var d = this.data;
|
162
|
+
var xmin = this._xaxis.min;
|
163
|
+
var xmax = this._xaxis.max;
|
164
|
+
// index of last value below range of plot.
|
165
|
+
var xminidx = 0;
|
166
|
+
// index of first value above range of plot.
|
167
|
+
var xmaxidx = d.length;
|
168
|
+
var xp = this._xaxis.series_u2p;
|
169
|
+
var yp = this._yaxis.series_u2p;
|
170
|
+
var i, prevColor, ops, b, h, w, a, points;
|
171
|
+
var o;
|
172
|
+
var r = this.renderer;
|
173
|
+
var opts = (options != undefined) ? options : {};
|
174
|
+
var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
|
175
|
+
var fill = (opts.fill != undefined) ? opts.fill : this.fill;
|
176
|
+
var fillAndStroke = (opts.fillAndStroke != undefined) ? opts.fillAndStroke : this.fillAndStroke;
|
177
|
+
r.bodyWidth = (opts.bodyWidth != undefined) ? opts.bodyWidth : r.bodyWidth;
|
178
|
+
r.tickLength = (opts.tickLength != undefined) ? opts.tickLength : r.tickLength;
|
179
|
+
ctx.save();
|
180
|
+
if (this.show) {
|
181
|
+
var x, open, hi, low, close;
|
182
|
+
// need to get widths based on number of points shown,
|
183
|
+
// not on total number of points. Use the results
|
184
|
+
// to speed up drawing in next step.
|
185
|
+
for (var i=0; i<d.length; i++) {
|
186
|
+
if (d[i][0] < xmin) {
|
187
|
+
xminidx = i;
|
188
|
+
}
|
189
|
+
else if (d[i][0] < xmax) {
|
190
|
+
xmaxidx = i+1;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
var dwidth = this.gridData[xmaxidx-1][0] - this.gridData[xminidx][0];
|
195
|
+
var nvisiblePoints = xmaxidx - xminidx;
|
196
|
+
try {
|
197
|
+
var dinterval = Math.abs(this._xaxis.series_u2p(parseInt(this._xaxis._intervalStats[0].sortedIntervals[0].interval, 10)) - this._xaxis.series_u2p(0));
|
198
|
+
}
|
199
|
+
|
200
|
+
catch (e) {
|
201
|
+
var dinterval = dwidth / nvisiblePoints;
|
202
|
+
}
|
203
|
+
|
204
|
+
if (r.candleStick) {
|
205
|
+
if (typeof(r.bodyWidth) == 'number') {
|
206
|
+
r._bodyWidth = r.bodyWidth;
|
207
|
+
}
|
208
|
+
else {
|
209
|
+
r._bodyWidth = Math.min(20, dinterval/1.65);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
else {
|
213
|
+
if (typeof(r.tickLength) == 'number') {
|
214
|
+
r._tickLength = r.tickLength;
|
215
|
+
}
|
216
|
+
else {
|
217
|
+
r._tickLength = Math.min(10, dinterval/3.5);
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
for (var i=xminidx; i<xmaxidx; i++) {
|
222
|
+
x = xp(d[i][0]);
|
223
|
+
if (r.hlc) {
|
224
|
+
open = null;
|
225
|
+
hi = yp(d[i][1]);
|
226
|
+
low = yp(d[i][2]);
|
227
|
+
close = yp(d[i][3]);
|
228
|
+
}
|
229
|
+
else {
|
230
|
+
open = yp(d[i][1]);
|
231
|
+
hi = yp(d[i][2]);
|
232
|
+
low = yp(d[i][3]);
|
233
|
+
close = yp(d[i][4]);
|
234
|
+
}
|
235
|
+
o = {};
|
236
|
+
if (r.candleStick && !r.hlc) {
|
237
|
+
w = r._bodyWidth;
|
238
|
+
a = x - w/2;
|
239
|
+
// draw candle
|
240
|
+
// determine if candle up or down
|
241
|
+
// up, remember grid coordinates increase downward
|
242
|
+
if (close < open) {
|
243
|
+
// draw wick
|
244
|
+
if (r.wickColor) {
|
245
|
+
o.color = r.wickColor;
|
246
|
+
}
|
247
|
+
else if (r.downBodyColor) {
|
248
|
+
o.color = r.upBodyColor;
|
249
|
+
}
|
250
|
+
ops = $.extend(true, {}, opts, o);
|
251
|
+
r.shapeRenderer.draw(ctx, [[x, hi], [x, close]], ops);
|
252
|
+
r.shapeRenderer.draw(ctx, [[x, open], [x, low]], ops);
|
253
|
+
o = {};
|
254
|
+
b = close;
|
255
|
+
h = open - close;
|
256
|
+
// if color specified, use it
|
257
|
+
if (r.fillUpBody) {
|
258
|
+
o.fillRect = true;
|
259
|
+
}
|
260
|
+
else {
|
261
|
+
o.strokeRect = true;
|
262
|
+
w = w - this.lineWidth;
|
263
|
+
a = x - w/2;
|
264
|
+
}
|
265
|
+
if (r.upBodyColor) {
|
266
|
+
o.color = r.upBodyColor;
|
267
|
+
o.fillStyle = r.upBodyColor;
|
268
|
+
}
|
269
|
+
points = [a, b, w, h];
|
270
|
+
}
|
271
|
+
// down
|
272
|
+
else if (close > open) {
|
273
|
+
// draw wick
|
274
|
+
if (r.wickColor) {
|
275
|
+
o.color = r.wickColor;
|
276
|
+
}
|
277
|
+
else if (r.downBodyColor) {
|
278
|
+
o.color = r.downBodyColor;
|
279
|
+
}
|
280
|
+
ops = $.extend(true, {}, opts, o);
|
281
|
+
r.shapeRenderer.draw(ctx, [[x, hi], [x, open]], ops);
|
282
|
+
r.shapeRenderer.draw(ctx, [[x, close], [x, low]], ops);
|
283
|
+
|
284
|
+
o = {};
|
285
|
+
|
286
|
+
b = open;
|
287
|
+
h = close - open;
|
288
|
+
// if color specified, use it
|
289
|
+
if (r.fillDownBody) {
|
290
|
+
o.fillRect = true;
|
291
|
+
}
|
292
|
+
else {
|
293
|
+
o.strokeRect = true;
|
294
|
+
w = w - this.lineWidth;
|
295
|
+
a = x - w/2;
|
296
|
+
}
|
297
|
+
if (r.downBodyColor) {
|
298
|
+
o.color = r.downBodyColor;
|
299
|
+
o.fillStyle = r.downBodyColor;
|
300
|
+
}
|
301
|
+
points = [a, b, w, h];
|
302
|
+
}
|
303
|
+
// even, open = close
|
304
|
+
else {
|
305
|
+
// draw wick
|
306
|
+
if (r.wickColor) {
|
307
|
+
o.color = r.wickColor;
|
308
|
+
}
|
309
|
+
ops = $.extend(true, {}, opts, o);
|
310
|
+
r.shapeRenderer.draw(ctx, [[x, hi], [x, low]], ops);
|
311
|
+
o = {};
|
312
|
+
o.fillRect = false;
|
313
|
+
o.strokeRect = false;
|
314
|
+
a = [x - w/2, open];
|
315
|
+
b = [x + w/2, close];
|
316
|
+
w = null;
|
317
|
+
h = null;
|
318
|
+
points = [a, b];
|
319
|
+
}
|
320
|
+
ops = $.extend(true, {}, opts, o);
|
321
|
+
r.shapeRenderer.draw(ctx, points, ops);
|
322
|
+
}
|
323
|
+
else {
|
324
|
+
prevColor = opts.color;
|
325
|
+
if (r.openColor) {
|
326
|
+
opts.color = r.openColor;
|
327
|
+
}
|
328
|
+
// draw open tick
|
329
|
+
if (!r.hlc) {
|
330
|
+
r.shapeRenderer.draw(ctx, [[x-r._tickLength, open], [x, open]], opts);
|
331
|
+
}
|
332
|
+
opts.color = prevColor;
|
333
|
+
// draw wick
|
334
|
+
if (r.wickColor) {
|
335
|
+
opts.color = r.wickColor;
|
336
|
+
}
|
337
|
+
r.shapeRenderer.draw(ctx, [[x, hi], [x, low]], opts);
|
338
|
+
opts.color = prevColor;
|
339
|
+
// draw close tick
|
340
|
+
if (r.closeColor) {
|
341
|
+
opts.color = r.closeColor;
|
342
|
+
}
|
343
|
+
r.shapeRenderer.draw(ctx, [[x, close], [x+r._tickLength, close]], opts);
|
344
|
+
opts.color = prevColor;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
ctx.restore();
|
350
|
+
};
|
351
|
+
|
352
|
+
$.jqplot.OHLCRenderer.prototype.drawShadow = function(ctx, gd, options) {
|
353
|
+
// This is a no-op, shadows drawn with lines.
|
354
|
+
};
|
355
|
+
|
356
|
+
// called with scope of plot.
|
357
|
+
$.jqplot.OHLCRenderer.checkOptions = function(target, data, options) {
|
358
|
+
// provide some sensible highlighter options by default
|
359
|
+
// These aren't good for hlc, only for ohlc or candlestick
|
360
|
+
if (!options.highlighter) {
|
361
|
+
options.highlighter = {
|
362
|
+
showMarker:false,
|
363
|
+
tooltipAxes: 'y',
|
364
|
+
yvalues: 4,
|
365
|
+
formatString:'<table class="jqplot-highlighter"><tr><td>date:</td><td>%s</td></tr><tr><td>open:</td><td>%s</td></tr><tr><td>hi:</td><td>%s</td></tr><tr><td>low:</td><td>%s</td></tr><tr><td>close:</td><td>%s</td></tr></table>'
|
366
|
+
};
|
367
|
+
}
|
368
|
+
};
|
369
|
+
|
370
|
+
//$.jqplot.preInitHooks.push($.jqplot.OHLCRenderer.checkOptions);
|
371
|
+
|
372
|
+
})(jQuery);
|
@@ -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(a){a.jqplot.OHLCRenderer=function(){a.jqplot.LineRenderer.call(this);this.candleStick=false;this.tickLength="auto";this.bodyWidth="auto";this.openColor=null;this.closeColor=null;this.wickColor=null;this.fillUpBody=false;this.fillDownBody=true;this.upBodyColor=null;this.downBodyColor=null;this.hlc=false;this.lineWidth=1.5;this._tickLength;this._bodyWidth};a.jqplot.OHLCRenderer.prototype=new a.jqplot.LineRenderer();a.jqplot.OHLCRenderer.prototype.constructor=a.jqplot.OHLCRenderer;a.jqplot.OHLCRenderer.prototype.init=function(e){e=e||{};this.lineWidth=e.lineWidth||1.5;a.jqplot.LineRenderer.prototype.init.call(this,e);this._type="ohlc";var b=this._yaxis._dataBounds;var f=this._plotData;if(f[0].length<5){this.renderer.hlc=true;for(var c=0;c<f.length;c++){if(f[c][2]<b.min||b.min==null){b.min=f[c][2]}if(f[c][1]>b.max||b.max==null){b.max=f[c][1]}}}else{for(var c=0;c<f.length;c++){if(f[c][3]<b.min||b.min==null){b.min=f[c][3]}if(f[c][2]>b.max||b.max==null){b.max=f[c][2]}}}};a.jqplot.OHLCRenderer.prototype.draw=function(A,N,j){var J=this.data;var v=this._xaxis.min;var z=this._xaxis.max;var l=0;var K=J.length;var p=this._xaxis.series_u2p;var G=this._yaxis.series_u2p;var D,E,f,M,F,n,O,C;var y;var u=this.renderer;var s=(j!=undefined)?j:{};var k=(s.shadow!=undefined)?s.shadow:this.shadow;var B=(s.fill!=undefined)?s.fill:this.fill;var c=(s.fillAndStroke!=undefined)?s.fillAndStroke:this.fillAndStroke;u.bodyWidth=(s.bodyWidth!=undefined)?s.bodyWidth:u.bodyWidth;u.tickLength=(s.tickLength!=undefined)?s.tickLength:u.tickLength;A.save();if(this.show){var m,q,g,Q,t;for(var D=0;D<J.length;D++){if(J[D][0]<v){l=D}else{if(J[D][0]<z){K=D+1}}}var I=this.gridData[K-1][0]-this.gridData[l][0];var L=K-l;try{var P=Math.abs(this._xaxis.series_u2p(parseInt(this._xaxis._intervalStats[0].sortedIntervals[0].interval,10))-this._xaxis.series_u2p(0))}catch(H){var P=I/L}if(u.candleStick){if(typeof(u.bodyWidth)=="number"){u._bodyWidth=u.bodyWidth}else{u._bodyWidth=Math.min(20,P/1.65)}}else{if(typeof(u.tickLength)=="number"){u._tickLength=u.tickLength}else{u._tickLength=Math.min(10,P/3.5)}}for(var D=l;D<K;D++){m=p(J[D][0]);if(u.hlc){q=null;g=G(J[D][1]);Q=G(J[D][2]);t=G(J[D][3])}else{q=G(J[D][1]);g=G(J[D][2]);Q=G(J[D][3]);t=G(J[D][4])}y={};if(u.candleStick&&!u.hlc){n=u._bodyWidth;O=m-n/2;if(t<q){if(u.wickColor){y.color=u.wickColor}else{if(u.downBodyColor){y.color=u.upBodyColor}}f=a.extend(true,{},s,y);u.shapeRenderer.draw(A,[[m,g],[m,t]],f);u.shapeRenderer.draw(A,[[m,q],[m,Q]],f);y={};M=t;F=q-t;if(u.fillUpBody){y.fillRect=true}else{y.strokeRect=true;n=n-this.lineWidth;O=m-n/2}if(u.upBodyColor){y.color=u.upBodyColor;y.fillStyle=u.upBodyColor}C=[O,M,n,F]}else{if(t>q){if(u.wickColor){y.color=u.wickColor}else{if(u.downBodyColor){y.color=u.downBodyColor}}f=a.extend(true,{},s,y);u.shapeRenderer.draw(A,[[m,g],[m,q]],f);u.shapeRenderer.draw(A,[[m,t],[m,Q]],f);y={};M=q;F=t-q;if(u.fillDownBody){y.fillRect=true}else{y.strokeRect=true;n=n-this.lineWidth;O=m-n/2}if(u.downBodyColor){y.color=u.downBodyColor;y.fillStyle=u.downBodyColor}C=[O,M,n,F]}else{if(u.wickColor){y.color=u.wickColor}f=a.extend(true,{},s,y);u.shapeRenderer.draw(A,[[m,g],[m,Q]],f);y={};y.fillRect=false;y.strokeRect=false;O=[m-n/2,q];M=[m+n/2,t];n=null;F=null;C=[O,M]}}f=a.extend(true,{},s,y);u.shapeRenderer.draw(A,C,f)}else{E=s.color;if(u.openColor){s.color=u.openColor}if(!u.hlc){u.shapeRenderer.draw(A,[[m-u._tickLength,q],[m,q]],s)}s.color=E;if(u.wickColor){s.color=u.wickColor}u.shapeRenderer.draw(A,[[m,g],[m,Q]],s);s.color=E;if(u.closeColor){s.color=u.closeColor}u.shapeRenderer.draw(A,[[m,t],[m+u._tickLength,t]],s);s.color=E}}}A.restore()};a.jqplot.OHLCRenderer.prototype.drawShadow=function(b,d,c){};a.jqplot.OHLCRenderer.checkOptions=function(d,c,b){if(!b.highlighter){b.highlighter={showMarker:false,tooltipAxes:"y",yvalues:4,formatString:'<table class="jqplot-highlighter"><tr><td>date:</td><td>%s</td></tr><tr><td>open:</td><td>%s</td></tr><tr><td>hi:</td><td>%s</td></tr><tr><td>low:</td><td>%s</td></tr><tr><td>close:</td><td>%s</td></tr></table>'}}}})(jQuery);
|