Skip to content

Commit 0fc47fd

Browse files
committed
wip otional argument interop
1 parent 63771ac commit 0fc47fd

File tree

6 files changed

+188
-0
lines changed

6 files changed

+188
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Plotly.NET;
7+
8+
namespace Plotly.NET.CSharp
9+
{
10+
public static class Chart
11+
{
12+
public static GenericChart.GenericChart Combine(IEnumerable<GenericChart.GenericChart> gCharts) => Plotly.NET.Chart.Combine(gCharts);
13+
14+
public static GenericChart.GenericChart Invisible() => Plotly.NET.Chart.Invisible();
15+
}
16+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Plotly.NET;
7+
using Plotly.NET.LayoutObjects;
8+
using Plotly.NET.TraceObjects;
9+
namespace Plotly.NET.CSharp.ChartAPI
10+
{
11+
public static class Test
12+
{
13+
public static int Foo<T>(IEnumerable<T> notopt, IEnumerable<T>? opt1) =>
14+
Plotly.NET.Chart2D.Chart.Foo<T, T>(
15+
notopt: notopt,
16+
opt1: opt1
17+
);
18+
}
19+
public static class Chart2D
20+
{
21+
/// <summary>
22+
/// Creates a Scatter plot.
23+
///
24+
/// 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
25+
/// </summary>
26+
/// <param name="x">Sets the x coordinates of the plotted data.</param>
27+
/// <param name="y">Sets the y coordinates of the plotted data.</param>
28+
/// <param name="mode">Determines the drawing mode for this scatter trace.</param>
29+
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
30+
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
31+
/// <param name="Opacity">Sets the opactity of the trace</param>
32+
/// <param name="MultiOpacity">Sets the opactity of individual datum markers</param>
33+
/// <param name="Text">Sets a text associated with each datum</param>
34+
/// <param name="MultiText">Sets individual text for each datum</param>
35+
/// <param name="TextPosition">Sets the position of text associated with each datum</param>
36+
/// <param name="MultiTextPosition">Sets the position of text associated with individual datum</param>
37+
/// <param name="MarkerColor">Sets the color of the marker</param>
38+
/// <param name="MarkerColorScale">Sets the colorscale of the marker</param>
39+
/// <param name="MarkerOutline">Sets the outline of the marker</param>
40+
/// <param name="MarkerSymbol">Sets the marker symbol for each datum</param>
41+
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
42+
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
43+
/// <param name="LineColor">Sets the color of the line</param>
44+
/// <param name="LineColorScale">Sets the colorscale of the line</param>
45+
/// <param name="LineWidth">Sets the width of the line</param>
46+
/// <param name="LineDash">sets the drawing style of the line</param>
47+
/// <param name="Line">Sets the line (use this for more finegrained control than the other line-associated arguments)</param>
48+
/// <param name="StackGroup">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</param>
49+
/// <param name="Orientation">Sets the stacking direction. Only relevant when `stackgroup` is used, and only the first `orientation` found in the `stackgroup` will be used.</param>
50+
/// <param name="GroupNorm">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</param>
51+
/// <param name="Fill">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.</param>
52+
/// <param name="FillColor">ets the fill color. Defaults to a half-transparent variant of the line color, marker color, or marker line color, whichever is available.</param>
53+
/// <param name="UseWebGL">If true, plotly.js will use the WebGL engine to render this chart. use this when you want to render many objects at once.</param>
54+
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
55+
public static GenericChart.GenericChart Scatter(
56+
IEnumerable<IConvertible> x,
57+
IEnumerable<IConvertible> y,
58+
StyleParam.Mode mode,
59+
string? Name,
60+
bool? ShowLegend,
61+
float? Opacity,
62+
IEnumerable<float>? MultiOpacity,
63+
IConvertible? Text,
64+
IEnumerable<IConvertible>? MultiText,
65+
StyleParam.TextPosition? TextPosition,
66+
IEnumerable<StyleParam.TextPosition>? MultiTextPosition,
67+
Color? MarkerColor,
68+
StyleParam.Colorscale? MarkerColorScale,
69+
Line? MarkerOutline,
70+
StyleParam.MarkerSymbol? MarkerSymbol,
71+
IEnumerable<StyleParam.MarkerSymbol>? MultiMarkerSymbol,
72+
Marker? Marker,
73+
Color? LineColor,
74+
StyleParam.Colorscale? LineColorScale,
75+
float? LineWidth,
76+
StyleParam.DrawingStyle? LineDash,
77+
Line? Line,
78+
string StackGroup,
79+
StyleParam.Orientation? Orientation,
80+
StyleParam.GroupNorm? GroupNorm,
81+
StyleParam.Fill? Fill,
82+
Color? FillColor,
83+
bool? UseWebGL,
84+
bool? UseDefaults
85+
) =>
86+
Plotly.NET.Chart2D.Chart.Scatter<IConvertible,IConvertible,IConvertible>(
87+
x, y, mode,
88+
Name: Name,
89+
ShowLegend: ShowLegend,
90+
Opacity: Opacity,
91+
MultiOpacity: MultiOpacity,
92+
Text: Text,
93+
MultiText: MultiText,
94+
TextPosition: TextPosition,
95+
MultiTextPosition: MultiTextPosition,
96+
MarkerColor: MarkerColor,
97+
MarkerColorScale: MarkerColorScale,
98+
MarkerOutline: MarkerOutline,
99+
MarkerSymbol: MarkerSymbol,
100+
MultiMarkerSymbol: MultiMarkerSymbol,
101+
Marker: Marker,
102+
LineColor: LineColor,
103+
LineColorScale: LineColorScale,
104+
LineWidth: LineWidth,
105+
LineDash: LineDash,
106+
Line: Line,
107+
StackGroup: StackGroup,
108+
Orientation: Orientation,
109+
GroupNorm: GroupNorm,
110+
Fill: Fill,
111+
FillColor: FillColor,
112+
UseWebGL: UseWebGL,
113+
UseDefaults: UseDefaults
114+
);
115+
};
116+
}

src/Plotly.NET.CSharp/GenericChartExtensions.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,37 @@ public static class GenericChartExtensions
88

99
public static Trace [] GetTraces(this GenericChart.GenericChart gChart) => GenericChart.getTraces(gChart).ToArray();
1010

11+
/// <summary>
12+
/// Saves the given Chart as html file at the given path (.html file extension is added if not present).
13+
/// Optionally opens the generated file in the browser.
14+
/// </summary>
15+
/// <param name="path">The path to save the chart html at.</param>
16+
/// <param name="OpenInBrowser">Wether or not to open the generated file in the browser (default: false)</param>
17+
public static void SaveHtml(
18+
this GenericChart.GenericChart gChart,
19+
string path,
20+
bool? OpenInBrowser
21+
) =>
22+
Plotly.NET.Chart.SaveHtml(
23+
path: path,
24+
OpenInBrowser: OpenInBrowser
25+
).Invoke(gChart);
26+
27+
/// <summary>
28+
/// Saves the given chart as a temporary html file and opens it in the browser.
29+
/// </summary>
30+
/// <param name="ch">The chart to show in the browser</param>
31+
public static void Show(this GenericChart.GenericChart gChart) => Plotly.NET.Chart.Show(gChart);
32+
33+
/// <summary>
34+
/// Sets trace information on the given chart.
35+
/// </summary>
36+
/// <param name="Name">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.</param>
37+
/// <param name="Visible">Wether or not the chart's traces are visible</param>
38+
/// <param name="ShowLegend">Determines whether or not item(s) corresponding to this chart's trace(s) is/are shown in the legend.</param>
39+
/// <param name="LegendRank">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.</param>
40+
/// <param name="LegendGroup">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.</param>
41+
/// <param name="LegendGroupTitle">Sets the title for the chart's trace legend group </param>
1142
public static GenericChart.GenericChart WithTraceInfo(
1243
this GenericChart.GenericChart gChart,
1344
string? Name,
@@ -26,4 +57,6 @@ public static GenericChart.GenericChart WithTraceInfo(
2657
LegendGroupTitle: LegendGroupTitle
2758
).Invoke(gChart);
2859
}
60+
61+
2962
}

