Skip to content

Commit 66d31f2

Browse files
committed
Improve API by using Optional and default checking for option conversion
1 parent 9998196 commit 66d31f2

10 files changed

Lines changed: 433 additions & 414 deletions

File tree

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Plotly.NET;
77
using Plotly.NET.LayoutObjects;
88
using Plotly.NET.TraceObjects;
9+
using System.Runtime.InteropServices;
910

1011
namespace Plotly.NET.CSharp
1112
{
@@ -36,16 +37,16 @@ public static GenericChart.GenericChart Grid(
3637
IEnumerable<GenericChart.GenericChart> gCharts,
3738
int nRows,
3839
int nCols,
39-
Tuple<StyleParam.LinearAxisId, StyleParam.LinearAxisId>[][]? SubPlots = null,
40-
StyleParam.LinearAxisId[]? XAxes = null,
41-
StyleParam.LinearAxisId[]? YAxes = null,
42-
StyleParam.LayoutGridRowOrder? RowOrder = null,
43-
StyleParam.LayoutGridPattern? Pattern = null,
44-
double? XGap = null,
45-
double? YGap = null,
46-
Domain? Domain = null,
47-
StyleParam.LayoutGridXSide? XSide = null,
48-
StyleParam.LayoutGridYSide? YSide = null
40+
[Optional] Tuple<StyleParam.LinearAxisId, StyleParam.LinearAxisId>[][]? SubPlots,
41+
[Optional] StyleParam.LinearAxisId[]? XAxes,
42+
[Optional] StyleParam.LinearAxisId[]? YAxes,
43+
[Optional] StyleParam.LayoutGridRowOrder? RowOrder,
44+
[Optional] StyleParam.LayoutGridPattern? Pattern,
45+
[Optional] double? XGap,
46+
[Optional] double? YGap,
47+
[Optional] Domain? Domain,
48+
[Optional] StyleParam.LayoutGridXSide? XSide,
49+
[Optional] StyleParam.LayoutGridYSide? YSide
4950
) =>
5051
Plotly.NET.Chart.Grid<IEnumerable<GenericChart.GenericChart>>(
5152
nRows: nRows,

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

Lines changed: 217 additions & 216 deletions
Large diffs are not rendered by default.

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

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Plotly.NET;
77
using Plotly.NET.LayoutObjects;
88
using Plotly.NET.TraceObjects;
9+
using System.Runtime.InteropServices;
10+
911

1012
namespace Plotly.NET.CSharp
1113
{
@@ -43,64 +45,64 @@ public static partial class Chart
4345
/// <param name="Line">Sets the line (use this for more finegrained control than the other line-associated arguments)</param>
4446
/// <param name="Projection">Sets the projection of this trace.</param>
4547
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
46-
public static GenericChart.GenericChart Scatter3D<XData, YData, ZData, TextData>(
47-
IEnumerable<XData> x,
48-
IEnumerable<YData> y,
49-
IEnumerable<ZData> z,
48+
public static GenericChart.GenericChart Scatter3D<XType, YType, ZType, TextType>(
49+
IEnumerable<XType> x,
50+
IEnumerable<YType> y,
51+
IEnumerable<ZType> z,
5052
StyleParam.Mode mode,
51-
string? Name = null,
52-
bool? ShowLegend = null,
53-
double? Opacity = null,
54-
IEnumerable<double>? MultiOpacity = null,
55-
TextData? Text = null,
56-
IEnumerable<TextData>? MultiText = null,
57-
StyleParam.TextPosition? TextPosition = null,
58-
IEnumerable<StyleParam.TextPosition>? MultiTextPosition = null,
59-
Color? MarkerColor = null,
60-
StyleParam.Colorscale? MarkerColorScale = null,
61-
Line? MarkerOutline = null,
62-
StyleParam.MarkerSymbol3D? MarkerSymbol = null,
63-
IEnumerable<StyleParam.MarkerSymbol3D>? MultiMarkerSymbol = null,
64-
Marker? Marker = null,
65-
Color? LineColor = null,
66-
StyleParam.Colorscale? LineColorScale = null,
67-
double? LineWidth = null,
68-
StyleParam.DrawingStyle? LineDash = null,
69-
Line? Line = null,
70-
Projection? Projection = null,
71-
bool? UseDefaults = null
53+
[Optional] string? Name,
54+
[Optional] bool? ShowLegend,
55+
[Optional] double? Opacity,
56+
[Optional] IEnumerable<double>? MultiOpacity,
57+
[Optional] TextType? Text,
58+
[Optional] IEnumerable<TextType>? MultiText,
59+
[Optional] StyleParam.TextPosition? TextPosition,
60+
[Optional] IEnumerable<StyleParam.TextPosition>? MultiTextPosition,
61+
[Optional] Color? MarkerColor,
62+
[Optional] StyleParam.Colorscale? MarkerColorScale,
63+
[Optional] Line? MarkerOutline,
64+
[Optional] StyleParam.MarkerSymbol3D? MarkerSymbol,
65+
[Optional] IEnumerable<StyleParam.MarkerSymbol3D>? MultiMarkerSymbol,
66+
[Optional] Marker? Marker,
67+
[Optional] Color? LineColor,
68+
[Optional] StyleParam.Colorscale? LineColorScale,
69+
[Optional] double? LineWidth,
70+
[Optional] StyleParam.DrawingStyle? LineDash,
71+
[Optional] Line? Line,
72+
[Optional] Projection? Projection,
73+
[Optional] bool? UseDefaults
7274
)
73-
where XData: IConvertible
74-
where YData: IConvertible
75-
where ZData: IConvertible
76-
where TextData: class, IConvertible
75+
where XType: IConvertible
76+
where YType: IConvertible
77+
where ZType : IConvertible
78+
where TextType : IConvertible
7779

78-
=> Plotly.NET.Chart3D.Chart.Scatter3D<XData, YData, ZData, TextData>(
80+
=> Plotly.NET.Chart3D.Chart.Scatter3D<XType, YType, ZType, TextType>(
7981
x: x,
8082
y: y,
8183
z: z,
8284
mode: mode,
83-
Name: Helpers.ToOption(Name),
84-
ShowLegend: Helpers.ToOptionV(ShowLegend),
85-
Opacity: Helpers.ToOptionV(Opacity),
86-
MultiOpacity: Helpers.ToOption(MultiOpacity),
87-
Text: Helpers.ToOption(Text),
88-
MultiText: Helpers.ToOption(MultiText),
89-
TextPosition: Helpers.ToOption(TextPosition),
90-
MultiTextPosition: Helpers.ToOption(MultiTextPosition),
91-
MarkerColor: Helpers.ToOption(MarkerColor),
92-
MarkerColorScale: Helpers.ToOption(MarkerColorScale),
93-
MarkerOutline: Helpers.ToOption(MarkerOutline),
94-
MarkerSymbol: Helpers.ToOption(MarkerSymbol),
95-
MultiMarkerSymbol: Helpers.ToOption(MultiMarkerSymbol),
96-
Marker: Helpers.ToOption(Marker),
97-
LineColor: Helpers.ToOption(LineColor),
98-
LineColorScale: Helpers.ToOption(LineColorScale),
99-
LineWidth: Helpers.ToOptionV(LineWidth),
100-
LineDash: Helpers.ToOption(LineDash),
101-
Line: Helpers.ToOption(Line),
102-
Projection: Helpers.ToOption(Projection),
103-
UseDefaults: Helpers.ToOptionV(UseDefaults)
85+
Name: Name.ToOption(),
86+
ShowLegend: ShowLegend.ToOptionV(),
87+
Opacity: Opacity.ToOptionV(),
88+
MultiOpacity: MultiOpacity.ToOption(),
89+
Text: Text.ToOption(),
90+
MultiText: MultiText.ToOption(),
91+
TextPosition: TextPosition.ToOption(),
92+
MultiTextPosition: MultiTextPosition.ToOption(),
93+
MarkerColor: MarkerColor.ToOption(),
94+
MarkerColorScale: MarkerColorScale.ToOption(),
95+
MarkerOutline: MarkerOutline.ToOption(),
96+
MarkerSymbol: MarkerSymbol.ToOption(),
97+
MultiMarkerSymbol: MultiMarkerSymbol.ToOption(),
98+
Marker: Marker.ToOption(),
99+
LineColor: LineColor.ToOption(),
100+
LineColorScale: LineColorScale.ToOption(),
101+
LineWidth: LineWidth.ToOptionV(),
102+
LineDash: LineDash.ToOption(),
103+
Line: Line.ToOption(),
104+
Projection: Projection.ToOption(),
105+
UseDefaults: UseDefaults.ToOptionV()
104106
);
105107
}
106108
}

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Plotly.NET.LayoutObjects;
77
using Plotly.NET.TraceObjects;
8+
using System.Runtime.InteropServices;
89

910
namespace Plotly.NET.CSharp
1011
{
@@ -46,22 +47,22 @@ public static partial class Chart
4647
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
4748
public static GenericChart.GenericChart Carpet<XType, MultiXType, YType, MultiYType, AType, BType>(
4849
string carpetId,
49-
string? Name = null,
50-
bool? ShowLegend = null,
51-
double? Opacity = null,
52-
IEnumerable<XType>? X = null,
53-
IEnumerable<IEnumerable<MultiXType>>? MultiX = null,
54-
IEnumerable<YType>? Y = null,
55-
IEnumerable<IEnumerable<MultiYType>>? MultiY = null,
56-
IEnumerable<AType>? A = null,
57-
IEnumerable<BType>? B = null,
58-
LinearAxis? AAxis = null,
59-
LinearAxis? BAxis = null,
60-
StyleParam.LinearAxisId? XAxis = null,
61-
StyleParam.LinearAxisId? YAxis = null,
62-
Color? Color = null,
63-
double? CheaterSlope = null,
64-
bool? UseDefaults = true
50+
[Optional] string? Name,
51+
[Optional] bool? ShowLegend,
52+
[Optional] double? Opacity,
53+
[Optional] IEnumerable<XType>? X,
54+
[Optional] IEnumerable<IEnumerable<MultiXType>>? MultiX,
55+
[Optional] IEnumerable<YType>? Y,
56+
[Optional] IEnumerable<IEnumerable<MultiYType>>? MultiY,
57+
[Optional] IEnumerable<AType>? A,
58+
[Optional] IEnumerable<BType>? B,
59+
[Optional] LinearAxis? AAxis,
60+
[Optional] LinearAxis? BAxis,
61+
[Optional] StyleParam.LinearAxisId? XAxis,
62+
[Optional] StyleParam.LinearAxisId? YAxis,
63+
[Optional] Color? Color,
64+
[Optional] double? CheaterSlope,
65+
[Optional] bool? UseDefaults
6566
)
6667
where XType : IConvertible
6768
where MultiXType : IConvertible

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Plotly.NET;
22
using Plotly.NET.LayoutObjects;
33
using Plotly.NET.TraceObjects;
4+
using System.Runtime.InteropServices;
45

56

67
namespace Plotly.NET.CSharp
@@ -39,33 +40,33 @@ public static partial class Chart
3940
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
4041
public static GenericChart.GenericChart Pie<ValuesType, LabelsType, TextType>(
4142
IEnumerable<ValuesType> values,
42-
string? Name = null,
43-
bool? ShowLegend = null,
44-
double? Opacity = null,
45-
IEnumerable<double>? MultiOpacity = null,
46-
IEnumerable<LabelsType>? Labels = null,
47-
double? Pull = null,
48-
IEnumerable<double>? MultiPull = null,
49-
TextType? Text = null,
50-
IEnumerable<TextType>? MultiText = null,
51-
StyleParam.TextPosition? TextPosition = null,
52-
IEnumerable<StyleParam.TextPosition>? MultiTextPosition = null,
53-
IEnumerable<Color>? SectionColors = null,
54-
Color? SectionOutlineColor = null,
55-
double? SectionOutlineWidth = null,
56-
IEnumerable<double>? SectionOutlineMultiWidth = null,
57-
Line? SectionOutline = null,
58-
Marker? Marker = null,
59-
StyleParam.TextInfo? TextInfo = null,
60-
StyleParam.Direction? Direction = null,
61-
double? Hole = null,
62-
double? Rotation = null,
63-
bool? Sort = null,
64-
bool? UseDefaults = null
43+
[Optional] string? Name,
44+
[Optional] bool? ShowLegend,
45+
[Optional] double? Opacity,
46+
[Optional] IEnumerable<double>? MultiOpacity,
47+
[Optional] IEnumerable<LabelsType>? Labels,
48+
[Optional] double? Pull,
49+
[Optional] IEnumerable<double>? MultiPull,
50+
[Optional] TextType? Text,
51+
[Optional] IEnumerable<TextType>? MultiText,
52+
[Optional] StyleParam.TextPosition? TextPosition,
53+
[Optional] IEnumerable<StyleParam.TextPosition>? MultiTextPosition,
54+
[Optional] IEnumerable<Color>? SectionColors,
55+
[Optional] Color? SectionOutlineColor,
56+
[Optional] double? SectionOutlineWidth,
57+
[Optional] IEnumerable<double>? SectionOutlineMultiWidth,
58+
[Optional] Line? SectionOutline,
59+
[Optional] Marker? Marker,
60+
[Optional] StyleParam.TextInfo? TextInfo,
61+
[Optional] StyleParam.Direction? Direction,
62+
[Optional] double? Hole,
63+
[Optional] double? Rotation,
64+
[Optional] bool? Sort,
65+
[Optional] bool? UseDefaults
6566
)
6667
where ValuesType : IConvertible
6768
where LabelsType : IConvertible
68-
where TextType : class, IConvertible
69+
where TextType : IConvertible
6970
=>
7071
Plotly.NET.ChartDomain.Chart.Pie<ValuesType, LabelsType, TextType>(
7172
values: values,

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Plotly.NET;
77
using Plotly.NET.LayoutObjects;
88
using Plotly.NET.TraceObjects;
9+
using System.Runtime.InteropServices;
910

1011
namespace Plotly.NET.CSharp
1112
{
@@ -48,33 +49,33 @@ public static GenericChart.GenericChart ScatterGeo<LongitudesType, LatitudesType
4849
IEnumerable<LongitudesType> longitudes,
4950
IEnumerable<LatitudesType> latitudes,
5051
StyleParam.Mode mode,
51-
string? Name = null,
52-
bool? ShowLegend = null,
53-
double? Opacity = null,
54-
IEnumerable<double>? MultiOpacity = null,
55-
TextType? Text = null,
56-
IEnumerable<TextType>? MultiText = null,
57-
StyleParam.TextPosition? TextPosition = null,
58-
IEnumerable<StyleParam.TextPosition>? MultiTextPosition = null,
59-
Color? MarkerColor = null,
60-
StyleParam.Colorscale? MarkerColorScale = null,
61-
Line? MarkerOutline = null,
62-
StyleParam.MarkerSymbol? MarkerSymbol = null,
63-
IEnumerable<StyleParam.MarkerSymbol>? MultiMarkerSymbol = null,
64-
Marker? Marker = null,
65-
Color? LineColor = null,
66-
StyleParam.Colorscale? LineColorScale = null,
67-
double? LineWidth = null,
68-
StyleParam.DrawingStyle? LineDash = null,
69-
Line? Line = null,
70-
StyleParam.LocationFormat? LocationMode = null,
71-
Object? GeoJson = null,
72-
string? FeatureIdKey = null,
73-
bool? UseDefaults = null
52+
[Optional] string? Name,
53+
[Optional] bool? ShowLegend,
54+
[Optional] double? Opacity,
55+
[Optional] IEnumerable<double>? MultiOpacity,
56+
[Optional] TextType? Text,
57+
[Optional] IEnumerable<TextType>? MultiText,
58+
[Optional] StyleParam.TextPosition? TextPosition,
59+
[Optional] IEnumerable<StyleParam.TextPosition>? MultiTextPosition,
60+
[Optional] Color? MarkerColor,
61+
[Optional] StyleParam.Colorscale? MarkerColorScale,
62+
[Optional] Line? MarkerOutline,
63+
[Optional] StyleParam.MarkerSymbol? MarkerSymbol,
64+
[Optional] IEnumerable<StyleParam.MarkerSymbol>? MultiMarkerSymbol,
65+
[Optional] Marker? Marker,
66+
[Optional] Color? LineColor,
67+
[Optional] StyleParam.Colorscale? LineColorScale,
68+
[Optional] double? LineWidth,
69+
[Optional] StyleParam.DrawingStyle? LineDash,
70+
[Optional] Line? Line,
71+
[Optional] StyleParam.LocationFormat? LocationMode,
72+
[Optional] Object? GeoJson,
73+
[Optional] string? FeatureIdKey,
74+
[Optional] bool? UseDefaults
7475
)
7576
where LongitudesType : IConvertible
7677
where LatitudesType : IConvertible
77-
where TextType : class, IConvertible
78+
where TextType : IConvertible
7879
=>
7980
Plotly.NET.ChartMap.Chart.ScatterGeo<LongitudesType, LatitudesType, TextType>(
8081
longitudes: longitudes,

0 commit comments

Comments
 (0)