|
11 | 11 |
|
12 | 12 | var mouseChange = require('mouse-change'); |
13 | 13 | var mouseWheel = require('mouse-wheel'); |
| 14 | +var mouseOffset = require('mouse-event-offset'); |
14 | 15 | var cartesianConstants = require('../cartesian/constants'); |
15 | 16 |
|
16 | 17 | module.exports = createCamera; |
@@ -55,7 +56,23 @@ function createCamera(scene) { |
55 | 56 | return false; |
56 | 57 | } |
57 | 58 |
|
58 | | - result.mouseListener = mouseChange(element, function(buttons, x, y) { |
| 59 | + result.mouseListener = mouseChange(element, handleInteraction); |
| 60 | + |
| 61 | + // enable simple touch interactions |
| 62 | + element.addEventListener('touchstart', function(ev) { |
| 63 | + var xy = mouseOffset(ev.changedTouches[0], element); |
| 64 | + handleInteraction(0, xy[0], xy[1]); |
| 65 | + handleInteraction(1, xy[0], xy[1]); |
| 66 | + }); |
| 67 | + element.addEventListener('touchmove', function(ev) { |
| 68 | + var xy = mouseOffset(ev.changedTouches[0], element); |
| 69 | + handleInteraction(1, xy[0], xy[1]); |
| 70 | + }); |
| 71 | + element.addEventListener('touchend', function() { |
| 72 | + handleInteraction(0, result.lastPos[0], result.lastPos[1]); |
| 73 | + }); |
| 74 | + |
| 75 | + function handleInteraction(buttons, x, y) { |
59 | 76 | var dataBox = scene.calcDataBox(), |
60 | 77 | viewBox = plot.viewBox; |
61 | 78 |
|
@@ -235,7 +252,7 @@ function createCamera(scene) { |
235 | 252 |
|
236 | 253 | result.lastPos[0] = x; |
237 | 254 | result.lastPos[1] = y; |
238 | | - }); |
| 255 | + } |
239 | 256 |
|
240 | 257 | result.wheelListener = mouseWheel(element, function(dx, dy) { |
241 | 258 | var dataBox = scene.calcDataBox(), |
|
0 commit comments