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

Problems with zoom #54

Open
Demak opened this issue Sep 2, 2019 · 5 comments
Open

Problems with zoom #54

Demak opened this issue Sep 2, 2019 · 5 comments

Comments

@Demak
Copy link

Demak commented Sep 2, 2019

Hi, found a few problems with zoom policy:

let scrollHeight = this.canvas.getScrollArea().width()

This line should use height() instead of width()

if (zoom === canvas.zoomFactor) {

This is always true when canvas dimensions are changed via setDimension here:
this.setZoom(this.zoomFactor, false)

Because of that currently if you call canvas.setDimension when canvas is zoomed, zoom is not applied back after resize, which results in zoom being visually reset, but still applied on canvas coordinates calculation producing wrong results.

@freegroup
Copy link
Owner

I understand the first part of the ticket (width instead of Height)...but the second part is not clear to me.
Can you please explain it in more detail?

@Demak
Copy link
Author

Demak commented Feb 27, 2020

Hi, it was quite a while ago, but as far as I can remember the problem in second part is that in setDimension we are calling this.setZoom with the first argument being zoomFactor of canvas, which after being passed to WheelZoomPolicy's zoom handler is checked for equality with itself in that condition and thus condition will always be true.
Here is a flow:

this.setZoom(this.zoomFactor, false)

this.zoomPolicy.setZoom(zoomFactor, animated)

this._zoom(zoomFactor, {x: centerX, y: centerY})

if (zoom === canvas.zoomFactor) {

in the end zoom and canvas.zoomFactor is the same variable. Thus there is no actions from WheelZoomPolicy's zoom handler on changing dimensions and as far as I can remember the problem was that zoom is reset to 1:1 in the start of setDimension but because of that condition was not applied back in the end.

Unfortunately I don't remember how I thought to fix it, haven't worked with draw2d for a while.

@freegroup
Copy link
Owner

I got it. Try to fix it

@acrimu
Copy link

acrimu commented Apr 14, 2021

I'm trying to use WeelZoomPolicy but I have some problems.

  1. If I try to use
canvas.installEditPolicy(new draw2d.policy.canvas.WheelZoomPolicy({
    onMouseWheel: function(){
      // This is a <span>
      $("#draw2d_canvas_zoom").text(canvas.getZoom());
    }
  }));

I get in console

WheelZoomPolicy.js:159 Uncaught TypeError: Cannot read property 'zoomFactor' of null
    at Class._zoom (WheelZoomPolicy.js:159)
    at step (WheelZoomPolicy.js:137)
    at t.value (shifty.js:2)
    at shifty.js:2

@phiferd
Copy link

phiferd commented Aug 28, 2021

Not sure if this is the same issue, but there is a bug in the wheel zoom policy.

This line calls _zoom with three parameters (zoom, centerX, centerY):

https://github.com/freegroup/draw2d/blob/master/src/policy/canvas/WheelZoomPolicy.js#L127

But _zoom expects two parameters (zoom, centerPoint).

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

No branches or pull requests

4 participants