Skip to content

Zoom along a single axis #470

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/Viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ export class Viewport extends Container
private _worldHeight?: number | null;
private _disableOnContextMenu = (e: MouseEvent) => e.preventDefault();

public _wheelAxis?: 'all' | 'x' | 'y';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's public, why the underscore? Should also make it non-optional and always have a value of one of the three, defaulting to 'all'. Possibly rename to something more generic like scaleAxis since scaling is not solely done by wheel, and wheel is not a global concept in this file but is handled by a plugin.


/**
* @param {IViewportOptions} ViewportOptions
* @param {number} [options.screenWidth=window.innerWidth]
Expand Down
16 changes: 12 additions & 4 deletions src/plugins/ClampZoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,29 @@ export class ClampZoom extends Plugin
if (this.options.minWidth !== null && width < this.options.minWidth)
{
const original = this.parent.scale.x;
console.log('-- minwidth', this.parent._wheelAxis);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove the console.log?


this.parent.fitWidth(this.options.minWidth, false, false, true);
this.parent.scale.y *= this.parent.scale.x / original;
width = this.parent.worldScreenWidth;
height = this.parent.worldScreenHeight;

if (this.parent._wheelAxis && ['all', 'y'].includes(this.parent._wheelAxis)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needlessly expensive. I'd switch this to a simple comparison.

this.parent.scale.y *= this.parent.scale.x / original;
height = this.parent.worldScreenHeight;
}
this.parent.emit('zoomed', { viewport: this.parent, type: 'clamp-zoom' });
}
if (this.options.maxWidth !== null && width > this.options.maxWidth)
{
const original = this.parent.scale.x;
console.log('-- maxwidth', this.parent._wheelAxis);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please remove the console.log?


this.parent.fitWidth(this.options.maxWidth, false, false, true);
this.parent.scale.y *= this.parent.scale.x / original;
width = this.parent.worldScreenWidth;
height = this.parent.worldScreenHeight;

if (this.parent._wheelAxis && ['all', 'y'].includes(this.parent._wheelAxis)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also switch to simple comparison.

this.parent.scale.y *= this.parent.scale.x / original;
height = this.parent.worldScreenHeight;
}
this.parent.emit('zoomed', { viewport: this.parent, type: 'clamp-zoom' });
}
if (this.options.minHeight !== null && height < this.options.minHeight)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/Wheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class Wheel extends Plugin
{
super(parent);
this.options = Object.assign({}, DEFAULT_WHEEL_OPTIONS, options);
this.parent._wheelAxis = this.options.axis;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not have to be in the wheel at all as it's not a wheel-specific concept.

this.keyIsPressed = false;

if (this.options.keyToPress)
Expand Down