1 | define([ |
---|
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.CircularLinearGauge", [CircularGauge, DefaultPropertiesMixin], { |
---|
15 | // summary: |
---|
16 | // A circular gauge widget. |
---|
17 | |
---|
18 | // _radius: Number |
---|
19 | _radius: 100, |
---|
20 | // borderColor: Object|Array|int |
---|
21 | // The border color. Default is "#C9DFF2". |
---|
22 | borderColor: "#C9DFF2", |
---|
23 | // fillColor: Object|Array|int |
---|
24 | // The background color. Default is "#FCFCFF". |
---|
25 | fillColor: "#FCFCFF", |
---|
26 | // indicatorColor: Object|Array|int |
---|
27 | // The indicator fill color. Default is "#F01E28". |
---|
28 | indicatorColor: "#F01E28", |
---|
29 | constructor: function(){ |
---|
30 | |
---|
31 | // Base colors |
---|
32 | this.borderColor = new Color(this.borderColor); |
---|
33 | this.fillColor = new Color(this.fillColor); |
---|
34 | this.indicatorColor = new Color(this.indicatorColor); |
---|
35 | |
---|
36 | // Draw background |
---|
37 | this.addElement("background", lang.hitch(this, this.drawBackground)); |
---|
38 | |
---|
39 | // Scaler |
---|
40 | var scaler = new LinearScaler(); |
---|
41 | |
---|
42 | // Scale |
---|
43 | var scale = new CircularScale(); |
---|
44 | scale.set("scaler", scaler); |
---|
45 | this.addElement("scale", scale); |
---|
46 | |
---|
47 | // Value indicator |
---|
48 | var indicator = new CircularValueIndicator(); |
---|
49 | scale.addIndicator("indicator", indicator); |
---|
50 | |
---|
51 | // Gauge Foreground (needle cap) |
---|
52 | this.addElement("foreground", lang.hitch(this, this.drawForeground)); |
---|
53 | |
---|
54 | // Indicator Text |
---|
55 | var indicatorText = new TextIndicator(); |
---|
56 | indicatorText.set("indicator", indicator); |
---|
57 | indicatorText.set("x", 100); |
---|
58 | indicatorText.set("y", 150); |
---|
59 | this.addElement("indicatorText", indicatorText); |
---|
60 | |
---|
61 | utils.genericCircularGauge(scale, indicator, this._radius, this._radius, 0.65 * this._radius, 130, 50, null, null, "outside"); |
---|
62 | }, |
---|
63 | |
---|
64 | drawBackground: function(g){ |
---|
65 | // summary: |
---|
66 | // Draws the background shape of the gauge. |
---|
67 | // g: dojox/gfx/Group |
---|
68 | // The group used to draw the background. |
---|
69 | // tags: |
---|
70 | // protected |
---|
71 | var r = this._radius; |
---|
72 | var w = 2 * r; |
---|
73 | var h = w; |
---|
74 | var entries = utils.createGradient([0, utils.brightness(this.borderColor, 70), 1, utils.brightness(this.borderColor, -40)]); |
---|
75 | g.createEllipse({ |
---|
76 | cx: r, |
---|
77 | cy: r, |
---|
78 | rx: r, |
---|
79 | ry: r |
---|
80 | }).setFill(lang.mixin({ |
---|
81 | type: "linear", |
---|
82 | x1: w, |
---|
83 | y1: 0, |
---|
84 | x2: 0, |
---|
85 | y2: h |
---|
86 | }, entries)).setStroke({ |
---|
87 | color: "#A5A5A5", |
---|
88 | width: 0.2 |
---|
89 | }); |
---|
90 | |
---|
91 | entries = utils.createGradient([0, utils.brightness(this.borderColor, 70), 1, utils.brightness(this.borderColor, -50)]); |
---|
92 | g.createEllipse({ |
---|
93 | cx: r, |
---|
94 | cy: r, |
---|
95 | rx: r * 0.99, |
---|
96 | ry: r * 0.99 |
---|
97 | }).setFill(lang.mixin({ |
---|
98 | type: "linear", |
---|
99 | x1: 0, |
---|
100 | y1: 0, |
---|
101 | x2: w, |
---|
102 | y2: h |
---|
103 | }, entries)); |
---|
104 | |
---|
105 | entries = utils.createGradient([0, utils.brightness(this.borderColor, 60), 1, utils.brightness(this.borderColor, -40)]); |
---|
106 | g.createEllipse({ |
---|
107 | cx: r, |
---|
108 | cy: r, |
---|
109 | rx: r * 0.92, |
---|
110 | ry: r * 0.92 |
---|
111 | }).setFill(lang.mixin({ |
---|
112 | type: "linear", |
---|
113 | x1: 0, |
---|
114 | y1: 0, |
---|
115 | x2: w, |
---|
116 | y2: h |
---|
117 | }, entries)); |
---|
118 | |
---|
119 | entries = utils.createGradient([0, utils.brightness(this.borderColor, 70), 1, utils.brightness(this.borderColor, -40)]); |
---|
120 | g.createEllipse({ |
---|
121 | cx: r, |
---|
122 | cy: r, |
---|
123 | rx: r * 0.9, |
---|
124 | ry: r * 0.9 |
---|
125 | }).setFill(lang.mixin({ |
---|
126 | type: "linear", |
---|
127 | x1: w, |
---|
128 | y1: 0, |
---|
129 | x2: 0, |
---|
130 | y2: h |
---|
131 | }, entries)); |
---|
132 | |
---|
133 | entries = utils.createGradient([0, [255, 255, 255, 220], 0.8, utils.brightness(this.fillColor, -5), 1, utils.brightness(this.fillColor, -30)]); |
---|
134 | g.createEllipse({ |
---|
135 | cx: r, |
---|
136 | cy: r, |
---|
137 | rx: r * 0.9, |
---|
138 | ry: r * 0.9 |
---|
139 | }).setFill(lang.mixin({ |
---|
140 | type: "radial", |
---|
141 | cx: r, |
---|
142 | cy: r, |
---|
143 | r: r |
---|
144 | }, entries)).setStroke({ |
---|
145 | color: utils.brightness(this.fillColor, -40), |
---|
146 | width: 0.4 |
---|
147 | }); |
---|
148 | |
---|
149 | }, |
---|
150 | |
---|
151 | drawForeground: function(g){ |
---|
152 | // summary: |
---|
153 | // Draws the foreground shape of the gauge. |
---|
154 | // g: dojox/gfx/Group |
---|
155 | // The group used to draw the foreground. |
---|
156 | // tags: |
---|
157 | // protected |
---|
158 | var r = 0.07 * this._radius; |
---|
159 | var entries = utils.createGradient([0, this.borderColor, 1, utils.brightness(this.borderColor, -20)]); |
---|
160 | g.createEllipse({ |
---|
161 | cx: this._radius, |
---|
162 | cy: this._radius, |
---|
163 | rx: r, |
---|
164 | ry: r |
---|
165 | }).setFill(lang.mixin({ |
---|
166 | type: "radial", |
---|
167 | cx: 0.96 * this._radius, |
---|
168 | cy: 0.96 * this._radius, |
---|
169 | r: r |
---|
170 | }, entries)).setStroke({ |
---|
171 | color: utils.brightness(this.fillColor, -50), |
---|
172 | width: 0.4 |
---|
173 | }); |
---|
174 | } |
---|
175 | }); |
---|
176 | }); |
---|