Skip to content

LINQPad integration #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 26, 2023
Merged

Conversation

Peter-B-
Copy link
Contributor

Hello,

at first I must declare, that this is my first F# pull request, so please let me ask for some patience :-)

Motivation

I am a big fan of LINQPad as a (C# and F#) code scratchpad. One of it's main features is the .Dump() extension method, which let's you bring almost everything into a nicely formatted output.

Almost everything: Plotly.Net charts are dumped as plain objects:

image

This is a pity, since LINQPad's output is html and it would perfectly support interactive charts.

How To

LINQPad supports customized dumps from F# in two ways:

  • As a static method is My Extensions. Then it executes for all types.
  • As an instance method on the type itself being dumped.

The first option would require every user to implement an extension, so the second is the way to go.

Implementation

After some try-and-error, I figured out a way to support Plotly.Net in LINQPad with relatively view changes.

  • Add a .ToDump() method to GenericChart
    This method can be (and is) private.
  • Make GenericChart a recirsive module
    ToDump must be able to call toEmbeddedHTML, which is defined later within this module.
    Maybe there is a better solution to this.
  • Within ToDump, an instance of LINQPad.Controls.IFrame is created using reflection and returned.
    The use of reflection avoids a static reference to LINQPad.Runtime

The Result

image

@kMutagene
Copy link
Collaborator

kMutagene commented Jul 26, 2023

Hi @Peter-B-

First of all, this is a very nicely formatted PR, clear and concise!

Also, I must say that LINQPad looks quite interesting. I do most interactive programming in dotnet notebooks these days, but from my limited look at it it seems like it also has a debugger which can be very handy.

What I like most about this PR is that we do not need to add external dependencies. Since the member is private, the public API stays the same and since the tests pass, everything looks good to me.

Regarding the module rec, this will be unnecessary once I start moving to v5, because I want to get rid of the GenericChart module in favor of a type with static members (so it is only Plotly.NET.GenericChart instead of Plotly.NET.GenericChart.GenericChart).

As of now, I think this PR itself does not add backwards-incompatible stuff, so adding it to a minor release (4.2.0) seems reasonable.

@kMutagene kMutagene merged commit 36a9c12 into plotly:dev Jul 26, 2023
@Peter-B-
Copy link
Contributor Author

Thanks a lot for your review and for merging it. I'm looking forward to seeing it published.

LINQPad is indeed a great app, especially as a database-scripting-tool in combination with Entity Framework. Just the plots were a bit old-school - until now :-)

@Peter-B- Peter-B- deleted the feature/linqpad-integration branch July 26, 2023 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants