ChartsOrg / ChartsOrg/Charts

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

Open
#4,072 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

* [x] I've read, understood, and done my best to follow the [*CONTRIBUTING guidelines](https://github.com/jjatie/Charts/blob/master/CONTRIBUTING.md).

## 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](https://github.com/danielgindi/Charts/blob/master/Source/Charts/Utils/ViewPortHandler.swift#L199) 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.