From e5a0617d860d63a3096ccc779ea55930c9ec9559 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Mon, 2 May 2022 13:50:55 +0200 Subject: [PATCH 01/17] POC for extension method written in C# --- Plotly.NET.sln | 18 +++++++++ .../GenericChartExtensions.cs | 38 +++++++++++++++++++ .../Plotly.NET.CSharp.csproj | 13 +++++++ .../ExtensionMethodsTests.cs | 24 ++++++++++++ .../Plotly.NET.CSharp.Tests.csproj | 26 +++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 src/Plotly.NET.CSharp/GenericChartExtensions.cs create mode 100644 src/Plotly.NET.CSharp/Plotly.NET.CSharp.csproj create mode 100644 tests/Plotly.NET.CSharp.Tests/ExtensionMethodsTests.cs create mode 100644 tests/Plotly.NET.CSharp.Tests/Plotly.NET.CSharp.Tests.csproj diff --git a/Plotly.NET.sln b/Plotly.NET.sln index 6bf5d8b13..71e035ef3 100644 --- a/Plotly.NET.sln +++ b/Plotly.NET.sln @@ -150,6 +150,10 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Plotly.NET.ImageExport.Test EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "build", "build\build.fsproj", "{403785C9-B5B1-4BA4-9944-A0F9D5D1B3CD}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plotly.NET.CSharp", "src\Plotly.NET.CSharp\Plotly.NET.CSharp.csproj", "{F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plotly.NET.CSharp.Tests", "tests\Plotly.NET.CSharp.Tests\Plotly.NET.CSharp.Tests.csproj", "{4C24BA53-F41C-4110-AD7A-28143DCF671E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -211,6 +215,18 @@ Global {403785C9-B5B1-4BA4-9944-A0F9D5D1B3CD}.Dotnet|Any CPU.Build.0 = Debug|Any CPU {403785C9-B5B1-4BA4-9944-A0F9D5D1B3CD}.Release|Any CPU.ActiveCfg = Release|Any CPU {403785C9-B5B1-4BA4-9944-A0F9D5D1B3CD}.Release|Any CPU.Build.0 = Release|Any CPU + {F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Dotnet|Any CPU.ActiveCfg = Debug|Any CPU + {F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Dotnet|Any CPU.Build.0 = Debug|Any CPU + {F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F944FE69-F4A5-4B48-8E4D-BE4B61E92B26}.Release|Any CPU.Build.0 = Release|Any CPU + {4C24BA53-F41C-4110-AD7A-28143DCF671E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C24BA53-F41C-4110-AD7A-28143DCF671E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C24BA53-F41C-4110-AD7A-28143DCF671E}.Dotnet|Any CPU.ActiveCfg = Debug|Any CPU + {4C24BA53-F41C-4110-AD7A-28143DCF671E}.Dotnet|Any CPU.Build.0 = Debug|Any CPU + {4C24BA53-F41C-4110-AD7A-28143DCF671E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C24BA53-F41C-4110-AD7A-28143DCF671E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -228,6 +244,8 @@ Global {26539796-0C9D-4856-8584-B58BE32CC495} = {EAE25A1F-86FC-426B-803F-1006D1AD06A8} {55A461C3-8018-4020-B16E-D6005BDFCAED} = {EAE25A1F-86FC-426B-803F-1006D1AD06A8} {403785C9-B5B1-4BA4-9944-A0F9D5D1B3CD} = {7C6D08E7-3EAC-4335-8F4B-252C193C27C9} + {F944FE69-F4A5-4B48-8E4D-BE4B61E92B26} = {0E87E47E-9EDC-4525-AF72-F0E139D54236} + {4C24BA53-F41C-4110-AD7A-28143DCF671E} = {EAE25A1F-86FC-426B-803F-1006D1AD06A8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7177F1E1-341C-48AB-9864-6B525FFF7633} diff --git a/src/Plotly.NET.CSharp/GenericChartExtensions.cs b/src/Plotly.NET.CSharp/GenericChartExtensions.cs new file mode 100644 index 000000000..763db06ac --- /dev/null +++ b/src/Plotly.NET.CSharp/GenericChartExtensions.cs @@ -0,0 +1,38 @@ +using Plotly.NET; + +namespace Plotly.NET.CSharp +{ + public static class GenericChartExtensions + { + public static Layout GetLayout(this GenericChart.GenericChart gChart) + { + return GenericChart.getLayout(gChart); + } + + public static Trace [] GetTraces(this GenericChart.GenericChart gChart) + { + return GenericChart.getTraces(gChart).ToArray(); + } + + public static GenericChart.GenericChart WithTraceInfo( + this GenericChart.GenericChart gChart, + string? Name, + StyleParam.Visible? Visible, + bool? ShowLegend, + int? LegendRank, + string? LegendGroup, + Title? LegendGroupTitle + ) + { + return + Plotly.NET.Chart.WithTraceInfo( + Name: Name, + Visible: Visible, + ShowLegend: ShowLegend, + LegendRank: LegendRank, + LegendGroup: LegendGroup, + LegendGroupTitle: LegendGroupTitle + ).Invoke(gChart); + } + } +} \ No newline at end of file diff --git a/src/Plotly.NET.CSharp/Plotly.NET.CSharp.csproj b/src/Plotly.NET.CSharp/Plotly.NET.CSharp.csproj new file mode 100644 index 000000000..132d856c4 --- /dev/null +++ b/src/Plotly.NET.CSharp/Plotly.NET.CSharp.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/tests/Plotly.NET.CSharp.Tests/ExtensionMethodsTests.cs b/tests/Plotly.NET.CSharp.Tests/ExtensionMethodsTests.cs new file mode 100644 index 000000000..1b3d83f4b --- /dev/null +++ b/tests/Plotly.NET.CSharp.Tests/ExtensionMethodsTests.cs @@ -0,0 +1,24 @@ +using System; +using Xunit; +using Plotly.NET.CSharp; + + +namespace Plotly.NET.CSharp.Tests +{ + public class ExtensionMethodsTests + { + internal GenericChart.GenericChart chart = Chart2D.Chart.Point(x: new double[] { 1, 2 }, y: new double[] { 5, 10 }); + + [Fact] + public void CanUseCSharpExtensionMethod() + { + Trace actual = + chart + .WithTraceInfo(Name: "Name") + .GetTraces() + [0]; + + Assert.Equal("Name", DynamicObj.DynamicObj.GetValue(actual,"name")); + } + } +} diff --git a/tests/Plotly.NET.CSharp.Tests/Plotly.NET.CSharp.Tests.csproj b/tests/Plotly.NET.CSharp.Tests/Plotly.NET.CSharp.Tests.csproj new file mode 100644 index 000000000..5806e6da5 --- /dev/null +++ b/tests/Plotly.NET.CSharp.Tests/Plotly.NET.CSharp.Tests.csproj @@ -0,0 +1,26 @@ + + + + net6.0 + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + From 63771ac3bec0f4af3d090131a4b8fcce7b328e42 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Mon, 2 May 2022 13:55:49 +0200 Subject: [PATCH 02/17] Arrow notation looks better --- .../GenericChartExtensions.cs | 31 +++++++------------ .../ExtensionMethodsTests.cs | 4 +-- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/Plotly.NET.CSharp/GenericChartExtensions.cs b/src/Plotly.NET.CSharp/GenericChartExtensions.cs index 763db06ac..f44d6738c 100644 --- a/src/Plotly.NET.CSharp/GenericChartExtensions.cs +++ b/src/Plotly.NET.CSharp/GenericChartExtensions.cs @@ -4,15 +4,9 @@ namespace Plotly.NET.CSharp { public static class GenericChartExtensions { - public static Layout GetLayout(this GenericChart.GenericChart gChart) - { - return GenericChart.getLayout(gChart); - } + public static Layout GetLayout(this GenericChart.GenericChart gChart) => GenericChart.getLayout(gChart); - public static Trace [] GetTraces(this GenericChart.GenericChart gChart) - { - return GenericChart.getTraces(gChart).ToArray(); - } + public static Trace [] GetTraces(this GenericChart.GenericChart gChart) => GenericChart.getTraces(gChart).ToArray(); public static GenericChart.GenericChart WithTraceInfo( this GenericChart.GenericChart gChart, @@ -22,17 +16,14 @@ public static GenericChart.GenericChart WithTraceInfo( int? LegendRank, string? LegendGroup, Title? LegendGroupTitle - ) - { - return - Plotly.NET.Chart.WithTraceInfo( - Name: Name, - Visible: Visible, - ShowLegend: ShowLegend, - LegendRank: LegendRank, - LegendGroup: LegendGroup, - LegendGroupTitle: LegendGroupTitle - ).Invoke(gChart); - } + ) => + Plotly.NET.Chart.WithTraceInfo( + Name: Name, + Visible: Visible, + ShowLegend: ShowLegend, + LegendRank: LegendRank, + LegendGroup: LegendGroup, + LegendGroupTitle: LegendGroupTitle + ).Invoke(gChart); } } \ No newline at end of file diff --git a/tests/Plotly.NET.CSharp.Tests/ExtensionMethodsTests.cs b/tests/Plotly.NET.CSharp.Tests/ExtensionMethodsTests.cs index 1b3d83f4b..21340e7df 100644 --- a/tests/Plotly.NET.CSharp.Tests/ExtensionMethodsTests.cs +++ b/tests/Plotly.NET.CSharp.Tests/ExtensionMethodsTests.cs @@ -14,11 +14,11 @@ public void CanUseCSharpExtensionMethod() { Trace actual = chart - .WithTraceInfo(Name: "Name") + .WithTraceInfo(Name: "Trace Name") .GetTraces() [0]; - Assert.Equal("Name", DynamicObj.DynamicObj.GetValue(actual,"name")); + Assert.Equal("Trace Name", DynamicObj.DynamicObj.GetValue(actual,"name")); } } } From 0fc47fdfc8f6948bc484e295a61dd8caf8d887d8 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Sun, 29 May 2022 21:05:08 +0200 Subject: [PATCH 03/17] wip otional argument interop --- src/Plotly.NET.CSharp/ChartAPI/Chart.cs | 16 +++ src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs | 116 ++++++++++++++++++ .../GenericChartExtensions.cs | 33 +++++ src/Plotly.NET.CSharp/Helpers.cs | 21 ++++ src/Plotly.NET/ChartAPI/Chart2D.fs | 1 + .../Plotly.NET.Tests.CSharpConsole.csproj | 1 + 6 files changed, 188 insertions(+) create mode 100644 src/Plotly.NET.CSharp/ChartAPI/Chart.cs create mode 100644 src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs create mode 100644 src/Plotly.NET.CSharp/Helpers.cs diff --git a/src/Plotly.NET.CSharp/ChartAPI/Chart.cs b/src/Plotly.NET.CSharp/ChartAPI/Chart.cs new file mode 100644 index 000000000..2e1a05f14 --- /dev/null +++ b/src/Plotly.NET.CSharp/ChartAPI/Chart.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Plotly.NET; + +namespace Plotly.NET.CSharp +{ + public static class Chart + { + public static GenericChart.GenericChart Combine(IEnumerable gCharts) => Plotly.NET.Chart.Combine(gCharts); + + public static GenericChart.GenericChart Invisible() => Plotly.NET.Chart.Invisible(); + } +} diff --git a/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs b/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs new file mode 100644 index 000000000..ca6d962cf --- /dev/null +++ b/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Plotly.NET; +using Plotly.NET.LayoutObjects; +using Plotly.NET.TraceObjects; +namespace Plotly.NET.CSharp.ChartAPI +{ + public static class Test + { + public static int Foo(IEnumerable notopt, IEnumerable? opt1) => + Plotly.NET.Chart2D.Chart.Foo( + notopt: notopt, + opt1: opt1 + ); + } + public static class Chart2D + { + /// + /// Creates a Scatter plot. + /// + /// Scatter charts are the basis of Point, Line, and Bubble Charts, and can be customized as such. We also provide abstractions for those Chart.Line, Chart.Point, Chart.Bubble + /// + /// Sets the x coordinates of the plotted data. + /// Sets the y coordinates of the plotted data. + /// Determines the drawing mode for this scatter trace. + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the opactity of the trace + /// Sets the opactity of individual datum markers + /// Sets a text associated with each datum + /// Sets individual text for each datum + /// Sets the position of text associated with each datum + /// Sets the position of text associated with individual datum + /// Sets the color of the marker + /// Sets the colorscale of the marker + /// Sets the outline of the marker + /// Sets the marker symbol for each datum + /// Sets the marker symbol for each individual datum + /// Sets the marker (use this for more finegrained control than the other marker-associated arguments) + /// Sets the color of the line + /// Sets the colorscale of the line + /// Sets the width of the line + /// sets the drawing style of the line + /// Sets the line (use this for more finegrained control than the other line-associated arguments) + /// Set several traces (on the same subplot) to the same stackgroup in order to add their y values (or their x values if `Orientation` is Horizontal). Stacking also turns `fill` on by default and sets the default `mode` to "lines" irrespective of point count. ou can only stack on a numeric (linear or log) axis. Traces in a `stackgroup` will only fill to (or be filled to) other traces in the same group. With multiple `stackgroup`s or some traces stacked and some not, if fill-linked traces are not already consecutive, the later ones will be pushed down in the drawing order + /// Sets the stacking direction. Only relevant when `stackgroup` is used, and only the first `orientation` found in the `stackgroup` will be used. + /// Sets the normalization for the sum of this `stackgroup. Only relevant when `stackgroup` is used, and only the first `groupnorm` found in the `stackgroup` will be used + /// Sets the area to fill with a solid color. Defaults to "none" unless this trace is stacked, then it gets "tonexty" ("tonextx") if `orientation` is "v" ("h") Use with `FillColor` if not "none". "tozerox" and "tozeroy" fill to x=0 and y=0 respectively. "tonextx" and "tonexty" fill between the endpoints of this trace and the endpoints of the trace before it, connecting those endpoints with straight lines (to make a stacked area graph); if there is no trace before it, they behave like "tozerox" and "tozeroy". "toself" connects the endpoints of the trace (or each segment of the trace if it has gaps) into a closed shape. "tonext" fills the space between two traces if one completely encloses the other (eg consecutive contour lines), and behaves like "toself" if there is no trace before it. "tonext" should not be used if one trace does not enclose the other. Traces in a `stackgroup` will only fill to (or be filled to) other traces in the same group. With multiple `stackgroup`s or some traces stacked and some not, if fill-linked traces are not already consecutive, the later ones will be pushed down in the drawing order. + /// ets the fill color. Defaults to a half-transparent variant of the line color, marker color, or marker line color, whichever is available. + /// If true, plotly.js will use the WebGL engine to render this chart. use this when you want to render many objects at once. + /// If set to false, ignore the global default settings set in `Defaults` + public static GenericChart.GenericChart Scatter( + IEnumerable x, + IEnumerable y, + StyleParam.Mode mode, + string? Name, + bool? ShowLegend, + float? Opacity, + IEnumerable? MultiOpacity, + IConvertible? Text, + IEnumerable? MultiText, + StyleParam.TextPosition? TextPosition, + IEnumerable? MultiTextPosition, + Color? MarkerColor, + StyleParam.Colorscale? MarkerColorScale, + Line? MarkerOutline, + StyleParam.MarkerSymbol? MarkerSymbol, + IEnumerable? MultiMarkerSymbol, + Marker? Marker, + Color? LineColor, + StyleParam.Colorscale? LineColorScale, + float? LineWidth, + StyleParam.DrawingStyle? LineDash, + Line? Line, + string StackGroup, + StyleParam.Orientation? Orientation, + StyleParam.GroupNorm? GroupNorm, + StyleParam.Fill? Fill, + Color? FillColor, + bool? UseWebGL, + bool? UseDefaults + ) => + Plotly.NET.Chart2D.Chart.Scatter( + x, y, mode, + Name: Name, + ShowLegend: ShowLegend, + Opacity: Opacity, + MultiOpacity: MultiOpacity, + Text: Text, + MultiText: MultiText, + TextPosition: TextPosition, + MultiTextPosition: MultiTextPosition, + MarkerColor: MarkerColor, + MarkerColorScale: MarkerColorScale, + MarkerOutline: MarkerOutline, + MarkerSymbol: MarkerSymbol, + MultiMarkerSymbol: MultiMarkerSymbol, + Marker: Marker, + LineColor: LineColor, + LineColorScale: LineColorScale, + LineWidth: LineWidth, + LineDash: LineDash, + Line: Line, + StackGroup: StackGroup, + Orientation: Orientation, + GroupNorm: GroupNorm, + Fill: Fill, + FillColor: FillColor, + UseWebGL: UseWebGL, + UseDefaults: UseDefaults + ); + }; +} diff --git a/src/Plotly.NET.CSharp/GenericChartExtensions.cs b/src/Plotly.NET.CSharp/GenericChartExtensions.cs index f44d6738c..815fe8e86 100644 --- a/src/Plotly.NET.CSharp/GenericChartExtensions.cs +++ b/src/Plotly.NET.CSharp/GenericChartExtensions.cs @@ -8,6 +8,37 @@ public static class GenericChartExtensions public static Trace [] GetTraces(this GenericChart.GenericChart gChart) => GenericChart.getTraces(gChart).ToArray(); + /// + /// Saves the given Chart as html file at the given path (.html file extension is added if not present). + /// Optionally opens the generated file in the browser. + /// + /// The path to save the chart html at. + /// Wether or not to open the generated file in the browser (default: false) + public static void SaveHtml( + this GenericChart.GenericChart gChart, + string path, + bool? OpenInBrowser + ) => + Plotly.NET.Chart.SaveHtml( + path: path, + OpenInBrowser: OpenInBrowser + ).Invoke(gChart); + + /// + /// Saves the given chart as a temporary html file and opens it in the browser. + /// + /// The chart to show in the browser + public static void Show(this GenericChart.GenericChart gChart) => Plotly.NET.Chart.Show(gChart); + + /// + /// Sets trace information on the given chart. + /// + /// Sets the name of the chart's trace(s). When the chart is a multichart (it contains multiple traces), the name is suffixed by '_%i' where %i is the index of the trace. + /// Wether or not the chart's traces are visible + /// Determines whether or not item(s) corresponding to this chart's trace(s) is/are shown in the legend. + /// Sets the legend rank for the chart's trace(s). Items and groups with smaller ranks are presented on top/left side while with `"reversed" `legend.traceorder` they are on bottom/right side. The default legendrank is 1000, so that you can use ranks less than 1000 to place certain items before all unranked items, and ranks greater than 1000 to go after all unranked items. + /// Sets the legend group for the chart's trace(s). Traces part of the same legend group hide/show at the same time when toggling legend items. + /// Sets the title for the chart's trace legend group public static GenericChart.GenericChart WithTraceInfo( this GenericChart.GenericChart gChart, string? Name, @@ -26,4 +57,6 @@ public static GenericChart.GenericChart WithTraceInfo( LegendGroupTitle: LegendGroupTitle ).Invoke(gChart); } + + } \ No newline at end of file diff --git a/src/Plotly.NET.CSharp/Helpers.cs b/src/Plotly.NET.CSharp/Helpers.cs new file mode 100644 index 000000000..c141feaf6 --- /dev/null +++ b/src/Plotly.NET.CSharp/Helpers.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.FSharp; +using Microsoft.FSharp.Core; + +namespace Plotly.NET.CSharp +{ + internal class OptionWrapper { + internal static FSharpOption WrapAsOption(T? Value) { + if (Value is null) { + return FSharpOption.None; + } else { + T v = (T)Value; + return FSharpOption.Some(v); + } + } + } +} diff --git a/src/Plotly.NET/ChartAPI/Chart2D.fs b/src/Plotly.NET/ChartAPI/Chart2D.fs index 322535668..b59959b06 100644 --- a/src/Plotly.NET/ChartAPI/Chart2D.fs +++ b/src/Plotly.NET/ChartAPI/Chart2D.fs @@ -30,6 +30,7 @@ module Chart2D = Trace2D.initHeatmap style |> GenericChart.ofTraceObject useDefaults + static member Foo(notopt: seq<#IConvertible>,?opt1: seq<#IConvertible>) = 2 /// /// Creates a Scatter plot. diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj b/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj index 715eef03c..5fcd7852b 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj +++ b/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj @@ -2,6 +2,7 @@ + From 858026546ea8583f6b37bb4e2f1a3ad846936ca9 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Mon, 30 May 2022 15:38:25 +0200 Subject: [PATCH 04/17] WIP optional parameter interop --- src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs | 95 +++++++++++-------- src/Plotly.NET.CSharp/Helpers.cs | 11 +-- src/Plotly.NET/ChartAPI/Chart2D.fs | 2 +- .../Plotly.NET.Tests.CSharpConsole.csproj | 2 +- .../Plotly.NET.Tests.CSharpConsole/Program.cs | 37 ++------ 5 files changed, 66 insertions(+), 81 deletions(-) diff --git a/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs b/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs index ca6d962cf..32e036cb5 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs @@ -6,14 +6,23 @@ using Plotly.NET; using Plotly.NET.LayoutObjects; using Plotly.NET.TraceObjects; + namespace Plotly.NET.CSharp.ChartAPI { public static class Test { - public static int Foo(IEnumerable notopt, IEnumerable? opt1) => - Plotly.NET.Chart2D.Chart.Foo( + public static int Foo( + IEnumerable notopt, + IEnumerable? opt1 = null, + T3? opt2 = null + ) + where T1 : IConvertible + where T2 : IConvertible + where T3 : IConvertible => + Plotly.NET.Chart2D.Chart.Foo( notopt: notopt, - opt1: opt1 + opt1: Helpers.ToOption>(opt1), + opt2: opt2 ); } public static class Chart2D @@ -52,52 +61,58 @@ public static class Chart2D /// ets the fill color. Defaults to a half-transparent variant of the line color, marker color, or marker line color, whichever is available. /// If true, plotly.js will use the WebGL engine to render this chart. use this when you want to render many objects at once. /// If set to false, ignore the global default settings set in `Defaults` - public static GenericChart.GenericChart Scatter( - IEnumerable x, - IEnumerable y, + public static GenericChart.GenericChart Scatter( + IEnumerable x, + IEnumerable y, StyleParam.Mode mode, - string? Name, - bool? ShowLegend, - float? Opacity, - IEnumerable? MultiOpacity, - IConvertible? Text, - IEnumerable? MultiText, - StyleParam.TextPosition? TextPosition, - IEnumerable? MultiTextPosition, - Color? MarkerColor, - StyleParam.Colorscale? MarkerColorScale, - Line? MarkerOutline, - StyleParam.MarkerSymbol? MarkerSymbol, - IEnumerable? MultiMarkerSymbol, - Marker? Marker, - Color? LineColor, - StyleParam.Colorscale? LineColorScale, - float? LineWidth, - StyleParam.DrawingStyle? LineDash, - Line? Line, - string StackGroup, - StyleParam.Orientation? Orientation, - StyleParam.GroupNorm? GroupNorm, - StyleParam.Fill? Fill, - Color? FillColor, - bool? UseWebGL, - bool? UseDefaults - ) => - Plotly.NET.Chart2D.Chart.Scatter( - x, y, mode, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + TextType? Text = null, + IEnumerable? MultiText = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + Color? MarkerColor = null, + StyleParam.Colorscale? MarkerColorScale = null, + Line? MarkerOutline = null, + StyleParam.MarkerSymbol? MarkerSymbol = null, + IEnumerable? MultiMarkerSymbol = null, + Marker? Marker = null, + Color? LineColor = null, + StyleParam.Colorscale? LineColorScale = null, + double? LineWidth = null, + StyleParam.DrawingStyle? LineDash = null, + Line? Line = null, + string? StackGroup = null, + StyleParam.Orientation? Orientation = null, + StyleParam.GroupNorm? GroupNorm = null, + StyleParam.Fill? Fill = null, + Color? FillColor = null, + bool? UseWebGL = null, + bool? UseDefaults = null + ) + where XType : IConvertible + where YType : IConvertible + where TextType : IConvertible + => + Plotly.NET.Chart2D.Chart.Scatter( + x: x, + y: y, + mode: mode, Name: Name, ShowLegend: ShowLegend, Opacity: Opacity, - MultiOpacity: MultiOpacity, - Text: Text, - MultiText: MultiText, + MultiOpacity: Helpers.ToOption(MultiOpacity), + Text: Helpers.ToOption(Text), + MultiText: Helpers.ToOption(MultiText), TextPosition: TextPosition, - MultiTextPosition: MultiTextPosition, + MultiTextPosition: Helpers.ToOption(MultiTextPosition), MarkerColor: MarkerColor, MarkerColorScale: MarkerColorScale, MarkerOutline: MarkerOutline, MarkerSymbol: MarkerSymbol, - MultiMarkerSymbol: MultiMarkerSymbol, + MultiMarkerSymbol: Helpers.ToOption(MultiMarkerSymbol), Marker: Marker, LineColor: LineColor, LineColorScale: LineColorScale, diff --git a/src/Plotly.NET.CSharp/Helpers.cs b/src/Plotly.NET.CSharp/Helpers.cs index c141feaf6..be4b2a142 100644 --- a/src/Plotly.NET.CSharp/Helpers.cs +++ b/src/Plotly.NET.CSharp/Helpers.cs @@ -8,14 +8,7 @@ namespace Plotly.NET.CSharp { - internal class OptionWrapper { - internal static FSharpOption WrapAsOption(T? Value) { - if (Value is null) { - return FSharpOption.None; - } else { - T v = (T)Value; - return FSharpOption.Some(v); - } - } + static class Helpers { + static internal Microsoft.FSharp.Core.FSharpOption ToOption(this T? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new(thing); } } diff --git a/src/Plotly.NET/ChartAPI/Chart2D.fs b/src/Plotly.NET/ChartAPI/Chart2D.fs index b59959b06..e1e075722 100644 --- a/src/Plotly.NET/ChartAPI/Chart2D.fs +++ b/src/Plotly.NET/ChartAPI/Chart2D.fs @@ -30,7 +30,7 @@ module Chart2D = Trace2D.initHeatmap style |> GenericChart.ofTraceObject useDefaults - static member Foo(notopt: seq<#IConvertible>,?opt1: seq<#IConvertible>) = 2 + static member Foo(notopt: seq<#IConvertible>,?opt1: seq<#IConvertible>, ?opt2: #IConvertible) = 2 /// /// Creates a Scatter plot. diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj b/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj index 5fcd7852b..acd152ac6 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj +++ b/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj @@ -2,7 +2,7 @@ - + diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index 0dc7514aa..fdedc1631 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -1,6 +1,6 @@ using System; -using Plotly.NET; -using Microsoft.FSharp.Core; // use this for less verbose and more helpful intellisense +using Plotly.NET.CSharp; +using Plotly.NET.CSharp.ChartAPI; using Plotly.NET.LayoutObjects; namespace Plotly.NET.Tests.CSharpConsole @@ -9,34 +9,11 @@ class Program { static void Main(string[] args) { - double[] x = new double[] { 1, 2 }; - double[] y = new double[] { 5, 10 }; - - LinearAxis xAxis = new LinearAxis(); - xAxis.SetValue("title", "xAxis"); - xAxis.SetValue("showgrid", false); - xAxis.SetValue("showline", true); - - LinearAxis yAxis = new LinearAxis(); - yAxis.SetValue("title", "yAxis"); - yAxis.SetValue("showgrid", false); - yAxis.SetValue("showline", true); - - Layout layout = new Layout(); - layout.SetValue("xaxis", xAxis); - layout.SetValue("yaxis", yAxis); - layout.SetValue("showlegend", true); - - Trace trace = new Trace("scatter"); - trace.SetValue("x", x); - trace.SetValue("y", y); - trace.SetValue("mode", "markers"); - trace.SetValue("name", "Hello from C#"); - - GenericChart - .ofTraceObject(true, trace) - .WithLayout(layout) - .Show(); + Plotly.NET.CSharp.ChartAPI.Chart2D.Scatter( + x: new int [] { 1, 2 }, + y: new int [] { 1, 2 }, + mode: StyleParam.Mode.Markers + ); } static void Main2(string[] args) { From 49a579c01d204073dd3c6d3204bca92aa0303d72 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Mon, 30 May 2022 16:04:20 +0200 Subject: [PATCH 05/17] Finish POC C# API for Chart.Scatter --- src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs | 46 +++++++++---------- src/Plotly.NET.CSharp/Helpers.cs | 4 ++ .../Plotly.NET.Tests.CSharpConsole/Program.cs | 10 +++- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs b/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs index 32e036cb5..77a27ec04 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs @@ -18,7 +18,7 @@ public static int Foo( ) where T1 : IConvertible where T2 : IConvertible - where T3 : IConvertible => + where T3 : class, IConvertible => Plotly.NET.Chart2D.Chart.Foo( notopt: notopt, opt1: Helpers.ToOption>(opt1), @@ -94,38 +94,38 @@ public static GenericChart.GenericChart Scatter( ) where XType : IConvertible where YType : IConvertible - where TextType : IConvertible + where TextType : class, IConvertible => Plotly.NET.Chart2D.Chart.Scatter( x: x, y: y, mode: mode, - Name: Name, - ShowLegend: ShowLegend, - Opacity: Opacity, + Name: Helpers.ToOption(Name), + ShowLegend: Helpers.ToOption(ShowLegend), + Opacity: Helpers.ToOption(Opacity), MultiOpacity: Helpers.ToOption(MultiOpacity), Text: Helpers.ToOption(Text), MultiText: Helpers.ToOption(MultiText), - TextPosition: TextPosition, + TextPosition: Helpers.ToOption(TextPosition), MultiTextPosition: Helpers.ToOption(MultiTextPosition), - MarkerColor: MarkerColor, - MarkerColorScale: MarkerColorScale, - MarkerOutline: MarkerOutline, - MarkerSymbol: MarkerSymbol, + MarkerColor: Helpers.ToOption(MarkerColor), + MarkerColorScale: Helpers.ToOption(MarkerColorScale), + MarkerOutline: Helpers.ToOption(MarkerOutline), + MarkerSymbol: Helpers.ToOption(MarkerSymbol), MultiMarkerSymbol: Helpers.ToOption(MultiMarkerSymbol), - Marker: Marker, - LineColor: LineColor, - LineColorScale: LineColorScale, - LineWidth: LineWidth, - LineDash: LineDash, - Line: Line, - StackGroup: StackGroup, - Orientation: Orientation, - GroupNorm: GroupNorm, - Fill: Fill, - FillColor: FillColor, - UseWebGL: UseWebGL, - UseDefaults: UseDefaults + Marker: Helpers.ToOption(Marker), + LineColor: Helpers.ToOption(LineColor), + LineColorScale: Helpers.ToOption(LineColorScale), + LineWidth: Helpers.ToOption(LineWidth), + LineDash: Helpers.ToOption(LineDash), + Line: Helpers.ToOption(Line), + StackGroup: Helpers.ToOption(StackGroup), + Orientation: Helpers.ToOption(Orientation), + GroupNorm: Helpers.ToOption(GroupNorm), + Fill: Helpers.ToOption(Fill), + FillColor: Helpers.ToOption(FillColor), + UseWebGL: Helpers.ToOption(UseWebGL), + UseDefaults: Helpers.ToOption(UseDefaults) ); }; } diff --git a/src/Plotly.NET.CSharp/Helpers.cs b/src/Plotly.NET.CSharp/Helpers.cs index be4b2a142..be76eb85f 100644 --- a/src/Plotly.NET.CSharp/Helpers.cs +++ b/src/Plotly.NET.CSharp/Helpers.cs @@ -10,5 +10,9 @@ namespace Plotly.NET.CSharp { static class Helpers { static internal Microsoft.FSharp.Core.FSharpOption ToOption(this T? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new(thing); + static internal Microsoft.FSharp.Core.FSharpOption ToOption(this bool? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new((bool)thing); + static internal Microsoft.FSharp.Core.FSharpOption ToOption(this string? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new((string)thing); + static internal Microsoft.FSharp.Core.FSharpOption ToOption(this double? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new((double)thing); + static internal Microsoft.FSharp.Core.FSharpOption ToOption(this int? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new((int)thing); } } diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index fdedc1631..030ed7f04 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -9,11 +9,17 @@ class Program { static void Main(string[] args) { - Plotly.NET.CSharp.ChartAPI.Chart2D.Scatter( + Plotly.NET.CSharp.ChartAPI.Chart2D.Scatter( x: new int [] { 1, 2 }, y: new int [] { 1, 2 }, mode: StyleParam.Mode.Markers - ); + ).Show(); + + Chart2D.Chart.Scatter ( + x: new int[] { 1, 2 }, + y: new int[] { 1, 2 }, + mode: StyleParam.Mode.Markers + ).Show(); } static void Main2(string[] args) { From 66b9176a6291171c5cb0b40c0096a5cb3bedec95 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Mon, 30 May 2022 17:33:29 +0200 Subject: [PATCH 06/17] Add Chart.Point and Chart.Line bindings --- src/Plotly.NET.CSharp/ChartAPI/Chart.cs | 2 +- src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs | 203 ++++++++++++++++-- src/Plotly.NET.CSharp/Helpers.cs | 5 +- src/Plotly.NET/ChartAPI/Chart2D.fs | 3 - .../Plotly.NET.Tests.CSharpConsole.csproj | 1 - .../Plotly.NET.Tests.CSharpConsole/Program.cs | 33 +-- 6 files changed, 202 insertions(+), 45 deletions(-) diff --git a/src/Plotly.NET.CSharp/ChartAPI/Chart.cs b/src/Plotly.NET.CSharp/ChartAPI/Chart.cs index 2e1a05f14..ac5d8d5db 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/Chart.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/Chart.cs @@ -7,7 +7,7 @@ namespace Plotly.NET.CSharp { - public static class Chart + public static partial class Chart { public static GenericChart.GenericChart Combine(IEnumerable gCharts) => Plotly.NET.Chart.Combine(gCharts); diff --git a/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs b/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs index 77a27ec04..e7fb81504 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs @@ -7,25 +7,9 @@ using Plotly.NET.LayoutObjects; using Plotly.NET.TraceObjects; -namespace Plotly.NET.CSharp.ChartAPI +namespace Plotly.NET.CSharp { - public static class Test - { - public static int Foo( - IEnumerable notopt, - IEnumerable? opt1 = null, - T3? opt2 = null - ) - where T1 : IConvertible - where T2 : IConvertible - where T3 : class, IConvertible => - Plotly.NET.Chart2D.Chart.Foo( - notopt: notopt, - opt1: Helpers.ToOption>(opt1), - opt2: opt2 - ); - } - public static class Chart2D + public static partial class Chart { /// /// Creates a Scatter plot. @@ -101,8 +85,8 @@ public static GenericChart.GenericChart Scatter( y: y, mode: mode, Name: Helpers.ToOption(Name), - ShowLegend: Helpers.ToOption(ShowLegend), - Opacity: Helpers.ToOption(Opacity), + ShowLegend: Helpers.ToOptionV(ShowLegend), + Opacity: Helpers.ToOptionV(Opacity), MultiOpacity: Helpers.ToOption(MultiOpacity), Text: Helpers.ToOption(Text), MultiText: Helpers.ToOption(MultiText), @@ -116,7 +100,7 @@ public static GenericChart.GenericChart Scatter( Marker: Helpers.ToOption(Marker), LineColor: Helpers.ToOption(LineColor), LineColorScale: Helpers.ToOption(LineColorScale), - LineWidth: Helpers.ToOption(LineWidth), + LineWidth: Helpers.ToOptionV(LineWidth), LineDash: Helpers.ToOption(LineDash), Line: Helpers.ToOption(Line), StackGroup: Helpers.ToOption(StackGroup), @@ -124,8 +108,181 @@ public static GenericChart.GenericChart Scatter( GroupNorm: Helpers.ToOption(GroupNorm), Fill: Helpers.ToOption(Fill), FillColor: Helpers.ToOption(FillColor), - UseWebGL: Helpers.ToOption(UseWebGL), - UseDefaults: Helpers.ToOption(UseDefaults) + UseWebGL: Helpers.ToOptionV(UseWebGL), + UseDefaults: Helpers.ToOptionV(UseDefaults) ); + + /// + /// Creates a Point chart, which uses Points in a 2D space to visualize data. + /// + /// Sets the x coordinates of the plotted data. + /// Sets the y coordinates of the plotted data. + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the opactity of the trace + /// Sets the opactity of individual datum markers + /// Sets a text associated with each datum + /// Sets individual text for each datum + /// Sets the position of text associated with each datum + /// Sets the position of text associated with individual datum + /// Sets the color of the marker + /// Sets the colorscale of the marker + /// Sets the outline of the marker + /// Sets the marker symbol for each datum + /// Sets the marker symbol for each individual datum + /// Sets the marker (use this for more finegrained control than the other marker-associated arguments) + /// Set several traces (on the same subplot) to the same stackgroup in order to add their y values (or their x values if `Orientation` is Horizontal). Stacking also turns `fill` on by default and sets the default `mode` to "lines" irrespective of point count. ou can only stack on a numeric (linear or log) axis. Traces in a `stackgroup` will only fill to (or be filled to) other traces in the same group. With multiple `stackgroup`s or some traces stacked and some not, if fill-linked traces are not already consecutive, the later ones will be pushed down in the drawing order + /// Sets the stacking direction. Only relevant when `stackgroup` is used, and only the first `orientation` found in the `stackgroup` will be used. + /// Sets the normalization for the sum of this `stackgroup. Only relevant when `stackgroup` is used, and only the first `groupnorm` found in the `stackgroup` will be used + /// If true, plotly.js will use the WebGL engine to render this chart. use this when you want to render many objects at once. + /// If set to false, ignore the global default settings set in `Defaults` + public static GenericChart.GenericChart Point( + IEnumerable x, + IEnumerable y, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + TextType? Text = null, + IEnumerable? MultiText = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + Color? MarkerColor = null, + StyleParam.Colorscale? MarkerColorScale = null, + Line? MarkerOutline = null, + StyleParam.MarkerSymbol? MarkerSymbol = null, + IEnumerable? MultiMarkerSymbol = null, + Marker? Marker = null, + string? StackGroup = null, + StyleParam.Orientation? Orientation = null, + StyleParam.GroupNorm? GroupNorm = null, + bool? UseWebGL = null, + bool? UseDefaults = null + ) + where XType : IConvertible + where YType : IConvertible + where TextType : class, IConvertible + => + Plotly.NET.Chart2D.Chart.Point( + x: x, + y: y, + Name: Helpers.ToOption(Name), + ShowLegend: Helpers.ToOptionV(ShowLegend), + Opacity: Helpers.ToOptionV(Opacity), + MultiOpacity: Helpers.ToOption(MultiOpacity), + Text: Helpers.ToOption(Text), + MultiText: Helpers.ToOption(MultiText), + TextPosition: Helpers.ToOption(TextPosition), + MultiTextPosition: Helpers.ToOption(MultiTextPosition), + MarkerColor: Helpers.ToOption(MarkerColor), + MarkerColorScale: Helpers.ToOption(MarkerColorScale), + MarkerOutline: Helpers.ToOption(MarkerOutline), + MarkerSymbol: Helpers.ToOption(MarkerSymbol), + MultiMarkerSymbol: Helpers.ToOption(MultiMarkerSymbol), + Marker: Helpers.ToOption(Marker), + StackGroup: Helpers.ToOption(StackGroup), + Orientation: Helpers.ToOption(Orientation), + GroupNorm: Helpers.ToOption(GroupNorm), + UseWebGL: Helpers.ToOptionV(UseWebGL), + UseDefaults: Helpers.ToOptionV(UseDefaults) + ); + + /// Creates a Line chart, which uses a Line plotted between the given datums in a 2D space to visualize typically an evolution of Y depending on X. + /// Sets the x coordinates of the plotted data. + /// Sets the y coordinates of the plotted data. + /// Wether to show markers for the individual data points + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the opactity of the trace + /// Sets the opactity of individual datum markers + /// Sets a text associated with each datum + /// Sets individual text for each datum + /// Sets the position of text associated with each datum + /// Sets the position of text associated with individual datum + /// Sets the color of the marker + /// Sets the colorscale of the marker + /// Sets the outline of the marker + /// Sets the marker symbol for each datum + /// Sets the marker symbol for each individual datum + /// Sets the marker (use this for more finegrained control than the other marker-associated arguments) + /// Sets the color of the line + /// Sets the colorscale of the line + /// Sets the width of the line + /// sets the drawing style of the line + /// Sets the line (use this for more finegrained control than the other line-associated arguments) + /// Set several traces (on the same subplot) to the same stackgroup in order to add their y values (or their x values if `Orientation` is Horizontal). Stacking also turns `fill` on by default and sets the default `mode` to "lines" irrespective of point count. ou can only stack on a numeric (linear or log) axis. Traces in a `stackgroup` will only fill to (or be filled to) other traces in the same group. With multiple `stackgroup`s or some traces stacked and some not, if fill-linked traces are not already consecutive, the later ones will be pushed down in the drawing order + /// Sets the stacking direction. Only relevant when `stackgroup` is used, and only the first `orientation` found in the `stackgroup` will be used. + /// Sets the normalization for the sum of this `stackgroup. Only relevant when `stackgroup` is used, and only the first `groupnorm` found in the `stackgroup` will be used + /// Sets the area to fill with a solid color. Defaults to "none" unless this trace is stacked, then it gets "tonexty" ("tonextx") if `orientation` is "v" ("h") Use with `FillColor` if not "none". "tozerox" and "tozeroy" fill to x=0 and y=0 respectively. "tonextx" and "tonexty" fill between the endpoints of this trace and the endpoints of the trace before it, connecting those endpoints with straight lines (to make a stacked area graph); if there is no trace before it, they behave like "tozerox" and "tozeroy". "toself" connects the endpoints of the trace (or each segment of the trace if it has gaps) into a closed shape. "tonext" fills the space between two traces if one completely encloses the other (eg consecutive contour lines), and behaves like "toself" if there is no trace before it. "tonext" should not be used if one trace does not enclose the other. Traces in a `stackgroup` will only fill to (or be filled to) other traces in the same group. With multiple `stackgroup`s or some traces stacked and some not, if fill-linked traces are not already consecutive, the later ones will be pushed down in the drawing order. + /// ets the fill color. Defaults to a half-transparent variant of the line color, marker color, or marker line color, whichever is available. + /// If true, plotly.js will use the WebGL engine to render this chart. use this when you want to render many objects at once. + /// If set to false, ignore the global default settings set in `Defaults` + public static GenericChart.GenericChart Line( + IEnumerable x, + IEnumerable y, + bool? ShowMarkers = null, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + TextType? Text = null, + IEnumerable? MultiText = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + Color? MarkerColor = null, + StyleParam.Colorscale? MarkerColorScale = null, + Line? MarkerOutline = null, + StyleParam.MarkerSymbol? MarkerSymbol = null, + IEnumerable? MultiMarkerSymbol = null, + Marker? Marker = null, + Color? LineColor = null, + StyleParam.Colorscale? LineColorScale = null, + double? LineWidth = null, + StyleParam.DrawingStyle? LineDash = null, + Line? Line = null, + string? StackGroup = null, + StyleParam.Orientation? Orientation = null, + StyleParam.GroupNorm? GroupNorm = null, + StyleParam.Fill? Fill = null, + Color? FillColor = null, + bool? UseWebGL = null, + bool? UseDefaults = null + ) + where XType : IConvertible + where YType : IConvertible + where TextType : class, IConvertible + => + Plotly.NET.Chart2D.Chart.Line( + x: x, + y: y, + ShowMarkers: Helpers.ToOptionV(ShowMarkers), + Name: Helpers.ToOption(Name), + ShowLegend: Helpers.ToOptionV(ShowLegend), + Opacity: Helpers.ToOptionV(Opacity), + MultiOpacity: Helpers.ToOption(MultiOpacity), + Text: Helpers.ToOption(Text), + MultiText: Helpers.ToOption(MultiText), + TextPosition: Helpers.ToOption(TextPosition), + MultiTextPosition: Helpers.ToOption(MultiTextPosition), + MarkerColor: Helpers.ToOption(MarkerColor), + MarkerColorScale: Helpers.ToOption(MarkerColorScale), + MarkerOutline: Helpers.ToOption(MarkerOutline), + MarkerSymbol: Helpers.ToOption(MarkerSymbol), + MultiMarkerSymbol: Helpers.ToOption(MultiMarkerSymbol), + Marker: Helpers.ToOption(Marker), + LineColor: Helpers.ToOption(LineColor), + LineColorScale: Helpers.ToOption(LineColorScale), + LineWidth: Helpers.ToOptionV(LineWidth), + LineDash: Helpers.ToOption(LineDash), + Line: Helpers.ToOption(Line), + StackGroup: Helpers.ToOption(StackGroup), + Orientation: Helpers.ToOption(Orientation), + GroupNorm: Helpers.ToOption(GroupNorm), + Fill: Helpers.ToOption(Fill), + FillColor: Helpers.ToOption(FillColor), + UseWebGL: Helpers.ToOptionV(UseWebGL), + UseDefaults: Helpers.ToOptionV(UseDefaults) + ); + }; } diff --git a/src/Plotly.NET.CSharp/Helpers.cs b/src/Plotly.NET.CSharp/Helpers.cs index be76eb85f..b4ce5256c 100644 --- a/src/Plotly.NET.CSharp/Helpers.cs +++ b/src/Plotly.NET.CSharp/Helpers.cs @@ -10,9 +10,6 @@ namespace Plotly.NET.CSharp { static class Helpers { static internal Microsoft.FSharp.Core.FSharpOption ToOption(this T? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new(thing); - static internal Microsoft.FSharp.Core.FSharpOption ToOption(this bool? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new((bool)thing); - static internal Microsoft.FSharp.Core.FSharpOption ToOption(this string? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new((string)thing); - static internal Microsoft.FSharp.Core.FSharpOption ToOption(this double? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new((double)thing); - static internal Microsoft.FSharp.Core.FSharpOption ToOption(this int? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new((int)thing); + static internal Microsoft.FSharp.Core.FSharpOption ToOptionV(this T? thing) where T : struct => thing is { } some ? new(some) : Microsoft.FSharp.Core.FSharpOption.None; } } diff --git a/src/Plotly.NET/ChartAPI/Chart2D.fs b/src/Plotly.NET/ChartAPI/Chart2D.fs index e1e075722..a7177638d 100644 --- a/src/Plotly.NET/ChartAPI/Chart2D.fs +++ b/src/Plotly.NET/ChartAPI/Chart2D.fs @@ -29,9 +29,6 @@ module Chart2D = else Trace2D.initHeatmap style |> GenericChart.ofTraceObject useDefaults - - static member Foo(notopt: seq<#IConvertible>,?opt1: seq<#IConvertible>, ?opt2: #IConvertible) = 2 - /// /// Creates a Scatter plot. /// diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj b/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj index acd152ac6..8412d1dfa 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj +++ b/tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj @@ -1,7 +1,6 @@ - diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index 030ed7f04..50725bf56 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -1,24 +1,31 @@ using System; using Plotly.NET.CSharp; -using Plotly.NET.CSharp.ChartAPI; -using Plotly.NET.LayoutObjects; +using static Plotly.NET.StyleParam; +using static Plotly.NET.GenericChart; -namespace Plotly.NET.Tests.CSharpConsole +namespace TestConsoleApp { class Program { static void Main(string[] args) { - Plotly.NET.CSharp.ChartAPI.Chart2D.Scatter( - x: new int [] { 1, 2 }, - y: new int [] { 1, 2 }, - mode: StyleParam.Mode.Markers - ).Show(); - - Chart2D.Chart.Scatter ( - x: new int[] { 1, 2 }, - y: new int[] { 1, 2 }, - mode: StyleParam.Mode.Markers + Chart.Combine( + new GenericChart [] + { + Chart.Scatter( + x: new int [] { 1, 2 }, + y: new int [] { 3, 4 }, + mode: Mode.Markers + ), + Chart.Point( + x: new int [] { 5, 6 }, + y: new int [] { 7, 8 } + ), + Chart.Line( + x: new int [] { 9, 10 }, + y: new int [] { 11, 12 } + ) + } ).Show(); } static void Main2(string[] args) From 0a2eafe874c0712a586caca50e51f5f572aeff5b Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 31 May 2022 09:01:29 +0200 Subject: [PATCH 07/17] Add C# bindings for Chart.Grid and Chart.Scatter3D --- src/Plotly.NET.CSharp/ChartAPI/Chart.cs | 49 ++++++++ src/Plotly.NET.CSharp/ChartAPI/Chart3D.cs | 106 ++++++++++++++++++ .../Plotly.NET.Tests.CSharpConsole/Program.cs | 43 ++++--- 3 files changed, 181 insertions(+), 17 deletions(-) create mode 100644 src/Plotly.NET.CSharp/ChartAPI/Chart3D.cs diff --git a/src/Plotly.NET.CSharp/ChartAPI/Chart.cs b/src/Plotly.NET.CSharp/ChartAPI/Chart.cs index ac5d8d5db..73f0dfeb4 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/Chart.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/Chart.cs @@ -4,6 +4,8 @@ using System.Text; using System.Threading.Tasks; using Plotly.NET; +using Plotly.NET.LayoutObjects; +using Plotly.NET.TraceObjects; namespace Plotly.NET.CSharp { @@ -11,6 +13,53 @@ public static partial class Chart { public static GenericChart.GenericChart Combine(IEnumerable gCharts) => Plotly.NET.Chart.Combine(gCharts); + public static GenericChart.GenericChart Invisible() => Plotly.NET.Chart.Invisible(); + + /// + /// Creates a subplot grid with the given dimensions (nRows x nCols) for the input charts. + /// + /// The charts to display on the grid. + /// The number of rows in the grid. If you provide a 2D `subplots` array or a `yaxes` array, its length is used as the default. But it's also possible to have a different length, if you want to leave a row at the end for non-cartesian subplots. + /// The number of columns in the grid. If you provide a 2D `subplots` array, the length of its longest row is used as the default. If you give an `xaxes` array, its length is used as the default. But it's also possible to have a different length, if you want to leave a row at the end for non-cartesian subplots. + /// Used for freeform grids, where some axes may be shared across subplots but others are not. Each entry should be a cartesian subplot id, like "xy" or "x3y2", or "" to leave that cell empty. You may reuse x axes within the same column, and y axes within the same row. Non-cartesian subplots and traces that support `domain` can place themselves in this grid separately using the `gridcell` attribute. + /// Used with `yaxes` when the x and y axes are shared across columns and rows. Each entry should be an y axis id like "y", "y2", etc., or "" to not put a y axis in that row. Entries other than "" must be unique. Ignored if `subplots` is present. If missing but `xaxes` is present, will generate consecutive IDs. + /// Used with `yaxes` when the x and y axes are shared across columns and rows. Each entry should be an x axis id like "x", "x2", etc., or "" to not put an x axis in that column. Entries other than "" must be unique. Ignored if `subplots` is present. If missing but `yaxes` is present, will generate consecutive IDs. + /// Is the first row the top or the bottom? Note that columns are always enumerated from left to right. + /// If no `subplots`, `xaxes`, or `yaxes` are given but we do have `rows` and `columns`, we can generate defaults using consecutive axis IDs, in two ways: "coupled" gives one x axis per column and one y axis per row. "independent" uses a new xy pair for each cell, left-to-right across each row then iterating rows according to `roworder`. + /// Horizontal space between grid cells, expressed as a fraction of the total width available to one cell. Defaults to 0.1 for coupled-axes grids and 0.2 for independent grids. + /// Vertical space between grid cells, expressed as a fraction of the total height available to one cell. Defaults to 0.1 for coupled-axes grids and 0.3 for independent grids. + /// Sets the domains of this grid subplot (in plot fraction). The first and last cells end exactly at the domain edges, with no grout around the edges. + /// Sets where the x axis labels and titles go. "bottom" means the very bottom of the grid. "bottom plot" is the lowest plot that each x axis is used in. "top" and "top plot" are similar. + /// Sets where the y axis labels and titles go. "left" means the very left edge of the grid. "left plot" is the leftmost plot that each y axis is used in. "right" and "right plot" are similar. + public static GenericChart.GenericChart Grid( + IEnumerable gCharts, + int nRows, + int nCols, + Tuple[][]? SubPlots = null, + StyleParam.LinearAxisId[]? XAxes = null, + StyleParam.LinearAxisId[]? YAxes = null, + StyleParam.LayoutGridRowOrder? RowOrder = null, + StyleParam.LayoutGridPattern? Pattern = null, + double? XGap = null, + double? YGap = null, + Domain? Domain = null, + StyleParam.LayoutGridXSide? XSide = null, + StyleParam.LayoutGridYSide? YSide = null + ) => + Plotly.NET.Chart.Grid>( + nRows: nRows, + nCols: nCols, + SubPlots: Helpers.ToOption(SubPlots), + XAxes: Helpers.ToOption(XAxes), + YAxes: Helpers.ToOption(YAxes), + RowOrder: Helpers.ToOption(RowOrder), + Pattern: Helpers.ToOption(Pattern), + XGap: Helpers.ToOptionV(XGap), + YGap: Helpers.ToOptionV(YGap), + Domain: Helpers.ToOption(Domain), + XSide: Helpers.ToOption(XSide), + YSide: Helpers.ToOption(YSide) + ).Invoke(gCharts); } } diff --git a/src/Plotly.NET.CSharp/ChartAPI/Chart3D.cs b/src/Plotly.NET.CSharp/ChartAPI/Chart3D.cs new file mode 100644 index 000000000..608f81c28 --- /dev/null +++ b/src/Plotly.NET.CSharp/ChartAPI/Chart3D.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Plotly.NET; +using Plotly.NET.LayoutObjects; +using Plotly.NET.TraceObjects; + +namespace Plotly.NET.CSharp +{ + public static partial class Chart + { + /// + /// Creates a Scatter3D plot. + /// + /// In general, Scatter3D Plots plot three-dimensional data on 3 cartesian position scales in the X, Y, and Z dimension. + /// + /// Scatter3D charts are the basis of Point3D, Line3D, and Bubble3D Charts, and can be customized as such. We also provide abstractions for those: Chart.Line3D, Chart.Point3D, Chart.Bubble3D + /// + /// Sets the x coordinates of the plotted data. + /// Sets the y coordinates of the plotted data. + /// Sets the z coordinates of the plotted data. + /// Determines the drawing mode for this scatter trace. + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the opactity of the trace + /// Sets the opactity of individual datum markers + /// Sets a text associated with each datum + /// Sets individual text for each datum + /// Sets the position of text associated with each datum + /// Sets the position of text associated with individual datum + /// Sets the color of the marker + /// Sets the colorscale of the marker + /// Sets the outline of the marker + /// Sets the marker symbol for each datum + /// Sets the marker symbol for each individual datum + /// Sets the marker (use this for more finegrained control than the other marker-associated arguments) + /// Sets the color of the line + /// Sets the colorscale of the line + /// Sets the width of the line + /// sets the drawing style of the line + /// Sets the line (use this for more finegrained control than the other line-associated arguments) + /// Sets the projection of this trace. + /// If set to false, ignore the global default settings set in `Defaults` + public static GenericChart.GenericChart Scatter3D( + IEnumerable x, + IEnumerable y, + IEnumerable z, + StyleParam.Mode mode, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + TextData? Text = null, + IEnumerable? MultiText = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + Color? MarkerColor = null, + StyleParam.Colorscale? MarkerColorScale = null, + Line? MarkerOutline = null, + StyleParam.MarkerSymbol3D? MarkerSymbol = null, + IEnumerable? MultiMarkerSymbol = null, + Marker? Marker = null, + Color? LineColor = null, + StyleParam.Colorscale? LineColorScale = null, + double? LineWidth = null, + StyleParam.DrawingStyle? LineDash = null, + Line? Line = null, + Projection? Projection = null, + bool? UseDefaults = null + ) + where XData: IConvertible + where YData: IConvertible + where ZData: IConvertible + where TextData: class, IConvertible + + => Plotly.NET.Chart3D.Chart.Scatter3D( + x: x, + y: y, + z: z, + mode: mode, + Name: Helpers.ToOption(Name), + ShowLegend: Helpers.ToOptionV(ShowLegend), + Opacity: Helpers.ToOptionV(Opacity), + MultiOpacity: Helpers.ToOption(MultiOpacity), + Text: Helpers.ToOption(Text), + MultiText: Helpers.ToOption(MultiText), + TextPosition: Helpers.ToOption(TextPosition), + MultiTextPosition: Helpers.ToOption(MultiTextPosition), + MarkerColor: Helpers.ToOption(MarkerColor), + MarkerColorScale: Helpers.ToOption(MarkerColorScale), + MarkerOutline: Helpers.ToOption(MarkerOutline), + MarkerSymbol: Helpers.ToOption(MarkerSymbol), + MultiMarkerSymbol: Helpers.ToOption(MultiMarkerSymbol), + Marker: Helpers.ToOption(Marker), + LineColor: Helpers.ToOption(LineColor), + LineColorScale: Helpers.ToOption(LineColorScale), + LineWidth: Helpers.ToOptionV(LineWidth), + LineDash: Helpers.ToOption(LineDash), + Line: Helpers.ToOption(Line), + Projection: Helpers.ToOption(Projection), + UseDefaults: Helpers.ToOptionV(UseDefaults) + ); + } +} diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index 50725bf56..9a1484973 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -9,23 +9,32 @@ class Program { static void Main(string[] args) { - Chart.Combine( - new GenericChart [] - { - Chart.Scatter( - x: new int [] { 1, 2 }, - y: new int [] { 3, 4 }, - mode: Mode.Markers - ), - Chart.Point( - x: new int [] { 5, 6 }, - y: new int [] { 7, 8 } - ), - Chart.Line( - x: new int [] { 9, 10 }, - y: new int [] { 11, 12 } - ) - } + Chart.Grid( + nRows: 2, + nCols: 3, + gCharts: + new GenericChart [] + { + Chart.Scatter( + x: new int [] { 1, 2 }, + y: new int [] { 3, 4 }, + mode: Mode.Markers + ), + Chart.Point( + x: new int [] { 5, 6 }, + y: new int [] { 7, 8 } + ), + Chart.Line( + x: new int [] { 9, 10 }, + y: new int [] { 11, 12 } + ), + Chart.Scatter3D( + x: new int[] { 12, 13 }, + y: new int [] { 13, 14 }, + z: new int [] { 14, 15 }, + mode: Mode.Markers + ) + } ).Show(); } static void Main2(string[] args) From 7e0b58aa27c712c0d5f6194c51efe2f40aa0a496 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 31 May 2022 10:59:26 +0200 Subject: [PATCH 08/17] Fix test console app --- tests/Plotly.NET.Tests.CSharpConsole/Program.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index 9a1484973..bb4963529 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -37,16 +37,5 @@ static void Main(string[] args) } ).Show(); } - static void Main2(string[] args) - { - double[] x = new double[] { 1, 2 }; - double[] y = new double[] { 5, 10 }; - GenericChart.GenericChart chart = Chart2D.Chart.Point(x: x, y: y); - chart - .WithTraceInfo("Hello from C#", ShowLegend: true) - .WithXAxisStyle(title: Title.init("xAxis")) - .WithYAxisStyle(title: Title.init("yAxis")) - .Show(); - } } } From 950dcdcdaea293d874526263c0d6d42d39aaddc1 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 1 Jun 2022 09:57:20 +0200 Subject: [PATCH 09/17] Add scatter polar C# binding --- src/Plotly.NET.CSharp/ChartAPI/ChartPolar.cs | 103 +++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/Plotly.NET.CSharp/ChartAPI/ChartPolar.cs diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartPolar.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartPolar.cs new file mode 100644 index 000000000..b76ddd3c2 --- /dev/null +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartPolar.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Plotly.NET; +using Plotly.NET.LayoutObjects; +using Plotly.NET.TraceObjects; + +namespace Plotly.NET.CSharp +{ + public static partial class Chart + { + /// + /// Creates a polar scatter plot. + /// + /// In general, ScatterPolar plots plot two-dimensional data on a polar coordinate system comprised of angular and radial position scales. + /// + /// ScatterPolar charts are the basis of PointPolar, LinePolar, SplinePolar, and BubblePolar Charts, and can be customized as such. We also provide abstractions for those: Chart.PointPolar, Chart.LinePolar, Chart.SplinePolar , Chart.BubblePolar + /// + /// Sets the radial coordinates of the plotted data + /// Sets the angular coordinates of the plotted data (in degrees) + /// Determines the drawing mode for this scatter trace. + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the opactity of the trace + /// Sets the opactity of individual datum markers + /// Sets a text associated with each datum + /// Sets individual text for each datum + /// Sets the position of text associated with each datum + /// Sets the position of text associated with individual datum + /// Sets the color of the marker + /// Sets the colorscale of the marker + /// Sets the outline of the marker + /// Sets the marker symbol for each datum + /// Sets the marker symbol for each individual datum + /// Sets the marker (use this for more finegrained control than the other marker-associated arguments) + /// Sets the color of the line + /// Sets the colorscale of the line + /// Sets the width of the line + /// sets the drawing style of the line + /// Sets the line (use this for more finegrained control than the other line-associated arguments) + /// If true, plotly.js will use the WebGL engine to render this chart. use this when you want to render many objects at once. + /// If set to false, ignore the global default settings set in `Defaults` + public static GenericChart.GenericChart ScatterPolar( + IEnumerable r, + IEnumerable theta, + StyleParam.Mode mode, + string? Name, + bool? ShowLegend, + double? Opacity, + IEnumerable? MultiOpacity, + TextType? Text, + IEnumerable? MultiText, + StyleParam.TextPosition? TextPosition, + IEnumerable? MultiTextPosition, + Color? MarkerColor, + StyleParam.Colorscale? MarkerColorScale, + Line? MarkerOutline, + StyleParam.MarkerSymbol3D? MarkerSymbol, + IEnumerable? MultiMarkerSymbol, + Marker? Marker, + Color? LineColor, + StyleParam.Colorscale? LineColorScale, + double? LineWidth, + StyleParam.DrawingStyle? LineDash, + Line? Line, + bool? UseWebGL, + bool? UseDefaults + ) + where RType : IConvertible + where ThetaType : IConvertible + where TextType : class, IConvertible + + => + Plotly.NET.ChartPolar.Chart.ScatterPolar( + r: r, + theta: theta, + mode: mode, + Name: Helpers.ToOption(Name), + ShowLegend: Helpers.ToOptionV(ShowLegend), + Opacity: Helpers.ToOptionV(Opacity), + MultiOpacity: Helpers.ToOption(MultiOpacity), + Text: Helpers.ToOption(Text), + MultiText: Helpers.ToOption(MultiText), + TextPosition: Helpers.ToOption(TextPosition), + MultiTextPosition: Helpers.ToOption(MultiTextPosition), + MarkerColor: Helpers.ToOption(MarkerColor), + MarkerColorScale: Helpers.ToOption(MarkerColorScale), + MarkerOutline: Helpers.ToOption(MarkerOutline), + MarkerSymbol: Helpers.ToOption(MarkerSymbol), + MultiMarkerSymbol: Helpers.ToOption(MultiMarkerSymbol), + Marker: Helpers.ToOption(Marker), + LineColor: Helpers.ToOption(LineColor), + LineColorScale: Helpers.ToOption(LineColorScale), + LineWidth: Helpers.ToOptionV(LineWidth), + LineDash: Helpers.ToOption(LineDash), + Line: Helpers.ToOption(Line), + UseWebGL: Helpers.ToOptionV(UseWebGL), + UseDefaults: Helpers.ToOptionV(UseDefaults) + ); + } +} From 7761784a7708d3b5e8d8529a122e037c34e335a4 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 1 Jun 2022 10:14:01 +0200 Subject: [PATCH 10/17] Fix scatter polar default values --- src/Plotly.NET.CSharp/ChartAPI/ChartPolar.cs | 42 ++++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartPolar.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartPolar.cs index b76ddd3c2..be5bd5a81 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/ChartPolar.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartPolar.cs @@ -46,27 +46,27 @@ public static GenericChart.GenericChart ScatterPolar IEnumerable r, IEnumerable theta, StyleParam.Mode mode, - string? Name, - bool? ShowLegend, - double? Opacity, - IEnumerable? MultiOpacity, - TextType? Text, - IEnumerable? MultiText, - StyleParam.TextPosition? TextPosition, - IEnumerable? MultiTextPosition, - Color? MarkerColor, - StyleParam.Colorscale? MarkerColorScale, - Line? MarkerOutline, - StyleParam.MarkerSymbol3D? MarkerSymbol, - IEnumerable? MultiMarkerSymbol, - Marker? Marker, - Color? LineColor, - StyleParam.Colorscale? LineColorScale, - double? LineWidth, - StyleParam.DrawingStyle? LineDash, - Line? Line, - bool? UseWebGL, - bool? UseDefaults + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + TextType? Text = null, + IEnumerable? MultiText = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + Color? MarkerColor = null, + StyleParam.Colorscale? MarkerColorScale = null, + Line? MarkerOutline = null, + StyleParam.MarkerSymbol3D? MarkerSymbol = null, + IEnumerable? MultiMarkerSymbol = null, + Marker? Marker = null, + Color? LineColor = null, + StyleParam.Colorscale? LineColorScale = null, + double? LineWidth = null, + StyleParam.DrawingStyle? LineDash = null, + Line? Line = null, + bool? UseWebGL = null, + bool? UseDefaults = null ) where RType : IConvertible where ThetaType : IConvertible From f84c2b1b279498389a68f1b2f823ade241f04651 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 1 Jun 2022 10:22:47 +0200 Subject: [PATCH 11/17] Add ScatterGeo C# binding --- src/Plotly.NET.CSharp/ChartAPI/ChartMap.cs | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/Plotly.NET.CSharp/ChartAPI/ChartMap.cs diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartMap.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartMap.cs new file mode 100644 index 000000000..d7e9e4dac --- /dev/null +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartMap.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Plotly.NET; +using Plotly.NET.LayoutObjects; +using Plotly.NET.TraceObjects; + +namespace Plotly.NET.CSharp +{ + public static partial class ChartMap + { + /// + /// Creates a ScatterGeo chart, where data is visualized using plotly's base geo map. + /// + /// In general, ScatterGeo Plots plot two-dimensional data on a geo map via (lat,lon) coordinates. + /// + /// ScatterGeo charts are the basis of PointGeo, LineGeo, and BubbleGeo Charts, and can be customized as such. We also provide abstractions for those: Chart.PointGeo, Chart.LineGeo, Chart.BubbleGeo + /// + /// Sets the longitude coordinates (in degrees East). + /// Sets the latitude coordinates (in degrees North). + /// Determines the drawing mode for this scatter trace. + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the opactity of the trace + /// Sets the opactity of individual datum markers + /// Sets a text associated with each datum + /// Sets individual text for each datum + /// Sets the position of text associated with each datum + /// Sets the position of text associated with individual datum + /// Sets the color of the marker + /// Sets the colorscale of the marker + /// Sets the outline of the marker + /// Sets the marker symbol for each datum + /// Sets the marker symbol for each individual datum + /// Sets the marker (use this for more finegrained control than the other marker-associated arguments) + /// Sets the color of the line + /// Sets the colorscale of the line + /// Sets the width of the line + /// sets the drawing style of the line + /// Sets the line (use this for more finegrained control than the other line-associated arguments) + /// Determines the set of locations used to match entries in `locations` to regions on the map. Values "ISO-3", "USA-states", "country names" correspond to features on the base map and value "geojson-id" corresponds to features from a custom GeoJSON linked to the `geojson` attribute. + /// Sets optional GeoJSON data associated with this trace. If not given, the features on the base map are used. It can be set as a valid GeoJSON object or as a URL string. Note that we only accept GeoJSONs of type "FeatureCollection" or "Feature" with geometries of type "Polygon" or "MultiPolygon". + /// Sets the key in GeoJSON features which is used as id to match the items included in the `locations` array. Only has an effect when `geojson` is set. Support nested property, for example "properties.name". + /// If set to false, ignore the global default settings set in `Defaults` + public static GenericChart.GenericChart ScatterGeo( + IEnumerable longitudes, + IEnumerable latitudes, + StyleParam.Mode mode, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + TextType? Text = null, + IEnumerable? MultiText = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + Color? MarkerColor = null, + StyleParam.Colorscale? MarkerColorScale = null, + Line? MarkerOutline = null, + StyleParam.MarkerSymbol? MarkerSymbol = null, + IEnumerable? MultiMarkerSymbol = null, + Marker? Marker = null, + Color? LineColor = null, + StyleParam.Colorscale? LineColorScale = null, + double? LineWidth = null, + StyleParam.DrawingStyle? LineDash = null, + Line? Line = null, + StyleParam.LocationFormat? LocationMode = null, + Object? GeoJson = null, + string? FeatureIdKey = null, + bool? UseDefaults = null + ) + where LongitudesType : IConvertible + where LatitudesType : IConvertible + where TextType : class, IConvertible + => + Plotly.NET.ChartMap.Chart.ScatterGeo( + longitudes: longitudes, + latitudes: latitudes, + mode: mode, + Name: Helpers.ToOption(Name), + ShowLegend: Helpers.ToOptionV(ShowLegend), + Opacity: Helpers.ToOptionV(Opacity), + MultiOpacity: Helpers.ToOption(MultiOpacity), + Text: Helpers.ToOption(Text), + MultiText: Helpers.ToOption(MultiText), + TextPosition: Helpers.ToOption(TextPosition), + MultiTextPosition: Helpers.ToOption(MultiTextPosition), + MarkerColor: Helpers.ToOption(MarkerColor), + MarkerColorScale: Helpers.ToOption(MarkerColorScale), + MarkerOutline: Helpers.ToOption(MarkerOutline), + MarkerSymbol: Helpers.ToOption(MarkerSymbol), + MultiMarkerSymbol: Helpers.ToOption(MultiMarkerSymbol), + Marker: Helpers.ToOption(Marker), + LineColor: Helpers.ToOption(LineColor), + LineColorScale: Helpers.ToOption(LineColorScale), + LineWidth: Helpers.ToOptionV(LineWidth), + LineDash: Helpers.ToOption(LineDash), + Line: Helpers.ToOption(Line), + LocationMode: Helpers.ToOption(LocationMode), + GeoJson: Helpers.ToOption(GeoJson), + FeatureIdKey: Helpers.ToOption(FeatureIdKey), + UseDefaults: Helpers.ToOptionV(UseDefaults) + ); + } +} From 8865d4d26662bba51103e8580a1d3eeae09a22a7 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 1 Jun 2022 18:02:06 +0200 Subject: [PATCH 12/17] Add ScatterTernary C# binding --- src/Plotly.NET.CSharp/ChartAPI/ChartMap.cs | 2 +- .../ChartAPI/ChartTernary.cs | 74 +++++++++++++++++++ .../Plotly.NET.Tests.CSharpConsole/Program.cs | 27 ++++++- 3 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartMap.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartMap.cs index d7e9e4dac..90ee010df 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/ChartMap.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartMap.cs @@ -9,7 +9,7 @@ namespace Plotly.NET.CSharp { - public static partial class ChartMap + public static partial class Chart { /// /// Creates a ScatterGeo chart, where data is visualized using plotly's base geo map. diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs new file mode 100644 index 000000000..ba2e39669 --- /dev/null +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Plotly.NET.LayoutObjects; +using Plotly.NET.TraceObjects; + +namespace Plotly.NET.CSharp +{ + public static partial class Chart + { + public static GenericChart.GenericChart Scatterternary( + IEnumerable? A = null, + IEnumerable? B = null, + IEnumerable? C = null, + SumType? Sum = null, + StyleParam.Mode? Mode = null, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + TextType? Text = null, + IEnumerable? MultiText = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + Color? MarkerColor = null, + StyleParam.Colorscale? MarkerColorScale = null, + Line? MarkerOutline = null, + StyleParam.MarkerSymbol? MarkerSymbol = null, + IEnumerable? MultiMarkerSymbol = null, + Marker? Marker = null, + Color? LineColor = null, + StyleParam.Colorscale? LineColorScale = null, + double? LineWidth = null, + StyleParam.DrawingStyle? LineDash = null, + Line? Line = null, + bool? UseDefaults = null + ) + where AType : IConvertible + where BType : IConvertible + where CType : IConvertible + where SumType : class, IConvertible + where TextType : class, IConvertible + => + Plotly.NET.ChartTernary.Chart.ScatterTernary( + A: A.ToOption(), + B: B.ToOption(), + C: C.ToOption(), + Sum: Sum.ToOption(), + Mode: Mode.ToOption(), + Name: Name.ToOption(), + ShowLegend: ShowLegend.ToOptionV(), + Opacity: Opacity.ToOptionV(), + MultiOpacity: MultiOpacity.ToOption(), + Text: Text.ToOption(), + MultiText: MultiText.ToOption(), + TextPosition: TextPosition.ToOption(), + MultiTextPosition: MultiTextPosition.ToOption(), + MarkerColor: MarkerColor.ToOption(), + MarkerColorScale: MarkerColorScale.ToOption(), + MarkerOutline: MarkerOutline.ToOption(), + MarkerSymbol: MarkerSymbol.ToOption(), + MultiMarkerSymbol: MultiMarkerSymbol.ToOption(), + Marker: Marker.ToOption(), + LineColor: LineColor.ToOption(), + LineColorScale: LineColorScale.ToOption(), + LineWidth: LineWidth.ToOptionV(), + LineDash: LineDash.ToOption(), + Line: Line.ToOption(), + UseDefaults: UseDefaults.ToOptionV() + ); + } +} diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index bb4963529..1fa0195df 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -10,7 +10,7 @@ class Program static void Main(string[] args) { Chart.Grid( - nRows: 2, + nRows: 5, nCols: 3, gCharts: new GenericChart [] @@ -33,7 +33,30 @@ static void Main(string[] args) y: new int [] { 13, 14 }, z: new int [] { 14, 15 }, mode: Mode.Markers - ) + ), + Chart.Invisible(), + Chart.Invisible(), + Chart.ScatterPolar( + theta: new int [] { 1, 2 }, + r: new int [] { 3, 4 }, + mode: Mode.Markers + ), + Chart.Invisible(), + Chart.Invisible(), + Chart.ScatterGeo( + longitudes: new int [] { 1, 2 }, + latitudes: new int [] { 3, 4 }, + mode: Mode.Markers + ), + Chart.Invisible(), + Chart.Invisible(), + Chart.Scatterternary( + A: new int [] { 1, 2 }, + B: new int [] { 3, 4 }, + C: new int [] { 5, 6 } + ), + Chart.Invisible(), + Chart.Invisible(), } ).Show(); } From b8e50f5024268e15ee68f5286b69614e998248c0 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Thu, 2 Jun 2022 09:00:35 +0200 Subject: [PATCH 13/17] Add Carpet C# bindings --- src/Plotly.NET.CSharp/ChartAPI/ChartCarpet.cs | 93 +++++++++++++++++++ .../ChartAPI/ChartTernary.cs | 32 +++++++ .../GenericChartExtensions.cs | 22 +++-- src/Plotly.NET/ChartAPI/Chart.fs | 2 +- .../Plotly.NET.Tests.CSharpConsole/Program.cs | 14 ++- 5 files changed, 153 insertions(+), 10 deletions(-) create mode 100644 src/Plotly.NET.CSharp/ChartAPI/ChartCarpet.cs diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartCarpet.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartCarpet.cs new file mode 100644 index 000000000..613c9f2c8 --- /dev/null +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartCarpet.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Plotly.NET.LayoutObjects; +using Plotly.NET.TraceObjects; + +namespace Plotly.NET.CSharp +{ + public static partial class Chart + { + /// + /// Creates a carpet in a 2D coordinate system to be used as additional coordinate system in a carpet plot. + /// + /// A carpet plot illustrates the interaction between two or more independent variables and one or more dependent variables in a two-dimensional plot. + /// Besides the ability to incorporate more variables, another feature that distinguishes a carpet plot from an equivalent contour plot or 3D surface plot is that a carpet plot can be used to more accurately interpolate data points. + /// A conventional carpet plot can capture the interaction of up to three independent variables and three dependent variables and still be easily read and interpolated. + /// + /// Three-variable carpet plot (cheater plot): + /// + /// A carpet plot with two independent variables and one dependent variable is often called a cheater plot for the use of a phantom "cheater" axis instead of the horizontal axis. As a result of this missing axis, the values can be shifted horizontally such that the intersections line up vertically. This allows easy interpolation by having fixed horizontal intervals correspond to fixed intervals in both independent variables. + /// + /// Four-variable carpet plot (true carpet plot) + /// + /// Instead of using the horizontal axis to adjust the plot perspective and align carpet intersections vertically, the horizontal axis can be used to show the effects on an additional dependent variable.[5] In this case the perspective is fixed, and any overlapping cannot be adjusted. Because a true carpet plot represents two independent variables and two dependent variables simultaneously, there is no corresponding way to show the information on a conventional contour plot or 3D surface plot. + /// + /// (from https://en.wikipedia.org/wiki/Carpet_plot @ 1/11/2021) + /// + /// An identifier for this carpet, so that `scattercarpet` and `contourcarpet` traces can specify a carpet plot on which they lie. + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the opactity of the trace + /// A one dimensional array of x coordinates matching the dimensions of `a` and `b`. + /// A two dimensional array of x coordinates at each carpet point. If omitted, the plot is a cheater plot and the xaxis is hidden by default. + /// A one dimensional array of y coordinates matching the dimensions of `a` and `b`. + /// A two dimensional array of y coordinates at each carpet point. + /// An array containing values of the first parameter value + /// An array containing values of the second parameter value + /// Sets this carpet's a axis. + /// Sets this carpet's b axis. + /// Sets a reference between this trace's x coordinates and a 2D cartesian x axis. If "x" (the default value), the x coordinates refer to `layout.xaxis`. If "x2", the x coordinates refer to `layout.xaxis2`, and so on. + /// Sets a reference between this trace's y coordinates and a 2D cartesian y axis. If "y" (the default value), the y coordinates refer to `layout.yaxis`. If "y2", the y coordinates refer to `layout.yaxis2`, and so on. + /// Sets default for all colors associated with this axis all at once: line, font, tick, and grid colors. Grid color is lightened by blending this with the plot background Individual pieces can override this. + /// The shift applied to each successive row of data in creating a cheater plot. Only used if `x` is been omitted. + /// If set to false, ignore the global default settings set in `Defaults` + public static GenericChart.GenericChart Carpet( + string carpetId, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? X = null, + IEnumerable>? MultiX = null, + IEnumerable? Y = null, + IEnumerable>? MultiY = null, + IEnumerable? A = null, + IEnumerable? B = null, + LinearAxis? AAxis = null, + LinearAxis? BAxis = null, + StyleParam.LinearAxisId? XAxis = null, + StyleParam.LinearAxisId? YAxis = null, + Color? Color = null, + double? CheaterSlope = null, + bool? UseDefaults = true + ) + where XType : IConvertible + where MultiXType : IConvertible + where YType : IConvertible + where MultiYType : IConvertible + where AType : IConvertible + where BType : IConvertible + => + Plotly.NET.ChartCarpet.Chart.Carpet, MultiXType, YType, IEnumerable, MultiYType, AType, BType>( + carpetId: carpetId, + Name: Name.ToOption(), + ShowLegend: ShowLegend.ToOptionV(), + Opacity: Opacity.ToOptionV(), + X: X.ToOption(), + MultiX: MultiX.ToOption(), + Y: Y.ToOption(), + MultiY: MultiY.ToOption(), + A: A.ToOption(), + B: B.ToOption(), + AAxis: AAxis.ToOption(), + BAxis: BAxis.ToOption(), + XAxis: XAxis.ToOption(), + YAxis: YAxis.ToOption(), + Color: Color.ToOption(), + CheaterSlope: CheaterSlope.ToOptionV(), + UseDefaults: UseDefaults.ToOptionV() + ); + } +} diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs index ba2e39669..f699f7d5e 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs @@ -10,6 +10,38 @@ namespace Plotly.NET.CSharp { public static partial class Chart { + /// + /// Creates a Scatter plot on a ternary coordinate system + /// + /// In general, ScatterTernary creates a barycentric plot on three variables which sum to a constant, graphically depicting the ratios of the three variables as positions in an equilateral triangle. + /// + /// ScatterTernary charts are the basis of PointTernary, LineTernary, and BubbleTernary Charts, and can be customized as such. We also provide abstractions for those: Chart.LineTernary, Chart.PointTernary, Chart.BubbleTernary + /// + /// Sets the quantity of component `a` in each data point. If `a`, `b`, and `c` are all provided, they need not be normalized, only the relative values matter. If only two arrays are provided they must be normalized to match `ternary<i>.sum`. + /// Sets the quantity of component `b` in each data point. If `a`, `b`, and `c` are all provided, they need not be normalized, only the relative values matter. If only two arrays are provided they must be normalized to match `ternary<i>.sum`. + /// Sets the quantity of component `c` in each data point. If `a`, `b`, and `c` are all provided, they need not be normalized, only the relative values matter. If only two arrays are provided they must be normalized to match `ternary<i>.sum`. + /// The number each triplet should sum to, if only two of `a`, `b`, and `c` are provided. This overrides `ternary<i>.sum` to normalize this specific trace, but does not affect the values displayed on the axes. 0 (or missing) means to use `ternary<i>.sum` + /// Determines the drawing mode for this scatter trace. + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the opactity of the trace + /// Sets the opactity of individual datum markers + /// Sets a text associated with each datum + /// Sets individual text for each datum + /// Sets the position of text associated with each datum + /// Sets the position of text associated with individual datum + /// Sets the color of the marker + /// Sets the colorscale of the marker + /// Sets the outline of the marker + /// Sets the marker symbol for each datum + /// Sets the marker symbol for each individual datum + /// Sets the marker (use this for more finegrained control than the other marker-associated arguments) + /// Sets the color of the line + /// Sets the colorscale of the line + /// Sets the width of the line + /// sets the drawing style of the line + /// Sets the line (use this for more finegrained control than the other line-associated arguments) + /// If set to false, ignore the global default settings set in `Defaults` public static GenericChart.GenericChart Scatterternary( IEnumerable? A = null, IEnumerable? B = null, diff --git a/src/Plotly.NET.CSharp/GenericChartExtensions.cs b/src/Plotly.NET.CSharp/GenericChartExtensions.cs index 815fe8e86..b96800641 100644 --- a/src/Plotly.NET.CSharp/GenericChartExtensions.cs +++ b/src/Plotly.NET.CSharp/GenericChartExtensions.cs @@ -17,7 +17,7 @@ public static class GenericChartExtensions public static void SaveHtml( this GenericChart.GenericChart gChart, string path, - bool? OpenInBrowser + bool? OpenInBrowser = null ) => Plotly.NET.Chart.SaveHtml( path: path, @@ -41,12 +41,12 @@ public static void SaveHtml( /// Sets the title for the chart's trace legend group public static GenericChart.GenericChart WithTraceInfo( this GenericChart.GenericChart gChart, - string? Name, - StyleParam.Visible? Visible, - bool? ShowLegend, - int? LegendRank, - string? LegendGroup, - Title? LegendGroupTitle + string? Name = null, + StyleParam.Visible? Visible = null, + bool? ShowLegend = null, + int? LegendRank = null, + string? LegendGroup = null, + Title? LegendGroupTitle = null ) => Plotly.NET.Chart.WithTraceInfo( Name: Name, @@ -56,6 +56,14 @@ public static GenericChart.GenericChart WithTraceInfo( LegendGroup: LegendGroup, LegendGroupTitle: LegendGroupTitle ).Invoke(gChart); + + /// Sets the size of a Chart (in pixels) + public static GenericChart.GenericChart WithSize( + this GenericChart.GenericChart gChart, + int? Width = null, + int? Height = null + ) => + Plotly.NET.Chart.WithSize(Width: Width, Height: Height).Invoke(gChart); } diff --git a/src/Plotly.NET/ChartAPI/Chart.fs b/src/Plotly.NET/ChartAPI/Chart.fs index c78e3f049..61290d59d 100644 --- a/src/Plotly.NET/ChartAPI/Chart.fs +++ b/src/Plotly.NET/ChartAPI/Chart.fs @@ -2638,7 +2638,7 @@ type Chart = GenericChart.addLayout layout ch) - // Set the size of a Chart + /// Sets the size of a Chart (in pixels) [] static member withSize ( diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index 1fa0195df..6049b702e 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -10,7 +10,7 @@ class Program static void Main(string[] args) { Chart.Grid( - nRows: 5, + nRows: 6, nCols: 3, gCharts: new GenericChart [] @@ -57,8 +57,18 @@ static void Main(string[] args) ), Chart.Invisible(), Chart.Invisible(), + Chart.Carpet( + carpetId: "testCarpet", + A: new double [] {4.0, 4.0, 4.0, 4.5, 4.5, 4.5, 5.0, 5.0, 5.0, 6.0, 6.0, 6.0}, + B: new double [] {1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0}, + Y: new double [] {2.0, 3.5, 4.0, 3.0, 4.5, 5.0, 5.5, 6.5, 7.5, 8.0, 8.5, 10.0} + ), + Chart.Invisible(), + Chart.Invisible(), } - ).Show(); + ) + .WithSize(750,2000) + .Show(); } } } From 104ce5559dc6c76635281e6cc07b73bc3569480b Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 7 Jun 2022 15:47:25 +0200 Subject: [PATCH 14/17] Add Chart.Pie C# binding --- src/Plotly.NET.CSharp/ChartAPI/ChartDomain.cs | 68 +++++++++++++++++++ .../Plotly.NET.Tests.CSharpConsole/Program.cs | 8 ++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/Plotly.NET.CSharp/ChartAPI/ChartDomain.cs diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartDomain.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartDomain.cs new file mode 100644 index 000000000..74486a8e3 --- /dev/null +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartDomain.cs @@ -0,0 +1,68 @@ +using Plotly.NET; +using Plotly.NET.LayoutObjects; +using Plotly.NET.TraceObjects; + + +namespace Plotly.NET.CSharp +{ + public static partial class Chart + { + public static GenericChart.GenericChart Pie( + IEnumerable values, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + IEnumerable? Labels = null, + double? Pull = null, + IEnumerable? MultiPull = null, + TextType? Text = null, + IEnumerable? MultiText = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + IEnumerable? SectionColors = null, + Color? SectionOutlineColor = null, + double? SectionOutlineWidth = null, + IEnumerable? SectionOutlineMultiWidth = null, + Line? SectionOutline = null, + Marker? Marker = null, + StyleParam.TextInfo? TextInfo = null, + StyleParam.Direction? Direction = null, + double? Hole = null, + double? Rotation = null, + bool? Sort = null, + bool? UseDefaults = null + ) + where ValuesType : IConvertible + where LabelsType : IConvertible + where TextType : class, IConvertible + => + Plotly.NET.ChartDomain.Chart.Pie( + values: values, + Name: Name.ToOption(), + ShowLegend: ShowLegend.ToOptionV(), + Opacity: Opacity.ToOptionV(), + MultiOpacity: MultiOpacity.ToOption(), + Labels: Labels.ToOption(), + Pull: Pull.ToOptionV(), + MultiPull: MultiPull.ToOption(), + Text: Text.ToOption(), + MultiText: MultiText.ToOption(), + TextPosition: TextPosition.ToOption(), + MultiTextPosition: MultiTextPosition.ToOption(), + SectionColors: SectionColors.ToOption(), + SectionOutlineColor: SectionOutlineColor.ToOption(), + SectionOutlineWidth: SectionOutlineWidth.ToOptionV(), + SectionOutlineMultiWidth: SectionOutlineMultiWidth.ToOption(), + SectionOutline: SectionOutline.ToOption(), + Marker: Marker.ToOption(), + TextInfo: TextInfo.ToOption(), + Direction: Direction.ToOption(), + Hole: Hole.ToOptionV(), + Rotation: Rotation.ToOptionV(), + Sort: Sort.ToOptionV(), + UseDefaults: UseDefaults.ToOptionV() + ); + + } +} diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index 6049b702e..79065b0ef 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -10,7 +10,7 @@ class Program static void Main(string[] args) { Chart.Grid( - nRows: 6, + nRows: 7, nCols: 3, gCharts: new GenericChart [] @@ -65,6 +65,12 @@ static void Main(string[] args) ), Chart.Invisible(), Chart.Invisible(), + Chart.Pie( + values: new double [] {1,2,3,4}, + Labels: new string [] {"soos", "saas", "fiif", "leel"} + ), + Chart.Invisible(), + Chart.Invisible(), } ) .WithSize(750,2000) From cfea76eb819447294e66467358816c44a82156a1 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 7 Jun 2022 16:11:35 +0200 Subject: [PATCH 15/17] Add Chart.ScatterSmith C# binding --- src/Plotly.NET.CSharp/ChartAPI/ChartDomain.cs | 30 ++++++ src/Plotly.NET.CSharp/ChartAPI/ChartSmith.cs | 100 ++++++++++++++++++ .../ChartAPI/ChartTernary.cs | 2 +- .../Plotly.NET.Tests.CSharpConsole/Program.cs | 11 +- 4 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 src/Plotly.NET.CSharp/ChartAPI/ChartSmith.cs diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartDomain.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartDomain.cs index 74486a8e3..64eca5507 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/ChartDomain.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartDomain.cs @@ -7,6 +7,36 @@ namespace Plotly.NET.CSharp { public static partial class Chart { + /// + /// Creates a pie chart. + /// + /// A pie chart (or a circle chart) is a circular statistical graphic, which is divided into slices to illustrate numerical proportion. + /// In a pie chart, the arc length of each slice (and consequently its central angle and area), is proportional to the quantity it represents. + /// + /// Sets the values of the sectors + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the opactity of the trace + /// Sets the opactity of individual datum markers + /// Sets the sector labels. If `labels` entries are duplicated, the associated `values` are summed. + /// Sets the fraction of larger radius to pull the sectors out from the center. This can be a constant to pull all slices apart from each other equally or an array to highlight one or more slices. + /// Sets the fraction of larger radius to pull the sectors out from the center. This can be a constant to pull all slices apart from each other equally or an array to highlight one or more slices. + /// Sets text elements associated with each (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates. If trace `hoverinfo` contains a "text" flag and "hovertext" is not set, these elements will be seen in the hover labels. + /// Sets text elements associated with each (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates. If trace `hoverinfo` contains a "text" flag and "hovertext" is not set, these elements will be seen in the hover labels. + /// Sets the positions of the `text` elements with respects to the (x,y) coordinates. + /// Sets the positions of the `text` elements with respects to the (x,y) coordinates. + /// Sets the colors associated with each section. + /// Sets the color of the section outline. + /// Sets the width of the section outline. + /// Sets the width of each individual section outline. + /// Sets the section outline (use this for more finegrained control than the other section outline-associated arguments). + /// Sets the marker of this trace. + /// Determines which trace information appear on the graph. + /// Specifies the direction at which succeeding sectors follow one another. + /// Sets the fraction of the radius to cut out of the pie. Use this to make a donut chart. + /// Instead of the first slice starting at 12 o'clock, rotate to some other angle. + /// Determines whether or not the sectors are reordered from largest to smallest. + /// If set to false, ignore the global default settings set in `Defaults` public static GenericChart.GenericChart Pie( IEnumerable values, string? Name = null, diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartSmith.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartSmith.cs new file mode 100644 index 000000000..f677fff2c --- /dev/null +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartSmith.cs @@ -0,0 +1,100 @@ +using Plotly.NET; +using Plotly.NET.LayoutObjects; +using Plotly.NET.TraceObjects; + +namespace Plotly.NET.CSharp +{ + public static partial class Chart + { + /// + /// Creates a Scatter plot on a smith coordinate system. + /// + /// In general, ScatterSmith charts plot complex numbers on a transformed two-dimensional Cartesian complex plane. Complex numbers with positive real parts map inside the circle. Those with negative real parts map outside the circle. + /// + /// ScatterSmith charts are the basis of PointSmith, LineSmith, and BubbleSmith Charts, and can be customized as such. We also provide abstractions for those: Chart.LineSmith, Chart.PointSmith, Chart.BubbleSmith + /// + /// Sets the real component of the data, in units of normalized impedance such that real=1, imag=0 is the center of the chart. + /// Sets the imaginary component of the data, in units of normalized impedance such that real=1, imag=0 is the center of the chart. + /// Determines the drawing mode for this scatter trace. + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the opactity of the trace + /// Sets the opactity of individual datum markers + /// Sets a text associated with each datum + /// Sets individual text for each datum + /// Sets the position of text associated with each datum + /// Sets the position of text associated with individual datum + /// Sets the color of the marker + /// Sets the colorscale of the marker + /// Sets the outline of the marker + /// Sets the marker symbol for each datum + /// Sets the marker symbol for each individual datum + /// Sets the marker (use this for more finegrained control than the other marker-associated arguments) + /// Sets the color of the line + /// Sets the colorscale of the line + /// Sets the width of the line + /// sets the drawing style of the line + /// Sets the line (use this for more finegrained control than the other line-associated arguments) + /// Sets the area to fill with a solid color. Defaults to "none" unless this trace is stacked, then it gets "tonexty" ("tonextx") if `orientation` is "v" ("h") Use with `FillColor` if not "none". "tozerox" and "tozeroy" fill to x=0 and y=0 respectively. "tonextx" and "tonexty" fill between the endpoints of this trace and the endpoints of the trace before it, connecting those endpoints with straight lines (to make a stacked area graph); if there is no trace before it, they behave like "tozerox" and "tozeroy". "toself" connects the endpoints of the trace (or each segment of the trace if it has gaps) into a closed shape. "tonext" fills the space between two traces if one completely encloses the other (eg consecutive contour lines), and behaves like "toself" if there is no trace before it. "tonext" should not be used if one trace does not enclose the other. Traces in a `stackgroup` will only fill to (or be filled to) other traces in the same group. With multiple `stackgroup`s or some traces stacked and some not, if fill-linked traces are not already consecutive, the later ones will be pushed down in the drawing order. + /// ets the fill color. Defaults to a half-transparent variant of the line color, marker color, or marker line color, whichever is available. + /// If set to false, ignore the global default settings set in `Defaults` + public static GenericChart.GenericChart ScatterSmith( + IEnumerable real, + IEnumerable imag, + StyleParam.Mode mode, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + TextType? Text = null, + IEnumerable? MultiText = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + Color? MarkerColor = null, + StyleParam.Colorscale? MarkerColorScale = null, + Line? MarkerOutline = null, + StyleParam.MarkerSymbol? MarkerSymbol = null, + IEnumerable? MultiMarkerSymbol = null, + Marker? Marker = null, + Color? LineColor = null, + StyleParam.Colorscale? LineColorScale = null, + double? LineWidth = null, + StyleParam.DrawingStyle? LineDash = null, + Line? Line = null, + StyleParam.Fill? Fill = null, + Color? FillColor = null, + bool? UseDefaults = true + ) + where RealType : IConvertible + where ImagType : IConvertible + where TextType : class, IConvertible + => + Plotly.NET.ChartSmith.Chart.ScatterSmith( + real: real, + imag: imag, + mode: mode, + Name: Name.ToOption(), + ShowLegend: ShowLegend.ToOptionV(), + Opacity: Opacity.ToOptionV(), + MultiOpacity: MultiOpacity.ToOption(), + Text: Text.ToOption(), + MultiText: MultiText.ToOption(), + TextPosition: TextPosition.ToOption(), + MultiTextPosition: MultiTextPosition.ToOption(), + MarkerColor: MarkerColor.ToOption(), + MarkerColorScale: MarkerColorScale.ToOption(), + MarkerOutline: MarkerOutline.ToOption(), + MarkerSymbol: MarkerSymbol.ToOption(), + MultiMarkerSymbol: MultiMarkerSymbol.ToOption(), + Marker: Marker.ToOption(), + LineColor: LineColor.ToOption(), + LineColorScale: LineColorScale.ToOption(), + LineWidth: LineWidth.ToOptionV(), + LineDash: LineDash.ToOption(), + Line: Line.ToOption(), + Fill: Fill.ToOption(), + FillColor: FillColor.ToOption(), + UseDefaults: UseDefaults.ToOptionV() + ); + } +} diff --git a/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs b/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs index f699f7d5e..9828d5601 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/ChartTernary.cs @@ -42,7 +42,7 @@ public static partial class Chart /// sets the drawing style of the line /// Sets the line (use this for more finegrained control than the other line-associated arguments) /// If set to false, ignore the global default settings set in `Defaults` - public static GenericChart.GenericChart Scatterternary( + public static GenericChart.GenericChart ScatterTernary( IEnumerable? A = null, IEnumerable? B = null, IEnumerable? C = null, diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index 79065b0ef..d09a1f819 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -10,7 +10,7 @@ class Program static void Main(string[] args) { Chart.Grid( - nRows: 7, + nRows: 8, nCols: 3, gCharts: new GenericChart [] @@ -50,7 +50,7 @@ static void Main(string[] args) ), Chart.Invisible(), Chart.Invisible(), - Chart.Scatterternary( + Chart.ScatterTernary( A: new int [] { 1, 2 }, B: new int [] { 3, 4 }, C: new int [] { 5, 6 } @@ -71,6 +71,13 @@ static void Main(string[] args) ), Chart.Invisible(), Chart.Invisible(), + Chart.ScatterSmith( + real: new double [] {1,2,3,4}, + imag: new double [] {1,2,3,4}, + mode: Mode.Markers + ), + Chart.Invisible(), + Chart.Invisible(), } ) .WithSize(750,2000) From 0c6444de338449cec6ddb6da78130ab0bf74ea09 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Fri, 10 Jun 2022 10:54:35 +0200 Subject: [PATCH 16/17] Add C# WithX/Yaxis extension methods, fix optional parameter usage in other extension methods --- .../GenericChartExtensions.cs | 225 +++++++++++++++++- src/Plotly.NET.CSharp/Helpers.cs | 12 + .../Plotly.NET.Tests.CSharpConsole/Program.cs | 9 + 3 files changed, 237 insertions(+), 9 deletions(-) diff --git a/src/Plotly.NET.CSharp/GenericChartExtensions.cs b/src/Plotly.NET.CSharp/GenericChartExtensions.cs index b96800641..a8d6e52b0 100644 --- a/src/Plotly.NET.CSharp/GenericChartExtensions.cs +++ b/src/Plotly.NET.CSharp/GenericChartExtensions.cs @@ -1,4 +1,6 @@ using Plotly.NET; +using Plotly.NET.LayoutObjects; +using Plotly.NET.TraceObjects; namespace Plotly.NET.CSharp { @@ -21,7 +23,7 @@ public static void SaveHtml( ) => Plotly.NET.Chart.SaveHtml( path: path, - OpenInBrowser: OpenInBrowser + OpenInBrowser: OpenInBrowser.ToOptionV() ).Invoke(gChart); /// @@ -49,12 +51,12 @@ public static GenericChart.GenericChart WithTraceInfo( Title? LegendGroupTitle = null ) => Plotly.NET.Chart.WithTraceInfo( - Name: Name, - Visible: Visible, - ShowLegend: ShowLegend, - LegendRank: LegendRank, - LegendGroup: LegendGroup, - LegendGroupTitle: LegendGroupTitle + Name: Name.ToOption(), + Visible: Visible.ToOption(), + ShowLegend: ShowLegend.ToOptionV(), + LegendRank: LegendRank.ToOptionV(), + LegendGroup: LegendGroup.ToOption(), + LegendGroupTitle: LegendGroupTitle.ToOption() ).Invoke(gChart); /// Sets the size of a Chart (in pixels) @@ -63,8 +65,213 @@ public static GenericChart.GenericChart WithSize( int? Width = null, int? Height = null ) => - Plotly.NET.Chart.WithSize(Width: Width, Height: Height).Invoke(gChart); - } + Plotly.NET.Chart.WithSize(Width: Width.ToOptionV(), Height: Height.ToOptionV()).Invoke(gChart); + + /// + /// Sets the given x axis styles on the input chart's layout. + /// + /// If there is already an axis set at the given id, the styles are applied to it. If there is no axis present, a new LinearAxis object with the given styles will be set. + /// + /// Sets the text of the axis title. + /// Sets the font of the axis title. + /// Sets the standoff distance (in px) between the axis labels and the title text. + /// Sets the Title (use this for more finegrained control than the other title-associated arguments) + /// Sets default for all colors associated with this axis all at once: line, font, tick, and grid colors. + /// Sets the axis type. By default, plotly attempts to determined the axis type by looking into the data of the traces that referenced the axis in question. + /// Tuple of (Min*Max value). Sets the range of this axis (the axis will go from Min to Max). If the axis `type` is "log", then you must take the log of your desired range (e.g. to set the range from 1 to 100, set the range from 0 to 2). + /// Determines if and how the axis lines or/and ticks are mirrored to the opposite side of the plotting area. + /// Determines whether or not spikes (aka droplines) are drawn for this axis. + /// Sets the spike color. If not set, will use the series color + /// Sets the width (in px) of the zero line. + /// Determines whether or not a line bounding this axis is drawn. + /// Sets the axis line color. + /// Determines whether or not grid lines are drawn. If "true", the grid lines are drawn at every tick mark. + /// Sets the color of the grid lines. + /// Determines whether or not a line is drawn at along the 0 value of this axis. If "true", the zero line is drawn on top of the grid lines. + /// Sets the line color of the zero line. + /// If set to an opposite-letter axis id (e.g. `x2`, `y`), this axis is bound to the corresponding opposite-letter axis. If set to "free", this axis' position is determined by `position`. + /// Determines whether a x (y) axis is positioned at the "bottom" ("left") or "top" ("right") of the plotting area. + /// If set a same-letter axis id, this axis is overlaid on top of the corresponding same-letter axis, with traces and axes visible for both axes. If "false", this axis does not overlay any same-letter axes. In this case, for axes with overlapping domains only the highest-numbered axis will be visible. + /// Tuple of (X*Y fractions). Sets the domain of this axis (in plot fraction). + /// Sets the position of this axis in the plotting space (in normalized coordinates). Only has an effect if `anchor` is set to "free". + /// Specifies the ordering logic for the case of categorical variables. By default, plotly uses "trace", which specifies the order that is present in the data supplied. Set `categoryorder` to "category ascending" or "category descending" if order should be determined by the alphanumerical order of the category names. Set `categoryorder` to "array" to derive the ordering from the attribute `categoryarray`. If a category is not found in the `categoryarray` array, the sorting behavior for that attribute will be identical to the "trace" mode. The unspecified categories will follow the categories in `categoryarray`. Set `categoryorder` to "total ascending" or "total descending" if order should be determined by the numerical order of the values. Similarly, the order can be determined by the min, max, sum, mean or median of all the values. + /// Sets the order in which categories on this axis appear. Only has an effect if `categoryorder` is set to "array". Used with `categoryorder`. + /// Sets a range slider for this axis + /// Sets a range selector for this axis. This object contains toggable presets for the rangeslider. + /// Sets the background color of this axis' wall. (Only has an effect on 3D scenes) + /// Sets whether or not this axis' wall has a background color. (Only has an effect on 3D scenes) + /// The target axis id on which the styles should be applied. Default is 1. + public static GenericChart.GenericChart WithXAxisStyle( + this GenericChart.GenericChart gChart, + string? TitleText = null, + Font? TitleFont = null, + int? TitleStandoff = null, + Title? Title = null, + Color? Color = null, + StyleParam.AxisType? AxisType = null, + Tuple? MinMax = null, + StyleParam.Mirror? Mirror = null, + bool? ShowSpikes = null, + Color? SpikeColor = null, + int? SpikeThickness = null, + bool? ShowLine = null, + Color? LineColor = null, + bool? ShowGrid = null, + Color? GridColor = null, + bool? ZeroLine = null, + Color? ZeroLineColor = null, + StyleParam.LinearAxisId? Anchor = null, + StyleParam.Side? Side = null, + StyleParam.LinearAxisId? Overlaying = null, + Tuple? Domain = null, + double? Position = null, + StyleParam.CategoryOrder? CategoryOrder = null, + IEnumerable? CategoryArray = null, + RangeSlider? RangeSlider = null, + RangeSelector? RangeSelector = null, + Color? BackgroundColor = null, + bool? ShowBackground = null, + StyleParam.SubPlotId? Id = null + ) + where MinType : IConvertible + where MaxType : IConvertible + where CategoryArrayType : class, IConvertible + => + Plotly.NET.Chart.WithXAxisStyle( + TitleText: TitleText.ToOption(), + TitleFont: TitleFont.ToOption(), + TitleStandoff: TitleStandoff.ToOptionV(), + Title: Title.ToOption(), + Color: Color.ToOption(), + AxisType: AxisType.ToOption(), + MinMax: MinMax.ToOption(), + Mirror: Mirror.ToOption(), + ShowSpikes: ShowSpikes.ToOptionV(), + SpikeColor: SpikeColor.ToOption(), + SpikeThickness: SpikeThickness.ToOptionV(), + ShowLine: ShowLine.ToOptionV(), + LineColor: LineColor.ToOption(), + ShowGrid: ShowGrid.ToOptionV(), + GridColor: GridColor.ToOption(), + ZeroLine: ZeroLine.ToOptionV(), + ZeroLineColor: ZeroLineColor.ToOption(), + Anchor: Anchor.ToOption(), + Side: Side.ToOption(), + Overlaying: Overlaying.ToOption(), + Domain: Domain.ToOption(), + Position: Position.ToOptionV(), + CategoryOrder: CategoryOrder.ToOption(), + CategoryArray: CategoryArray.ToOption(), + RangeSlider: RangeSlider.ToOption(), + RangeSelector: RangeSelector.ToOption(), + BackgroundColor: BackgroundColor.ToOption(), + ShowBackground: ShowBackground.ToOptionV(), + Id: Id.ToOption() + + ).Invoke(gChart); + /// + /// Sets the given y axis styles on the input chart's layout. + /// + /// If there is already an axis set at the given id, the styles are applied to it. If there is no axis present, a new LinearAxis object with the given styles will be set. + /// + /// Sets the text of the axis title. + /// Sets the font of the axis title. + /// Sets the standoff distance (in px) between the axis labels and the title text. + /// Sets the Title (use this for more finegrained control than the other title-associated arguments) + /// Sets default for all colors associated with this axis all at once: line, font, tick, and grid colors. + /// Sets the axis type. By default, plotly attempts to determined the axis type by looking into the data of the traces that referenced the axis in question. + /// Tuple of (Min*Max value). Sets the range of this axis (the axis will go from Min to Max). If the axis `type` is "log", then you must take the log of your desired range (e.g. to set the range from 1 to 100, set the range from 0 to 2). + /// Determines if and how the axis lines or/and ticks are mirrored to the opposite side of the plotting area. + /// Determines whether or not spikes (aka droplines) are drawn for this axis. + /// Sets the spike color. If not set, will use the series color + /// Sets the width (in px) of the zero line. + /// Determines whether or not a line bounding this axis is drawn. + /// Sets the axis line color. + /// Determines whether or not grid lines are drawn. If "true", the grid lines are drawn at every tick mark. + /// Sets the color of the grid lines. + /// Determines whether or not a line is drawn at along the 0 value of this axis. If "true", the zero line is drawn on top of the grid lines. + /// Sets the line color of the zero line. + /// If set to an opposite-letter axis id (e.g. `x2`, `y`), this axis is bound to the corresponding opposite-letter axis. If set to "free", this axis' position is determined by `position`. + /// Determines whether a x (y) axis is positioned at the "bottom" ("left") or "top" ("right") of the plotting area. + /// If set a same-letter axis id, this axis is overlaid on top of the corresponding same-letter axis, with traces and axes visible for both axes. If "false", this axis does not overlay any same-letter axes. In this case, for axes with overlapping domains only the highest-numbered axis will be visible. + /// Tuple of (X*Y fractions). Sets the domain of this axis (in plot fraction). + /// Sets the position of this axis in the plotting space (in normalized coordinates). Only has an effect if `anchor` is set to "free". + /// Specifies the ordering logic for the case of categorical variables. By default, plotly uses "trace", which specifies the order that is present in the data supplied. Set `categoryorder` to "category ascending" or "category descending" if order should be determined by the alphanumerical order of the category names. Set `categoryorder` to "array" to derive the ordering from the attribute `categoryarray`. If a category is not found in the `categoryarray` array, the sorting behavior for that attribute will be identical to the "trace" mode. The unspecified categories will follow the categories in `categoryarray`. Set `categoryorder` to "total ascending" or "total descending" if order should be determined by the numerical order of the values. Similarly, the order can be determined by the min, max, sum, mean or median of all the values. + /// Sets the order in which categories on this axis appear. Only has an effect if `categoryorder` is set to "array". Used with `categoryorder`. + /// Sets a range slider for this axis + /// Sets a range selector for this axis. This object contains toggable presets for the rangeslider. + /// Sets the background color of this axis' wall. (Only has an effect on 3D scenes) + /// Sets whether or not this axis' wall has a background color. (Only has an effect on 3D scenes) + /// The target axis id on which the styles should be applied. Default is 1. + public static GenericChart.GenericChart WithYAxisStyle( + this GenericChart.GenericChart gChart, + string? TitleText = null, + Font? TitleFont = null, + int? TitleStandoff = null, + Title? Title = null, + Color? Color = null, + StyleParam.AxisType? AxisType = null, + Tuple? MinMax = null, + StyleParam.Mirror? Mirror = null, + bool? ShowSpikes = null, + Color? SpikeColor = null, + int? SpikeThickness = null, + bool? ShowLine = null, + Color? LineColor = null, + bool? ShowGrid = null, + Color? GridColor = null, + bool? ZeroLine = null, + Color? ZeroLineColor = null, + StyleParam.LinearAxisId? Anchor = null, + StyleParam.Side? Side = null, + StyleParam.LinearAxisId? Overlaying = null, + Tuple? Domain = null, + double? Position = null, + StyleParam.CategoryOrder? CategoryOrder = null, + IEnumerable? CategoryArray = null, + RangeSlider? RangeSlider = null, + RangeSelector? RangeSelector = null, + Color? BackgroundColor = null, + bool? ShowBackground = null, + StyleParam.SubPlotId? Id = null + ) + where MinType : IConvertible + where MaxType : IConvertible + where CategoryArrayType : class, IConvertible + => + Plotly.NET.Chart.WithYAxisStyle( + TitleText: TitleText.ToOption(), + TitleFont: TitleFont.ToOption(), + TitleStandoff: TitleStandoff.ToOptionV(), + Title: Title.ToOption(), + Color: Color.ToOption(), + AxisType: AxisType.ToOption(), + MinMax: MinMax.ToOption(), + Mirror: Mirror.ToOption(), + ShowSpikes: ShowSpikes.ToOptionV(), + SpikeColor: SpikeColor.ToOption(), + SpikeThickness: SpikeThickness.ToOptionV(), + ShowLine: ShowLine.ToOptionV(), + LineColor: LineColor.ToOption(), + ShowGrid: ShowGrid.ToOptionV(), + GridColor: GridColor.ToOption(), + ZeroLine: ZeroLine.ToOptionV(), + ZeroLineColor: ZeroLineColor.ToOption(), + Anchor: Anchor.ToOption(), + Side: Side.ToOption(), + Overlaying: Overlaying.ToOption(), + Domain: Domain.ToOption(), + Position: Position.ToOptionV(), + CategoryOrder: CategoryOrder.ToOption(), + CategoryArray: CategoryArray.ToOption(), + RangeSlider: RangeSlider.ToOption(), + RangeSelector: RangeSelector.ToOption(), + BackgroundColor: BackgroundColor.ToOption(), + ShowBackground: ShowBackground.ToOptionV(), + Id: Id.ToOption() + + ).Invoke(gChart); + } } \ No newline at end of file diff --git a/src/Plotly.NET.CSharp/Helpers.cs b/src/Plotly.NET.CSharp/Helpers.cs index b4ce5256c..253baf0de 100644 --- a/src/Plotly.NET.CSharp/Helpers.cs +++ b/src/Plotly.NET.CSharp/Helpers.cs @@ -9,7 +9,19 @@ namespace Plotly.NET.CSharp { static class Helpers { + /// + /// Helper extension method to convert any nullable reference type to a FSharpOption, to be used with F# optional parameters. + /// The resulting opton will be `None` when the value is null, and Some(value) otherwise + /// + /// the thing to turn into a FSharpOption + /// The original value wrapped as a FSharpOption static internal Microsoft.FSharp.Core.FSharpOption ToOption(this T? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption.None : new(thing); + /// + /// Helper extension method to convert any nullable value type to a FSharpOption, to be used with F# optional parameters. + /// The resulting opton will be `None` when the value is null, and Some(value) otherwise + /// + /// the thing to turn into a FSharpOption + /// The original value wrapped as a FSharpOption static internal Microsoft.FSharp.Core.FSharpOption ToOptionV(this T? thing) where T : struct => thing is { } some ? new(some) : Microsoft.FSharp.Core.FSharpOption.None; } } diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index d09a1f819..889ab31fb 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -82,6 +82,15 @@ static void Main(string[] args) ) .WithSize(750,2000) .Show(); + + Chart.Point( + x: new int[] { 1, 2 }, + y: new int[] { 3, 4 } + ) + .WithTraceInfo("Hello from C#", ShowLegend: true) + .WithXAxisStyle(TitleText: "x axis") + .WithYAxisStyle(TitleText: "y axis") + .Show(); } } } From 3e8023ee4dd5f5ed602e70a7f5013bf7a87505a6 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Fri, 10 Jun 2022 11:25:57 +0200 Subject: [PATCH 17/17] Add Chart.Bar and Chart.Column C# bindings --- src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs | 152 ++++++++++++++++++ .../Plotly.NET.Tests.CSharpConsole/Program.cs | 28 +++- 2 files changed, 177 insertions(+), 3 deletions(-) diff --git a/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs b/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs index e7fb81504..ead50d7d4 100644 --- a/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs +++ b/src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs @@ -284,5 +284,157 @@ public static GenericChart.GenericChart Line( UseDefaults: Helpers.ToOptionV(UseDefaults) ); + /// + /// Creates a bar chart, with bars plotted horizontally + /// + /// A bar chart is a chart that presents categorical data with rectangular bars with heights or lengths proportional to the values that they represent. + /// + /// Sets the values that are plotted as the size of each bar. + /// Sets the keys associated with each bar. + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the Opacity of the trace. + /// Sets the Opacity of each individual bar. + /// Sets a text associated with each datum + /// Sets individual text for each datum + /// Sets the color of the bars + /// Sets the colorscale for the bars. To have an effect, `MarkerColor` must map to color scale values. + /// Sets the color of the bar outlines + /// Sets a pattern shape for all bars + /// Sets an individual pattern shape for each bar + /// Sets the marker pattern (use this for more finegrained control than the other pattern-associated arguments). + /// Sets the marker for the bars (use this for more finegrained control than the other marker-associated arguments). + /// Sets where the bar base is drawn (in position axis units). + /// Sets the bar width (in position axis units) of all bars. + /// Sets the individual bar width (in position axis units) for each bar. + /// Sets the position of text associated with each datum + /// Sets the position of text associated with individual datum + /// If set to false, ignore the global default settings set in `Defaults` + public static GenericChart.GenericChart Bar( + IEnumerable values, + IEnumerable? Keys = null, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + TextType? Text = null, + IEnumerable? MultiText = null, + Color? MarkerColor = null, + StyleParam.Colorscale? MarkerColorScale = null, + Line? MarkerOutline = null, + StyleParam.PatternShape? MarkerPatternShape = null, + IEnumerable? MultiMarkerPatternShape = null, + Pattern? MarkerPattern = null, + Marker? Marker = null, + IConvertible? Base = null, + IConvertible? Width = null, + IEnumerable? MultiWidth = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + bool? UseDefaults = null + ) + where ValuesType : IConvertible + where KeysType : IConvertible + where TextType: class, IConvertible + => + Plotly.NET.Chart2D.Chart.Bar( + values: values, + Keys: Keys.ToOption(), + Name: Name.ToOption(), + ShowLegend: ShowLegend.ToOptionV(), + Opacity: Opacity.ToOptionV(), + MultiOpacity: MultiOpacity.ToOption(), + Text: Text.ToOption(), + MultiText: MultiText.ToOption(), + MarkerColor: MarkerColor.ToOption(), + MarkerColorScale: MarkerColorScale.ToOption(), + MarkerOutline: MarkerOutline.ToOption(), + MarkerPatternShape: MarkerPatternShape.ToOption(), + MultiMarkerPatternShape: MultiMarkerPatternShape.ToOption(), + MarkerPattern: MarkerPattern.ToOption(), + Marker: Marker.ToOption(), + Base: Base.ToOption(), + Width: Width.ToOption(), + MultiWidth: MultiWidth.ToOption(), + TextPosition: TextPosition.ToOption(), + MultiTextPosition: MultiTextPosition.ToOption(), + UseDefaults: UseDefaults.ToOptionV() + ); + /// + /// Creates a column chart, with bars plotted vertically + /// + /// A column chart is a chart that presents categorical data with rectangular bars with heights or lengths proportional to the values that they represent. + /// + /// Sets the values that are plotted as the size of each bar. + /// Sets the keys associated with each bar. + /// Sets the trace name. The trace name appear as the legend item and on hover + /// Determines whether or not an item corresponding to this trace is shown in the legend. + /// Sets the Opacity of the trace. + /// Sets the Opacity of each individual bar. + /// Sets a text associated with each datum + /// Sets individual text for each datum + /// Sets the color of the bars + /// Sets the colorscale for the bars. To have an effect, `MarkerColor` must map to color scale values. + /// Sets the color of the bar outlines + /// Sets a pattern shape for all bars + /// Sets an individual pattern shape for each bar + /// Sets the marker pattern (use this for more finegrained control than the other pattern-associated arguments). + /// Sets the marker for the bars (use this for more finegrained control than the other marker-associated arguments). + /// Sets where the bar base is drawn (in position axis units). + /// Sets the bar width (in position axis units) of all bars. + /// Sets the individual bar width (in position axis units) for each bar. + /// Sets the position of text associated with each datum + /// Sets the position of text associated with individual datum + /// If set to false, ignore the global default settings set in `Defaults` + public static GenericChart.GenericChart Column( + IEnumerable values, + IEnumerable? Keys = null, + string? Name = null, + bool? ShowLegend = null, + double? Opacity = null, + IEnumerable? MultiOpacity = null, + TextType? Text = null, + IEnumerable? MultiText = null, + Color? MarkerColor = null, + StyleParam.Colorscale? MarkerColorScale = null, + Line? MarkerOutline = null, + StyleParam.PatternShape? MarkerPatternShape = null, + IEnumerable? MultiMarkerPatternShape = null, + Pattern? MarkerPattern = null, + Marker? Marker = null, + IConvertible? Base = null, + IConvertible? Width = null, + IEnumerable? MultiWidth = null, + StyleParam.TextPosition? TextPosition = null, + IEnumerable? MultiTextPosition = null, + bool? UseDefaults = null + ) + where ValuesType : IConvertible + where KeysType : IConvertible + where TextType : class, IConvertible + => + Plotly.NET.Chart2D.Chart.Column( + values: values, + Keys: Keys.ToOption(), + Name: Name.ToOption(), + ShowLegend: ShowLegend.ToOptionV(), + Opacity: Opacity.ToOptionV(), + MultiOpacity: MultiOpacity.ToOption(), + Text: Text.ToOption(), + MultiText: MultiText.ToOption(), + MarkerColor: MarkerColor.ToOption(), + MarkerColorScale: MarkerColorScale.ToOption(), + MarkerOutline: MarkerOutline.ToOption(), + MarkerPatternShape: MarkerPatternShape.ToOption(), + MultiMarkerPatternShape: MultiMarkerPatternShape.ToOption(), + MarkerPattern: MarkerPattern.ToOption(), + Marker: Marker.ToOption(), + Base: Base.ToOption(), + Width: Width.ToOption(), + MultiWidth: MultiWidth.ToOption(), + TextPosition: TextPosition.ToOption(), + MultiTextPosition: MultiTextPosition.ToOption(), + UseDefaults: UseDefaults.ToOptionV() + ); }; } diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index 889ab31fb..9c4d5abd2 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -11,9 +11,9 @@ static void Main(string[] args) { Chart.Grid( nRows: 8, - nCols: 3, + nCols: 5, gCharts: - new GenericChart [] + new GenericChart[] { Chart.Scatter( x: new int [] { 1, 2 }, @@ -28,6 +28,14 @@ static void Main(string[] args) x: new int [] { 9, 10 }, y: new int [] { 11, 12 } ), + Chart.Bar( + values: new int [] { 1,2 }, + Keys: new string [] { "first", "second"} + ), + Chart.Column( + values: new int [] { 1,2 }, + Keys: new string [] { "first", "second"} + ), Chart.Scatter3D( x: new int[] { 12, 13 }, y: new int [] { 13, 14 }, @@ -36,6 +44,8 @@ static void Main(string[] args) ), Chart.Invisible(), Chart.Invisible(), + Chart.Invisible(), + Chart.Invisible(), Chart.ScatterPolar( theta: new int [] { 1, 2 }, r: new int [] { 3, 4 }, @@ -43,6 +53,8 @@ static void Main(string[] args) ), Chart.Invisible(), Chart.Invisible(), + Chart.Invisible(), + Chart.Invisible(), Chart.ScatterGeo( longitudes: new int [] { 1, 2 }, latitudes: new int [] { 3, 4 }, @@ -50,6 +62,8 @@ static void Main(string[] args) ), Chart.Invisible(), Chart.Invisible(), + Chart.Invisible(), + Chart.Invisible(), Chart.ScatterTernary( A: new int [] { 1, 2 }, B: new int [] { 3, 4 }, @@ -57,6 +71,8 @@ static void Main(string[] args) ), Chart.Invisible(), Chart.Invisible(), + Chart.Invisible(), + Chart.Invisible(), Chart.Carpet( carpetId: "testCarpet", A: new double [] {4.0, 4.0, 4.0, 4.5, 4.5, 4.5, 5.0, 5.0, 5.0, 6.0, 6.0, 6.0}, @@ -65,12 +81,16 @@ static void Main(string[] args) ), Chart.Invisible(), Chart.Invisible(), + Chart.Invisible(), + Chart.Invisible(), Chart.Pie( values: new double [] {1,2,3,4}, Labels: new string [] {"soos", "saas", "fiif", "leel"} ), Chart.Invisible(), Chart.Invisible(), + Chart.Invisible(), + Chart.Invisible(), Chart.ScatterSmith( real: new double [] {1,2,3,4}, imag: new double [] {1,2,3,4}, @@ -78,9 +98,11 @@ static void Main(string[] args) ), Chart.Invisible(), Chart.Invisible(), + Chart.Invisible(), + Chart.Invisible(), } ) - .WithSize(750,2000) + .WithSize(1250,2000) .Show(); Chart.Point(