-
Notifications
You must be signed in to change notification settings - Fork 184
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
base: master
Are you sure you want to change the base?
Conversation
678d24f
to
a6d5613
Compare
a6d5613
to
a9dd631
Compare
hi @voidcenter can you please update PR title and description? |
@danielbarion sure, it has been a while and I updated the description according to my memory. |
thanks @voidcenter ! |
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); |
There was a problem hiding this comment.
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?
@@ -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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably move the _wheelAxis
out of the Viewport.ts file entirely and have this entire functionality live solely in the clamp plugin, passing the axis to clamp into the plugin's options.
width = this.parent.worldScreenWidth; | ||
height = this.parent.worldScreenHeight; | ||
|
||
if (this.parent._wheelAxis && ['all', 'y'].includes(this.parent._wheelAxis)) { |
There was a problem hiding this comment.
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.
@@ -194,6 +194,8 @@ export class Viewport extends Container | |||
private _worldHeight?: number | null; | |||
private _disableOnContextMenu = (e: MouseEvent) => e.preventDefault(); | |||
|
|||
public _wheelAxis?: 'all' | 'x' | 'y'; |
There was a problem hiding this comment.
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.
width = this.parent.worldScreenWidth; | ||
height = this.parent.worldScreenHeight; | ||
|
||
if (this.parent._wheelAxis && ['all', 'y'].includes(this.parent._wheelAxis)) { |
There was a problem hiding this comment.
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.
@@ -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; |
There was a problem hiding this comment.
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 change enables zooming along only the x-axis or y-axis.