@@ -35,12 +35,25 @@ type HTML() =
35
35
36
36
let scriptContent = """
37
37
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
+ });
42
45
};
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
+ }
44
57
"""
45
58
let guid = Guid.NewGuid() .ToString()
46
59
@@ -49,6 +62,7 @@ renderPlotly_[SCRIPTID]();
49
62
script [_ type " text/javascript" ] [
50
63
rawText (
51
64
scriptContent
65
+ .Replace( " [PLOTLYJS_VERSION]" , Globals.PLOTLYJS_ VERSION)
52
66
.Replace( " [SCRIPTID]" , guid.Replace( " -" , " " ))
53
67
.Replace( " [ID]" , guid)
54
68
.Replace( " [DATA]" , data)
@@ -275,7 +289,7 @@ module GenericChart =
275
289
// let l' = layout |> List.rev
276
290
// reduce l' (Layout())
277
291
278
- let toChartHTML gChart =
292
+ let toChartHTMLNodes gChart =
279
293
let tracesJson =
280
294
let traces = getTraces gChart
281
295
JsonConvert.SerializeObject( traces, Globals.JSON_ CONFIG)
@@ -298,6 +312,10 @@ module GenericChart =
298
312
)
299
313
yield ! displayOpts.Description
300
314
]
315
+
316
+ let toChartHTML gChart =
317
+ gChart
318
+ |> toChartHTMLNodes
301
319
|> RenderView.AsString.htmlNode
302
320
303
321
/// Converts a GenericChart to it HTML representation and embeds it into a html page.
0 commit comments