1 | define(["dojo/_base/declare","dojo/_base/fx","dojo/_base/connect","dojo/_base/lang","./BarLineIndicator"], |
---|
2 | function(declare, fx, connect, lang, BarLineIndicator) { |
---|
3 | |
---|
4 | /*===== |
---|
5 | BarLineIndicator = dojox.gauges.BarLineIndicator; |
---|
6 | =====*/ |
---|
7 | |
---|
8 | return declare("dojox.gauges.BarIndicator",[BarLineIndicator],{ |
---|
9 | |
---|
10 | // summary: |
---|
11 | // An indicator for the BarGauge that draws a bar corresponding to the indicator value. |
---|
12 | |
---|
13 | _getShapes: function(group){ |
---|
14 | // summary: |
---|
15 | // Override of dojox.gauges.BarLineIndicator._getShapes |
---|
16 | if(!this._gauge){ |
---|
17 | return null; |
---|
18 | } |
---|
19 | var v = this.value; |
---|
20 | if(v < this._gauge.min){v = this._gauge.min;} |
---|
21 | if(v > this._gauge.max){v = this._gauge.max;} |
---|
22 | var pos = this._gauge._getPosition(v); |
---|
23 | if(pos == this.dataX){pos = this.dataX+1;} |
---|
24 | var y = this._gauge.dataY + Math.floor((this._gauge.dataHeight - this.width)/2) + this.offset; |
---|
25 | |
---|
26 | var shapes = []; |
---|
27 | shapes[0] = group.createRect({x:this._gauge.dataX, y:y, width:pos - this._gauge.dataX, height:this.width}); |
---|
28 | shapes[0].setStroke({color: this.color}); |
---|
29 | shapes[0].setFill(this.color); |
---|
30 | shapes[1] = group.createLine({ x1:this._gauge.dataX, y1:y, x2:pos, y2:y }); |
---|
31 | shapes[1].setStroke({color: this.highlight}); |
---|
32 | if(this.highlight2){ |
---|
33 | y--; |
---|
34 | shapes[2] = group.createLine({ x1:this._gauge.dataX, y1:y, x2:pos, y2:y }); |
---|
35 | shapes[2].setStroke({color: this.highlight2}); |
---|
36 | } |
---|
37 | |
---|
38 | return shapes; |
---|
39 | }, |
---|
40 | _createShapes: function(val){ |
---|
41 | // summary: |
---|
42 | // Creates a shallow copy of the current shapes while adjusting for the new value |
---|
43 | for(var i in this.shape.children){ |
---|
44 | i = this.shape.children[i]; |
---|
45 | var newShape = {}; |
---|
46 | for(var j in i){ |
---|
47 | newShape[j] = i[j]; |
---|
48 | } |
---|
49 | if(i.shape.type == "line"){ |
---|
50 | newShape.shape.x2 = val+newShape.shape.x1; |
---|
51 | }else if(i.shape.type == "rect"){ |
---|
52 | newShape.width = val; |
---|
53 | } |
---|
54 | i.setShape(newShape); |
---|
55 | } |
---|
56 | }, |
---|
57 | _move: function(/*Boolean?*/ dontAnimate){ |
---|
58 | // summary: |
---|
59 | // Override of dojox.gauges.BarLineIndicator._move to resize the bar (rather than moving it) |
---|
60 | |
---|
61 | var c; |
---|
62 | var v = this.value ; |
---|
63 | if(v < this.min){v = this.min;} |
---|
64 | if(v > this.max){v = this.max;} |
---|
65 | c = this._gauge._getPosition(this.currentValue); |
---|
66 | this.currentValue = v; |
---|
67 | v = this._gauge._getPosition(v)-this._gauge.dataX; |
---|
68 | if(dontAnimate){ |
---|
69 | this._createShapes(v); |
---|
70 | }else{ |
---|
71 | if(c!=v){ |
---|
72 | var anim = new fx.Animation({curve: [c, v], duration: this.duration, easing: this.easing}); |
---|
73 | connect.connect(anim, "onAnimate", lang.hitch(this, this._createShapes)); |
---|
74 | anim.play(); |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | }); |
---|
79 | }); |
---|