Anyone working on OxyPlot for GTk# or MonoMac?

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

dsyme wrote at 2013-10-25 14:19:

Hi all,

Is anyone working on an OxyPlot backend for GTk#, or for MonoMac?

People in the F# community are looking for cross-platform charting solutions for basic data visualization purposes in data science programming, and OxyPlot looks like a good candidate for native charting (as opposed to HTML5 charting).

Thanks
Don

objo wrote at 2013-10-25 22:50:

It would be very interesting to see an implementations for OS X!

moljac is working on a Xamarin component - it would be great to see a Xamarin.Mac version in there too!
https://oxyplot.codeplex.com/SourceControl/network/forks/moljac/OxyPlotXamarinComponent

evolvedmicrobe wrote at 2013-11-02 05:10:

Objo, the altsoft guys who just ported Oxyplot (http://www.altsoftlab.com/) make mention of QT and GTK on their website, do you know if this implies it would be easy to use GTK# as a native charting option?

Alternatively, I have been playing around a lot with R.NET. The grid package in R contains all the primitives needed for IRenderContext (excepting some things like ellipses which could be manually done). Most importantly, they implement a textsizemeasurement technique, which for some reason seems hard to find in many places (are you still hoping to remove this though?).

I am writing a wrapper around the R grid package in .NET right now. One advantage of this is if we had Oxyplot to R-Grid Package, we would instantly get access to all the devices in the R "grDevices" package, namely PDF, EPS, PNG, BMP, X11, Screens, etc. etc. This would allow for PDF output on mac and linux to. Not sure if the R dependency would preclude inclusion in the main trunk or if the GTK option is already implied by altsoft, but would be curious to know.

Cheers,
N

objo wrote at 2013-11-03 09:14:

I have only tested the Silverlight version of the altsoftlab port, and the implementation of the IRenderContext seems to be 100%! I don't know how to use it with QT or GTK.

Do you mean http://rdotnet.codeplex.com/ ? I did not see grDevices there.

I am planning to add simple pdf export capabilities into the core library, this will make it available on all platforms and produce identical output everywhere. Hopefully I can submit the code soon!

evolvedmicrobe wrote at 2013-11-03 18:21:

I just tried to get oxyplot working on my mac through altsketch GTK Image.

On the positive side, the plot appears! However, the program gave me a SIGSEV right after taking that screen shot, so I don't know whether or not to call that a proof of principal. The altsketch code also looks a bit hairy and undocumented, so I am not sure how easy it would be to turn it into a native plot utility for F# purposes. Will take a bit of a longer look at it if I can find the time later.

Yep, I did mean http://rdotnet.codeplex.com/ . The grDevices is a library that comes by default with an R installation and handles all the different output devices that can be rendered to. (The figure at the very start of 1.2 in this book probably explains it best: http://www.e-reading.biz/bookreader.php/137370/C486x_C06.pdf )

Simple cross platform PDF export would be AWESOME. Will definitely look forward to seeing that soon!

All the best,
Nigel

dsyme wrote at 2013-11-03 18:24:

I have been looking at this today, going directly to the Mono GTk bindings. I have some most things working, but will need help from a GTk expert for some things. Working on the ExampleBrowser now.

Will share in a few days I hope.

dsyme wrote at 2013-11-04 19:25:

Here's a first cut at a Gtk# backend: https://oxyplot.codeplex.com/SourceControl/network/forks/dsyme/gtksharp/changeset/5f2a17d02561. it uses Mono.Cairo to do the drawing. There are still some TODOs, but all the plots in the ExampleBrowser basically seem to work on both Mac and Windows (using the same portable executable). Caveats
  • Events aren't being processed correctly. I'll look into that.
  • The ExampleBrowser tree control doesn't display correctly on Mac for some reason, but that's not a problem with the oxyplot backend. Also to run Gtk# applications on Mac you have to set an environment variable, see http://stackoverflow.com/questions/13885454/mono-on-osx-couldnt-find-gtksharpglue-2-dll.
  • I haven't tried on Linux X11 or other Gtk# display surfaces.
  • There are a number of TODOs where things were being done in the WindowsForms code which I couldn't map across to Cairo. If anyone knows GtkSharp and can offer advice that would be appreciated.

dsyme wrote at 2013-11-04 19:33:

Example plot using OxyPlot.GtkSharp:

Image

objo wrote at 2013-11-04 19:41:

This is very cool, I'll check it out!

dsyme wrote at 2013-11-05 12:34:

Event handling has been fixed here: https://oxyplot.codeplex.com/SourceControl/network/forks/dsyme/gtksharp/changeset/d9705ea6c345

Here are the possible TODOs (I don't think any are blocking, though it would be very nice to fix the first, and the others would likely improve the beauty of the plots)
  • Fix the example browser so the TreeView works on Mac
  • Configure smoothing mode in GTk#. The equivalent of this GDI:
        g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality; // TODO: Smoothing modes
    
  • Get the DpiX and DpiY values for an image using GDK:
        return image == null ? null : new OxyImageInfo { Width = image.Width, Height = image.Height, __DpiX = 96, DpiY = 96__ }; // TODO DpiX, DpiY
    
  • In DrawImage, the srcX and srcY are being ignored. It doesn't seem to matter though
  • In DrawImage, the opacity is being ignored.
  • In DrawImage, the interpolate is being ignored.
            // g.InterpolationMode = interpolate ? InterpolationMode.HighQualityBicubic : InterpolationMode.NearestNeighbor;
    
  • Is this the right anti-aliasing setting? Other options are "Default", "Grey" and "None"
        g.Antialias = Antialias.Subpixel; // TODO  .TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
    
    

objo wrote at 2013-11-05 13:33:

Great! I could not get the ExampleBrowser to run (Windows 8.1) yesterday, will try to reinstall XamarinStudio and GTK#.
DpiX and DpiY are no more needed in the render context. Sync with the latest version and remove the GetImageInfo method.

dsyme wrote at 2013-11-05 15:38:

I've just
  • updated to head
  • built and run on OSX (all working ok now)
  • built and run on Windows 7 (all ok)
Haven't tried on Windows 8.1

dsyme wrote at 2013-11-05 16:34:

For those interested, here is a script which shows an example of using OxyPlot.GtkSharp.dll from F# Interactive on OSX.
#r "../gtk-sharp-2.0/gtk-sharp.dll"
#r "../gtk-sharp-2.0/gdk-sharp.dll"
#r "../gtk-sharp-2.0/atk-sharp.dll"
#r "../gtk-sharp-2.0/glib-sharp.dll"
        
open System;
open Gtk;

Application.Init();

fsi.EventLoop <- 
 { new Microsoft.FSharp.Compiler.Interactive.IEventLoop with
   member x.Run() = Application.Run() |> ignore; false
   member x.Invoke f = 
     let res = ref None
     let evt = new System.Threading.AutoResetEvent(false)
     Application.Invoke(new System.EventHandler(fun _ _ ->
       res := Some(f())
       evt.Set() |> ignore ))
     evt.WaitOne() |> ignore
     res.Value.Value 
   member x.ScheduleRestart() = () }
   
#r @"/Users/Don/codeplex/gtksharp/Source/OxyPlot.GtkSharp/bin/Debug/OxyPlot.dll"
#r @"/Users/Don/codeplex/gtksharp/Source/OxyPlot.GtkSharp/bin/Debug/OxyPlot.GtkSharp.dll"

module ExampleChart = 
    open OxyPlot   
    open OxyPlot.Series   

    let pm = new PlotModel("Trigonometric functions", "Example using the FunctionSeries", PlotType=PlotType.Cartesian,Background=OxyColors.White)

    pm.Series.Add(new FunctionSeries(Math.Sin, -10.0, 10.0, 0.1, "sin(x)",Color = OxyColors.Black))
    pm.Series.Add(new FunctionSeries(Math.Cos, -10.0, 10.0, 0.1, "cos(x)",Color = OxyColors.Green))
    pm.Series.Add(new FunctionSeries((fun t -> 5.0 * cos t), (fun t -> 5.0 * sin t), 0.0, 2.0 * Math.PI, 0.1, "cos(t),sin(t)", Color = OxyColors.Yellow))
    let plot = new OxyPlot.GtkSharp.Plot(Model = pm )
    plot.SetSizeRequest(400, 400)
    plot.Visible <- true

    let win = new Window("Hello")
    win.SetSizeRequest(600, 600)
    win.Add(plot)
    win.Show()

dsyme wrote at 2013-11-05 16:54:

@objo - can you check tthat I did the merge of the latest oxyplot code correctly? When I try to prepare a pull request it is showing many more diffs than I expected.

The branch I'm trying to send the PR from is here: https://oxyplot.codeplex.com/SourceControl/network/forks/dsyme/gtksharp?branch=default

I did something like this:
hg pull https://hg.codeplex.com/oxyplot
hg merge
hg commit
hg push
Did I forget something? I'm new to Mercurial.

thanks

objo wrote at 2013-11-05 20:20:

It looks good! I pulled it into the main branch!
I also added an OxyPlot.GtkSharp solution and applied StyleCop code cleanup to the new files.

dsyme wrote at 2013-11-05 21:52:

Great! Could you also add a nuget package for this? We want to use it in FSharp.Charting on OSX.

objo wrote at 2013-11-05 22:42:

I have built for .NET 4.0:
http://www.nuget.org/packages/OxyPlot.GtkSharp/
Can this assembly be used on OSX?

dsyme wrote at 2013-11-06 01:16:

Yes, it works just fine. See the sample here (this is using it from F# Interactive - called fsharpi on OSX)

https://gist.github.com/dsyme/7327184

dsyme wrote at 2013-11-06 01:17:

There is also a discussion thread here in the the F# community: https://groups.google.com/forum/#!topic/fsharp-opensource/SlOS0-vyyKI