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

WIP - Add interactive extension packaging #153

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 17 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet3-dev" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1/nuget/v3/index.json" />
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
<add key="MachineLearning" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/MachineLearning/nuget/v3/index.json" />
<add key="PSGallery" value="https://www.powershellgallery.com/api/v2/" />
</packageSources>
<disabledPackageSources />
</configuration>
9 changes: 9 additions & 0 deletions XPlot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{E496D57B
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "XPlot.Plotly.Tests", "tests\XPlot.Plotly.Tests\XPlot.Plotly.Tests.fsproj", "{55A86A1D-0845-45FE-8AB8-88226CCAD4FF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{493A4548-3241-4967-83FD-6B4371EFE677}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "XPlot.Plotly.InteractiveExtension", "src\XPlot.Plotly.InteractiveExtension\XPlot.Plotly.InteractiveExtension.fsproj", "{033E06DB-9831-4702-AD7F-188848319743}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -127,6 +131,10 @@ Global
{55A86A1D-0845-45FE-8AB8-88226CCAD4FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{55A86A1D-0845-45FE-8AB8-88226CCAD4FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{55A86A1D-0845-45FE-8AB8-88226CCAD4FF}.Release|Any CPU.Build.0 = Release|Any CPU
{033E06DB-9831-4702-AD7F-188848319743}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{033E06DB-9831-4702-AD7F-188848319743}.Debug|Any CPU.Build.0 = Debug|Any CPU
{033E06DB-9831-4702-AD7F-188848319743}.Release|Any CPU.ActiveCfg = Release|Any CPU
{033E06DB-9831-4702-AD7F-188848319743}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -137,6 +145,7 @@ Global
{1F19571C-5074-44FC-973B-3E93E9FF531B} = {8E6D5255-776D-4B61-85F9-73C37AA1FB9A}
{96EA8D03-DF03-4F6F-B11F-C44457AA1F24} = {2FEE29BC-56F6-4189-BF78-F6E0462AC116}
{55A86A1D-0845-45FE-8AB8-88226CCAD4FF} = {E496D57B-837B-477C-8688-BC861C34DEBB}
{033E06DB-9831-4702-AD7F-188848319743} = {493A4548-3241-4967-83FD-6B4371EFE677}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {63675CE2-3907-4F15-9CB8-7D2494ECAA7B}
Expand Down
50 changes: 50 additions & 0 deletions src/XPlot.Plotly.InteractiveExtension/KernelExtension.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace XPlot.DotNet.Interactive.KernelExtensions

open System
open System.Text
open System.IO
open System.Threading.Tasks

open Microsoft.AspNetCore.Html
open Microsoft.DotNet.Interactive
open Microsoft.DotNet.Interactive.Formatting
open Microsoft.DotNet.Interactive.Http
open XPlot.Plotly

open Giraffe.ViewEngine

type KernelExtension() =
let getScriptElementWithRequire (script: string) =
let newScript = StringBuilder()
newScript.AppendLine("""<script type="text/javascript">""") |> ignore
newScript.AppendLine("""
var renderPlotly = function() {
var xplotRequire = require.config({context:'xplot-3.0.1',paths:{plotly:'https://cdn.plot.ly/plotly-1.49.2.min'}}) || require;
xplotRequire(['plotly'], function(Plotly) {" """) |> ignore
newScript.AppendLine(script) |> ignore
newScript.AppendLine(@"});
};"
) |> ignore
newScript.AppendLine(JavascriptUtilities.GetCodeForEnsureRequireJs(Uri("https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"), "renderPlotly")) |> ignore
newScript.ToString()

let getHtml (chart: PlotlyChart) =
let styleStr = sprintf "width: %dpx; height: %dpx;" chart.Width chart.Height
let divElem =
div [_style styleStr; _id chart.Id] [] |> RenderView.AsString.htmlDocument

let js = chart.GetInlineJS().Replace("<script>", String.Empty).Replace("</script>", String.Empty)
HtmlString(divElem + getScriptElementWithRequire js)

let registerPlotlyFormatters () =
Formatter.Register<PlotlyChart>(
Action<_,_>(fun (chart: PlotlyChart) (writer: TextWriter) ->
writer.Write(getHtml chart)),
HtmlFormatter.MimeType)

interface IKernelExtension with
member _.OnLoadAsync _ =
registerPlotlyFormatters()
Task.CompletedTask


Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="KernelExtension.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Giraffe.ViewEngine" Version="1.2.0" />
<PackageReference Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.20522.4" />
<PackageReference Include="Microsoft.Dotnet.Interactive.http" Version="1.0.0-beta.20522.4"/>
<PackageReference Update="FSharp.Core" Version="4.7.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\XPlot.Plotly\XPlot.Plotly.fsproj" />
</ItemGroup>
</Project>
35 changes: 35 additions & 0 deletions src/XPlot.Plotly.nuget/XPlot.Plotly.nuget.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IncludeBuildOutput>false</IncludeBuildOutput>
<PackageId>XPlot.Plotly</PackageId>
<IsPackable>true</IsPackable>
<PackageVersion>3.1.0-beta-2</PackageVersion>
<PackageLicense></PackageLicense>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://fslab.org/XPlot/</PackageProjectUrl>
<RepositoryUrl>http://github.com/fsprojects/FSharp.TypeProviders.SDK</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\XPlot.Plotly\XPlot.Plotly.fsproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\XPlot.Plotly.InteractiveExtension\XPlot.Plotly.InteractiveExtension.fsproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<None
Include="../XPlot.Plotly/bin/$(Configuration)/netstandard2.0/*.dll"
Pack="true"
PackagePath="lib/netstandard2.0" />
<None
Include="../XPlot.Plotly.InteractiveExtension/bin/$(Configuration)/$(TargetFramework)/XPlot.Plotly.InteractiveExtension.dll"
Pack="true"
PackagePath="interactive-extensions/dotnet" />
</ItemGroup>
</Project>
9 changes: 8 additions & 1 deletion src/XPlot.Plotly/XPlot.Plotly.fsproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
</PropertyGroup>

<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="PlotBase/Angularaxis.fs" />
Expand Down Expand Up @@ -72,5 +74,10 @@
<Compile Include="Main.fs" />
<Content Include="paket.references" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Update="FSharp.Core" Version="4.7.2" />
</ItemGroup>

</Project>
2 changes: 0 additions & 2 deletions src/XPlot.Plotly/paket.references

This file was deleted.

27 changes: 0 additions & 27 deletions src/XPlot.Plotly/paket.template

This file was deleted.