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