OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / scripts / jquery / jqplot / plugins / jqplot.ohlcRenderer.min.js
1 /**
2  * Copyright (c) 2009 - 2010 Chris Leonello
3  * jqPlot is currently available for use in all personal or commercial projects 
4  * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL 
5  * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can 
6  * choose the license that best suits your project and use it accordingly. 
7  *
8  * Although not required, the author would appreciate an email letting him 
9  * know of any substantial use of jqPlot.  You can reach the author at: 
10  * chris at jqplot  or see http://www.jqplot.com/info.php .
11  *
12  * If you are feeling kind and generous, consider supporting the project by
13  * making a donation at: http://www.jqplot.com/donate.php .
14  *
15  * jqPlot includes date instance methods and printf/sprintf functions by other authors:
16  *
17  * Date instance methods contained in jqplot.dateMethods.js:
18  *
19  *     author Ken Snyder (ken d snyder at gmail dot com)
20  *     date 2008-09-10
21  *     version 2.0.2 (http://kendsnyder.com/sandbox/date/)     
22  *     license Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
23  *
24  * JavaScript printf/sprintf functions contained in jqplot.sprintf.js:
25  *
26  *     version 2007.04.27
27  *     author Ash Searle
28  *     http://hexmen.com/blog/2007/03/printf-sprintf/
29  *     http://hexmen.com/js/sprintf.js
30  *     The author (Ash Searle) has placed this code in the public domain:
31  *     "This code is unrestricted: you are free to use it however you like."
32  * 
33  */
34 (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._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){this.lineWidth=1.5;a.jqplot.LineRenderer.prototype.init.call(this,e);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(z,J,g){var G=this.data;var u=this._xaxis.min;var y=this._xaxis.max;var k=0;var H=G.length;var n=this._xaxis.series_u2p;var F=this._yaxis.series_u2p;var C,D,e,I,E,m,K,B;var v;var t=this.renderer;var q=(g!=undefined)?g:{};var j=(q.shadow!=undefined)?q.shadow:this.shadow;var A=(q.fill!=undefined)?q.fill:this.fill;var c=(q.fillAndStroke!=undefined)?q.fillAndStroke:this.fillAndStroke;t.bodyWidth=(q.bodyWidth!=undefined)?q.bodyWidth:t.bodyWidth;t.tickLength=(q.tickLength!=undefined)?q.tickLength:t.tickLength;z.save();if(this.show){var l,p,f,L,s;for(var C=0;C<G.length;C++){if(G[C][0]<u){k=C}else{if(G[C][0]<y){H=C+1}}}if(t.candleStick){if(typeof(t.bodyWidth)=="number"){t._bodyWidth=t.bodyWidth}else{t._bodyWidth=Math.min(20,z.canvas.width/(H-k)/2)}}else{if(typeof(t.tickLength)=="number"){t._tickLength=t.tickLength}else{t._tickLength=Math.min(10,z.canvas.width/(H-k)/4)}}for(var C=k;C<H;C++){l=n(G[C][0]);if(t.hlc){p=null;f=F(G[C][1]);L=F(G[C][2]);s=F(G[C][3])}else{p=F(G[C][1]);f=F(G[C][2]);L=F(G[C][3]);s=F(G[C][4])}v={};if(t.candleStick&&!t.hlc){m=t._bodyWidth;K=l-m/2;if(s<p){if(t.wickColor){v.color=t.wickColor}else{if(t.downBodyColor){v.color=t.upBodyColor}}e=a.extend(true,{},q,v);t.shapeRenderer.draw(z,[[l,f],[l,s]],e);t.shapeRenderer.draw(z,[[l,p],[l,L]],e);v={};I=s;E=p-s;if(t.fillUpBody){v.fillRect=true}else{v.strokeRect=true;m=m-this.lineWidth;K=l-m/2}if(t.upBodyColor){v.color=t.upBodyColor;v.fillStyle=t.upBodyColor}B=[K,I,m,E]}else{if(s>p){if(t.wickColor){v.color=t.wickColor}else{if(t.downBodyColor){v.color=t.downBodyColor}}e=a.extend(true,{},q,v);t.shapeRenderer.draw(z,[[l,f],[l,p]],e);t.shapeRenderer.draw(z,[[l,s],[l,L]],e);v={};I=p;E=s-p;if(t.fillDownBody){v.fillRect=true}else{v.strokeRect=true;m=m-this.lineWidth;K=l-m/2}if(t.downBodyColor){v.color=t.downBodyColor;v.fillStyle=t.downBodyColor}B=[K,I,m,E]}else{if(t.wickColor){v.color=t.wickColor}e=a.extend(true,{},q,v);t.shapeRenderer.draw(z,[[l,f],[l,L]],e);v={};v.fillRect=false;v.strokeRect=false;K=[l-m/2,p];I=[l+m/2,s];m=null;E=null;B=[K,I]}}e=a.extend(true,{},q,v);t.shapeRenderer.draw(z,B,e)}else{D=q.color;if(t.openColor){q.color=t.openColor}if(!t.hlc){t.shapeRenderer.draw(z,[[l-t._tickLength,p],[l,p]],q)}q.color=D;if(t.wickColor){q.color=t.wickColor}t.shapeRenderer.draw(z,[[l,f],[l,L]],q);q.color=D;if(t.closeColor){q.color=t.closeColor}t.shapeRenderer.draw(z,[[l,s],[l+t._tickLength,s]],q);q.color=D}}}z.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);