diff --git a/src/Plotly.NET/ChartAPI/GenericChart.fs b/src/Plotly.NET/ChartAPI/GenericChart.fs index ba6336b4..34c3c4c9 100644 --- a/src/Plotly.NET/ChartAPI/GenericChart.fs +++ b/src/Plotly.NET/ChartAPI/GenericChart.fs @@ -5,6 +5,9 @@ open System open Newtonsoft.Json open System.Runtime.CompilerServices open Giraffe.ViewEngine +open System +open System.IO +open System.Collections.Generic /// Figure is a domain transfer object that can be used to serialize a Chart to JSON. It is used internally and for most use cases should not be used directly. /// @@ -55,6 +58,7 @@ type ChartDTO = /// - `Config` is an object that configures high level properties of the chart like making all chart elements editable or the tool bar on top /// /// - `DisplayOptions` is an object that contains meta information about how the html document that contains the chart. +[)>] type GenericChart = | Chart of data: Trace * layout: Layout * config: Config * displayOpts: DisplayOptions | MultiChart of data: Trace list * layout: Layout * config: Config * displayOpts: DisplayOptions @@ -584,3 +588,22 @@ type GenericChart = match gChart with | Chart(trace, _, _, _) -> [ TraceID.ofTrace trace ] | MultiChart(traces, _, _, _) -> traces |> List.map TraceID.ofTrace + +and GenericChartFormatter() = + let mutable mimeType = "text/html" + member this.MimeType + with get() = mimeType + and set(v) = mimeType <- v + member this.Format(instance:obj, writer:TextWriter) = + match instance with + | :? GenericChart as c -> + writer.Write("LOL!") + true + | _ -> false + +and GenericChartFormatterSource = + member this.CreateTypeFormatters() : seq = + seq { + yield GenericChartFormatter() + } + diff --git a/src/Plotly.NET/InternalUtils.fs b/src/Plotly.NET/InternalUtils.fs index c55db149..bc09619a 100644 --- a/src/Plotly.NET/InternalUtils.fs +++ b/src/Plotly.NET/InternalUtils.fs @@ -5,6 +5,7 @@ open DynamicObj open System.Runtime.InteropServices open System.IO open System.Reflection +open System let combineOptSeqs (first: seq<'A> option) (second: seq<'A> option) = match first, second with @@ -129,3 +130,13 @@ module internal ChartIO = System.Diagnostics.Process.Start("open", path) |> ignore else invalidOp "Not supported OS platform" + +[] +type internal TypeFormatterSourceAttribute(formatterSourceType: Type) = + inherit Attribute() + let mutable preferredMimeTypes : string[] = [||] + member this.TypeFormatterSourceType = formatterSourceType + member this.PreferredMimeTypes + with get() = preferredMimeTypes + and set(v) = preferredMimeTypes <- v + \ No newline at end of file diff --git a/tests/InteractiveTests/Repack.ps1 b/tests/InteractiveTests/Repack.ps1 new file mode 100644 index 00000000..22c615a4 --- /dev/null +++ b/tests/InteractiveTests/Repack.ps1 @@ -0,0 +1,7 @@ +# Clean up the previously-cached NuGet packages. +# Lower-case is intentional (that's how nuget stores those packages). +Remove-Item -Recurse ~\.nuget\packages\plotly.net* -Force + +# build and pack Plotly.NET.Interactive +dotnet pack ../../src/Plotly.NET/Plotly.NET.fsproj -tl -c Release -p:PackageVersion=0.0.1-dev -o "./pkg" + diff --git a/tests/InteractiveTests/TestNotebook.ipynb b/tests/InteractiveTests/TestNotebook.ipynb new file mode 100644 index 00000000..77a561bc --- /dev/null +++ b/tests/InteractiveTests/TestNotebook.ipynb @@ -0,0 +1,121 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "source": [ + "To reproduce the package, run `./Repack.ps1` in powershell. It will clean your cache in `~/.nuget/packages` and pack the library to `Plotly.NET/pkg` folder, which you should specify below (absolute paths only) in `#i` line.\n", + "\n", + "The version of the package is always `0.0.0-dev`." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
Restore sources
  • C:/Users/schne/source/repos/plotly/Plotly.NET/pkg
Installed Packages
  • Plotly.NET, 2.0.0-alpha2
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "// be advised, that you always should set absolute paths for local nuget packages - change this to reflect your own setup\n", + "#i \"nuget: C:/Users/schne/source/repos/plotly/Plotly.NET/tests/Interactivetests/pkg\"\n", + "#r \"nuget: Plotly.NET, 0.0.1-dev\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "

lel!

" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "open Plotly.NET\n", + "open Giraffe.ViewEngine\n", + "\n", + "Chart.Point([1,2; 3,4])\n", + "|> Chart.withDescription [\n", + " h1 [] [str \"lel!\"]\n", + "]" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [], + "name": "csharp" + }, + { + "aliases": [ + "frontend" + ], + "name": "vscode" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}