Skip to content

Commit 36a9c12

Browse files
authored
LINQPad integration (#404)
* 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. * Define GernericChart as recursive module * Return real html in Dump * Make ToDump private * Add xml comment * Avoid null references, if LINQPad.Runtime is not loaded
1 parent c752bf3 commit 36a9c12

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Plotly.NET/ChartAPI/GenericChart.fs

+14-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type HTML() =
9999

100100
/// Module to represent a GenericChart
101101
[<Extension>]
102-
module GenericChart =
102+
module rec GenericChart =
103103

104104
type Figure =
105105
{
@@ -137,6 +137,19 @@ module GenericChart =
137137
type GenericChart =
138138
| Chart of Trace * Layout * Config * DisplayOptions
139139
| MultiChart of Trace list * Layout * Config * DisplayOptions
140+
141+
/// Method to support dumping charts in LINQPad.
142+
// See https://www.linqpad.net/CustomizingDump.aspx
143+
member private this.ToDump () : System.Object =
144+
let html = toEmbeddedHTML this
145+
146+
let iFrameType = Type.GetType("LINQPad.Controls.IFrame, LINQPad.Runtime")
147+
148+
if isNull iFrameType then
149+
this
150+
else
151+
let iFrame = System.Activator.CreateInstance(iFrameType, html, true);
152+
iFrame
140153

141154
let toFigure (gChart: GenericChart) =
142155
match gChart with
@@ -218,9 +231,7 @@ module GenericChart =
218231
// let l' = getLayouts gChart
219232
// MultiChart (traces, Some (layouts@l'))
220233

221-
open Plotly.NET.LayoutObjects
222234
// Combines two GenericChart
223-
224235
let combine (gCharts: seq<GenericChart>) =
225236
// temporary hard fix for some props, see https://github.com/CSBiology/DynamicObj/issues/11
226237

0 commit comments

Comments
 (0)