Touch event data on brush events

201 views
Skip to first unread message

Shripad K

unread,
Jan 20, 2013, 7:49:54 AM1/20/13
to d3...@googlegroups.com
Hello all,

The event data fetched from touch events "brush", "brushend" and "brushstart" via d3.touches returns an empty array. Anyone know why?

Here is my code:

var self = this;
brush.on('brushend', function() {
    var coordinates;
    if(self.is_touch_device) {
        coordinates = d3.touches(this);
        console.log(coordinates); // returns []
    } else {
        coordinates = d3.mouse(this);
        console.log(coordinates); // returns [33, 45];
    }
});

Thanks.

Shripad K

unread,
Jan 20, 2013, 8:26:19 AM1/20/13
to d3...@googlegroups.com
Okay figured it out, for "brushend" i need to fetch from changedTouches instead of touches. Fix:

var coordinates = d3.touches(this, d3.event.sourceEvent.changedTouches)[0];

As a side note, can we have a d3.changedTouches too? :)

Shripad K.

Pratik pandey

unread,
Feb 1, 2013, 4:53:16 AM2/1/13
to d3...@googlegroups.com

hey, if I'm not wrong, you are retrieving the coordinates of your brush selection, right?
    If thats the case, all that you need to do is use 
                brush.extent() function. It will automatically give you the selection based on your scale.

Shripad K

unread,
Feb 1, 2013, 11:52:26 AM2/1/13
to d3...@googlegroups.com
Nope :) I wanted to extend the brush functionality to not just selection/resize, but also allow for more options (like moving the brush to the selected coordinate, preserving the extent -> behaving like a resizable scrollbar). For brushend, d3.event.sourceEvent.touches returns an empty array (because you would have already removed your fingers from the touch screen). So the coordinates are stored in d3.event.sourceEvent.changedTouches. I needed these coordinates to find the difference between the x coordinate (when clicked/touched) and the extents so I could move the brush to that point.

--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Pratik pandey

unread,
Feb 4, 2013, 5:52:42 AM2/4/13
to d3...@googlegroups.com
oh okay..:)
Reply all
Reply to author
Forward
0 new messages