source: Dev/trunk/src/client/dojox/dgauges/components/default/SemiCircularLinearGauge.js

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

Added Dojo 1.9.3 release.

  • Property svn:executable set to *
File size: 5.2 KB
Line 
1define([
2                "dojo/_base/lang",
3                "dojo/_base/declare",
4                "dojo/_base/Color",
5                "../utils",
6                "../../CircularGauge",
7                "../../LinearScaler",
8                "../../CircularScale",
9                "../../CircularValueIndicator",
10                "../../TextIndicator",
11                "../DefaultPropertiesMixin"
12                ],
13        function(lang, declare, Color, utils, CircularGauge, LinearScaler, CircularScale, CircularValueIndicator, TextIndicator, DefaultPropertiesMixin){
14        return declare("dojox.dgauges.components.default.SemiCircularLinearGauge", [CircularGauge, DefaultPropertiesMixin], {
15                // summary:
16                //              A semi circular gauge widget.
17
18                _radius: 88,
19                _width: 200,
20                _height: 123,
21                // borderColor: Object|Array|int
22                //              The border color. Default is "#C9DFF2".
23                borderColor: "#C9DFF2",
24                // fillColor: Object|Array|int
25                //              The background color. Default is "#FCFCFF".
26                fillColor: "#FCFCFF",
27                // indicatorColor: Object|Array|int
28                //              The indicator fill color. Default is "#F01E28".
29                indicatorColor: "#F01E28",
30                constructor: function(){
31                       
32                        // Base colors
33                        this.borderColor = new Color(this.borderColor);
34                        this.fillColor = new Color(this.fillColor);
35                        this.indicatorColor = new Color(this.indicatorColor);
36
37                        // Draw background
38                        this.addElement("background", lang.hitch(this, this.drawBackground));
39                       
40                        // Scaler
41                        var scaler = new LinearScaler();
42                       
43                        // Scale
44                        var scale = new CircularScale();
45                        scale.set("scaler", scaler);
46                        this.addElement("scale", scale);
47                       
48                        // Value indicator
49                        var indicator = new CircularValueIndicator();
50                        scale.addIndicator("indicator", indicator);
51                       
52                        // Gauge Foreground (needle cap)
53                        this.addElement("foreground", lang.hitch(this, this.drawForeground));
54                       
55                        // Indicator Text Border
56                        this.addElement("indicatorTextBorder", lang.hitch(this, this.drawTextBorder), "leading");
57                       
58                        // Indicator Text
59                        var indicatorText = new TextIndicator();
60                        indicatorText.set("indicator", indicator);
61                        indicatorText.set("x", 100);
62                        indicatorText.set("y", 115);
63                        this.addElement("indicatorText", indicatorText);                       
64                       
65                        utils.genericCircularGauge(scale, indicator, this._width / 2, 0.76 * this._height, this._radius, 166, 14, null, null, "inside");
66                },
67               
68                drawBackground: function(g){
69                        // summary:
70                        //              Draws the background shape of the gauge.
71                        // g: dojox/gfx/Group
72                        //              The group used to draw the background.
73                        // tags:
74                        //              protected
75                        var w = this._width;
76                        var h = this._height;
77                        var gap = 0;
78                        var cr = 3;
79                        var entries = utils.createGradient([0, utils.brightness(this.borderColor, -20), 0.1, utils.brightness(this.borderColor, -40)]);
80                        g.createRect({
81                                x: 0,
82                                y: 0,
83                                width: w,
84                                height: h,
85                                r: cr
86                        }).setFill(lang.mixin({
87                                type: "linear",
88                                x1: 0,
89                                y1: 0,
90                                x2: w,
91                                y2: h
92                        }, entries)).setStroke({
93                                color: "#A5A5A5",
94                                width: 0.2
95                        });
96                        entries = utils.createGradient([0, utils.brightness(this.borderColor, 70), 1, utils.brightness(this.borderColor, -50)]);
97                        gap = 4;
98                        cr = 2
99                        g.createRect({
100                                x: gap,
101                                y: gap,
102                                width: w - 2 * gap,
103                                height: h - 2 * gap,
104                                r: cr
105                        }).setFill(lang.mixin({
106                                type: "linear",
107                                x1: 0,
108                                y1: 0,
109                                x2: w,
110                                y2: h
111                        }, entries));
112                        gap = 6;
113                        cr = 1
114                        entries = utils.createGradient([0, utils.brightness(this.borderColor, 60), 1, utils.brightness(this.borderColor, -40)]);
115                        g.createRect({
116                                x: gap,
117                                y: gap,
118                                width: w - 2 * gap,
119                                height: h - 2 * gap,
120                                r: cr
121                        }).setFill(lang.mixin({
122                                type: "linear",
123                                x1: 0,
124                                y1: 0,
125                                x2: w,
126                                y2: h
127                        }, entries));
128                       
129                        gap = 7;
130                        cr = 0
131                        entries = utils.createGradient([0, utils.brightness(this.borderColor, 70), 1, utils.brightness(this.borderColor, -40)]);
132                        g.createRect({
133                                x: gap,
134                                y: gap,
135                                width: w - 2 * gap,
136                                height: h - 2 * gap,
137                                r: cr
138                        }).setFill(lang.mixin({
139                                type: "linear",
140                                x1: w,
141                                y1: 0,
142                                x2: 0,
143                                y2: h
144                        }, entries));
145                        gap = 5;
146                        cr = 0                 
147                        entries = utils.createGradient([0, [255, 255, 255, 220], 0.8, utils.brightness(this.fillColor, -5), 1, utils.brightness(this.fillColor, -30)]);
148                        g.createRect({
149                                x: gap,
150                                y: gap,
151                                width: w - 2 * gap,
152                                height: h - 2 * gap,
153                                r: cr
154                        }).setFill(lang.mixin({
155                                type: "radial",
156                                cx: w/2,
157                                cy: h/2,
158                                r: h
159                        }, entries)).setStroke({
160                                color: utils.brightness(this.fillColor, -40),
161                                width: 0.4
162                        });
163                       
164                },
165               
166                drawForeground: function(g){
167                        // summary:
168                        //              Draws the foreground shape of the gauge.
169                        // g: dojox/gfx/Group
170                        //              The group used to draw the foreground.
171                        // tags:
172                        //              protected
173                        var r = 0.07 * this._radius;
174                        var entries = utils.createGradient([0, this.borderColor, 1, utils.brightness(this.borderColor, -20)]);
175                        g.createEllipse({
176                                cx: this._width / 2,
177                                cy: 0.76 * this._height,
178                                rx: r,
179                                ry: r
180                        }).setFill(lang.mixin({
181                                type: "radial",
182                                cx: this._width / 2 - 5,
183                                cy: this._height * 0.76 - 5,
184                                r: r
185                        }, entries)).setStroke({
186                                color: utils.brightness(this.fillColor, -50),
187                                width: 0.4
188                        });
189                },
190               
191                drawTextBorder: function(g){
192                        // summary:
193                        //              Internal method.
194                        // tags:
195                        //              private
196                        return g.createRect({
197                                x: this._width / 2 - 12,
198                                y: this._height - 20,
199                                width: 24,
200                                height: 14
201                        }).setStroke({
202                                color: utils.brightness(this.fillColor, -20),
203                                width: 0.3
204                        });
205                }
206        });
207});
208
Note: See TracBrowser for help on using the repository browser.