Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to dib extension #572

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@

<ItemGroup>
<Compile Include="Plot.fs" />
<None Include="Repack.ps1" />

<Compile Include="KernelExtension.fs" />
<None Include="DevRepack.ps1" />
<Compile Include="AggressiveOperators.fs" />
</ItemGroup>

Expand All @@ -42,20 +40,18 @@

<ItemGroup>
<PackageReference Include="AngouriMath.FSharp" Version="1.4.0-preview.3" />
<PackageReference Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.21606.1" />
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.21606.1" />
<PackageReference Include="Plotly.NET" Version="2.0.0-preview.16" />
<PackageReference Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.22314.1" />
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.22314.1" />
<PackageReference Include="Plotly.NET" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<None Include="$(OutputPath)/AngouriMath.Interactive.dll">
<Pack>True</Pack>
<PackagePath>interactive-extensions/dotnet</PackagePath>
</None>
<None Include="extension.dib" Pack="true" PackagePath="interactive-extensions/dotnet" />
<Content Include="README.md" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="5.0.0" />
<PackageReference Update="FSharp.Core" Version="6.0.2" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions Sources/Wrappers/AngouriMath.Interactive/DevRepack.ps1
Original file line number Diff line number Diff line change
@@ -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"
54 changes: 0 additions & 54 deletions Sources/Wrappers/AngouriMath.Interactive/KernelExtension.fs

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/Wrappers/AngouriMath.Interactive/Plot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions Sources/Wrappers/AngouriMath.Interactive/README.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 0 additions & 9 deletions Sources/Wrappers/AngouriMath.Interactive/Repack.ps1

This file was deleted.

45 changes: 45 additions & 0 deletions Sources/Wrappers/AngouriMath.Interactive/extension.dib
Original file line number Diff line number Diff line change
@@ -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 -> $@"
<script src='https://polyfill.io/v3/polyfill.min.js?features=es6'></script>
<script id='MathJax-script' async src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'></script>
\[{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<EDecimal>, "text/plain")
Formatter.Register<EDecimal>(new Func<EDecimal, string>(fun o -> o.ToString()), "text/plain")

Formatter.SetPreferredMimeTypesFor(typeof<EInteger>, "text/plain")
Formatter.Register<EInteger>(new Func<EInteger, string>(fun o -> o.ToString()), "text/plain")

registerLatexRendering (fun (o : ILatexiseable) -> latex o)

registerLatexRendering (fun (o : ERational) -> $@"\frac{{{o.Numerator}}}{{{o.Denominator}}}")

Formatter.SetPreferredMimeTypesFor(typeof<GenericChart>, "text/html")
Formatter.Register<GenericChart> (toChartHTML, "text/html")

printfn $"LaTeX renderer binded. Enjoy!"