Skip to content

Commit

Permalink
fix3801 legend touch-scrolling: natural scrolling with no jumping
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbaldock committed May 21, 2019
1 parent 26ea3bc commit 53fa7f3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,16 @@ module.exports = function draw(gd) {

var eventY0, eventY1, scrollBoxY0;

var getScrollBoxDragY = function(scrollBoxY0, eventY0, eventY1) {
var getScrollBarDragY = function(scrollBoxY0, eventY0, eventY1) {
var y = ((eventY1 - eventY0) / scrollRatio) + scrollBoxY0;
return Lib.constrain(y, 0, scrollBoxYMax);
};

var getNaturalDragY = function(scrollBoxY0, eventY0, eventY1) {
var y = ((eventY0 - eventY1) / scrollRatio) + scrollBoxY0;
return Lib.constrain(y, 0, scrollBoxYMax);
};

// scroll legend by dragging scrollBAR
var scrollBarDrag = d3.behavior.drag()
.on('dragstart', function() {
Expand All @@ -301,7 +306,7 @@ module.exports = function draw(gd) {
} else {
eventY1 = e.clientY;
}
scrollBoxY = getScrollBoxDragY(scrollBoxY0, eventY0, eventY1);
scrollBoxY = getScrollBarDragY(scrollBoxY0, eventY0, eventY1);
scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);
});
scrollBar.call(scrollBarDrag);
Expand All @@ -319,9 +324,8 @@ module.exports = function draw(gd) {
var e = d3.event.sourceEvent;
if(e.type === 'touchmove') {
eventY1 = e.changedTouches[0].clientY;
scrollBoxY = getScrollBoxDragY(scrollBoxY0, eventY0, eventY1);
var naturalScrollBoxY = scrollBoxYMax - scrollBoxY; // inverted for natural-scroll
scrollHandler(naturalScrollBoxY, scrollBarHeight, scrollRatio);
scrollBoxY = getNaturalDragY(scrollBoxY0, eventY0, eventY1);
scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);
}
});
scrollBox.call(scrollBoxTouchDrag);
Expand Down

0 comments on commit 53fa7f3

Please sign in to comment.