MouseIndicator.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. define("dojox/charting/action2d/MouseIndicator", ["dojo/_base/lang", "dojo/_base/declare", "dojo/_base/connect", "dojo/_base/window", "dojo/_base/sniff",
  2. "./ChartAction", "./_IndicatorElement", "dojox/lang/utils", "dojo/_base/event","dojo/_base/array"],
  3. function(lang, declare, hub, win, has, ChartAction, IndicatorElement, du, eventUtil, arr){
  4. /*=====
  5. dojo.declare("dojox.charting.action2d.__MouseIndicatorCtorArgs", null, {
  6. // summary:
  7. // Additional arguments for mouse indicator.
  8. // series: String
  9. // Target series name for this action.
  10. series: "",
  11. // autoScroll: Boolean?
  12. // Whether when moving indicator the chart is automatically scrolled. Default is true.
  13. autoScroll: true,
  14. // vertical: Boolean?
  15. // Whether the indicator is vertical or not. Default is true.
  16. vertical: true,
  17. // fixed: Boolean?
  18. // Whether a fixed precision must be applied to data values for display. Default is true.
  19. fixed: true,
  20. // precision: Number?
  21. // The precision at which to round data values for display. Default is 1.
  22. precision: 0,
  23. // lineStroke: dojo.gfx.Stroke?
  24. // An optional stroke to use for indicator line.
  25. lineStroke: {},
  26. // lineOutline: dojo.gfx.Stroke?
  27. // An optional outline to use for indicator line.
  28. lineOutline: {},
  29. // lineShadow: dojo.gfx.Stroke?
  30. // An optional shadow to use for indicator line.
  31. lineShadow: {},
  32. // stroke: dojo.gfx.Stroke?
  33. // An optional stroke to use for indicator label background.
  34. stroke: {},
  35. // outline: dojo.gfx.Stroke?
  36. // An optional outline to use for indicator label background.
  37. outline: {},
  38. // shadow: dojo.gfx.Stroke?
  39. // An optional shadow to use for indicator label background.
  40. shadow: {},
  41. // fill: dojo.gfx.Fill?
  42. // An optional fill to use for indicator label background.
  43. fill: {},
  44. // fillFunc: Function?
  45. // An optional function to use to compute label background fill. It takes precedence over
  46. // fill property when available.
  47. fillFunc: null,
  48. // labelFunc: Function?
  49. // An optional function to use to compute label text. It takes precedence over
  50. // the default text when available.
  51. labelFunc: {},
  52. // font: String?
  53. // A font definition to use for indicator label background.
  54. font: "",
  55. // fontColor: String|dojo.Color?
  56. // The color to use for indicator label background.
  57. fontColor: "",
  58. // markerStroke: dojo.gfx.Stroke?
  59. // An optional stroke to use for indicator marker.
  60. markerStroke: {},
  61. // markerOutline: dojo.gfx.Stroke?
  62. // An optional outline to use for indicator marker.
  63. markerOutline: {},
  64. // markerShadow: dojo.gfx.Stroke?
  65. // An optional shadow to use for indicator marker.
  66. markerShadow: {},
  67. // markerFill: dojo.gfx.Fill?
  68. // An optional fill to use for indicator marker.
  69. markerFill: {},
  70. // markerSymbol: String?
  71. // An optional symbol string to use for indicator marker.
  72. markerFill: {}
  73. });
  74. var ChartAction = dojox.charting.action2d.ChartAction;
  75. =====*/
  76. return declare("dojox.charting.action2d.MouseIndicator", ChartAction, {
  77. // summary:
  78. // Create a mouse indicator action. You can drag mouse over the chart to display a data indicator.
  79. // the data description block for the widget parser
  80. defaultParams: {
  81. series: "",
  82. vertical: true,
  83. autoScroll: true,
  84. fixed: true,
  85. precision: 0
  86. },
  87. optionalParams: {
  88. lineStroke: {},
  89. outlineStroke: {},
  90. shadowStroke: {},
  91. stroke: {},
  92. outline: {},
  93. shadow: {},
  94. fill: {},
  95. fillFunc: null,
  96. labelFunc: null,
  97. font: "",
  98. fontColor: "",
  99. markerStroke: {},
  100. markerOutline: {},
  101. markerShadow: {},
  102. markerFill: {},
  103. markerSymbol: ""
  104. },
  105. constructor: function(chart, plot, kwArgs){
  106. // summary:
  107. // Create an mouse indicator action and connect it.
  108. // chart: dojox.charting.Chart
  109. // The chart this action applies to.
  110. // kwArgs: dojox.charting.action2d.__MouseIndicatorCtorArgs?
  111. // Optional arguments for the chart action.
  112. this._listeners = [{eventName: "onmousedown", methodName: "onMouseDown"}];
  113. this.opt = lang.clone(this.defaultParams);
  114. du.updateWithObject(this.opt, kwArgs);
  115. du.updateWithPattern(this.opt, kwArgs, this.optionalParams);
  116. this._uName = "mouseIndicator"+this.opt.series;
  117. this._handles = [];
  118. this.connect();
  119. },
  120. _disconnectHandles: function(){
  121. if(has("ie")){
  122. this.chart.node.releaseCapture();
  123. }
  124. arr.forEach(this._handles, hub.disconnect);
  125. this._handles = [];
  126. },
  127. connect: function(){
  128. // summary:
  129. // Connect this action to the chart. This adds a indicator plot
  130. // to the chart that's why Chart.render() must be called after connect.
  131. this.inherited(arguments);
  132. // add plot with unique name
  133. this.chart.addPlot(this._uName, {type: IndicatorElement, inter: this});
  134. },
  135. disconnect: function(){
  136. // summary:
  137. // Disconnect this action from the chart.
  138. if(this._isMouseDown){
  139. this.onMouseUp();
  140. }
  141. this.chart.removePlot(this._uName);
  142. this.inherited(arguments);
  143. this._disconnectHandles();
  144. },
  145. onMouseDown: function(event){
  146. // summary:
  147. // Called when mouse is down on the chart.
  148. this._isMouseDown = true;
  149. // we now want to capture mouse move events everywhere to avoid
  150. // stop scrolling when going out of the chart window
  151. if(has("ie")){
  152. this._handles.push(hub.connect(this.chart.node, "onmousemove", this, "onMouseMove"));
  153. this._handles.push(hub.connect(this.chart.node, "onmouseup", this, "onMouseUp"));
  154. this.chart.node.setCapture();
  155. }else{
  156. this._handles.push(hub.connect(win.doc, "onmousemove", this, "onMouseMove"));
  157. this._handles.push(hub.connect(win.doc, "onmouseup", this, "onMouseUp"));
  158. }
  159. this._onMouseSingle(event);
  160. },
  161. onMouseMove: function(event){
  162. // summary:
  163. // Called when the mouse is moved on the chart.
  164. if(this._isMouseDown){
  165. this._onMouseSingle(event);
  166. }
  167. },
  168. _onMouseSingle: function(event){
  169. var plot = this.chart.getPlot(this._uName);
  170. plot.pageCoord = {x: event.pageX, y: event.pageY};
  171. plot.dirty = true;
  172. this.chart.render();
  173. eventUtil.stop(event);
  174. },
  175. onMouseUp: function(event){
  176. // summary:
  177. // Called when mouse is up on the chart.
  178. var plot = this.chart.getPlot(this._uName);
  179. plot.stopTrack();
  180. this._isMouseDown = false;
  181. this._disconnectHandles();
  182. plot.pageCoord = null;
  183. plot.dirty = true;
  184. this.chart.render();
  185. }
  186. });
  187. });