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

Add static setters to KernelExtension. #180

Merged
merged 1 commit into from
Apr 24, 2024
Merged
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
18 changes: 13 additions & 5 deletions src/XPlot.Plotly.Interactive/KernelExtension.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ open Giraffe.ViewEngine
open XPlot.Plotly.Interactive.PowerShell.Commands

type KernelExtension() =
static let mutable PlotlyUrl = "https://cdn.plot.ly/plotly-1.49.2.min"
static let mutable RequireJsUrl = "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"
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($"""
var renderPlotly = function() {{
var xplotRequire = require.config({{context:'xplot-3.0.1',paths:{{plotly:'%s{PlotlyUrl}'}}}}) || 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.AppendLine(JavascriptUtilities.GetCodeForEnsureRequireJs(Uri(RequireJsUrl), "renderPlotly")) |> ignore
newScript.AppendLine("</script>") |> ignore
newScript.ToString()

Expand Down Expand Up @@ -70,6 +72,12 @@ var renderPlotly = function() {
registerPowerShellAccelerators()
registerPowerShellModule()

/// Override the Plotly cdn url value used in all KernelExtensions.
static member SetPlotlyUrl(url: string) = PlotlyUrl <- url

/// Override the RequireJS cdn url value used in all KernelExtensions.
static member SetRequireJsUrl(url: string) = RequireJsUrl <- url

interface IKernelExtension with
member _.OnLoadAsync kernel =
registerPlotlyFormatters()
Expand Down