dojo.provide("dojox.widget.BarGauge");
dojo.require("dojox.gfx");
dojo.require("dojox.widget.gauge._Gauge");
dojo.experimental("dojox.widget.BarGauge");
dojo.declare("dojox.widget.gauge.BarLineIndicator",[dojox.widget.gauge._Indicator],{
width: 1,
_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 BarIndicator).
if(!this._gauge){
return null;
}
var v = this.value;
if(v < this._gauge.min){v = this._gauge.min;}
if(v > this._gauge.max){v = this._gauge.max;}
var pos = this._gauge._getPosition(v);
var shapes = [];
if(this.width > 1){
shapes[0] = this._gauge.surface.createRect({
x:pos,
y:this._gauge.dataY + this.offset,
width:this.width,
height:this.length
});
shapes[0].setStroke({color: this.color});
shapes[0].setFill(this.color);
}else{
shapes[0] = this._gauge.surface.createLine({
x1:pos,
y1:this._gauge.dataY + this.offset,
x2:pos,
y2:this._gauge.dataY + this.offset + this.length
});
shapes[0].setStroke({color: this.color});
}
return shapes;
},
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)
var i;
if(this.shapes){
this._move(dontAnimate);
}else{
if(this.shapes){
for(i=0; i
this._gauge.surface.remove(this.shapes[i]);
}
this.shapes = null;
}
if(this.text){
this._gauge.surface.rawNode.removeChild(this.text);
this.text = null;
}
this.color = this.color || '#000000';
this.length = this.length || this._gauge.dataHeight;
this.width = this.width || 3;
this.offset = this.offset || 0;
this.highlight = this.highlight || '#4D4D4D';
this.highlight2 = this.highlight2 || '#A3A3A3';
this.shapes = this._getShapes(this._gauge, this);
if(this.label){
var v = this.value;
if(v < this._gauge.min){v = this._gauge.min;}
if(v > this._gauge.max){v = this._gauge.max;}
var pos = this._gauge._getPosition(v);
this.text = this._gauge.drawText(''+this.label, pos, this._gauge.dataY + this.offset - 5, 'middle','top', this.color, this.font);
}
for(i=0; i if(this.hover){
this.shapes[i].getEventSource().setAttribute('hover',this.hover);
}
if(this.onDragMove && !this.noChange){
this._gauge.connect(this.shapes[i].getEventSource(), 'onmousedown', this._gauge.handleMouseDown);
this.shapes[i].getEventSource().style.cursor = 'pointer';
}
}
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 = this.value ;
if(v < this.min){v = this.min;}
if(v > this.max){v = this.max;}
var c = this._gauge._getPosition(this.currentValue);
this.currentValue = v;
v = this._gauge._getPosition(v)-this._gauge.dataX;
if(dontAnimate){
this.shapes[0].applyTransform(dojox.gfx.matrix.translate(v-(this.shapes[0].matrix?this.shapes[0].matrix.dx:0),0));
}else{
var anim = new dojo.Animation({curve: [c, v], duration: this.duration, easing: this.easing});
dojo.connect(anim, "onAnimate", dojo.hitch(this, function(jump){
this.shapes[0].applyTransform(dojox.gfx.matrix.translate(jump-(this.shapes[0].matrix?this.shapes[0].matrix.dx:0),0));
}));
anim.play();
}
}
});
dojo.declare("dojox.widget.BarGauge",dojox.widget.gauge._Gauge,{
// summary:
// a bar graph 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 bar graph component, used to display numerical data in a familiar format.
//
// usage:
//
// ...
// // id="testBarGauge"
// barGaugeHeight="55"
// dataY="25"
// dataHeight="25"
// dataWidth="225">
//
// dataX: Number
// x position of data area (default 5)
dataX: 5,
// dataY: Number
// y position of data area (default 5)
dataY: 5,
// dataWidth: Number
// width of data area (default is bar graph width - 10)
dataWidth: 0,
// dataHeight: Number
// height of data area (default is bar graph width - 10)
dataHeight: 0,
// _defaultIndicator: override of dojox.widget._Gauge._defaultIndicator
_defaultIndicator: dojox.widget.gauge.BarLineIndicator,
startup: function(){
// handle settings from HTML by making sure all the options are
// converted correctly to numbers
//
// also connects mouse handling events
if(this.getChildren){
dojo.forEach(this.getChildren(), function(child){ child.startup(); });
}
if(!this.dataWidth){this.dataWidth = this.gaugeWidth - 10;}
if(!this.dataHeight){this.dataHeight = this.gaugeHeight - 10;}
this.inherited(arguments);