Skip to content

Conversation

@voidcenter
Copy link

@voidcenter voidcenter commented Oct 11, 2023

This change enables zooming along only the x-axis or y-axis.

@voidcenter voidcenter force-pushed the fix-clampzoom branch 2 times, most recently from 678d24f to a6d5613 Compare October 11, 2023 07:54
@danielbarion
Copy link
Collaborator

hi @voidcenter can you please update PR title and description?

@voidcenter voidcenter changed the title cl Zoom by a single axis Nov 13, 2024
@voidcenter voidcenter changed the title Zoom by a single axis Zoom for a single axis Nov 13, 2024
@voidcenter voidcenter changed the title Zoom for a single axis Zoom along a single axis Nov 13, 2024
@voidcenter
Copy link
Author

@danielbarion sure, it has been a while and I updated the description according to my memory.

@danielbarion
Copy link
Collaborator

thanks @voidcenter !

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?

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?

Copy link
Contributor

@lunarraid lunarraid left a 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)) {
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.

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.

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.

{
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants