(type: string, target: SimpleSelection<void>, touchPoints: Plottable.Point[], ids: number[] = [])
| 234 | } |
| 235 | |
| 236 | export function triggerFakeTouchEvent(type: string, target: SimpleSelection<void>, touchPoints: Plottable.Point[], ids: number[] = []) { |
| 237 | const targetNode = <Element> target.node(); |
| 238 | const clientRect = targetNode.getBoundingClientRect(); |
| 239 | const e = <TouchEvent> document.createEvent("UIEvent"); |
| 240 | e.initUIEvent(type, true, true, window, 1); |
| 241 | const fakeTouchList: any = []; |
| 242 | |
| 243 | touchPoints.forEach((touchPoint, i) => { |
| 244 | const xPos = clientRect.left + touchPoint.x; |
| 245 | const yPos = clientRect.top + touchPoint.y; |
| 246 | const identifier = ids[i] == null ? 0 : ids[i]; |
| 247 | fakeTouchList.push({ |
| 248 | identifier: identifier, |
| 249 | target: targetNode, |
| 250 | screenX: xPos, |
| 251 | screenY: yPos, |
| 252 | clientX: xPos, |
| 253 | clientY: yPos, |
| 254 | pageX: xPos, |
| 255 | pageY: yPos, |
| 256 | }); |
| 257 | }); |
| 258 | fakeTouchList.item = (index: number) => fakeTouchList[index]; |
| 259 | (e as any).touches = <TouchList> fakeTouchList; |
| 260 | (e as any).targetTouches = <TouchList> fakeTouchList; |
| 261 | (e as any).changedTouches = <TouchList> fakeTouchList; |
| 262 | |
| 263 | (e as any).altKey = false; |
| 264 | (e as any).metaKey = false; |
| 265 | (e as any).ctrlKey = false; |
| 266 | (e as any).shiftKey = false; |
| 267 | (<HTMLElement> target.node()).dispatchEvent(e); |
| 268 | } |
| 269 | |
| 270 | export enum InteractionMode { |
| 271 | Mouse, |
no test coverage detected