Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / charting / plot2d / Grid.js

History | View | Annotate | Download (4.45 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.Grid"]){
9
dojo._hasResource["dojox.charting.plot2d.Grid"]=true;
10
dojo.provide("dojox.charting.plot2d.Grid");
11
dojo.require("dojox.charting.Element");
12
dojo.require("dojox.charting.plot2d.common");
13
dojo.require("dojox.lang.functional");
14
dojo.require("dojox.lang.utils");
15
(function(){
16
var du=dojox.lang.utils,dc=dojox.charting.plot2d.common;
17
dojo.declare("dojox.charting.plot2d.Grid",dojox.charting.Element,{defaultParams:{hAxis:"x",vAxis:"y",hMajorLines:true,hMinorLines:false,vMajorLines:true,vMinorLines:false,hStripes:"none",vStripes:"none",animate:null},optionalParams:{},constructor:function(_1,_2){
18
this.opt=dojo.clone(this.defaultParams);
19
du.updateWithObject(this.opt,_2);
20
this.hAxis=this.opt.hAxis;
21
this.vAxis=this.opt.vAxis;
22
this.dirty=true;
23
this.animate=this.opt.animate;
24
this.zoom=null,this.zoomQueue=[];
25
this.lastWindow={vscale:1,hscale:1,xoffset:0,yoffset:0};
26
},clear:function(){
27
this._hAxis=null;
28
this._vAxis=null;
29
this.dirty=true;
30
return this;
31
},setAxis:function(_3){
32
if(_3){
33
this[_3.vertical?"_vAxis":"_hAxis"]=_3;
34
}
35
return this;
36
},addSeries:function(_4){
37
return this;
38
},getSeriesStats:function(){
39
return dojo.delegate(dc.defaultStats);
40
},initializeScalers:function(){
41
return this;
42
},isDirty:function(){
43
return this.dirty||this._hAxis&&this._hAxis.dirty||this._vAxis&&this._vAxis.dirty;
44
},performZoom:function(_5,_6){
45
var vs=this._vAxis.scale||1,hs=this._hAxis.scale||1,_7=_5.height-_6.b,_8=this._hAxis.getScaler().bounds,_9=(_8.from-_8.lower)*_8.scale,_a=this._vAxis.getScaler().bounds,_b=(_a.from-_a.lower)*_a.scale;
46
rVScale=vs/this.lastWindow.vscale,rHScale=hs/this.lastWindow.hscale,rXOffset=(this.lastWindow.xoffset-_9)/((this.lastWindow.hscale==1)?hs:this.lastWindow.hscale),rYOffset=(_b-this.lastWindow.yoffset)/((this.lastWindow.vscale==1)?vs:this.lastWindow.vscale),shape=this.group,anim=dojox.gfx.fx.animateTransform(dojo.delegate({shape:shape,duration:1200,transform:[{name:"translate",start:[0,0],end:[_6.l*(1-rHScale),_7*(1-rVScale)]},{name:"scale",start:[1,1],end:[rHScale,rVScale]},{name:"original"},{name:"translate",start:[0,0],end:[rXOffset,rYOffset]}]},this.zoom));
47
dojo.mixin(this.lastWindow,{vscale:vs,hscale:hs,xoffset:_9,yoffset:_b});
48
this.zoomQueue.push(anim);
49
dojo.connect(anim,"onEnd",this,function(){
50
this.zoom=null;
51
this.zoomQueue.shift();
52
if(this.zoomQueue.length>0){
53
this.zoomQueue[0].play();
54
}
55
});
56
if(this.zoomQueue.length==1){
57
this.zoomQueue[0].play();
58
}
59
return this;
60
},getRequiredColors:function(){
61
return 0;
62
},render:function(_c,_d){
63
if(this.zoom){
64
return this.performZoom(_c,_d);
65
}
66
this.dirty=this.isDirty();
67
if(!this.dirty){
68
return this;
69
}
70
this.cleanGroup();
71
var s=this.group,ta=this.chart.theme.axis;
72
try{
73
var _e=this._vAxis.getScaler(),vt=_e.scaler.getTransformerFromModel(_e),_f=this._vAxis.getTicks();
74
if(this.opt.hMinorLines){
75
dojo.forEach(_f.minor,function(_10){
76
var y=_c.height-_d.b-vt(_10.value);
77
var _11=s.createLine({x1:_d.l,y1:y,x2:_c.width-_d.r,y2:y}).setStroke(ta.minorTick);
78
if(this.animate){
79
this._animateGrid(_11,"h",_d.l,_d.r+_d.l-_c.width);
80
}
81
},this);
82
}
83
if(this.opt.hMajorLines){
84
dojo.forEach(_f.major,function(_12){
85
var y=_c.height-_d.b-vt(_12.value);
86
var _13=s.createLine({x1:_d.l,y1:y,x2:_c.width-_d.r,y2:y}).setStroke(ta.majorTick);
87
if(this.animate){
88
this._animateGrid(_13,"h",_d.l,_d.r+_d.l-_c.width);
89
}
90
},this);
91
}
92
}
93
catch(e){
94
}
95
try{
96
var _14=this._hAxis.getScaler(),ht=_14.scaler.getTransformerFromModel(_14),_f=this._hAxis.getTicks();
97
if(_f&&this.opt.vMinorLines){
98
dojo.forEach(_f.minor,function(_15){
99
var x=_d.l+ht(_15.value);
100
var _16=s.createLine({x1:x,y1:_d.t,x2:x,y2:_c.height-_d.b}).setStroke(ta.minorTick);
101
if(this.animate){
102
this._animateGrid(_16,"v",_c.height-_d.b,_c.height-_d.b-_d.t);
103
}
104
},this);
105
}
106
if(_f&&this.opt.vMajorLines){
107
dojo.forEach(_f.major,function(_17){
108
var x=_d.l+ht(_17.value);
109
var _18=s.createLine({x1:x,y1:_d.t,x2:x,y2:_c.height-_d.b}).setStroke(ta.majorTick);
110
if(this.animate){
111
this._animateGrid(_18,"v",_c.height-_d.b,_c.height-_d.b-_d.t);
112
}
113
},this);
114
}
115
}
116
catch(e){
117
}
118
this.dirty=false;
119
return this;
120
},_animateGrid:function(_19,_1a,_1b,_1c){
121
var _1d=_1a=="h"?[_1b,0]:[0,_1b];
122
var _1e=_1a=="h"?[1/_1c,1]:[1,1/_1c];
123
dojox.gfx.fx.animateTransform(dojo.delegate({shape:_19,duration:1200,transform:[{name:"translate",start:_1d,end:[0,0]},{name:"scale",start:_1e,end:[1,1]},{name:"original"}]},this.animate)).play();
124
}});
125
})();
126
}