Skip to content

Commit

Permalink
Merge pull request #180 from nojaf/static-setters
Browse files Browse the repository at this point in the history
Add static setters to KernelExtension.
  • Loading branch information
cartermp authored Apr 24, 2024
2 parents 6316952 + ad52660 commit 3efef90
Showing 1 changed file with 13 additions and 5 deletions.
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

0 comments on commit 3efef90

Please sign in to comment.