Xamarin.mac mouse events not working in OxyPlot

DmitryMineevDmitryMineev USMember
edited April 19 in Xamarin.Mac

I use Xamarin Studio 6.3 with Xamarin.Mac. I want to always show tracking info in OzyPlot.PlotView. I have try to use PlotModel.TrackerChanged, PlotModel.MouseMove, CandleStickSeries.MouseMove and other events. PlotModel.TrackerChanged never happened, CandleStickSeries.MouseMove have happen only when left mouse button down and move.
How can I catch events? In the GTK# all fine.

using System;
using System.Collections.Generic;
using AppKit;
using Foundation;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using OxyPlot.Xamarin.Mac;

namespace OxyPlotTest
{
    public partial class ViewController : NSViewController
    {
        List<HighLowItem> bars;

        public ViewController(IntPtr handle) : base(handle)
        {
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            bars = new List<HighLowItem>();

            PlotView plotView = new PlotView(viewCtrl.Frame);

            PlotModel model = new PlotModel { };

            model.TrackerChanged += OnTrackerChanged;
            model.MouseMove += onSeriesMouseMove;

            model.Axes.Add(new DateTimeAxis
            {
                Position = AxisPosition.Bottom,
                MajorGridlineStyle = LineStyle.Dot,
                MinorGridlineStyle = LineStyle.Dot,
            });

            model.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Left,
                MajorGridlineStyle = LineStyle.Dot,
                MinorGridlineStyle = LineStyle.Dot,
            });

            CandleStickSeries cs = new CandleStickSeries()
            {
                IncreasingFill = OxyColors.DarkGreen,
                DecreasingFill = OxyColors.Red,
                DataFieldX = "X",
                DataFieldHigh = "High",
                DataFieldLow = "Low",
                DataFieldOpen = "Open",
                DataFieldClose = "Close",
                TrackerFormatString = "High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
                ItemsSource = bars

            };

            cs.MouseMove += OnCSMouseMove;

            model.Series.Add(cs);
            plotView.Model = model;

            viewCtrl.AddSubview(plotView);

            bars.Add(new HighLowItem(DateTimeAxis.ToDouble(DateTime.Now), 10, 2, 5, 8));
            bars.Add(new HighLowItem(DateTimeAxis.ToDouble(DateTime.Now.AddMinutes(1)), 15, 6, 8, 11));
            bars.Add(new HighLowItem(DateTimeAxis.ToDouble(DateTime.Now.AddMinutes(2)), 10, 2, 11, 15));
            bars.Add(new HighLowItem(DateTimeAxis.ToDouble(DateTime.Now.AddMinutes(3)), 16, 9, 15, 10));
            bars.Add(new HighLowItem(DateTimeAxis.ToDouble(DateTime.Now.AddMinutes(4)), 11, 5, 10, 8));
            bars.Add(new HighLowItem(DateTimeAxis.ToDouble(DateTime.Now.AddMinutes(5)), 12, 3, 8, 6));

            plotView.InvalidatePlot();
        }

        void OnCSMouseMove(object sender, OxyMouseEventArgs e)
        {
            Console.WriteLine("OnCSMouseMove");
        }

        void onSeriesMouseMove(object sender, OxyMouseEventArgs e)
        {
            Console.WriteLine("onSeriesMouseMove");
        }

        void OnTrackerChanged(object sender, TrackerEventArgs e)
        {
            Console.WriteLine("OnTrackerChanged");
        }

        public override NSObject RepresentedObject
        {
            get
            {
                return base.RepresentedObject;
            }
            set
            {
                base.RepresentedObject = value;
                // Update the view, if already loaded.
            }
        }
    }
}
Tagged:

Answers

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Since OzyPlot is an open source c# library, you might want to start with their community.

    I've never used that library personally, and figuring out why it is not working as expected (are you using library wrong? is there a bug inside it?) will involve some digging into it.

  • DmitryMineevDmitryMineev USMember

    Hello, Chris.

    Thank you for reply. I think that problem in the OxyPlot.Xamarin.Mac library (OxyPlot.Xamarin.Mac.PlotView). Because in other reason (WinForms, GTK# e.t.s) it work fine. I fix it by add NSView object, catch mouse events, and translate it to the Model. But this is no good decision, I think.

Sign In or Register to comment.