From 7f6aecd507a925f3c7b7eda9a16880011ce5e169 Mon Sep 17 00:00:00 2001 From: WhiteBlackGoose Date: Tue, 12 Jul 2022 08:13:19 +0300 Subject: [PATCH] added dib extension for C# --- .../Plotly.NET.CSharp.csproj | 3 +- src/Plotly.NET.CSharp/extension.dib | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/Plotly.NET.CSharp/extension.dib diff --git a/src/Plotly.NET.CSharp/Plotly.NET.CSharp.csproj b/src/Plotly.NET.CSharp/Plotly.NET.CSharp.csproj index fe8c6cde1..84679f6b0 100644 --- a/src/Plotly.NET.CSharp/Plotly.NET.CSharp.csproj +++ b/src/Plotly.NET.CSharp/Plotly.NET.CSharp.csproj @@ -36,7 +36,8 @@ - + + diff --git a/src/Plotly.NET.CSharp/extension.dib b/src/Plotly.NET.CSharp/extension.dib new file mode 100644 index 000000000..a1ccbc9bb --- /dev/null +++ b/src/Plotly.NET.CSharp/extension.dib @@ -0,0 +1,30 @@ +#!csharp + +using Microsoft.DotNet.Interactive; +using Microsoft.DotNet.Interactive.Formatting; + +var interactiveDoc = @" +
+ [CHART] + [DESCRIPTION] +
+"; + + + +Formatter.Register( + (chart, writer) => + { + var chartMarkup = Plotly.NET.GenericChart.toChartHTML(chart); + var displayOpts = Plotly.NET.GenericChart.getDisplayOptions(chart); + var html = Plotly.NET.DisplayOptions.replaceHtmlPlaceholders( + displayOpts, + interactiveDoc.Replace("[CHART]", chartMarkup) + ); + writer.Write(html); + }, + "text/html" +); + +"Interactive module loaded, enjoy!" +