oxyplot / oxyplot-maui

OxyPlot for Maui
MIT License
37 stars 7 forks source link

Mac zoom support #3

Closed janusw closed 3 weeks ago

janusw commented 11 months ago

Carry-over from https://github.com/iniceice88/OxyPlot.Maui.Skia/issues/4 (reported by @KunalKshatriya):

The pan and zoom doesnt work for Mac, I fixed zoom by creating the PlatformTouchEffect for Mac (used the same file as that of iOS).

To make zoom work,

  1. I added the following to the PlotController.cs,

    if MACCATALYST

    this.BindMouseWheel(OxyPlot.PlotCommands.ZoomWheel); this.BindMouseWheel(OxyModifierKeys.Control, OxyPlot.PlotCommands.ZoomWheelFine);

    endif

  2. added the Pan gesture recognizer, and raised the onTouchAction

             CGPoint delta = panGestureRecognizer.TranslationInView(view);
             CGPoint point =  panGestureRecognizer.LocationInView(view);
             var touchArgs = new TouchActionEventArgs(1,
                TouchActionType.MouseWheel,
                new Point[] { new(point.X, point.Y) },
                true)
             {
                 ModifierKeys = OxyModifierKeys.None
             };
             touchArgs.MouseWheelDelta = (int)((1000 + delta.Y) / 1000);
             onTouchAction(Element, touchArgs);

However, it didn't work. Is there something I am missing?