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