ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.62k stars 6k forks source link

Setting maximum zoom scale causes a scroll problem on reaching maximum zoom scale #3939

Open yigitserin opened 5 years ago

yigitserin commented 5 years ago

What did you do?

I set my chart's maximum zoom scale to a value by using:

barChartView.viewPortHandler.setMaximumScaleX(100.0)

What did you expect to happen?

I expected my chart to be zoomed to 100x scale without problems.

What happened instead?

My chart can be scrolled to 100x scale. But when you reach this zoom level, chart offset slightly changes and user loses their zoom position. Check the attached video.

Charts Environment

Charts version/Branch/Commit Number: 3.2.2 Xcode version: 10.2 Swift version: 4.2 Platform(s) running Charts: iOS macOS version running Xcode: 10.14.4

Demo Video

Demo Video Link

Demo Code

import UIKit
import Charts

class ViewController: UIViewController {

    @IBOutlet weak var barChartView: BarChartView!
    override func viewDidLoad() {
        super.viewDidLoad()

        //Set Chart.
        var dataSets: [BarChartDataSet] = []

        for i in 1...5{
            let entry = BarChartDataEntry(x: Double(i * 10), y: 10.0)
            let dataSet = BarChartDataSet(values: [entry], label: String(i))
            dataSets.append(dataSet)
        }

        barChartView.data = BarChartData(dataSets: dataSets)
        barChartView.viewPortHandler.setMaximumScaleX(100.0)
    }
}
liuxuan30 commented 5 years ago

seems a known issue. but a tough one to fix.

Andy1984 commented 5 years ago

My product manager is arguing about this. Is there any solution, or a compromise solution to hide the bug?

yigitserin commented 5 years ago

My workaround was not setting maximum zoom scale and allowing infinite zoom.

Andy1984 commented 5 years ago

Thank you. My workaround is in ViewPortHandler.swift, private func limitTransAndScale(matrix: inout CGAffineTransform, content: CGRect?)

_scaleX = max(_minScaleX, matrix.a)
_scaleY = max(_minScaleY,  matrix.d)
haemi commented 3 years ago

is there any update on this?