From e0c8ae644fff2673f708cf81aead6b145ae57bb7 Mon Sep 17 00:00:00 2001 From: Peter-B- Date: Sun, 23 Jul 2023 21:27:10 +0200 Subject: [PATCH 1/6] Add .ToDump method to GenericChart The method is recognized by LinqPad, and dumps a chart's html into an IFrame, but Chart.saveHtml cannot be called here. --- src/Plotly.NET/ChartAPI/GenericChart.fs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Plotly.NET/ChartAPI/GenericChart.fs b/src/Plotly.NET/ChartAPI/GenericChart.fs index ff0383160..737e1f35a 100644 --- a/src/Plotly.NET/ChartAPI/GenericChart.fs +++ b/src/Plotly.NET/ChartAPI/GenericChart.fs @@ -137,6 +137,16 @@ module GenericChart = type GenericChart = | Chart of Trace * Layout * Config * DisplayOptions | MultiChart of Trace list * Layout * Config * DisplayOptions + + member this.ToDump () = + //let temp = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"{Guid.NewGuid()}.html") + + let html = System.IO.File.ReadAllText "d:\\temp\\chart.html" + + let iFrameType = Type.GetType("LINQPad.Controls.IFrame, LINQPad.Runtime") + let iFrame = System.Activator.CreateInstance(iFrameType, html, true); + + iFrame let toFigure (gChart: GenericChart) = match gChart with From d50a2722b822e3db4799464b46af51550a5a33d0 Mon Sep 17 00:00:00 2001 From: Peter-B- Date: Tue, 25 Jul 2023 20:20:40 +0200 Subject: [PATCH 2/6] Define GernericChart as recursive module --- src/Plotly.NET/ChartAPI/GenericChart.fs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Plotly.NET/ChartAPI/GenericChart.fs b/src/Plotly.NET/ChartAPI/GenericChart.fs index 737e1f35a..d3a5f890f 100644 --- a/src/Plotly.NET/ChartAPI/GenericChart.fs +++ b/src/Plotly.NET/ChartAPI/GenericChart.fs @@ -99,7 +99,7 @@ type HTML() = /// Module to represent a GenericChart [] -module GenericChart = +module rec GenericChart = type Figure = { @@ -228,9 +228,7 @@ module GenericChart = // let l' = getLayouts gChart // MultiChart (traces, Some (layouts@l')) - open Plotly.NET.LayoutObjects // Combines two GenericChart - let combine (gCharts: seq) = // temporary hard fix for some props, see https://github.com/CSBiology/DynamicObj/issues/11 From b7e978807449bf0e13fd394dc356a4428ed308cf Mon Sep 17 00:00:00 2001 From: Peter-B- Date: Tue, 25 Jul 2023 20:20:59 +0200 Subject: [PATCH 3/6] Return real html in Dump --- src/Plotly.NET/ChartAPI/GenericChart.fs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Plotly.NET/ChartAPI/GenericChart.fs b/src/Plotly.NET/ChartAPI/GenericChart.fs index d3a5f890f..a6939727b 100644 --- a/src/Plotly.NET/ChartAPI/GenericChart.fs +++ b/src/Plotly.NET/ChartAPI/GenericChart.fs @@ -139,9 +139,7 @@ module rec GenericChart = | MultiChart of Trace list * Layout * Config * DisplayOptions member this.ToDump () = - //let temp = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"{Guid.NewGuid()}.html") - - let html = System.IO.File.ReadAllText "d:\\temp\\chart.html" + let html = toEmbeddedHTML this let iFrameType = Type.GetType("LINQPad.Controls.IFrame, LINQPad.Runtime") let iFrame = System.Activator.CreateInstance(iFrameType, html, true); From 3d19d96bec66fb41e2821d139abab07d44ce027d Mon Sep 17 00:00:00 2001 From: Peter-B- Date: Tue, 25 Jul 2023 20:43:23 +0200 Subject: [PATCH 4/6] Make ToDump private --- src/Plotly.NET/ChartAPI/GenericChart.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plotly.NET/ChartAPI/GenericChart.fs b/src/Plotly.NET/ChartAPI/GenericChart.fs index a6939727b..784744004 100644 --- a/src/Plotly.NET/ChartAPI/GenericChart.fs +++ b/src/Plotly.NET/ChartAPI/GenericChart.fs @@ -138,7 +138,7 @@ module rec GenericChart = | Chart of Trace * Layout * Config * DisplayOptions | MultiChart of Trace list * Layout * Config * DisplayOptions - member this.ToDump () = + member private this.ToDump () = let html = toEmbeddedHTML this let iFrameType = Type.GetType("LINQPad.Controls.IFrame, LINQPad.Runtime") From 1d7eb0f8a4ec64bc98b94ddc84caeb1cf303b2f9 Mon Sep 17 00:00:00 2001 From: Peter-B- Date: Tue, 25 Jul 2023 20:49:01 +0200 Subject: [PATCH 5/6] Add xml comment --- src/Plotly.NET/ChartAPI/GenericChart.fs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Plotly.NET/ChartAPI/GenericChart.fs b/src/Plotly.NET/ChartAPI/GenericChart.fs index 784744004..87abdd2b1 100644 --- a/src/Plotly.NET/ChartAPI/GenericChart.fs +++ b/src/Plotly.NET/ChartAPI/GenericChart.fs @@ -138,6 +138,8 @@ module rec GenericChart = | Chart of Trace * Layout * Config * DisplayOptions | MultiChart of Trace list * Layout * Config * DisplayOptions + /// Method to support dumping charts in LINQPad. + // See https://www.linqpad.net/CustomizingDump.aspx member private this.ToDump () = let html = toEmbeddedHTML this From b381634b8ab00a7ed351839a254c7f580098cd6a Mon Sep 17 00:00:00 2001 From: Peter-B- Date: Tue, 25 Jul 2023 21:00:43 +0200 Subject: [PATCH 6/6] Avoid null references, if LINQPad.Runtime is not loaded --- src/Plotly.NET/ChartAPI/GenericChart.fs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Plotly.NET/ChartAPI/GenericChart.fs b/src/Plotly.NET/ChartAPI/GenericChart.fs index 87abdd2b1..bb6870239 100644 --- a/src/Plotly.NET/ChartAPI/GenericChart.fs +++ b/src/Plotly.NET/ChartAPI/GenericChart.fs @@ -140,13 +140,16 @@ module rec GenericChart = /// Method to support dumping charts in LINQPad. // See https://www.linqpad.net/CustomizingDump.aspx - member private this.ToDump () = + member private this.ToDump () : System.Object = let html = toEmbeddedHTML this let iFrameType = Type.GetType("LINQPad.Controls.IFrame, LINQPad.Runtime") - let iFrame = System.Activator.CreateInstance(iFrameType, html, true); - - iFrame + + if isNull iFrameType then + this + else + let iFrame = System.Activator.CreateInstance(iFrameType, html, true); + iFrame let toFigure (gChart: GenericChart) = match gChart with