gillius / jfxutils

JavaFX Utilities - Zoom and Pan Charts and Pane Scaling
Apache License 2.0
68 stars 22 forks source link

Zooming with mouse drag from right to left #19

Closed Jeredriq closed 6 years ago

Jeredriq commented 6 years ago

Hi,

My application can zoom when primary mouse key is pressed, dragged right side of the screen and released and it draws a rectangle to show the area it'll zoom.

But whenever I try to do this from right to lleft, nothing happens. What may be the cause?

Edit: Checked the demo for jfxutils, it has the same issue. How can I fix this?

gillius commented 6 years ago

I don't see a reason for this other than not implementing the code to properly handle the Rectangle in ChartZoomManager. A Rectangle has x, y, width, height. Logic would be needed to know whether to adjust x/y, or both x/y and width/height. I used property binding to keep it easier.

The methods that would need to change are start, onMousePressed, onMouseDragged, and onMouseReleased.

Jeredriq commented 6 years ago

The thing is I cant do the motion I've told in org.gillius.jfxutils.examples.Charting too. And I'm looking for a way to do this.

Maybe I didnt tell what happens quite right, lets say I pressed left mouse key at 346,368 coordinates. If I drag it to 400,400 It works without any problem but if I try to drag them to 300,368 / 346,300 / 300,300 it does not zoom.

I believe there is a check whether its positive distance for drawing the rectangle and zooming but sadly I couldnt find it

gillius commented 6 years ago

Yes, I understand what you are trying to do. In my earlier comment, I mentioned that because of the way the Rectangle class works with x/y/w/h, I didn't go through the logic to adjust the x and y as well so to be quick in coding I just clamped it to only allow positive x and y. The ChartZoomManager start, onMousePressed, onMouseDragged, and onMouseRelease methods could be modified to better track the state to modify all 4 Rectangle attributes depending on negative or positive mouse drags. I'm no longer maintaining the library but I'll be responsive for any PRs.

Jeredriq commented 6 years ago

Thanks, I'll try to fix it and whenever I can, I'll send a PR