Skip to content

Commit 5969de8

Browse files
committed
use plotlyjs v2.18.1 where require bug is fixed
1 parent 6b19df1 commit 5969de8

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/Plotly.NET/ChartAPI/GenericChart.fs

+24-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,25 @@ type HTML() =
3535

3636
let scriptContent = """
3737
var renderPlotly_[SCRIPTID] = function() {
38-
var data = [DATA];
39-
var layout = [LAYOUT];
40-
var config = [CONFIG];
41-
Plotly.newPlot('[ID]', data, layout, config);
38+
var fsharpPlotlyRequire = requirejs.config({context:'fsharp-plotly',paths:{plotly:'https://cdn.plot.ly/plotly-[PLOTLYJS_VERSION].min'}}) || require;
39+
fsharpPlotlyRequire(['plotly'], function(Plotly) {
40+
var data = [DATA];
41+
var layout = [LAYOUT];
42+
var config = [CONFIG];
43+
Plotly.newPlot('[ID]', data, layout, config);
44+
});
4245
};
43-
renderPlotly_[SCRIPTID]();
46+
if ((typeof(requirejs) !== typeof(Function)) || (typeof(requirejs.config) !== typeof(Function))) {
47+
var script = document.createElement("script");
48+
script.setAttribute("src", "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js");
49+
script.onload = function(){
50+
renderPlotly_[SCRIPTID]();
51+
};
52+
document.getElementsByTagName("head")[0].appendChild(script);
53+
}
54+
else {
55+
renderPlotly_[SCRIPTID]();
56+
}
4457
"""
4558
let guid = Guid.NewGuid().ToString()
4659

@@ -49,6 +62,7 @@ renderPlotly_[SCRIPTID]();
4962
script [_type "text/javascript"] [
5063
rawText (
5164
scriptContent
65+
.Replace("[PLOTLYJS_VERSION]",Globals.PLOTLYJS_VERSION)
5266
.Replace("[SCRIPTID]",guid.Replace("-",""))
5367
.Replace("[ID]",guid)
5468
.Replace("[DATA]",data)
@@ -275,7 +289,7 @@ module GenericChart =
275289
// let l' = layout |> List.rev
276290
// reduce l' (Layout())
277291

278-
let toChartHTML gChart =
292+
let toChartHTMLNodes gChart =
279293
let tracesJson =
280294
let traces = getTraces gChart
281295
JsonConvert.SerializeObject(traces, Globals.JSON_CONFIG)
@@ -298,6 +312,10 @@ module GenericChart =
298312
)
299313
yield! displayOpts.Description
300314
]
315+
316+
let toChartHTML gChart =
317+
gChart
318+
|> toChartHTMLNodes
301319
|> RenderView.AsString.htmlNode
302320

303321
/// Converts a GenericChart to it HTML representation and embeds it into a html page.

src/Plotly.NET/Globals.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open Newtonsoft.Json
66
open Giraffe.ViewEngine
77

88
/// The plotly js version loaded from cdn in rendered html docs
9-
let [<Literal>] PLOTLYJS_VERSION = "2.17.1"
9+
let [<Literal>] PLOTLYJS_VERSION = "2.18.1"
1010

1111
///
1212
let internal JSON_CONFIG =

0 commit comments

Comments
 (0)