Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScrollZoomHandler: allow to set zoomRate #7863

Merged
merged 5 commits into from
Apr 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/ui/handler/scroll_zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {TaskID} from '../../util/task_queue';

// deltaY value for mouse scroll wheel identification
const wheelZoomDelta = 4.000244140625;

// These magic numbers control the rate of zoom. Trackpad events fire at a greater
// frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick
const defaultZoomRate = 1 / 100;
Expand Down Expand Up @@ -53,6 +54,9 @@ class ScrollZoomHandler {

_frameId: ?TaskID;

_defaultZoomRate: number;
_wheelZoomRate: number;

/**
* @private
*/
Expand All @@ -62,6 +66,9 @@ class ScrollZoomHandler {

this._delta = 0;

this._defaultZoomRate = defaultZoomRate;
this._wheelZoomRate = wheelZoomRate;

bindAll([
'_onWheel',
'_onTimeout',
Expand All @@ -70,6 +77,22 @@ class ScrollZoomHandler {
], this);
}

/**
* Set the zoom rate of a trackpad
* @param {number} [zoomRate = 1/100]
*/
setZoomRate(zoomRate: number) {
this._defaultZoomRate = zoomRate;
}

/**
* Set the zoom rate of a mouse wheel
* @param {number} [wheelZoomRate = 1/450]
*/
setWheelZoomRate(wheelZoomRate: number) {
this._wheelZoomRate = wheelZoomRate;
}

/**
* Returns a Boolean indicating whether the "scroll to zoom" interaction is enabled.
*
Expand Down Expand Up @@ -218,7 +241,7 @@ class ScrollZoomHandler {
// accumulated delta, and update the target zoom level accordingly
if (this._delta !== 0) {
// For trackpad events and single mouse wheel ticks, use the default zoom rate
const zoomRate = (this._type === 'wheel' && Math.abs(this._delta) > wheelZoomDelta) ? wheelZoomRate : defaultZoomRate;
const zoomRate = (this._type === 'wheel' && Math.abs(this._delta) > wheelZoomDelta) ? this._wheelZoomRate : this._defaultZoomRate;
// Scale by sigmoid of scroll wheel delta.
let scale = maxScalePerFrame / (1 + Math.exp(-Math.abs(this._delta * zoomRate)));

Expand Down