1 | define(["dojo/_base/lang","dojo/_base/declare","dojo/_base/fx","dojo/_base/html","dojo/_base/connect","dijit/_Widget","dojo/dom-construct", "dojo/dom-class"], |
---|
2 | function(lang,declare,fx,html,connect,Widget,dom,domClass) { |
---|
3 | |
---|
4 | return declare("dojox.gauges._Indicator",[Widget],{ |
---|
5 | // summary: |
---|
6 | // An indicator to be used in a gauge |
---|
7 | // |
---|
8 | // description: |
---|
9 | // An indicator widget, which has given properties. drawn by a gauge. |
---|
10 | // |
---|
11 | // example: |
---|
12 | // | <script type="text/javascript"> |
---|
13 | // | require(["dojox/gauges/AnalogGauge","dojox/gauges/Indicator"]); |
---|
14 | // | </script> |
---|
15 | // | ... |
---|
16 | // | <div dojoType="dojox.gauges.AnalogGauge" |
---|
17 | // | id="testGauge" |
---|
18 | // | width="300" |
---|
19 | // | height="200" |
---|
20 | // | cx=150 |
---|
21 | // | cy=175 |
---|
22 | // | radius=125 |
---|
23 | // | image="gaugeOverlay.png" |
---|
24 | // | imageOverlay="false" |
---|
25 | // | imageWidth="280" |
---|
26 | // | imageHeight="155" |
---|
27 | // | imageX="12" |
---|
28 | // | imageY="38"> |
---|
29 | // | <div dojoType="dojox.gauges.Indicator" |
---|
30 | // | value=17 |
---|
31 | // | type="arrow" |
---|
32 | // | length=135 |
---|
33 | // | width=3 |
---|
34 | // | hover="Value: 17" |
---|
35 | // | onDragMove="handleDragMove"> |
---|
36 | // | </div> |
---|
37 | // | </div> |
---|
38 | |
---|
39 | // value: Number |
---|
40 | // The value (on the gauge) that this indicator should be placed at |
---|
41 | value: 0, |
---|
42 | |
---|
43 | // type: String |
---|
44 | // The type of indicator to draw. Varies by gauge type. Some examples include |
---|
45 | // "line", "arrow", and "bar" |
---|
46 | type: '', |
---|
47 | |
---|
48 | // color: String |
---|
49 | // The color of the indicator. |
---|
50 | color: 'black', |
---|
51 | |
---|
52 | // strokeColor: String |
---|
53 | // The color to stroke the outline of the indicator. |
---|
54 | strokeColor: '', |
---|
55 | |
---|
56 | // label: String |
---|
57 | // The text label for the indicator. |
---|
58 | label: '', |
---|
59 | |
---|
60 | // font: Object |
---|
61 | // The font for the indicator. The font is enerally in a format similar to: |
---|
62 | // {family: "Helvetica", weight: "bold", style: "italic", size: "18pt", rotated: true} |
---|
63 | font: {family: "sans-serif", size: "12px"}, |
---|
64 | |
---|
65 | // length: Number |
---|
66 | // The length of the indicator. In the above example, the radius of the AnalogGauge |
---|
67 | // is 125, but the length of the indicator is 135, meaning it would project beyond |
---|
68 | // the edge of the AnalogGauge |
---|
69 | length: 0, |
---|
70 | |
---|
71 | // width: Number |
---|
72 | // The width of the indicator. |
---|
73 | width: 0, |
---|
74 | |
---|
75 | // offset: Number |
---|
76 | // The offset of the indicator |
---|
77 | offset: 0, |
---|
78 | |
---|
79 | // hover: String |
---|
80 | // The string to put in the tooltip when this indicator is hovered over. |
---|
81 | hover: '', |
---|
82 | |
---|
83 | // front: boolean |
---|
84 | // Keep this indicator at the front |
---|
85 | front: false, |
---|
86 | |
---|
87 | // onDragMove: String |
---|
88 | // The function to call when this indicator is moved by dragging. |
---|
89 | // onDragMove: '', |
---|
90 | |
---|
91 | // easing: String|Object |
---|
92 | // indicates the easing function to be used when animating the of an indicator. |
---|
93 | easing: fx._defaultEasing, |
---|
94 | |
---|
95 | // duration: Number |
---|
96 | // indicates how long an animation of the indicator should take |
---|
97 | duration: 1000, |
---|
98 | |
---|
99 | // hideValues: Boolean |
---|
100 | // Indicates whether the text boxes showing the value of the indicator (as text |
---|
101 | // content) should be hidden or shown. Default is not hidden, aka shown. |
---|
102 | hideValue: false, |
---|
103 | |
---|
104 | // noChange: Boolean |
---|
105 | // Indicates whether the indicator's value can be changed. Useful for |
---|
106 | // a static target indicator. Default is false (that the value can be changed). |
---|
107 | noChange: false, |
---|
108 | |
---|
109 | // interactionMode: String |
---|
110 | // The interactionMode can have two values: "indicator" (the default) or "gauge". |
---|
111 | // When the value is "indicator", the user must click on the indicator to change the value. |
---|
112 | // When the value is "gauge", the user can click on the gauge to change the indicator value. |
---|
113 | // If a gauge contains several indicators with the indicatorMode property set to "gauge", then |
---|
114 | // only the first indicator will be moved when clicking the gauge. |
---|
115 | interactionMode: "indicator", |
---|
116 | |
---|
117 | _gauge: null, |
---|
118 | |
---|
119 | // title: String |
---|
120 | // The title of the indicator, to be displayed next to it's input box for the text-representation. |
---|
121 | title: "", |
---|
122 | |
---|
123 | startup: function(){ |
---|
124 | if(this.onDragMove){ |
---|
125 | this.onDragMove = lang.hitch(this.onDragMove); |
---|
126 | } |
---|
127 | if (this.strokeColor === ""){ |
---|
128 | this.strokeColor = undefined; |
---|
129 | } |
---|
130 | }, |
---|
131 | |
---|
132 | postCreate: function(){ |
---|
133 | if(this.title === ""){ |
---|
134 | html.style(this.domNode, "display", "none"); |
---|
135 | } |
---|
136 | if(lang.isString(this.easing)){ |
---|
137 | this.easing = lang.getObject(this.easing); |
---|
138 | } |
---|
139 | }, |
---|
140 | |
---|
141 | buildRendering: function(){ |
---|
142 | // summary: |
---|
143 | // Overrides _Widget.buildRendering |
---|
144 | |
---|
145 | var n = this.domNode = this.srcNodeRef ? this.srcNodeRef: dom.create("div"); |
---|
146 | domClass.add(n, "dojoxGaugeIndicatorDiv"); |
---|
147 | var title = dom.create("label"); |
---|
148 | if (this.title) title.innerHTML = this.title + ":"; |
---|
149 | dom.place(title, n); |
---|
150 | this.valueNode = dom.create("input", { |
---|
151 | className: "dojoxGaugeIndicatorInput", |
---|
152 | size: 5, |
---|
153 | value: this.value |
---|
154 | }); |
---|
155 | |
---|
156 | dom.place(this.valueNode, n); |
---|
157 | connect.connect(this.valueNode, "onchange", this, this._update); |
---|
158 | }, |
---|
159 | |
---|
160 | _update: function(){ |
---|
161 | // summary: |
---|
162 | // A private function, handling the updating of the gauge |
---|
163 | |
---|
164 | this._updateValue(true); |
---|
165 | }, |
---|
166 | |
---|
167 | _updateValue: function(animate){ |
---|
168 | // summary: |
---|
169 | // A private function, handling the updating of the gauge |
---|
170 | var value = this.valueNode.value; |
---|
171 | if(value === ''){ |
---|
172 | this.value = null; |
---|
173 | }else{ |
---|
174 | this.value = Number(value); |
---|
175 | this.hover = this.title+': '+value; |
---|
176 | } |
---|
177 | if(this._gauge){ |
---|
178 | this.draw(this._gauge._indicatorsGroup, animate || animate==undefined ? false: true); |
---|
179 | this.valueNode.value = this.value; |
---|
180 | if((this.title == 'Target' || this.front) && this._gauge.moveIndicator){ |
---|
181 | // if re-drawing value, make sure target is still on top |
---|
182 | this._gauge.moveIndicatorToFront(this); |
---|
183 | } |
---|
184 | this.valueChanged(); |
---|
185 | } |
---|
186 | }, |
---|
187 | |
---|
188 | valueChanged: function(){ |
---|
189 | // summary: |
---|
190 | // Invoked every time the value of the indicator changes. |
---|
191 | |
---|
192 | }, |
---|
193 | |
---|
194 | update: function(value, animate){ |
---|
195 | // summary: |
---|
196 | // Updates the value of the indicator, including moving/re-drawing at it's new location and |
---|
197 | // updating the text box |
---|
198 | if(!this.noChange){ |
---|
199 | this.valueNode.value = value; |
---|
200 | this._updateValue(animate); |
---|
201 | } |
---|
202 | }, |
---|
203 | |
---|
204 | handleMouseOver: function(e){ |
---|
205 | // summary: |
---|
206 | // Handles mouse-over events in the indicator. |
---|
207 | this._gauge._handleMouseOverIndicator(this, e); |
---|
208 | }, |
---|
209 | |
---|
210 | handleMouseOut: function(e){ |
---|
211 | // summary: |
---|
212 | // Handles mouse-out events in the indicator. |
---|
213 | this._gauge._handleMouseOutIndicator(this,e); |
---|
214 | this._gauge.gaugeContent.style.cursor = ''; |
---|
215 | }, |
---|
216 | |
---|
217 | handleMouseDown: function(e){ |
---|
218 | // summary: |
---|
219 | // Handles mouse-down events in the indicator. |
---|
220 | this._gauge._handleMouseDownIndicator(this,e); |
---|
221 | }, |
---|
222 | |
---|
223 | handleTouchStart: function(e){ |
---|
224 | // summary: |
---|
225 | // Handles touch start events in the indicator. |
---|
226 | this._gauge.handleTouchStartIndicator(this, e); |
---|
227 | }, |
---|
228 | |
---|
229 | onDragMove: function(){ |
---|
230 | // summary: |
---|
231 | // Handles updating the text box and the hover text while dragging an indicator |
---|
232 | this.value = Math.floor(this.value); |
---|
233 | this.valueNode.value = this.value; |
---|
234 | this.hover = this.title+': '+this.value; |
---|
235 | }, |
---|
236 | |
---|
237 | draw: function(/* Boolean? */ dontAnimate){ |
---|
238 | // summary: |
---|
239 | // Performs the initial drawing of the indicator. |
---|
240 | // dontAnimate: Boolean |
---|
241 | // Indicates if the drawing should not be animated (rather than teh default, to animate) |
---|
242 | }, |
---|
243 | |
---|
244 | remove: function(){ |
---|
245 | // summary: |
---|
246 | // Removes the indicator's shape from the gauge surface. |
---|
247 | if (this.shape) |
---|
248 | this.shape.parent.remove(this.shape); |
---|
249 | this.shape = null; |
---|
250 | if(this.text){ |
---|
251 | this.text.parent.remove(this.text); |
---|
252 | } |
---|
253 | this.text = null; |
---|
254 | } |
---|
255 | }); |
---|
256 | }); |
---|