From 7c25c5d5b1d5da99fd1bb91cc3d51a234e2eb296 Mon Sep 17 00:00:00 2001 From: WhiteBlackGoose Date: Thu, 23 Jun 2022 18:14:14 +0300 Subject: [PATCH] WIP --- .../AngouriMath.Interactive.fsproj | 18 +++---- .../AngouriMath.Interactive/DevRepack.ps1 | 13 +++++ .../KernelExtension.fs | 54 ------------------- .../Wrappers/AngouriMath.Interactive/Plot.fs | 2 +- .../AngouriMath.Interactive/README.md | 11 ++++ .../AngouriMath.Interactive/Repack.ps1 | 9 ---- .../AngouriMath.Interactive/extension.dib | 45 ++++++++++++++++ 7 files changed, 77 insertions(+), 75 deletions(-) create mode 100644 Sources/Wrappers/AngouriMath.Interactive/DevRepack.ps1 delete mode 100644 Sources/Wrappers/AngouriMath.Interactive/KernelExtension.fs create mode 100644 Sources/Wrappers/AngouriMath.Interactive/README.md delete mode 100644 Sources/Wrappers/AngouriMath.Interactive/Repack.ps1 create mode 100644 Sources/Wrappers/AngouriMath.Interactive/extension.dib diff --git a/Sources/Wrappers/AngouriMath.Interactive/AngouriMath.Interactive.fsproj b/Sources/Wrappers/AngouriMath.Interactive/AngouriMath.Interactive.fsproj index 6eeda4799..cb204fe7a 100644 --- a/Sources/Wrappers/AngouriMath.Interactive/AngouriMath.Interactive.fsproj +++ b/Sources/Wrappers/AngouriMath.Interactive/AngouriMath.Interactive.fsproj @@ -28,9 +28,7 @@ - - - + @@ -42,20 +40,18 @@ - - - + + + - - True - interactive-extensions/dotnet - + + - + diff --git a/Sources/Wrappers/AngouriMath.Interactive/DevRepack.ps1 b/Sources/Wrappers/AngouriMath.Interactive/DevRepack.ps1 new file mode 100644 index 000000000..5bf7786f6 --- /dev/null +++ b/Sources/Wrappers/AngouriMath.Interactive/DevRepack.ps1 @@ -0,0 +1,13 @@ +# This file is for developers only + +# clean up the previously-cached NuGet packages +Remove-Item -Recurse ~\.nuget\packages\AngouriMath.Interactive* -Force +Remove-Item -Recurse ~\.nuget\packages\AngouriMath.FSharp* -Force + +# build AngouriMath.Interactive +dotnet restore +dotnet clean +dotnet build -c Release /p:Version=10.0.0 +dotnet pack -c Release /p:Version=10.0.0 + +Write-Host "Path to package: $PSScriptRoot/bin/Release" diff --git a/Sources/Wrappers/AngouriMath.Interactive/KernelExtension.fs b/Sources/Wrappers/AngouriMath.Interactive/KernelExtension.fs deleted file mode 100644 index 2fff916e5..000000000 --- a/Sources/Wrappers/AngouriMath.Interactive/KernelExtension.fs +++ /dev/null @@ -1,54 +0,0 @@ -namespace AngouriMath.InteractiveExtension - -open Microsoft.DotNet.Interactive -open Microsoft.DotNet.Interactive.Formatting -open AngouriMath.Core -open System.Threading.Tasks -open PeterO.Numbers -open System -open Plotly.NET -open Plotly.NET.GenericChart -open AngouriMath.FSharp.Functions - -type KernelExtension() = - static member public applyMagic () = - let registerLatexRendering (latexiser : 'a -> string) = - // register text/latex - (fun o -> $"$${latexiser o}$$") - |> (fun f -> new Func<'a, string>(f)) - |> (fun f -> Formatter.Register<'a>(f, "text/latex")) - - // register text/html - (fun o -> $@" - - -\[{latexiser o}\]") - |> (fun f -> new Func<'a, string>(f)) - |> (fun f -> Formatter.Register<'a>(f, "text/html")) - - // if possible, use text/latex - Formatter.SetPreferredMimeTypesFor(typeof<'a>, "text/latex") - - - Formatter.SetPreferredMimeTypesFor(typeof, "text/plain") - Formatter.Register(new Func(fun o -> o.ToString()), "text/plain") - - Formatter.SetPreferredMimeTypesFor(typeof, "text/plain") - Formatter.Register(new Func(fun o -> o.ToString()), "text/plain") - - registerLatexRendering (fun (o : ILatexiseable) -> latex o) - - registerLatexRendering (fun (o : ERational) -> $@"\frac{{{o.Numerator}}}{{{o.Denominator}}}") - - Formatter.SetPreferredMimeTypesFor(typeof, "text/html") - Formatter.Register (toChartHTML, "text/html") - - - - interface IKernelExtension with - member _.OnLoadAsync _ = - KernelExtension.applyMagic() - // let message = "LaTeX renderer binded. Enjoy!" - // KernelInvocationContext.Current.Display(message, "text/html") |> ignore - printfn $"LaTeX renderer binded. Enjoy!" - Task.CompletedTask \ No newline at end of file diff --git a/Sources/Wrappers/AngouriMath.Interactive/Plot.fs b/Sources/Wrappers/AngouriMath.Interactive/Plot.fs index 8cab7b14d..5ebafbb70 100644 --- a/Sources/Wrappers/AngouriMath.Interactive/Plot.fs +++ b/Sources/Wrappers/AngouriMath.Interactive/Plot.fs @@ -210,7 +210,7 @@ let private withSliderND<'a, 'b> n (chartPlotter : 'a -> obj -> GenericChart.Gen |> Seq.map (fun step -> let newFunc = compiled step chartPlotter ranges newFunc - |> Chart.withTraceName(Visible = if step = Seq.head paramRange then StyleParam.Visible.True else StyleParam.Visible.False) + |> Chart.withTraceInfo(Visible = if step = Seq.head paramRange then StyleParam.Visible.True else StyleParam.Visible.False) ) |> GenericChart.combine let slider = getSlider paramRange diff --git a/Sources/Wrappers/AngouriMath.Interactive/README.md b/Sources/Wrappers/AngouriMath.Interactive/README.md new file mode 100644 index 000000000..c0ddab03b --- /dev/null +++ b/Sources/Wrappers/AngouriMath.Interactive/README.md @@ -0,0 +1,11 @@ +### Docs for contributors + +To test the extension in notebooks +1. Run `DevRepack.ps1` in powershell +2. Copy the produced path in the end +3. Run these +``` +#i "the_path_from_script" +#r "nuget:AngouriMath.Interactive, *-*" +``` +replacing `the_path_from_script` with the path you just copied. \ No newline at end of file diff --git a/Sources/Wrappers/AngouriMath.Interactive/Repack.ps1 b/Sources/Wrappers/AngouriMath.Interactive/Repack.ps1 deleted file mode 100644 index 558104b98..000000000 --- a/Sources/Wrappers/AngouriMath.Interactive/Repack.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -# clean up the previously-cached NuGet packages -Remove-Item -Recurse ~\.nuget\packages\AngouriMath.Interactive* -Force -Remove-Item -Recurse ~\.nuget\packages\AngouriMath.FSharp* -Force - -# build AngouriMath.Interactive -dotnet restore -dotnet clean -dotnet build -c Release -dotnet pack -c Release \ No newline at end of file diff --git a/Sources/Wrappers/AngouriMath.Interactive/extension.dib b/Sources/Wrappers/AngouriMath.Interactive/extension.dib new file mode 100644 index 000000000..07da6740d --- /dev/null +++ b/Sources/Wrappers/AngouriMath.Interactive/extension.dib @@ -0,0 +1,45 @@ +#!fsharp + +open Microsoft.DotNet.Interactive +open Microsoft.DotNet.Interactive.Formatting +open AngouriMath.Core +open System.Threading.Tasks +open PeterO.Numbers +open System +open Plotly.NET +open Plotly.NET.GenericChart +open AngouriMath.FSharp.Functions + +let registerLatexRendering (latexiser : 'a -> string) = + // register text/latex + (fun o -> $"$${latexiser o}$$") + |> (fun f -> new Func<'a, string>(f)) + |> (fun f -> Formatter.Register<'a>(f, "text/latex")) + + // register text/html + (fun o -> $@" + + +\[{latexiser o}\]") + |> (fun f -> new Func<'a, string>(f)) + |> (fun f -> Formatter.Register<'a>(f, "text/html")) + + // if possible, use text/latex + Formatter.SetPreferredMimeTypesFor(typeof<'a>, "text/latex") + + +Formatter.SetPreferredMimeTypesFor(typeof, "text/plain") +Formatter.Register(new Func(fun o -> o.ToString()), "text/plain") + +Formatter.SetPreferredMimeTypesFor(typeof, "text/plain") +Formatter.Register(new Func(fun o -> o.ToString()), "text/plain") + +registerLatexRendering (fun (o : ILatexiseable) -> latex o) + +registerLatexRendering (fun (o : ERational) -> $@"\frac{{{o.Numerator}}}{{{o.Denominator}}}") + +Formatter.SetPreferredMimeTypesFor(typeof, "text/html") +Formatter.Register (toChartHTML, "text/html") + +printfn $"LaTeX renderer binded. Enjoy!" +