root / trunk / web / dojo / dojox / charting / plot2d / OHLC.js @ 12
History | View | Annotate | Download (4.07 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.OHLC"]){ |
9 |
dojo._hasResource["dojox.charting.plot2d.OHLC"]=true; |
10 |
dojo.provide("dojox.charting.plot2d.OHLC");
|
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.OHLC",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(low>_19){
|
92 |
var tmp=_19;
|
93 |
_19=low; |
94 |
low=tmp; |
95 |
} |
96 |
if(_10>=1){ |
97 |
var hl={x1:_10/2,x2:_10/2,y1:y-_19,y2:y-low},op={x1:0,x2:((_10/2)+((_16.series.stroke.width||1)/2)),y1:y-_17,y2:y-_17},cl={x1:((_10/2)-((_16.series.stroke.width||1)/2)),x2:_10,y1:y-_18,y2:y-_18}; |
98 |
shape=s.createGroup(); |
99 |
shape.setTransform({dx:x,dy:0}); |
100 |
var _1a=shape.createGroup();
|
101 |
_1a.createLine(hl).setStroke(_16.series.stroke); |
102 |
_1a.createLine(op).setStroke(_16.series.stroke); |
103 |
_1a.createLine(cl).setStroke(_16.series.stroke); |
104 |
run.dyn.stroke=_16.series.stroke; |
105 |
if(_13){
|
106 |
var o={element:"candlestick",index:j,run:run,shape:_1a,x:x,y:y-Math.max(_17,_18),cx:_10/2,cy:(y-Math.max(_17,_18))+(Math.max(_17>_18?_17-_18:_18-_17,1)/2),width:_10,height:Math.max(_17>_18?_17-_18:_18-_17,1),data:v}; |
107 |
this._connectEvents(o);
|
108 |
_15[j]=o; |
109 |
} |
110 |
} |
111 |
if(this.animate){ |
112 |
this._animateOHLC(shape,y-low,_19-low);
|
113 |
} |
114 |
} |
115 |
} |
116 |
this._eventSeries[run.name]=_15;
|
117 |
run.dirty=false;
|
118 |
} |
119 |
this.dirty=false; |
120 |
return this; |
121 |
},_animateOHLC:function(_1b,_1c,_1d){ |
122 |
dojox.gfx.fx.animateTransform(dojo.delegate({shape:_1b,duration:1200,transform:[{name:"translate",start:[0,_1c-(_1c/_1d)],end:[0,0]},{name:"scale",start:[1,1/_1d],end:[1,1]},{name:"original"}]},this.animate)).play(); |
123 |
}}); |
124 |
})(); |
125 |
} |