src/Plotly.NET.CSharp/Helpers.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.FSharp;
7+
using Microsoft.FSharp.Core;
8+
9+
namespace Plotly.NET.CSharp
10+
{
11+
internal class OptionWrapper<T> {
12+
internal static FSharpOption<T> WrapAsOption(T? Value) {
13+
if (Value is null) {
14+
return FSharpOption<T>.None;
15+
} else {
16+
T v = (T)Value;
17+
return FSharpOption<T>.Some(v);
18+
}
19+
}
20+
}
21+
}

src/Plotly.NET/ChartAPI/Chart2D.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Chart2D =
3030
Trace2D.initHeatmap style |> GenericChart.ofTraceObject useDefaults
3131

3232

33+
static member Foo(notopt: seq<#IConvertible>,?opt1: seq<#IConvertible>) = 2
3334

3435
/// <summary>
3536
/// Creates a Scatter plot.

tests/Plotly.NET.Tests.CSharpConsole/Plotly.NET.Tests.CSharpConsole.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<ItemGroup>
44
<ProjectReference Include="..\..\src\Plotly.NET\Plotly.NET.fsproj" />
5+
<ProjectReference Include="..\..\src\Plotly.NET.CSharp\Plotly.NET.CSharp.fsproj" />
56
</ItemGroup>
67

78
<PropertyGroup>

0 commit comments

Comments
 (0)