Skip to content

Commit a9d1a11

Browse files
committed
Add Chart.Point and Chart.Line bindings
1 parent 7ee4987 commit a9d1a11

File tree

6 files changed

+202
-45
lines changed

6 files changed

+202
-45
lines changed

src/Plotly.NET.CSharp/ChartAPI/Chart.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Plotly.NET.CSharp
99
{
10-
public static class Chart
10+
public static partial class Chart
1111
{
1212
public static GenericChart.GenericChart Combine(IEnumerable<GenericChart.GenericChart> gCharts) => Plotly.NET.Chart.Combine(gCharts);
1313

src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs

Lines changed: 180 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,9 @@
77
using Plotly.NET.LayoutObjects;
88
using Plotly.NET.TraceObjects;
99

10-
namespace Plotly.NET.CSharp.ChartAPI
10+
namespace Plotly.NET.CSharp
1111
{
12-
public static class Test
13-
{
14-
public static int Foo<T1,T2,T3>(
15-
IEnumerable<T1> notopt,
16-
IEnumerable<T2>? opt1 = null,
17-
T3? opt2 = null
18-
)
19-
where T1 : IConvertible
20-
where T2 : IConvertible
21-
where T3 : class, IConvertible =>
22-
Plotly.NET.Chart2D.Chart.Foo<T1, T2, T3>(
23-
notopt: notopt,
24-
opt1: Helpers.ToOption<IEnumerable<T2>>(opt1),
25-
opt2: opt2
26-
);
27-
}
28-
public static class Chart2D
12+
public static partial class Chart
2913
{
3014
/// <summary>
3115
/// Creates a Scatter plot.
@@ -101,8 +85,8 @@ public static GenericChart.GenericChart Scatter<XType,YType,TextType>(
10185
y: y,
10286
mode: mode,
10387
Name: Helpers.ToOption(Name),
104-
ShowLegend: Helpers.ToOption(ShowLegend),
105-
Opacity: Helpers.ToOption(Opacity),
88+
ShowLegend: Helpers.ToOptionV(ShowLegend),
89+
Opacity: Helpers.ToOptionV(Opacity),
10690
MultiOpacity: Helpers.ToOption(MultiOpacity),
10791
Text: Helpers.ToOption(Text),
10892
MultiText: Helpers.ToOption(MultiText),
@@ -116,16 +100,189 @@ public static GenericChart.GenericChart Scatter<XType,YType,TextType>(
116100
Marker: Helpers.ToOption(Marker),
117101
LineColor: Helpers.ToOption(LineColor),
118102
LineColorScale: Helpers.ToOption(LineColorScale),
119-
LineWidth: Helpers.ToOption(LineWidth),
103+
LineWidth: Helpers.ToOptionV(LineWidth),
120104
LineDash: Helpers.ToOption(LineDash),
121105
Line: Helpers.ToOption(Line),
122106
StackGroup: Helpers.ToOption(StackGroup),
123107
Orientation: Helpers.ToOption(Orientation),
124108
GroupNorm: Helpers.ToOption(GroupNorm),
125109
Fill: Helpers.ToOption(Fill),
126110
FillColor: Helpers.ToOption(FillColor),
127-
UseWebGL: Helpers.ToOption(UseWebGL),
128-
UseDefaults: Helpers.ToOption(UseDefaults)
111+
UseWebGL: Helpers.ToOptionV(UseWebGL),
112+
UseDefaults: Helpers.ToOptionV(UseDefaults)
129113
);
114+
115+
/// <summary>
116+
/// Creates a Point chart, which uses Points in a 2D space to visualize data.
117+
/// </summary>
118+
/// <param name="x">Sets the x coordinates of the plotted data.</param>
119+
/// <param name="y">Sets the y coordinates of the plotted data.</param>
120+
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
121+
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
122+
/// <param name="Opacity">Sets the opactity of the trace</param>
123+
/// <param name="MultiOpacity">Sets the opactity of individual datum markers</param>
124+
/// <param name="Text">Sets a text associated with each datum</param>
125+
/// <param name="MultiText">Sets individual text for each datum</param>
126+
/// <param name="TextPosition">Sets the position of text associated with each datum</param>
127+
/// <param name="MultiTextPosition">Sets the position of text associated with individual datum</param>
128+
/// <param name="MarkerColor">Sets the color of the marker</param>
129+
/// <param name="MarkerColorScale">Sets the colorscale of the marker</param>
130+
/// <param name="MarkerOutline">Sets the outline of the marker</param>
131+
/// <param name="MarkerSymbol">Sets the marker symbol for each datum</param>
132+
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
133+
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
134+
/// <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>
135+
/// <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>
136+
/// <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>
137+
/// <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>
138+
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
139+
public static GenericChart.GenericChart Point<XType, YType, TextType>(
140+
IEnumerable<XType> x,
141+
IEnumerable<YType> y,
142+
string? Name = null,
143+
bool? ShowLegend = null,
144+
double? Opacity = null,
145+
IEnumerable<double>? MultiOpacity = null,
146+
TextType? Text = null,
147+
IEnumerable<TextType>? MultiText = null,
148+
StyleParam.TextPosition? TextPosition = null,
149+
IEnumerable<StyleParam.TextPosition>? MultiTextPosition = null,
150+
Color? MarkerColor = null,
151+
StyleParam.Colorscale? MarkerColorScale = null,
152+
Line? MarkerOutline = null,
153+
StyleParam.MarkerSymbol? MarkerSymbol = null,
154+
IEnumerable<StyleParam.MarkerSymbol>? MultiMarkerSymbol = null,
155+
Marker? Marker = null,
156+
string? StackGroup = null,
157+
StyleParam.Orientation? Orientation = null,
158+
StyleParam.GroupNorm? GroupNorm = null,
159+
bool? UseWebGL = null,
160+
bool? UseDefaults = null
161+
)
162+
where XType : IConvertible
163+
where YType : IConvertible
164+
where TextType : class, IConvertible
165+
=>
166+
Plotly.NET.Chart2D.Chart.Point(
167+
x: x,
168+
y: y,
169+
Name: Helpers.ToOption(Name),
170+
ShowLegend: Helpers.ToOptionV(ShowLegend),
171+
Opacity: Helpers.ToOptionV(Opacity),
172+
MultiOpacity: Helpers.ToOption(MultiOpacity),
173+
Text: Helpers.ToOption(Text),
174+
MultiText: Helpers.ToOption(MultiText),
175+
TextPosition: Helpers.ToOption(TextPosition),
176+
MultiTextPosition: Helpers.ToOption(MultiTextPosition),
177+
MarkerColor: Helpers.ToOption(MarkerColor),
178+
MarkerColorScale: Helpers.ToOption(MarkerColorScale),
179+
MarkerOutline: Helpers.ToOption(MarkerOutline),
180+
MarkerSymbol: Helpers.ToOption(MarkerSymbol),
181+
MultiMarkerSymbol: Helpers.ToOption(MultiMarkerSymbol),
182+
Marker: Helpers.ToOption(Marker),
183+
StackGroup: Helpers.ToOption(StackGroup),
184+
Orientation: Helpers.ToOption(Orientation),
185+
GroupNorm: Helpers.ToOption(GroupNorm),
186+
UseWebGL: Helpers.ToOptionV(UseWebGL),
187+
UseDefaults: Helpers.ToOptionV(UseDefaults)
188+
);
189+
190+
/// <summary> 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.</summary>
191+
/// <param name="x">Sets the x coordinates of the plotted data.</param>
192+
/// <param name="y">Sets the y coordinates of the plotted data.</param>
193+
/// <param name="ShowMarkers">Wether to show markers for the individual data points</param>
194+
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
195+
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
196+
/// <param name="Opacity">Sets the opactity of the trace</param>
197+
/// <param name="MultiOpacity">Sets the opactity of individual datum markers</param>
198+
/// <param name="Text">Sets a text associated with each datum</param>
199+
/// <param name="MultiText">Sets individual text for each datum</param>
200+
/// <param name="TextPosition">Sets the position of text associated with each datum</param>
201+
/// <param name="MultiTextPosition">Sets the position of text associated with individual datum</param>
202+
/// <param name="MarkerColor">Sets the color of the marker</param>
203+
/// <param name="MarkerColorScale">Sets the colorscale of the marker</param>
204+
/// <param name="MarkerOutline">Sets the outline of the marker</param>
205+
/// <param name="MarkerSymbol">Sets the marker symbol for each datum</param>
206+
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
207+
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
208+
/// <param name="LineColor">Sets the color of the line</param>
209+
/// <param name="LineColorScale">Sets the colorscale of the line</param>
210+
/// <param name="LineWidth">Sets the width of the line</param>
211+
/// <param name="LineDash">sets the drawing style of the line</param>
212+
/// <param name="Line">Sets the line (use this for more finegrained control than the other line-associated arguments)</param>
213+
/// <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>
214+
/// <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>
215+
/// <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>
216+
/// <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>
217+
/// <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>
218+
/// <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>
219+
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
220+
public static GenericChart.GenericChart Line<XType, YType, TextType>(
221+
IEnumerable<XType> x,
222+
IEnumerable<YType> y,
223+
bool? ShowMarkers = null,
224+
string? Name = null,
225+
bool? ShowLegend = null,
226+
double? Opacity = null,
227+
IEnumerable<double>? MultiOpacity = null,
228+
TextType? Text = null,
229+
IEnumerable<TextType>? MultiText = null,
230+
StyleParam.TextPosition? TextPosition = null,
231+
IEnumerable<StyleParam.TextPosition>? MultiTextPosition = null,
232+
Color? MarkerColor = null,
233+
StyleParam.Colorscale? MarkerColorScale = null,
234+
Line? MarkerOutline = null,
235+
StyleParam.MarkerSymbol? MarkerSymbol = null,
236+
IEnumerable<StyleParam.MarkerSymbol>? MultiMarkerSymbol = null,
237+
Marker? Marker = null,
238+
Color? LineColor = null,
239+
StyleParam.Colorscale? LineColorScale = null,
240+
double? LineWidth = null,
241+
StyleParam.DrawingStyle? LineDash = null,
242+
Line? Line = null,
243+
string? StackGroup = null,
244+
StyleParam.Orientation? Orientation = null,
245+
StyleParam.GroupNorm? GroupNorm = null,
246+
StyleParam.Fill? Fill = null,
247+
Color? FillColor = null,
248+
bool? UseWebGL = null,
249+
bool? UseDefaults = null
250+
)
251+
where XType : IConvertible
252+
where YType : IConvertible
253+
where TextType : class, IConvertible
254+
=>
255+
Plotly.NET.Chart2D.Chart.Line(
256+
x: x,
257+
y: y,
258+
ShowMarkers: Helpers.ToOptionV(ShowMarkers),
259+
Name: Helpers.ToOption(Name),
260+
ShowLegend: Helpers.ToOptionV(ShowLegend),
261+
Opacity: Helpers.ToOptionV(Opacity),
262+
MultiOpacity: Helpers.ToOption(MultiOpacity),
263+
Text: Helpers.ToOption(Text),
264+
MultiText: Helpers.ToOption(MultiText),
265+
TextPosition: Helpers.ToOption(TextPosition),
266+
MultiTextPosition: Helpers.ToOption(MultiTextPosition),
267+
MarkerColor: Helpers.ToOption(MarkerColor),
268+
MarkerColorScale: Helpers.ToOption(MarkerColorScale),
269+
MarkerOutline: Helpers.ToOption(MarkerOutline),
270+
MarkerSymbol: Helpers.ToOption(MarkerSymbol),
271+
MultiMarkerSymbol: Helpers.ToOption(MultiMarkerSymbol),
272+
Marker: Helpers.ToOption(Marker),
273+
LineColor: Helpers.ToOption(LineColor),
274+
LineColorScale: Helpers.ToOption(LineColorScale),
275+
LineWidth: Helpers.ToOptionV(LineWidth),
276+
LineDash: Helpers.ToOption(LineDash),
277+
Line: Helpers.ToOption(Line),
278+
StackGroup: Helpers.ToOption(StackGroup),
279+
Orientation: Helpers.ToOption(Orientation),
280+
GroupNorm: Helpers.ToOption(GroupNorm),
281+
Fill: Helpers.ToOption(Fill),
282+
FillColor: Helpers.ToOption(FillColor),
283+
UseWebGL: Helpers.ToOptionV(UseWebGL),
284+
UseDefaults: Helpers.ToOptionV(UseDefaults)
285+
);
286+
130287
};
131288
}

src/Plotly.NET.CSharp/Helpers.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ namespace Plotly.NET.CSharp
1010
{
1111
static class Helpers {
1212
static internal Microsoft.FSharp.Core.FSharpOption<T> ToOption<T>(this T? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption<T>.None : new(thing);
13-
static internal Microsoft.FSharp.Core.FSharpOption<bool> ToOption(this bool? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption<bool>.None : new((bool)thing);
14-
static internal Microsoft.FSharp.Core.FSharpOption<string> ToOption(this string? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption<string>.None : new((string)thing);
15-
static internal Microsoft.FSharp.Core.FSharpOption<double> ToOption(this double? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption<double>.None : new((double)thing);
16-
static internal Microsoft.FSharp.Core.FSharpOption<int> ToOption(this int? thing) => thing is null ? Microsoft.FSharp.Core.FSharpOption<int>.None : new((int)thing);
13+
static internal Microsoft.FSharp.Core.FSharpOption<T> ToOptionV<T>(this T? thing) where T : struct => thing is { } some ? new(some) : Microsoft.FSharp.Core.FSharpOption<T>.None;
1714
}
1815
}

src/Plotly.NET/ChartAPI/Chart2D.fs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ module Chart2D =
2929
else
3030
Trace2D.initHeatmap style |> GenericChart.ofTraceObject useDefaults
3131

32-
33-
static member Foo(notopt: seq<#IConvertible>,?opt1: seq<#IConvertible>, ?opt2: #IConvertible) = 2
34-
3532
/// <summary>
3633
/// Creates a Scatter plot.
3734
///

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<ItemGroup>
4-
<ProjectReference Include="..\..\src\Plotly.NET\Plotly.NET.fsproj" />
54
<ProjectReference Include="..\..\src\Plotly.NET.CSharp\Plotly.NET.CSharp.csproj" />
65
</ItemGroup>
76

tests/Plotly.NET.Tests.CSharpConsole/Program.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
using System;
22
using Plotly.NET.CSharp;
3-
using Plotly.NET.CSharp.ChartAPI;
4-
using Plotly.NET.LayoutObjects;
3+
using static Plotly.NET.StyleParam;
4+
using static Plotly.NET.GenericChart;
55

6-
namespace Plotly.NET.Tests.CSharp
6+
namespace TestConsoleApp
77
{
88
class Program
99
{
1010
static void Main(string[] args)
1111
{
12-
Plotly.NET.CSharp.ChartAPI.Chart2D.Scatter<int,int,string>(
13-
x: new int [] { 1, 2 },
14-
y: new int [] { 1, 2 },
15-
mode: StyleParam.Mode.Markers
16-
).Show();
17-
18-
Chart2D.Chart.Scatter<int,int,string> (
19-
x: new int[] { 1, 2 },
20-
y: new int[] { 1, 2 },
21-
mode: StyleParam.Mode.Markers
12+
Chart.Combine(
13+
new GenericChart []
14+
{
15+
Chart.Scatter<int,int,string>(
16+
x: new int [] { 1, 2 },
17+
y: new int [] { 3, 4 },
18+
mode: Mode.Markers
19+
),
20+
Chart.Point<int,int,string>(
21+
x: new int [] { 5, 6 },
22+
y: new int [] { 7, 8 }
23+
),
24+
Chart.Line<int,int,string>(
25+
x: new int [] { 9, 10 },
26+
y: new int [] { 11, 12 }
27+
)
28+
}
2229
).Show();
2330
}
2431
}

0 commit comments

Comments
 (0)