Debian Codegraph @

dojox/charting/action2d/TouchIndicator.js

raw symbols SCIP
1 define(["dojo/_base/lang", "dojo/_base/declare", "dojo/_base/event", "dojo/has", "dojo/touch", "dojo/_base/connect", "./ChartAction", "./_IndicatorElement", "dojox/lang/utils"],
2 function(lang, declare, eventUtil, has, touch, dconnect, 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
118 // we should not have to do that, but dojo/touch is causing performances issue
119 // we have to workaround here for now
120 if(has("touch-events")){
121 this._listeners = [
122 {eventName: "touchstart", methodName: "onTouchStart"},
123 {eventName: "touchmove", methodName: "onTouchMove"},
124 {eventName: "touchend", methodName: "onTouchEnd"},
125 {eventName: "touchcancel", methodName: "onTouchEnd"}
126 ];
127 } else {
128 this._listeners = [
129 {eventName: touch.press, methodName: "onTouchStart"},
130 {eventName: touch.move, methodName: "onTouchMove"},
131 {eventName: touch.cancel, methodName: "onTouchEnd"}
132 ];
133 }
134 this.opt = lang.clone(this.defaultParams);
135 du.updateWithObject(this.opt, kwArgs);
136 du.updateWithPattern(this.opt, kwArgs, this.optionalParams);
137 this._uName = "touchIndicator"+this.opt.series;
138 this.connect();
139 },
140
141 connect: function(){
142 // summary:
143 // Connect this action to the chart. This adds a indicator plot
144 // to the chart that's why Chart.render() must be called after connect.
145 this.inherited(arguments);
146 // add plot with unique name
147 this.chart.addPlot(this._uName, {type: IndicatorElement, inter: this});
148 },
149
150 disconnect: function(){
151 // summary:
152 // Disconnect this action from the chart.
153 var plot = this.chart.getPlot(this._uName);
154 if(plot.pageCoord){
155 // we might still have something drawn on the screen
156 this.onTouchEnd();
157 }
158 this.chart.removePlot(this._uName);
159 this.inherited(arguments);
160 },
161
162 onChange: function(event){
163 // summary:
164 // Called when the indicator value changed.
165 // event:
166 // An event with a start and end properties containing the {x, y} data points of the first and
167 // second (if available) touch indicators. It also contains a label property containing the displayed
168 // text.
169 },
170
171 onTouchStart: function(event){
172 // summary:
173 // Called when touch is started on the chart.
174 if(!event.touches || event.touches.length == 1){
175 this._onTouchSingle(event, true);
176 }else if(this.opt.dualIndicator && event.touches.length == 2){
177 this._onTouchDual(event);
178 }
179 },
180
181 onTouchMove: function(event){
182 // summary:
183 // Called when touch is moved on the chart.
184 if(!event.touches || event.touches.length == 1){
185 this._onTouchSingle(event);
186 }else if(this.opt.dualIndicator && event.touches.length == 2){
187 this._onTouchDual(event);
188 }
189 },
190
191 _onTouchSingle: function(event, delayed){
192 if(!has("touch-events") && !this._onTouchEndHandler){
193 this._onTouchEndHandler =
194 dconnect.connect(this.chart.node.ownerDocument, touch.release, this, "onTouchEnd");
195 }
196 if(this.chart._delayedRenderHandle && !delayed){
197 // we have pending rendering from a previous call, let's sync
198 this.chart.render();
199 }
200 var plot = this.chart.getPlot(this._uName);
201 plot.pageCoord = {x: event.touches?event.touches[0].pageX:event.pageX, y: event.touches?event.touches[0].pageY:event.pageY};
202 plot.dirty = true;
203 if(delayed){
204 this.chart.delayedRender();
205 }else{
206 this.chart.render();
207 }
208 eventUtil.stop(event);
209 },
210
211 _onTouchDual: function(event){
212 // sync
213 if(!has("touch-events") && !this._onTouchEndHandler){
214 this._onTouchEndHandler =
215 dconnect.connect(this.chart.node.ownerDocument, touch.release, this, "onTouchEnd");
216 }
217 if(this.chart._delayedRenderHandle){
218 // we have pending rendering from a previous call, let's sync
219 this.chart.render();
220 }
221 var plot = this.chart.getPlot(this._uName);
222 plot.pageCoord = {x: event.touches[0].pageX, y: event.touches[0].pageY};
223 plot.secondCoord = {x: event.touches[1].pageX, y: event.touches[1].pageY};
224 plot.dirty = true;
225 this.chart.render();
226 eventUtil.stop(event);
227 },
228
229 onTouchEnd: function(event){
230 // summary:
231 // Called when touch is ended or canceled on the chart.
232 if(!has("touch-events") && this._onTouchEndHandler){
233 dconnect.disconnect(this._onTouchEndHandler);
234 this._onTouchEndHandler = null;
235 }
236 var plot = this.chart.getPlot(this._uName);
237 plot.stopTrack();
238 plot.pageCoord = null;
239 plot.secondCoord = null;
240 plot.dirty = true;
241 this.chart.delayedRender();
242 }
243 });
244 });