| 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 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
return declare("dojox.charting.action2d.TouchIndicator", ChartAction, { |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 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 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 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 |
|
| 143 |
|
| 144 |
|
| 145 |
this.inherited(arguments); |
| 146 |
|
| 147 |
this.chart.addPlot(this._uName, {type: IndicatorElement, inter: this}); |
| 148 |
}, |
| 149 |
|
| 150 |
disconnect: function(){ |
| 151 |
|
| 152 |
|
| 153 |
var plot = this.chart.getPlot(this._uName); |
| 154 |
if(plot.pageCoord){ |
| 155 |
|
| 156 |
this.onTouchEnd(); |
| 157 |
} |
| 158 |
this.chart.removePlot(this._uName); |
| 159 |
this.inherited(arguments); |
| 160 |
}, |
| 161 |
|
| 162 |
onChange: function(event){ |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
}, |
| 170 |
|
| 171 |
onTouchStart: function(event){ |
| 172 |
|
| 173 |
|
| 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 |
|
| 183 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 231 |
|
| 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 |
}); |