_Indicator.js 7.1 KB

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