source: Dev/trunk/src/client/dojox/gauges/BarLineIndicator.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 4.2 KB
Line 
1define(["dojo/_base/declare","dojo/_base/fx","dojo/_base/connect","dojo/_base/lang", "dojox/gfx", "./_Indicator"],
2  function(declare, fx, connect, lang, gfx, Indicator) {
3
4return declare("dojox.gauges.BarLineIndicator",[Indicator],{
5       
6        // summary:
7        //              An indicator for the BarGauge that draws a segment a line corresponding to the indicator value.
8       
9        width: 1,
10        _getShapes: function(/*dojox.gfx.Group*/ group){
11                // summary:
12                //              Private function for generating the shapes for this indicator. An indicator that behaves the
13                //              same might override this one and simply replace the shapes (such as BarIndicator).
14                if(!this._gauge){
15                        return null;
16                }
17                var v = this.value;
18                if(v < this._gauge.min){v = this._gauge.min;}
19                if(v > this._gauge.max){v = this._gauge.max;}
20                var pos = this._gauge._getPosition(v);
21                var shapes = [];
22                if(this.width > 1){
23                        shapes[0] = group.createRect({
24                                x:0,
25                                y:this._gauge.dataY + this.offset,
26                                width:this.width,
27                                height:this.length
28                        });
29                        shapes[0].setStroke({color: this.color});
30                        shapes[0].setFill(this.color);
31                        shapes[0].setTransform(gfx.matrix.translate(pos,0));
32                }else{
33                        shapes[0] = group.createLine({
34                                x1:0,
35                                y1:this._gauge.dataY + this.offset,
36                                x2:0,
37                                y2:this._gauge.dataY + this.offset + this.length
38                        });
39                        shapes[0].setStroke({color: this.color});
40                        shapes[0].setTransform(gfx.matrix.translate(pos,0));
41                }
42                return shapes;
43        },
44        draw: function(/*dojox.gfx.Group*/group, /*Boolean?*/ dontAnimate){
45                // summary:
46                //              Override of dojox.gauges._Indicator.draw
47                // dontAnimate: Boolean
48                //              Indicates if the drawing should not be animated (vs. the default of doing an animation)
49                var i;
50                if (this.shape){
51                        this._move(dontAnimate);
52                }else{
53                        if (this.shape){
54                                this.shape.parent.remove(this.shape);
55                                this.shape = null;
56                        }
57                        if (this.text){
58                                this.text.parent.remove(this.text);
59                                this.text = null;
60                        }
61                       
62                        this.color = this.color || '#000000';
63                        this.length = this.length || this._gauge.dataHeight;
64                        this.width = this.width || 3;
65                        this.offset = this.offset || 0;
66                        this.highlight = this.highlight || '#4D4D4D';
67                        this.highlight2 = this.highlight2 || '#A3A3A3';
68                       
69                        var shapes = this._getShapes(group, this._gauge, this);
70                       
71                        if (shapes.length > 1){
72                                this.shape = group.createGroup();
73                                for (var s = 0; s < shapes.length; s++){
74                                        this.shape.add(shapes[s]);
75                                }
76                        } else this.shape = shapes[0];
77                       
78                        if (this.label){
79                                var v = this.value;
80                                if (v < this._gauge.min){
81                                        v = this._gauge.min;
82                                }
83                                if (v > this._gauge.max){
84                                        v = this._gauge.max;
85                                }
86                                var pos = this._gauge._getPosition(v);
87                               
88                                if (this.direction == 'inside'){
89                                        var font = this.font ? this.font : gfx.defaultFont;
90                                        var fz = font.size;
91                                        var th = gfx.normalizedLength(fz);
92                                       
93                                        this.text = this._gauge.drawText(group, '' + this.label, pos, this._gauge.dataY + this.offset + this.length + 5 + th, 'middle', this.color, this.font);
94                                } else this.text = this._gauge.drawText(group, '' + this.label, pos, this._gauge.dataY + this.offset - 5, 'middle', this.color, this.font);
95                        }
96                       
97                        this.shape.connect("onmouseover", this, this.handleMouseOver);
98                        this.shape.connect("onmouseout", this, this.handleMouseOut);
99                        this.shape.connect("onmousedown", this, this.handleMouseDown);
100                        this.shape.connect("touchstart", this, this.handleTouchStart);
101                        this.currentValue = this.value;
102                }
103        },
104       
105        _move: function(/*Boolean?*/ dontAnimate){
106                // summary:
107                //              Moves this indicator (since it's already been drawn once)
108                // dontAnimate: Boolean
109                //              Indicates if the drawing should not be animated (vs. the default of doing an animation)
110                var v = this.value ;
111                if(v < this._gauge.min){v = this._gauge.min;}
112                if(v > this._gauge.max){v = this._gauge.max;}
113                var c = this._gauge._getPosition(this.currentValue);
114                this.currentValue = v;
115                v = this._gauge._getPosition(v);
116 
117                if(dontAnimate || (c==v)){
118                        this.shape.setTransform(gfx.matrix.translate(v,0));
119                }else{
120                        var anim = new fx.Animation({curve: [c, v], duration: this.duration, easing: this.easing});
121                        connect.connect(anim, "onAnimate", lang.hitch(this, function(jump){
122                                if (this.shape)
123                                 this.shape.setTransform(gfx.matrix.translate(jump,0));
124                        }));
125                        anim.play();
126                }
127        }
128});
129});
Note: See TracBrowser for help on using the repository browser.