source: Dev/branches/rest-dojo-ui/client/dojox/gauges/AnalogArcIndicator.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: 3.0 KB
Line 
1define(["dojo/_base/declare","dojo/_base/lang","dojo/_base/connect","dojo/_base/fx","./AnalogIndicatorBase"],
2function(declare, lang, connect, fx, AnalogIndicatorBase) {
3
4/*=====
5        AnalogIndicatorBase = dojox.gauges.AnalogIndicatorBase;
6=====*/
7
8return declare("dojox.gauges.AnalogArcIndicator",[AnalogIndicatorBase],{
9       
10        // summary:
11        //              An indicator for the AnalogGauge that draws a segment of arc.
12        //              The segment of arc starts at the start angle of the gauge and ends at the
13        //              angle that corresponds to the value of the indicator.
14       
15        _createArc: function(val){
16               
17                // Creating the Arc Path string manually.  This is instead of creating new dojox.gfx.Path object
18                // each time since we really just need the Path string (to use with setShape) and we don't want to
19                // have to redo the connects, etc.
20                if(this.shape){
21                        var startAngle = this._gauge._mod360(this._gauge.startAngle);
22                        var a = this._gauge._getRadians(this._gauge._getAngle(val));
23                        var sa = this._gauge._getRadians(startAngle);
24
25                        if (this._gauge.orientation == 'cclockwise'){
26                                var tmp = a;
27                                a = sa;
28                                sa = tmp;
29                        }
30
31                        var arange;
32                        var big = 0;
33                        if (sa<=a)
34                                arange = a-sa;
35                        else
36                                arange = 2*Math.PI+a-sa;
37                        if(arange>Math.PI){big=1;}
38                       
39                        var cosa = Math.cos(a);
40                        var sina = Math.sin(a);
41                        var cossa = Math.cos(sa);
42                        var sinsa = Math.sin(sa);
43                        var off = this.offset + this.width;
44                        var p = ['M'];
45                        p.push(this._gauge.cx+this.offset*sinsa);
46                        p.push(this._gauge.cy-this.offset*cossa);
47                        p.push('A', this.offset, this.offset, 0, big, 1);
48                        p.push(this._gauge.cx+this.offset*sina);
49                        p.push(this._gauge.cy-this.offset*cosa);
50                        p.push('L');
51                        p.push(this._gauge.cx+off*sina);
52                        p.push(this._gauge.cy-off*cosa);
53                        p.push('A', off, off, 0, big, 0);
54                        p.push(this._gauge.cx+off*sinsa);
55                        p.push(this._gauge.cy-off*cossa);
56                        p.push('z');
57                        this.shape.setShape(p.join(' '));
58                        this.currentValue = val;
59                }
60        },
61        draw: function(group, /*Boolean?*/ dontAnimate){
62                // summary:
63                //              Override of dojox.gauges._Indicator.draw
64                var v = this.value;
65                if(v < this._gauge.min){v = this._gauge.min;}
66                if(v > this._gauge.max){v = this._gauge.max;}
67                if(this.shape){
68                        if(dontAnimate){
69                                this._createArc(v);
70                        }else{
71                                var anim = new fx.Animation({curve: [this.currentValue, v], duration: this.duration, easing: this.easing});
72                                connect.connect(anim, "onAnimate", lang.hitch(this, this._createArc));
73                                anim.play();
74                        }
75                }else{
76                        var color = this.color ? this.color : 'black';
77                        var strokeColor = this.strokeColor ? this.strokeColor : color;
78                        var stroke = {color: strokeColor, width: 1};
79                        if(this.color.type && !this.strokeColor){
80                                stroke.color = this.color.colors[0].color;
81                        }
82                        this.shape = group.createPath().setStroke(stroke).setFill(color);
83                        this._createArc(v);
84                        this.shape.connect("onmouseover", this, this.handleMouseOver);
85                        this.shape.connect("onmouseout", this,  this.handleMouseOut);
86                        this.shape.connect("onmousedown", this, this.handleMouseDown);
87                        this.shape.connect("touchstart", this, this.handleTouchStart);
88                }
89        }
90});
91
92});
Note: See TracBrowser for help on using the repository browser.