XPlot icon indicating copy to clipboard operation
XPlot copied to clipboard

Adding support for .NET Interactive extensions

Open malisimo opened this issue 4 years ago • 0 comments

It would be great if XPlot could support the .NET Interactive extension mechanisms to allow it to work as a plugin to Jupyter Notebooks via a nuget package reference, rather than the .NET Interactive tools taking a hard dependency on XPlot. This is related to the open issue on the .NET Interactive repo #582. This would also address another issue #534.

Describe the solution you'd like The discussion here (in particular this reply) suggests that it should already be possible by adding a dependency on dotnet.interactive and declaring an appropriate implementation of IKernelExtension and registering a handler for the appropriate chart type, for example:

type Layout() =
    member this.Register() =
        let formatFun = 
            fun (chart:PlotlyChart) (writer:System.IO.TextWriter) -> writer.Write(PlotlyChartExtensions.GetHtml(chart))
            |> fun f -> System.Action<_,_>(f)

        Formatter.Register<PlotlyChart>(formatFun,
            HtmlFormatter.MimeType,
            true)

Adding these types in the correct place (i.e. interactive-extensions/dotnet) to the nuget package should allow the .NET Interactive tools to find and register the XPlot type to allow it to be used as a plugin which will render XPlot charts to a MIME type that can be rendered in the notebook.

There may be an issue with target platforms currently - dotnet interactive targets netcoreapp3.1 and not netstandard which means that the XPlot nuget package should likely multitarget both netstandard2.0 and netcoreapp3.1. However this makes things a little ugly where there is conditionally compiled code and references, since XPlot itself should remain platform agnostic.

Doing this work will also pave the way for other plugins to be used within this new .NET Interactive platform.

malisimo avatar Sep 06 '20 17:09 malisimo