ChartsOrg / Charts

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

Scrollwheel/trackpad scrolling for MacOS #5012

Open RCCoop opened 1 year ago

RCCoop commented 1 year ago

Goals :soccer:

Allow for scrolling around the chart on MacOS using two-finger trackpad scrolling, which is a more natural interaction than having to click and drag.

Implementation Details :construction:

Being new to this library, I may not be doing this the most elegant way, but I added override func scrollWheel(with:) to BarLineChartViewBase, and wrapped it with #if os(macOS). To implement the scrollWheel function, I mostly copied panGestureRecognized(_:), removing options that seemed specific to GestureRecognizer implementations, and replacing the translation and velocity calculations with NSEvent versions. The end result is that you can pan around in the view using two-finger trackpad scrolling.

Testing Details :mag:

I tested by using the ChartsDemo-macOS app in both BarDemoViewController and LineDemoViewController, each with and without dragDecelerationEnabled, to zoom and scroll. It was very simple testing, but it seemed to work.