Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upHow to handle touch events? #12
Comments
|
Are you trying to enable panzoom for existing d3 visualization? Or do you want to disable touch events? |
|
I want to use touch events with d3. I have panzoom enabled for an svg g element "svgG" and then want to detect touch events on child elements (cirles and text) of the g element ("nodeCircles") In the code snippet below, the .on("click", nodeClick) works, but the .on("touchStart", nodeClick) does not.
|
|
I see. Might be relevant to #11 and comments in this thread. Unless @odai-alali or someone else beats me to it, I can give a callback approach a try later this week or next. |
|
Just pushed the changes. Should be available in version panzoom(document.getElementById('g4'), {
onTouch: function(e) {
// `e` - is current touch event.
return false; // tells the library to not preventDefault.
}
});Please let me know if this does not work. |
|
Yes, it works! Thanks! Unrelated, is there a way to programmatically control panzoom? For instance, something like: panzoom.setZoomFactor(2.0); |
|
I guess I don't completely understand handling events, because now that touch events work, zooming with a mouse (actually touchpad on macbook) now does not. How can I get both touch events on iOS and zooming with a mouse to work? |
|
@tracycollins sorry - I missed this one. To set zoom level from code, you'd need to call As for broken zoom with mouse - can you share a jsbin with me? |
|
The mouse zoom seems to have fixed itself. Not sure if something I did fixed it. Anyway... I'm not sure how to use the code snippet to set zoom level. I tried and got the error: This is how I'm using it:
|
I can't figure out how to get touch events (using the d3.js library) to work.
Is there a way to tell panzoom to not ignore touch events?