root / trunk / web / dojo / dojox / charting / plot2d / Candlesticks.js @ 12
History | View | Annotate | Download (4.28 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dojox.charting.plot2d.Candlesticks"]){ |
| 9 |
dojo._hasResource["dojox.charting.plot2d.Candlesticks"]=true; |
| 10 |
dojo.provide("dojox.charting.plot2d.Candlesticks");
|
| 11 |
dojo.require("dojox.charting.plot2d.common");
|
| 12 |
dojo.require("dojox.charting.plot2d.Base");
|
| 13 |
dojo.require("dojox.lang.utils");
|
| 14 |
dojo.require("dojox.lang.functional");
|
| 15 |
dojo.require("dojox.lang.functional.reversed");
|
| 16 |
(function(){
|
| 17 |
var df=dojox.lang.functional,du=dojox.lang.utils,dc=dojox.charting.plot2d.common,_1=df.lambda("item.purgeGroup()"); |
| 18 |
dojo.declare("dojox.charting.plot2d.Candlesticks",dojox.charting.plot2d.Base,{defaultParams:{hAxis:"x",vAxis:"y",gap:2,animate:null},optionalParams:{minBarSize:1,maxBarSize:1,stroke:{},outline:{},shadow:{},fill:{},font:"",fontColor:""},constructor:function(_2,_3){ |
| 19 |
this.opt=dojo.clone(this.defaultParams); |
| 20 |
du.updateWithObject(this.opt,_3);
|
| 21 |
du.updateWithPattern(this.opt,_3,this.optionalParams); |
| 22 |
this.series=[];
|
| 23 |
this.hAxis=this.opt.hAxis; |
| 24 |
this.vAxis=this.opt.vAxis; |
| 25 |
this.animate=this.opt.animate; |
| 26 |
},collectStats:function(_4){ |
| 27 |
var _5=dojo.delegate(dc.defaultStats);
|
| 28 |
for(var i=0;i<_4.length;i++){ |
| 29 |
var _6=_4[i];
|
| 30 |
if(!_6.data.length){
|
| 31 |
continue;
|
| 32 |
} |
| 33 |
var _7=_5.vmin,_8=_5.vmax;
|
| 34 |
if(!("ymin" in _6)||!("ymax" in _6)){ |
| 35 |
dojo.forEach(_6.data,function(_9,_a){
|
| 36 |
if(_9!==null){ |
| 37 |
var x=_9.x||_a+1; |
| 38 |
_5.hmin=Math.min(_5.hmin,x); |
| 39 |
_5.hmax=Math.max(_5.hmax,x); |
| 40 |
_5.vmin=Math.min(_5.vmin,_9.open,_9.close,_9.high,_9.low); |
| 41 |
_5.vmax=Math.max(_5.vmax,_9.open,_9.close,_9.high,_9.low); |
| 42 |
} |
| 43 |
}); |
| 44 |
} |
| 45 |
if("ymin" in _6){ |
| 46 |
_5.vmin=Math.min(_7,_6.ymin); |
| 47 |
} |
| 48 |
if("ymax" in _6){ |
| 49 |
_5.vmax=Math.max(_8,_6.ymax); |
| 50 |
} |
| 51 |
} |
| 52 |
return _5;
|
| 53 |
},getSeriesStats:function(){ |
| 54 |
var _b=this.collectStats(this.series); |
| 55 |
_b.hmin-=0.5;
|
| 56 |
_b.hmax+=0.5;
|
| 57 |
return _b;
|
| 58 |
},render:function(_c,_d){ |
| 59 |
if(this.zoom&&!this.isDataDirty()){ |
| 60 |
return this.performZoom(_c,_d); |
| 61 |
} |
| 62 |
this.resetEvents();
|
| 63 |
this.dirty=this.isDirty(); |
| 64 |
if(this.dirty){ |
| 65 |
dojo.forEach(this.series,_1);
|
| 66 |
this._eventSeries={};
|
| 67 |
this.cleanGroup();
|
| 68 |
var s=this.group; |
| 69 |
df.forEachRev(this.series,function(_e){ |
| 70 |
_e.cleanGroup(s); |
| 71 |
}); |
| 72 |
} |
| 73 |
var t=this.chart.theme,f,_f,_10,ht=this._hScaler.scaler.getTransformerFromModel(this._hScaler),vt=this._vScaler.scaler.getTransformerFromModel(this._vScaler),_11=Math.max(0,this._vScaler.bounds.lower),_12=vt(_11),_13=this.events(); |
| 74 |
f=dc.calculateBarSize(this._hScaler.bounds.scale,this.opt); |
| 75 |
_f=f.gap; |
| 76 |
_10=f.size; |
| 77 |
for(var i=this.series.length-1;i>=0;--i){ |
| 78 |
var run=this.series[i]; |
| 79 |
if(!this.dirty&&!run.dirty){ |
| 80 |
t.skip(); |
| 81 |
this._reconnectEvents(run.name);
|
| 82 |
continue;
|
| 83 |
} |
| 84 |
run.cleanGroup(); |
| 85 |
var _14=t.next("candlestick",[this.opt,run]),s=run.group,_15=new Array(run.data.length); |
| 86 |
for(var j=0;j<run.data.length;++j){ |
| 87 |
var v=run.data[j];
|
| 88 |
if(v!==null){ |
| 89 |
var _16=t.addMixin(_14,"candlestick",v,true); |
| 90 |
var x=ht(v.x||(j+0.5))+_d.l+_f,y=_c.height-_d.b,_17=vt(v.open),_18=vt(v.close),_19=vt(v.high),low=vt(v.low); |
| 91 |
if("mid" in v){ |
| 92 |
var mid=vt(v.mid);
|
| 93 |
} |
| 94 |
if(low>_19){
|
| 95 |
var tmp=_19;
|
| 96 |
_19=low; |
| 97 |
low=tmp; |
| 98 |
} |
| 99 |
if(_10>=1){ |
| 100 |
var _1a=_17>_18;
|
| 101 |
var _1b={x1:_10/2,x2:_10/2,y1:y-_19,y2:y-low},_1c={x:0,y:y-Math.max(_17,_18),width:_10,height:Math.max(_1a?_17-_18:_18-_17,1)}; |
| 102 |
shape=s.createGroup(); |
| 103 |
shape.setTransform({dx:x,dy:0});
|
| 104 |
var _1d=shape.createGroup();
|
| 105 |
_1d.createLine(_1b).setStroke(_16.series.stroke); |
| 106 |
_1d.createRect(_1c).setStroke(_16.series.stroke).setFill(_1a?_16.series.fill:"white");
|
| 107 |
if("mid" in v){ |
| 108 |
_1d.createLine({x1:(_16.series.stroke.width||1),x2:_10-(_16.series.stroke.width||1),y1:y-mid,y2:y-mid}).setStroke(_1a?"white":_16.series.stroke);
|
| 109 |
} |
| 110 |
run.dyn.fill=_16.series.fill; |
| 111 |
run.dyn.stroke=_16.series.stroke; |
| 112 |
if(_13){
|
| 113 |
var o={element:"candlestick",index:j,run:run,shape:_1d,x:x,y:y-Math.max(_17,_18),cx:_10/2,cy:(y-Math.max(_17,_18))+(Math.max(_1a?_17-_18:_18-_17,1)/2),width:_10,height:Math.max(_1a?_17-_18:_18-_17,1),data:v}; |
| 114 |
this._connectEvents(o);
|
| 115 |
_15[j]=o; |
| 116 |
} |
| 117 |
} |
| 118 |
if(this.animate){ |
| 119 |
this._animateCandlesticks(shape,y-low,_19-low);
|
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
this._eventSeries[run.name]=_15;
|
| 124 |
run.dirty=false;
|
| 125 |
} |
| 126 |
this.dirty=false; |
| 127 |
return this; |
| 128 |
},_animateCandlesticks:function(_1e,_1f,_20){ |
| 129 |
dojox.gfx.fx.animateTransform(dojo.delegate({shape:_1e,duration:1200,transform:[{name:"translate",start:[0,_1f-(_1f/_20)],end:[0,0]},{name:"scale",start:[1,1/_20],end:[1,1]},{name:"original"}]},this.animate)).play();
|
| 130 |
}}); |
| 131 |
})(); |
| 132 |
} |