@@ -287,24 +287,18 @@ ScrollBox.prototype.disable = function disable() {
287
287
* @method
288
288
*/
289
289
ScrollBox . prototype . _onBoxDrag = function onBarDrag ( ) {
290
- var xf = this . _xf ,
291
- yf = this . _yf ;
290
+ var translateX = this . _translateX ,
291
+ translateY = this . _translateY ;
292
292
293
293
if ( this . _hbar ) {
294
- var translateXMax = this . position . w - this . _box . w ;
295
-
296
- xf = Lib . constrain ( xf - d3 . event . dx / translateXMax , 0 , 1 ) ;
294
+ translateX -= d3 . event . dx ;
297
295
}
298
- else xf = 0 ;
299
296
300
297
if ( this . _vbar ) {
301
- var translateYMax = this . position . h - this . _box . h ;
302
-
303
- yf = Lib . constrain ( yf - d3 . event . dy / translateYMax , 0 , 1 ) ;
298
+ translateY -= d3 . event . dy ;
304
299
}
305
- else yf = 0 ;
306
300
307
- this . setTranslate ( xf , yf ) ;
301
+ this . setTranslate ( translateX , translateY ) ;
308
302
} ;
309
303
310
304
/**
@@ -313,53 +307,51 @@ ScrollBox.prototype._onBoxDrag = function onBarDrag() {
313
307
* @method
314
308
*/
315
309
ScrollBox . prototype . _onBarDrag = function onBarDrag ( ) {
316
- var xf = this . _xf ,
317
- yf = this . _yf ;
310
+ var translateX = this . _translateX ,
311
+ translateY = this . _translateY ;
318
312
319
313
if ( this . _hbar ) {
320
- var translateXMax = this . position . w - this . _box . w ,
321
- translateX = xf * translateXMax ,
322
- xMin = translateX + this . _hbarXMin ,
314
+ var xMin = translateX + this . _hbarXMin ,
323
315
xMax = xMin + this . _hbarTranslateMax ,
324
- x = Lib . constrain ( d3 . event . x , xMin , xMax ) ;
316
+ x = Lib . constrain ( d3 . event . x , xMin , xMax ) ,
317
+ xf = ( x - xMin ) / ( xMax - xMin ) ;
325
318
326
- xf = ( x - xMin ) / ( xMax - xMin ) ;
319
+ var translateXMax = this . position . w - this . _box . w ;
320
+
321
+ translateX = xf * translateXMax ;
327
322
}
328
- else xf = 0 ;
329
323
330
324
if ( this . _vbar ) {
331
- var translateYMax = this . position . h - this . _box . h ,
332
- translateY = yf * translateYMax ,
333
- yMin = translateY + this . _vbarYMin ,
325
+ var yMin = translateY + this . _vbarYMin ,
334
326
yMax = yMin + this . _vbarTranslateMax ,
335
- y = Lib . constrain ( d3 . event . y , yMin , yMax ) ;
327
+ y = Lib . constrain ( d3 . event . y , yMin , yMax ) ,
328
+ yf = ( y - yMin ) / ( yMax - yMin ) ;
329
+
330
+ var translateYMax = this . position . h - this . _box . h ;
336
331
337
- yf = ( y - yMin ) / ( yMax - yMin ) ;
332
+ translateY = yf * translateYMax ;
338
333
}
339
- else yf = 0 ;
340
334
341
- this . setTranslate ( xf , yf ) ;
335
+ this . setTranslate ( translateX , translateY ) ;
342
336
} ;
343
337
344
338
/**
345
339
* Set clip path and scroll bar translate transform
346
340
*
347
341
* @method
348
- * @param {number } [xf =0] Horizontal position as a container fraction
349
- * @param {number } [yf =0] Vertical position as a container fraction
342
+ * @param {number } [translateX =0] Horizontal offset (in pixels)
343
+ * @param {number } [translateY =0] Vertical offset (in pixels)
350
344
*/
351
- ScrollBox . prototype . setTranslate = function setTranslate ( xf , yf ) {
352
- xf = Lib . constrain ( xf || 0 , 0 , 1 ) ;
353
- yf = Lib . constrain ( yf || 0 , 0 , 1 ) ;
345
+ ScrollBox . prototype . setTranslate = function setTranslate ( translateX , translateY ) {
346
+ // store translateX and translateY (needed by mouse event handlers)
347
+ var translateXMax = this . position . w - this . _box . w ,
348
+ translateYMax = this . position . h - this . _box . h ;
354
349
355
- // store xf and yf (needed by ScrollBox.prototype._on*Drag)
356
- this . _xf = xf ;
357
- this . _yf = yf ;
350
+ translateX = Lib . constrain ( translateX || 0 , 0 , translateXMax ) ;
351
+ translateY = Lib . constrain ( translateY || 0 , 0 , translateYMax ) ;
358
352
359
- var translateXMax = this . position . w - this . _box . w ,
360
- translateYMax = this . position . h - this . _box . h ,
361
- translateX = xf * translateXMax ,
362
- translateY = yf * translateYMax ;
353
+ this . _translateX = translateX ;
354
+ this . _translateY = translateY ;
363
355
364
356
this . container . call ( Lib . setTranslate ,
365
357
this . _box . l - this . position . l - translateX ,
@@ -373,12 +365,16 @@ ScrollBox.prototype.setTranslate = function setTranslate(xf, yf) {
373
365
}
374
366
375
367
if ( this . _hbar ) {
368
+ var xf = translateX / translateXMax ;
369
+
376
370
this . _hbar . call ( Lib . setTranslate ,
377
371
translateX + xf * this . _hbarTranslateMax ,
378
372
translateY ) ;
379
373
}
380
374
381
375
if ( this . _vbar ) {
376
+ var yf = translateY / translateYMax ;
377
+
382
378
this . _vbar . call ( Lib . setTranslate ,
383
379
translateX ,
384
380
translateY + yf * this . _vbarTranslateMax ) ;
0 commit comments