@@ -35,12 +35,25 @@ type HTML() =
3535
3636 let scriptContent = """
3737var 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.
0 commit comments