Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / widget / BarGauge.js @ 12

History | View | Annotate | Download (5.16 KB)

1 9 andrej.cim
/*
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.widget.BarGauge"]){
9
dojo._hasResource["dojox.widget.BarGauge"]=true;
10
dojo.provide("dojox.widget.BarGauge");
11
dojo.require("dojox.gfx");
12
dojo.require("dojox.widget.gauge._Gauge");
13
dojo.experimental("dojox.widget.BarGauge");
14
dojo.declare("dojox.widget.gauge.BarLineIndicator",[dojox.widget.gauge._Indicator],{width:1,_getShapes:function(){
15
if(!this._gauge){
16
return null;
17
}
18
var v=this.value;
19
if(v<this._gauge.min){
20
v=this._gauge.min;
21
}
22
if(v>this._gauge.max){
23
v=this._gauge.max;
24
}
25
var _1=this._gauge._getPosition(v);
26
var _2=[];
27
if(this.width>1){
28
_2[0]=this._gauge.surface.createRect({x:_1,y:this._gauge.dataY+this.offset,width:this.width,height:this.length});
29
_2[0].setStroke({color:this.color});
30
_2[0].setFill(this.color);
31
}else{
32
_2[0]=this._gauge.surface.createLine({x1:_1,y1:this._gauge.dataY+this.offset,x2:_1,y2:this._gauge.dataY+this.offset+this.length});
33
_2[0].setStroke({color:this.color});
34
}
35
return _2;
36
},draw:function(_3){
37
var i;
38
if(this.shapes){
39
this._move(_3);
40
}else{
41
if(this.shapes){
42
for(i=0;i<this.shapes.length;i++){
43
this._gauge.surface.remove(this.shapes[i]);
44
}
45
this.shapes=null;
46
}
47
if(this.text){
48
this._gauge.surface.rawNode.removeChild(this.text);
49
this.text=null;
50
}
51
this.color=this.color||"#000000";
52
this.length=this.length||this._gauge.dataHeight;
53
this.width=this.width||3;
54
this.offset=this.offset||0;
55
this.highlight=this.highlight||"#4D4D4D";
56
this.highlight2=this.highlight2||"#A3A3A3";
57
this.shapes=this._getShapes(this._gauge,this);
58
if(this.label){
59
var v=this.value;
60
if(v<this._gauge.min){
61
v=this._gauge.min;
62
}
63
if(v>this._gauge.max){
64
v=this._gauge.max;
65
}
66
var _4=this._gauge._getPosition(v);
67
this.text=this._gauge.drawText(""+this.label,_4,this._gauge.dataY+this.offset-5,"middle","top",this.color,this.font);
68
}
69
for(i=0;i<this.shapes.length;i++){
70
if(this.hover){
71
this.shapes[i].getEventSource().setAttribute("hover",this.hover);
72
}
73
if(this.onDragMove&&!this.noChange){
74
this._gauge.connect(this.shapes[i].getEventSource(),"onmousedown",this._gauge.handleMouseDown);
75
this.shapes[i].getEventSource().style.cursor="pointer";
76
}
77
}
78
this.currentValue=this.value;
79
}
80
},_move:function(_5){
81
var v=this.value;
82
if(v<this.min){
83
v=this.min;
84
}
85
if(v>this.max){
86
v=this.max;
87
}
88
var c=this._gauge._getPosition(this.currentValue);
89
this.currentValue=v;
90
v=this._gauge._getPosition(v)-this._gauge.dataX;
91
if(_5){
92
this.shapes[0].applyTransform(dojox.gfx.matrix.translate(v-(this.shapes[0].matrix?this.shapes[0].matrix.dx:0),0));
93
}else{
94
var _6=new dojo.Animation({curve:[c,v],duration:this.duration,easing:this.easing});
95
dojo.connect(_6,"onAnimate",dojo.hitch(this,function(_7){
96
this.shapes[0].applyTransform(dojox.gfx.matrix.translate(_7-(this.shapes[0].matrix?this.shapes[0].matrix.dx:0),0));
97
}));
98
_6.play();
99
}
100
}});
101
dojo.declare("dojox.widget.BarGauge",dojox.widget.gauge._Gauge,{dataX:5,dataY:5,dataWidth:0,dataHeight:0,_defaultIndicator:dojox.widget.gauge.BarLineIndicator,startup:function(){
102
if(this.getChildren){
103
dojo.forEach(this.getChildren(),function(_8){
104
_8.startup();
105
});
106
}
107
if(!this.dataWidth){
108
this.dataWidth=this.gaugeWidth-10;
109
}
110
if(!this.dataHeight){
111
this.dataHeight=this.gaugeHeight-10;
112
}
113
this.inherited(arguments);
114
},_getPosition:function(_9){
115
return this.dataX+Math.floor((_9-this.min)/(this.max-this.min)*this.dataWidth);
116
},_getValueForPosition:function(_a){
117
return (_a-this.dataX)*(this.max-this.min)/this.dataWidth+this.min;
118
},draw:function(){
119
if(!this.surface){
120
this.createSurface();
121
}
122
var i;
123
if(this._rangeData){
124
for(i=0;i<this._rangeData.length;i++){
125
this.drawRange(this._rangeData[i]);
126
}
127
if(this._img&&this.image.overlay){
128
this._img.moveToFront();
129
}
130
}
131
if(this._indicatorData){
132
for(i=0;i<this._indicatorData.length;i++){
133
this._indicatorData[i].draw();
134
}
135
}
136
},drawRange:function(_b){
137
if(_b.shape){
138
this.surface.remove(_b.shape);
139
_b.shape=null;
140
}
141
var x1=this._getPosition(_b.low);
142
var x2=this._getPosition(_b.high);
143
var _c=this.surface.createRect({x:x1,y:this.dataY,width:x2-x1,height:this.dataHeight});
144
if(dojo.isArray(_b.color)||dojo.isString(_b.color)){
145
_c.setStroke({color:_b.color});
146
_c.setFill(_b.color);
147
}else{
148
if(_b.color.type){
149
var y=this.dataY+this.dataHeight/2;
150
_b.color.x1=x1;
151
_b.color.x2=x2;
152
_b.color.y1=y;
153
_b.color.y2=y;
154
_c.setFill(_b.color);
155
_c.setStroke({color:_b.color.colors[0].color});
156
}else{
157
_c.setStroke({color:"green"});
158
_c.setFill("green");
159
_c.getEventSource().setAttribute("class",_b.color.style);
160
}
161
}
162
if(_b.hover){
163
_c.getEventSource().setAttribute("hover",_b.hover);
164
}
165
_b.shape=_c;
166
},getRangeUnderMouse:function(_d){
167
var _e=null;
168
var _f=dojo.coords(this.gaugeContent);
169
var x=_d.clientX-_f.x;
170
var _10=this._getValueForPosition(x);
171
if(this._rangeData){
172
for(var i=0;(i<this._rangeData.length)&&!_e;i++){
173
if((Number(this._rangeData[i].low)<=_10)&&(Number(this._rangeData[i].high)>=_10)){
174
_e=this._rangeData[i];
175
}
176
}
177
}
178
return _e;
179
},_dragIndicator:function(_11,_12){
180
var pos=dojo.coords(_11.gaugeContent);
181
var x=_12.clientX-pos.x;
182
var _13=_11._getValueForPosition(x);
183
if(_13<_11.min){
184
_13=_11.min;
185
}
186
if(_13>_11.max){
187
_13=_11.max;
188
}
189
_11._drag.value=_13;
190
_11._drag.onDragMove(_11._drag);
191
_11._drag.draw(true);
192
dojo.stopEvent(_12);
193
}});
194
}