source: Dev/branches/rest-dojo-ui/client/dojox/gauges/BarLineIndicator.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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