这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@akshita31
Copy link
Contributor

@akshita31 akshita31 commented Aug 8, 2019

This PR adds a KernelExtension which is loaded by default for now. On loading this extension adds a formatter for the "PlotlyChart". This formatter produces a javascript which looks something like this:

image

@akshita31
Copy link
Contributor Author

cc @eerhardt @pgovind

var kernel = CreateKernel();
kernel.UseDefaultExtensions();

await kernel.SendAsync(new SubmitCode("#r nuget:XPlot.Plotly"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now this shouldn't be needed (although we'll need to modify the ScriptOptions in CSharpKernel). Like PocketView and the display helper, it should be available by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case things will work in c# out of the box and not for fsharp unless we explicitly add that dependency for f# as well. Do we need a list of references "somewhere" and those should be added to both f# and c# by default ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brettfo Thoughts?


html.AppendLine(@"});");

html.Append(chartHtml.AsSpan().Slice(scriptEnd).ToString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use the same StringBuilder overloads as you have above - (string, start, length), and not create a span and call ToString on it, since that creates and copies unnecessary memory.

Copy link
Contributor

@jonsequitur jonsequitur Aug 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even simpler is to pass in the TextWriter from the Formatter.Register call on line 15 and write to it directly. No StringBuilder needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better. In that case, I'd suggest making this project target netcoreapp2.1 or higher (or netstandard2.1), and then take advantage of the new ReadOnlySpan overload - https://docs.microsoft.com/en-us/dotnet/api/system.io.textwriter.write?view=netcore-2.1#System_IO_TextWriter_Write_System_ReadOnlySpan_System_Char__.

I'm sure it won't make a dramatic different performance wise, but why make the computer do unnecessary work when it doesn't have to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of parsing strings, I have modified the code to use the HTMLAgilityPack

{
public partial class XplotKernelExtensionTests : CSharpKernelTestBase
{

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line

public Task OnLoadAsync(IKernel kernel)
{
Formatter<PlotlyChart>.Register((chart, writer) =>
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird indenting

@akshita31 akshita31 merged commit 1de8cb9 into dotnet:master Aug 9, 2019
@akshita31 akshita31 deleted the add_xplot branch August 9, 2019 22:09
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.

4 participants