@@ -133,16 +133,26 @@ function differentInterval(int1) {
133
133
} ;
134
134
}
135
135
136
+ // is the cursor over the north, middle, or south of a bar?
137
+ // the end handles extend over the last 10% of the bar
136
138
function north ( fPix , y ) {
137
- return fPix [ 1 ] <= y && y <= fPix [ 1 ] + c . bar . handleHeight ;
139
+ return north90 ( fPix ) <= y && y <= fPix [ 1 ] + c . bar . handleHeight ;
138
140
}
139
141
140
142
function south ( fPix , y ) {
141
- return fPix [ 0 ] - c . bar . handleHeight <= y && y <= fPix [ 0 ] ;
143
+ return fPix [ 0 ] - c . bar . handleHeight <= y && y <= south90 ( fPix ) ;
142
144
}
143
145
144
146
function middle ( fPix , y ) {
145
- return fPix [ 0 ] < y && y < fPix [ 1 ] ;
147
+ return south90 ( fPix ) < y && y < north90 ( fPix ) ;
148
+ }
149
+
150
+ function north90 ( fPix ) {
151
+ return 0.9 * fPix [ 1 ] + 0.1 * fPix [ 0 ] ;
152
+ }
153
+
154
+ function south90 ( fPix ) {
155
+ return 0.9 * fPix [ 0 ] + 0.1 * fPix [ 1 ] ;
146
156
}
147
157
148
158
function clearCursor ( ) {
@@ -220,7 +230,7 @@ function attachDragBehavior(selection) {
220
230
if ( d . parent . inBrushDrag ) {
221
231
return ;
222
232
}
223
- var y = d . unitScaleInOrder ( d . unitScale . invert ( d3 . mouse ( this ) [ 1 ] ) ) ;
233
+ var y = d . unitScaleInOrder ( d . unitScale . invert ( d3 . mouse ( this ) [ 1 ] + c . verticalPadding ) ) ;
224
234
var interval = getInterval ( b , d . unitScaleInOrder , y ) ;
225
235
d3 . select ( document . body )
226
236
. style ( 'cursor' , interval . n ? 'n-resize' : interval . s ? 's-resize' : ! interval . m ? 'crosshair' : filterActive ( b ) ? 'ns-resize' : 'crosshair' ) ;
@@ -235,13 +245,13 @@ function attachDragBehavior(selection) {
235
245
. on ( 'dragstart' , function ( d ) {
236
246
var e = d3 . event ;
237
247
e . sourceEvent . stopPropagation ( ) ;
238
- var y = d . unitScaleInOrder ( d . unitScale . invert ( d3 . mouse ( this ) [ 1 ] ) ) ;
248
+ var y = d . unitScaleInOrder ( d . unitScale . invert ( d3 . mouse ( this ) [ 1 ] + c . verticalPadding ) ) ;
239
249
var unitLocation = d . unitScaleInOrder . invert ( y ) ;
240
250
var b = d . brush ;
241
251
var intData = getInterval ( b , d . unitScaleInOrder , y ) ;
242
252
var unitRange = intData . interval ;
243
253
var pixelRange = unitRange . map ( d . unitScaleInOrder ) ;
244
- var s = b . svgBrush2 ;
254
+ var s = b . svgBrush ;
245
255
var active = filterActive ( b ) ;
246
256
var barInteraction = unitRange && ( intData . m || intData . s || intData . n ) ;
247
257
s . wasDragged = false ; // we start assuming there won't be a drag - useful for reset
@@ -264,8 +274,8 @@ function attachDragBehavior(selection) {
264
274
} )
265
275
. on ( 'drag' , function ( d ) {
266
276
var e = d3 . event ;
267
- var y = d . unitScaleInOrder ( d . unitScale . invert ( e . y ) ) ;
268
- var s = d . brush . svgBrush2 ;
277
+ var y = d . unitScaleInOrder ( d . unitScale . invert ( e . y + c . verticalPadding ) ) ;
278
+ var s = d . brush . svgBrush ;
269
279
s . wasDragged = true ;
270
280
e . sourceEvent . stopPropagation ( ) ;
271
281
@@ -300,7 +310,7 @@ function attachDragBehavior(selection) {
300
310
e . sourceEvent . stopPropagation ( ) ;
301
311
var brush = d . brush ;
302
312
var filter = brush . filter ;
303
- var s = brush . svgBrush2 ;
313
+ var s = brush . svgBrush ;
304
314
var grabbingBar = s . grabbingBar ;
305
315
s . grabbingBar = false ;
306
316
s . grabLocation = undefined ;
@@ -311,10 +321,10 @@ function attachDragBehavior(selection) {
311
321
if ( grabbingBar ) {
312
322
s . extent = s . stayingIntervals ;
313
323
if ( s . extent . length === 0 ) {
314
- clearBrushExtent ( brush ) ;
324
+ brushClear ( brush ) ;
315
325
}
316
326
} else {
317
- clearBrushExtent ( brush ) ;
327
+ brushClear ( brush ) ;
318
328
}
319
329
s . brushCallback ( d ) ;
320
330
renderHighlight ( this . parentElement ) ;
@@ -403,37 +413,20 @@ function ensureAxisBrush(axisOverlays) {
403
413
var axisBrush = axisOverlays . selectAll ( '.' + c . cn . axisBrush )
404
414
. data ( repeat , keyFun ) ;
405
415
406
- var axisBrushEnter = axisBrush . enter ( )
416
+ axisBrush . enter ( )
407
417
. append ( 'g' )
408
418
. classed ( c . cn . axisBrush , true ) ;
409
419
410
- var axisBrush2 = axisOverlays . selectAll ( '.' + c . cn . axisBrush + '2' )
411
- . data ( repeat , keyFun ) ;
412
-
413
- axisBrush2 . enter ( )
414
- . append ( 'g' )
415
- . classed ( c . cn . axisBrush + '2' , true ) ;
416
-
417
- setAxisBrush ( axisBrush , axisBrushEnter ) ;
418
- renderAxisBrush ( axisBrush2 ) ;
419
- }
420
-
421
- function clearBrushExtent ( brush ) {
422
- brushClear ( brush ) ;
423
- }
424
-
425
- function setBrushExtent ( brush , range ) {
426
- brush . svgBrush2 . extent [ 0 ] = range [ 0 ] ;
427
- brush . svgBrush2 . extent [ 1 ] = range [ 1 ] ;
420
+ renderAxisBrush ( axisBrush ) ;
428
421
}
429
422
430
423
function getBrushExtent ( brush ) {
431
- return brush . svgBrush2 . extent . map ( function ( e ) { return e . slice ( ) ; } ) ;
424
+ return brush . svgBrush . extent . map ( function ( e ) { return e . slice ( ) ; } ) ;
432
425
}
433
426
434
427
function brushClear ( brush ) {
435
428
brush . filterSpecified = false ;
436
- brush . svgBrush2 . extent = [ [ 0 , 1 ] ] ;
429
+ brush . svgBrush . extent = [ [ 0 , 1 ] ] ;
437
430
}
438
431
439
432
@@ -451,21 +444,6 @@ function axisBrushMoved(callback) {
451
444
} ;
452
445
}
453
446
454
- function setAxisBrush ( axisBrush , root ) {
455
- axisBrush
456
- . each ( function updateBrushExtent ( d ) {
457
- // Set the brush programmatically if data requires so, eg. Plotly `constraintrange` specifies a proper subset.
458
- // This is only to ensure the SVG brush is correct; WebGL lines are controlled from `d.brush.filter` directly.
459
- var b = d . brush ;
460
- var f = b . filter . getBounds ( ) ;
461
- if ( filterActive ( b ) ) {
462
- setBrushExtent ( b , f ) ;
463
- } else {
464
- clearBrushExtent ( b , root ) ;
465
- }
466
- } ) ;
467
- }
468
-
469
447
function dedupeRealRanges ( intervals ) {
470
448
// Fuses elements of intervals if they overlap, yielding discontiguous intervals, results.length <= intervals.length
471
449
// Currently uses closed intervals, ie. dedupeRealRanges([[400, 800], [300, 400]]) -> [300, 800]
@@ -503,8 +481,8 @@ function makeBrush(state, rangeSpecified, initialRange, brushStartCallback, brus
503
481
return {
504
482
filter : filter ,
505
483
filterSpecified : rangeSpecified , // there's a difference between not filtering and filtering a non-proper subset
506
- svgBrush2 : {
507
- extent : [ ] , // this is where the svgBrush2 writes contents into
484
+ svgBrush : {
485
+ extent : [ ] , // this is where the svgBrush writes contents into
508
486
brushStartCallback : brushStartCallback ,
509
487
brushCallback : axisBrushMoved ( brushCallback ) ,
510
488
brushEndCallback : brushEndCallback
0 commit comments