1 | define(["dojo/_base/lang", "dojo/_base/declare", "dojo/_base/event", "dojo/touch", "./ChartAction", "./_IndicatorElement", "dojox/lang/utils"], |
---|
2 | function(lang, declare, eventUtil, touch, ChartAction, IndicatorElement, du){ |
---|
3 | |
---|
4 | /*===== |
---|
5 | var __TouchIndicatorCtorArgs = { |
---|
6 | // summary: |
---|
7 | // Additional arguments for touch indicator. |
---|
8 | // series: String |
---|
9 | // Target series name for this action. |
---|
10 | // autoScroll: Boolean? |
---|
11 | // Whether when moving indicator the chart is automatically scrolled. Default is true. |
---|
12 | // lines: Boolean? |
---|
13 | // Whether the indicator lines are visible or not. Default is true. |
---|
14 | // labels: Boolean? |
---|
15 | // Whether the indicator label is visible or not. Default is true. |
---|
16 | // markers: Boolean? |
---|
17 | // Whether the indicator markers are visible or not. Default is true. |
---|
18 | // offset: {x, y}? |
---|
19 | // A pair of (x, y) pixel coordinate to specify the offset between the end of the indicator line and the |
---|
20 | // position at which the labels are rendered. Default is no offset which means it is automatically computed. |
---|
21 | // start: Boolean? |
---|
22 | // Whether the label is rendered at the start or end of the indicator. Default is false meaning end of |
---|
23 | // the line. |
---|
24 | // vertical: Boolean? |
---|
25 | // Whether the indicator is vertical or not. Default is true. |
---|
26 | // fixed: Boolean? |
---|
27 | // Whether a fixed precision must be applied to data values for display. Default is true. |
---|
28 | // precision: Number? |
---|
29 | // The precision at which to round data values for display. Default is 0. |
---|
30 | // lineStroke: dojo/gfx/Stroke? |
---|
31 | // An optional stroke to use for indicator line. |
---|
32 | // lineOutline: dojo/gfx/Stroke? |
---|
33 | // An optional outline to use for indicator line. |
---|
34 | // lineShadow: dojo/gfx/Stroke? |
---|
35 | // An optional shadow to use for indicator line. |
---|
36 | // stroke: dojo.gfx.Stroke? |
---|
37 | // An optional stroke to use for indicator label background. |
---|
38 | // outline: dojo.gfx.Stroke? |
---|
39 | // An optional outline to use for indicator label background. |
---|
40 | // shadow: dojo.gfx.Stroke? |
---|
41 | // An optional shadow to use for indicator label background. |
---|
42 | // fill: dojo.gfx.Fill? |
---|
43 | // An optional fill to use for indicator label background. |
---|
44 | // fillFunc: Function? |
---|
45 | // An optional function to use to compute label background fill. It takes precedence over |
---|
46 | // fill property when available. |
---|
47 | // labelFunc: Function? |
---|
48 | // An optional function to use to compute label text. It takes precedence over |
---|
49 | // the default text when available. |
---|
50 | // | function labelFunc(firstDataPoint, secondDataPoint, fixed, precision) {} |
---|
51 | // `firstDataPoint` is the `{x, y}` data coordinates pointed by the touch point. |
---|
52 | // `secondDataPoint` is the data coordinates pointed by the second touch point. |
---|
53 | // `fixed` is true if fixed precision must be applied. |
---|
54 | // `precision` is the requested precision to be applied. |
---|
55 | // font: String? |
---|
56 | // A font definition to use for indicator label background. |
---|
57 | // fontColor: String|dojo.Color? |
---|
58 | // The color to use for indicator label background. |
---|
59 | // markerStroke: dojo.gfx.Stroke? |
---|
60 | // An optional stroke to use for indicator marker. |
---|
61 | // markerOutline: dojo.gfx.Stroke? |
---|
62 | // An optional outline to use for indicator marker. |
---|
63 | // markerShadow: dojo.gfx.Stroke? |
---|
64 | // An optional shadow to use for indicator marker. |
---|
65 | // markerFill: dojo.gfx.Fill? |
---|
66 | // An optional fill to use for indicator marker. |
---|
67 | // markerSymbol: String? |
---|
68 | // An optional symbol string to use for indicator marker. |
---|
69 | }; |
---|
70 | =====*/ |
---|
71 | |
---|
72 | return declare("dojox.charting.action2d.TouchIndicator", ChartAction, { |
---|
73 | // summary: |
---|
74 | // Create a touch indicator action. You can touch over the chart to display a data indicator. |
---|
75 | |
---|
76 | // the data description block for the widget parser |
---|
77 | defaultParams: { |
---|
78 | series: "", |
---|
79 | dualIndicator: false, |
---|
80 | vertical: true, |
---|
81 | autoScroll: true, |
---|
82 | fixed: true, |
---|
83 | precision: 0, |
---|
84 | lines: true, |
---|
85 | labels: true, |
---|
86 | markers: true |
---|
87 | }, |
---|
88 | optionalParams: { |
---|
89 | lineStroke: {}, |
---|
90 | outlineStroke: {}, |
---|
91 | shadowStroke: {}, |
---|
92 | lineFill: {}, |
---|
93 | stroke: {}, |
---|
94 | outline: {}, |
---|
95 | shadow: {}, |
---|
96 | fill: {}, |
---|
97 | fillFunc: null, |
---|
98 | labelFunc: null, |
---|
99 | font: "", |
---|
100 | fontColor: "", |
---|
101 | markerStroke: {}, |
---|
102 | markerOutline: {}, |
---|
103 | markerShadow: {}, |
---|
104 | markerFill: {}, |
---|
105 | markerSymbol: "", |
---|
106 | offset: {}, |
---|
107 | start: false |
---|
108 | }, |
---|
109 | |
---|
110 | constructor: function(chart, plot, kwArgs){ |
---|
111 | // summary: |
---|
112 | // Create a new touch indicator action and connect it. |
---|
113 | // chart: dojox/charting/Chart |
---|
114 | // The chart this action applies to. |
---|
115 | // kwArgs: __TouchIndicatorCtorArgs? |
---|
116 | // Optional arguments for the chart action. |
---|
117 | this._listeners = [ |
---|
118 | {eventName: touch.press, methodName: "onTouchStart"}, |
---|
119 | {eventName: touch.move, methodName: "onTouchMove"}, |
---|
120 | {eventName: touch.release, methodName: "onTouchEnd"}, |
---|
121 | {eventName: touch.cancel, methodName: "onTouchEnd"} |
---|
122 | ]; |
---|
123 | this.opt = lang.clone(this.defaultParams); |
---|
124 | du.updateWithObject(this.opt, kwArgs); |
---|
125 | du.updateWithPattern(this.opt, kwArgs, this.optionalParams); |
---|
126 | this._uName = "touchIndicator"+this.opt.series; |
---|
127 | this.connect(); |
---|
128 | }, |
---|
129 | |
---|
130 | connect: function(){ |
---|
131 | // summary: |
---|
132 | // Connect this action to the chart. This adds a indicator plot |
---|
133 | // to the chart that's why Chart.render() must be called after connect. |
---|
134 | this.inherited(arguments); |
---|
135 | // add plot with unique name |
---|
136 | this.chart.addPlot(this._uName, {type: IndicatorElement, inter: this}); |
---|
137 | }, |
---|
138 | |
---|
139 | disconnect: function(){ |
---|
140 | // summary: |
---|
141 | // Disconnect this action from the chart. |
---|
142 | var plot = this.chart.getPlot(this._uName); |
---|
143 | if(plot.pageCoord){ |
---|
144 | // we might still have something drawn on the screen |
---|
145 | this.onTouchEnd(); |
---|
146 | } |
---|
147 | this.chart.removePlot(this._uName); |
---|
148 | this.inherited(arguments); |
---|
149 | }, |
---|
150 | |
---|
151 | onChange: function(event){ |
---|
152 | // summary: |
---|
153 | // Called when the indicator value changed. |
---|
154 | // event: |
---|
155 | // An event with a start and end properties containing the {x, y} data points of the first and |
---|
156 | // second (if available) touch indicators. It also contains a label property containing the displayed |
---|
157 | // text. |
---|
158 | }, |
---|
159 | |
---|
160 | onTouchStart: function(event){ |
---|
161 | // summary: |
---|
162 | // Called when touch is started on the chart. |
---|
163 | if(!event.touches || event.touches.length == 1){ |
---|
164 | this._onTouchSingle(event, true); |
---|
165 | }else if(this.opt.dualIndicator && event.touches.length == 2){ |
---|
166 | this._onTouchDual(event); |
---|
167 | } |
---|
168 | }, |
---|
169 | |
---|
170 | onTouchMove: function(event){ |
---|
171 | // summary: |
---|
172 | // Called when touch is moved on the chart. |
---|
173 | if(!event.touches || event.touches.length == 1){ |
---|
174 | this._onTouchSingle(event); |
---|
175 | }else if(this.opt.dualIndicator && event.touches.length == 2){ |
---|
176 | this._onTouchDual(event); |
---|
177 | } |
---|
178 | }, |
---|
179 | |
---|
180 | _onTouchSingle: function(event, delayed){ |
---|
181 | if(this.chart._delayedRenderHandle && !delayed){ |
---|
182 | // we have pending rendering from a previous call, let's sync |
---|
183 | this.chart.render(); |
---|
184 | } |
---|
185 | var plot = this.chart.getPlot(this._uName); |
---|
186 | plot.pageCoord = {x: event.touches?event.touches[0].pageX:event.pageX, y: event.touches?event.touches[0].pageY:event.pageY}; |
---|
187 | plot.dirty = true; |
---|
188 | if(delayed){ |
---|
189 | this.chart.delayedRender(); |
---|
190 | }else{ |
---|
191 | this.chart.render(); |
---|
192 | } |
---|
193 | eventUtil.stop(event); |
---|
194 | }, |
---|
195 | |
---|
196 | _onTouchDual: function(event){ |
---|
197 | // sync |
---|
198 | if(this.chart._delayedRenderHandle){ |
---|
199 | // we have pending rendering from a previous call, let's sync |
---|
200 | this.chart.render(); |
---|
201 | } |
---|
202 | var plot = this.chart.getPlot(this._uName); |
---|
203 | plot.pageCoord = {x: event.touches[0].pageX, y: event.touches[0].pageY}; |
---|
204 | plot.secondCoord = {x: event.touches[1].pageX, y: event.touches[1].pageY}; |
---|
205 | plot.dirty = true; |
---|
206 | this.chart.render(); |
---|
207 | eventUtil.stop(event); |
---|
208 | }, |
---|
209 | |
---|
210 | onTouchEnd: function(event){ |
---|
211 | // summary: |
---|
212 | // Called when touch is ended or canceled on the chart. |
---|
213 | var plot = this.chart.getPlot(this._uName); |
---|
214 | plot.stopTrack(); |
---|
215 | plot.pageCoord = null; |
---|
216 | plot.secondCoord = null; |
---|
217 | plot.dirty = true; |
---|
218 | this.chart.delayedRender(); |
---|
219 | } |
---|
220 | }); |
---|
221 | }); |
---|