I am failing to correctly define the translation/center of a LineChartView when calling:
zoom(scaleX: CGFloat, scaleY: CGFloat, x: CGFloat, y: CGFloat)
I want to store the scale & center chosen by the user and then use it later to recreate the users earlier settings of scale & center.
scaleX & scaleY arrive fine from:
chartScaled(_ chartView: ChartViewBase, scaleX: CGFloat, scaleY: CGFloat)
However I am failing to get/calculate the correct displacement values of x:
& y:
where they are the coordinates (in pixels) of the zoom center. I've tried using transX = lineChartView.viewPortHandler.transX
which I read when chartViewDidEndPanning(_ chartView: ChartViewBase)
is called.
I call fitScreen()
prior to the call to zoom so I end up with the following:
lineChartView.fitScreen() // reset settings
lineChartView.zoom(scaleX: xScale, scaleY: 1.0, x: lineChartView.centerOffsets.x + transX, y: lineChartView.centerOffsets.y + transY)
However this isn't working - all wisdom gratefully accepted.
using ios-charts 3.5.0, ios 14.1, swift 5