Charts icon indicating copy to clipboard operation
Charts copied to clipboard

`ViewportHandler.resetZoom()` doesn't reset zoom level to `1.0`, `1.0`

Open jeanetienne opened this issue 5 years ago • 2 comments

What did you do?

In my LineChartView subclass, I called viewPortHandler.resetZoom().

What did you expect to happen?

I expected the viewPortHandler.scaleX to be equal to 1.0

What happened instead?

The value for viewPortHandler.scaleX remained the same as what it was before calling viewPortHandler.resetZoom().

Calling viewPortHandler.resetZoom() had no effect on the zoom level.

Comment

It appears that resetZoom internally calls zoom(scaleX: 1.0, scaleY: 1.0, x: 0.0, y: 0.0) when it seems that it should actually call setZoom(scaleX: 1.0, scaleY: 1.0) instead to achieve the documented effect of Zooms out to original size.

My understanding is that

  • zoom(scaleX: 1.0, scaleY: 1.0, x: 0.0, y: 0.0) zooms the viewport with a zoom factor of 1.0 (no zoom in or zoom out, zoom remains at the same level)
  • setZoom(scaleX: 1.0, scaleY: 1.0) sets the zoom level to the passed value, which is the behaviour expected by resetZoom()

I'm happy to submit a PR for this simple change if you can confirm this is indeed a bug and that resetZoom() doesn't behave as documented.

Thanks!

Charts Environment

Charts version/Branch/Commit Number: 3.3.0 Xcode version: 10.2.1 (10E1001) Swift version: 5.0 Platform(s) running Charts: iOS 12.2 Simulator macOS version running Xcode: Mojave 10.14.5

Demo Project

n/a

jeanetienne avatar Jul 17 '19 05:07 jeanetienne

Having same understanding. Replacing zoom with setZoom seems to be the fix.

RomainPln avatar Apr 24 '20 07:04 RomainPln

@RomainPln 1)how have you "replaced" it with setZoom? Both viewPortHandler.resetZoom() and viewPortHandler.setZoom(...) just return a CGAffineTransform object and apply no changes to zoom by themselves 2)Should I use setZoom returned value or could I just set CGAffineTransform.identity?

Gargo avatar Jul 19 '23 09:07 Gargo