@@ -4068,7 +4068,9 @@ d3.svg.brush = function() {
40684068 : [ ] ;
40694069
40704070 g . each ( function ( ) {
4071- var g = d3 . select ( this ) . on ( "mousedown.brush" , down ) ,
4071+ var g = d3 . select ( this )
4072+ . on ( "mousedown.brush" , down )
4073+ . on ( "touchstart.brush" , down ) ,
40724074 bg = g . selectAll ( ".background" ) . data ( [ 0 ] ) ,
40734075 fg = g . selectAll ( ".extent" ) . data ( [ 0 ] ) ,
40744076 tz = g . selectAll ( ".resize" ) . data ( resizes , String ) ,
@@ -4116,13 +4118,16 @@ d3.svg.brush = function() {
41164118 }
41174119
41184120 function down ( ) {
4119- var target = d3 . select ( d3 . event . target ) ;
4121+ var target = d3 . select ( d3 . event . target ) ,
4122+ touches = d3 . event . changedTouches ;
41204123
41214124 // Store some global state for the duration of the brush gesture.
41224125 d3_svg_brush = brush ;
41234126 d3_svg_brushTarget = this ;
41244127 d3_svg_brushExtent = extent ;
4125- d3_svg_brushOffset = d3 . svg . mouse ( d3_svg_brushTarget ) ;
4128+ d3_svg_brushOffset = touches
4129+ ? d3 . svg . touches ( d3_svg_brushTarget , touches ) [ 0 ]
4130+ : d3 . svg . mouse ( d3_svg_brushTarget ) ;
41264131
41274132 // If the extent was clicked on, drag rather than brush;
41284133 // store the offset between the mouse and extent origin instead.
@@ -4232,6 +4237,8 @@ d3.svg.brush = function() {
42324237 d3 . select ( window )
42334238 . on ( "mousemove.brush" , d3_svg_brushMove )
42344239 . on ( "mouseup.brush" , d3_svg_brushUp )
4240+ . on ( "touchmove.brush" , d3_svg_brushMove )
4241+ . on ( "touchend.brush" , d3_svg_brushUp )
42354242 . on ( "keydown.brush" , d3_svg_brushKeydown )
42364243 . on ( "keyup.brush" , d3_svg_brushKeyup ) ;
42374244
@@ -4284,7 +4291,10 @@ function d3_svg_brushKeyup() {
42844291
42854292function d3_svg_brushMove ( ) {
42864293 if ( d3_svg_brushOffset ) {
4287- var mouse = d3 . svg . mouse ( d3_svg_brushTarget ) ,
4294+ var touches = d3 . event . changedTouches ,
4295+ mouse = touches
4296+ ? d3 . svg . touches ( d3_svg_brushTarget , touches ) [ 0 ]
4297+ : d3 . svg . mouse ( d3_svg_brushTarget ) ,
42884298 g = d3 . select ( d3_svg_brushTarget ) ;
42894299
42904300 if ( ! d3_svg_brushDrag ) {
0 commit comments