LorenVS / Eto.OxyPlot

OxyPlot bindings for the Eto UI library
MIT License
2 stars 2 forks source link

Oxyplot for Eto.Mac #3

Open arisrell opened 8 years ago

arisrell commented 8 years ago

I made a test application using OxyPlot. I tried attaching file but too large.

But here's the gist of the issue I am having...

using System; using Eto.Forms; using Eto.Drawing; using Eto.OxyPlot; using OxyPlot; using OxyPlot.Series;

namespace PieChartDemo { public class MainForm : Form { public MainForm() { Title = "My Eto Form"; Title = "My Eto Form"; ClientSize = new Size(600, 600);

        var pf = Eto.Platform.Detect;

        if (pf.IsWpf)
        {
            this.Platform.Add(typeof(Plot.IHandler), () => new Eto.OxyPlot.Wpf.PlotHandler());
        }
        else if (pf.IsMac)
        {
            this.Platform.Add(typeof(Plot.IHandler), () => new MacPlotHandler());  //  <---- i dont know how to make a Plothandler for OSX
        }
        else
        {
            this.Platform.Add(typeof(Plot.IHandler), () => new GtkPlotHandler());
        }

        Eto.OxyPlot.Plot p = new Eto.OxyPlot.Plot();
        p.Width = 400;
        p.Height = 400;
        PlotModel plotModel = new PlotModel { Title = "Pie Sample1" };

        PieSeries seriesP1 = new PieSeries { StrokeThickness = 2.0, InsideLabelPosition = 0.8, AngleSpan = 360, StartAngle = 0 };

        seriesP1.Slices.Add(new PieSlice("Africa", 1030) { IsExploded = false, Fill = OxyColors.PaleVioletRed });
        seriesP1.Slices.Add(new PieSlice("Americas", 929) { IsExploded = true });
        seriesP1.Slices.Add(new PieSlice("Asia", 4157) { IsExploded = true });
        seriesP1.Slices.Add(new PieSlice("Europe", 739) { IsExploded = true });
        seriesP1.Slices.Add(new PieSlice("Oceania", 35) { IsExploded = true });

        plotModel.Series.Add(seriesP1);
        p.Model = plotModel;

        p.Visible = true;

        Content = new StackLayout
        {
            Padding = 10,
            Items =
            {
               p,
                // add more controls here
            }
        };

        // create a few commands that can be used for the menu and toolbar
        var clickMe = new Command { MenuText = "Click Me!", ToolBarText = "Click Me!" };
        clickMe.Executed += (sender, e) => MessageBox.Show(this, "I was clicked!");

        var quitCommand = new Command { MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q };
        quitCommand.Executed += (sender, e) => Application.Instance.Quit();

        var aboutCommand = new Command { MenuText = "About..." };
        aboutCommand.Executed += (sender, e) => MessageBox.Show(this, "About my app...");

        // create menu
        Menu = new MenuBar
        {
            Items =
            {
                // File submenu
                new ButtonMenuItem { Text = "&File", Items = { clickMe } },
                // new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } },
                // new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } },
            },
            ApplicationItems =
            {
                // application (OS X) or file menu (others)
                new ButtonMenuItem { Text = "&Preferences..." },
            },
            QuitItem = quitCommand,
            AboutItem = aboutCommand
        };

        // create toolbar           
        ToolBar = new ToolBar { Items = { clickMe } };
    }
}

}

It works in windows using Wpf and also works in linux using Gtk2.

However, I do not know how to make it work in OSX. I don't know how to make a PlotHandler for OSX.

e.g. Gtk2 plot handler

namespace PieChartDemo {

public class GtkPlotHandler : Eto.GtkSharp.Forms.GtkControl<PlotView, Plot, Control.ICallback>, Plot.IHandler
{
    public PlotModel Model
    {
        get { return Control.Model; }
        set { Control.Model = value; }
    }

    public GtkPlotHandler()
    {
        Control = new global::OxyPlot.GtkSharp.PlotView()
        {
        };
    }
}

}

e.g. Mac PlotHandler ???

namespace PieChartDemo {

//-----------------------------------------whats the correct way to add PlotHandler for Mac OSX ? --------------------------------------------------------------------------
//public class MacPlotHandler : Eto.Mac.Forms.MacContainer<PlotView, Plot, Control.ICallback>, Plot.IHandler // what's the plothandler for Mac
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class MacPlotHandler : Eto.GtkSharp.Forms.GtkControl<PlotView, Plot, Control.ICallback>, Plot.IHandler  // obviously this won't run in OSX
{
    public PlotModel Model
    {
        get { return Control.Model; }
        set { Control.Model = value; }
    }

    public MacPlotHandler()
    {
        Control = new global::OxyPlot.GtkSharp.PlotView()
        {
        };
    }
}

}

Thank you very much for any help you can provide.

willem640 commented 3 years ago

In case anyone runs into this: The Mac platform is (still) not supported by Oxyplot, so until then, writing a PlotHandler is going to be impossible. Xamarin.Mac could work, except for the fact that Eto.Platform.XamMac(2) is weird, and does not include the classes necessary to make this work.