dojo.provide("dojox.widget.AnalogGauge");
dojo.require("dojox.gfx");
dojo.require("dojox.widget.gauge._Gauge");
dojo.experimental("dojox.widget.AnalogGauge");
dojo.declare("dojox.widget.gauge.AnalogLineIndicator",[dojox.widget.gauge._Indicator],{
_getShapes: function(){
// summary:
// Private function for generating the shapes for this indicator. An indicator that behaves the
// same might override this one and simply replace the shapes (such as ArrowIndicator).
return [this._gauge.surface.createLine({x1: 0, y1: -this.offset,
x2: 0, y2: -this.length-this.offset})
.setStroke({color: this.color, width: this.width})];
},
draw: function(/*Boolean?*/ dontAnimate){
// summary:
// Override of dojox.widget.gauge._Indicator.draw
// dontAnimate: Boolean
// Indicates if the drawing should not be animated (vs. the default of doing an animation)
if(this.shapes){
this._move(dontAnimate);
}else{
if(this.text){
this._gauge.surface.rawNode.removeChild(this.text);
this.text = null;
}
var a = this._gauge._getAngle(Math.min(Math.max(this.value, this._gauge.min), this._gauge.max));
this.color = this.color || '#000000';
this.length = this.length || this._gauge.radius;
this.width = this.width || 1;
this.offset = this.offset || 0;
this.highlight = this.highlight || '#D0D0D0';
this.shapes = this._getShapes(this._gauge, this);
if(this.shapes){
for(var s = 0; s < this.shapes.length; s++){
this.shapes[s].setTransform([{dx:this._gauge.cx,dy:this._gauge.cy}, dojox.gfx.matrix.rotateg(a)]);
if(this.hover){
this.shapes[s].getEventSource().setAttribute('hover',this.hover);
}
if(this.onDragMove && !this.noChange){
//TODO
this._gauge.connect(this.shapes[s].getEventSource(), 'onmousedown', this._gauge.handleMouseDown);
this.shapes[s].getEventSource().style.cursor = 'pointer';
}
}
}
if(this.label){
var len=this.length+this.offset,
rad=this._gauge._getRadians(a),
x=this._gauge.cx+(len+5)*Math.sin(rad),
y=this._gauge.cy-(len+5)*Math.cos(rad),
align = 'start',
aa = Math.abs(a)
;
if(a <= -10){align = 'end';}
if(aa < 10){align='middle';}
var vAlign = 'bottom';
if(aa > 90){vAlign = 'top';}
this.text = this._gauge.drawText(''+this.label, x, y, align, vAlign, this.color, this.font);
}
this.currentValue = this.value;
}
},
_move: function(/*Boolean?*/ dontAnimate){
// summary:
// Moves this indicator (since it's already been drawn once)
// dontAnimate: Boolean
// Indicates if the drawing should not be animated (vs. the default of doing an animation)
var v = Math.min(Math.max(this.value, this._gauge.min), this._gauge.max),
c = this.currentValue
;
if(dontAnimate){
var angle = this._gauge._getAngle(v);
for(var i in this.shapes){
this.shapes[i].setTransform([{dx:this._gauge.cx,dy:this._gauge.cy}, dojox.gfx.matrix.rotateg(angle)]);
if(this.hover){
this.shapes[i].getEventSource().setAttribute('hover',this.hover);
}
}
}else{
if(c!=v){
var anim = new dojo.Animation({curve: [c, v], duration: this.duration, easing: this.easing});
dojo.connect(anim, "onAnimate", dojo.hitch(this, function(step){
for(var i in this.shapes){
this.shapes[i].setTransform([{dx:this._gauge.cx,dy:this._gauge.cy}, dojox.gfx.matrix.rotateg(this._gauge._getAngle(step))]);
if(this.hover){
this.shapes[i].getEventSource().setAttribute('hover',this.hover);
}
}
this.currentValue = step;
}));
anim.play();
}
}
}
});
dojo.declare("dojox.widget.AnalogGauge",dojox.widget.gauge._Gauge,{
// summary:
// a gauge built using the dojox.gfx package.
//
// description:
// using dojo.gfx (and thus either SVG or VML based on what is supported), this widget
// builds a gauge component, used to display numerical data in a familiar format
//
// usage:
//
// ...
//
// id="testGauge"
// width="300"
// height="200"
// cx=150
// cy=175
// radius=125
// image="gaugeOverlay.png"
// imageOverlay="false"
// imageWidth="280"
// imageHeight="155"
// imageX="12"
// imageY="38">
//