Skip to content

Commit a7b492f

Browse files
authored
Merge pull request #316 from plotly/csharp-layer
Add C# bindings for statistical charts, improve optional argument APIs
2 parents 19d8e10 + c1dc390 commit a7b492f

File tree

13 files changed

+1466
-603
lines changed

13 files changed

+1466
-603
lines changed

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

Lines changed: 21 additions & 20 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,30 +37,30 @@ 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 = default,
41+
Optional<StyleParam.LinearAxisId[]> XAxes = default,
42+
Optional<StyleParam.LinearAxisId[]> YAxes = default,
43+
Optional<StyleParam.LayoutGridRowOrder> RowOrder = default,
44+
Optional<StyleParam.LayoutGridPattern> Pattern = default,
45+
Optional<double> XGap = default,
46+
Optional<double> YGap = default,
47+
Optional<Domain> Domain = default,
48+
Optional<StyleParam.LayoutGridXSide> XSide = default,
49+
Optional<StyleParam.LayoutGridYSide> YSide = default
4950
) =>
5051
Plotly.NET.Chart.Grid<IEnumerable<GenericChart.GenericChart>>(
5152
nRows: nRows,
5253
nCols: nCols,
53-
SubPlots: Helpers.ToOption(SubPlots),
54-
XAxes: Helpers.ToOption(XAxes),
55-
YAxes: Helpers.ToOption(YAxes),
56-
RowOrder: Helpers.ToOption(RowOrder),
57-
Pattern: Helpers.ToOption(Pattern),
58-
XGap: Helpers.ToOptionV(XGap),
59-
YGap: Helpers.ToOptionV(YGap),
60-
Domain: Helpers.ToOption(Domain),
61-
XSide: Helpers.ToOption(XSide),
62-
YSide: Helpers.ToOption(YSide)
54+
SubPlots: SubPlots.ToOption(),
55+
XAxes: XAxes.ToOption(),
56+
YAxes: YAxes.ToOption(),
57+
RowOrder: RowOrder.ToOption(),
58+
Pattern: Pattern.ToOption(),
59+
XGap: XGap.ToOption(),
60+
YGap: YGap.ToOption(),
61+
Domain: Domain.ToOption(),
62+
XSide: XSide.ToOption(),
63+
YSide: YSide.ToOption()
6364
).Invoke(gCharts);
6465
}
6566
}

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

Lines changed: 733 additions & 198 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 = default,
54+
Optional<bool> ShowLegend = default,
55+
Optional<double> Opacity = default,
56+
Optional<IEnumerable<double>> MultiOpacity = default,
57+
Optional<TextType> Text = default,
58+
Optional<IEnumerable<TextType>> MultiText = default,
59+
Optional<StyleParam.TextPosition> TextPosition = default,
60+
Optional<IEnumerable<StyleParam.TextPosition>> MultiTextPosition = default,
61+
Optional<Color> MarkerColor = default,
62+
Optional<StyleParam.Colorscale> MarkerColorScale = default,
63+
Optional<Line> MarkerOutline = default,
64+
Optional<StyleParam.MarkerSymbol3D> MarkerSymbol = default,
65+
Optional<IEnumerable<StyleParam.MarkerSymbol3D>> MultiMarkerSymbol = default,
66+
Optional<Marker> Marker = default,
67+
Optional<Color> LineColor = default,
68+
Optional<StyleParam.Colorscale> LineColorScale = default,
69+
Optional<double> LineWidth = default,
70+
Optional<StyleParam.DrawingStyle> LineDash = default,
71+
Optional<Line> Line = default,
72+
Optional<Projection> Projection = default,
73+
Optional<bool> UseDefaults = default
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.ToOption(),
87+
Opacity: Opacity.ToOption(),
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.ToOption(),
102+
LineDash: LineDash.ToOption(),
103+
Line: Line.ToOption(),
104+
Projection: Projection.ToOption(),
105+
UseDefaults: UseDefaults.ToOption()
104106
);
105107
}
106108
}

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

Lines changed: 111 additions & 20 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 = default,
51+
Optional<bool> ShowLegend = default,
52+
Optional<double> Opacity = default,
53+
Optional<IEnumerable<XType>> X = default,
54+
Optional<IEnumerable<IEnumerable<MultiXType>>> MultiX = default,
55+
Optional<IEnumerable<YType>> Y = default,
56+
Optional<IEnumerable<IEnumerable<MultiYType>>> MultiY = default,
57+
Optional<IEnumerable<AType>> A = default,
58+
Optional<IEnumerable<BType>> B = default,
59+
Optional<LinearAxis> AAxis = default,
60+
Optional<LinearAxis> BAxis = default,
61+
Optional<StyleParam.LinearAxisId> XAxis = default,
62+
Optional<StyleParam.LinearAxisId> YAxis = default,
63+
Optional<Color> Color = default,
64+
Optional<double> CheaterSlope = default,
65+
Optional<bool> UseDefaults = default
6566
)
6667
where XType : IConvertible
6768
where MultiXType : IConvertible
@@ -73,8 +74,8 @@ public static GenericChart.GenericChart Carpet<XType, MultiXType, YType, MultiYT
7374
Plotly.NET.ChartCarpet.Chart.Carpet<XType, IEnumerable<MultiXType>, MultiXType, YType, IEnumerable<MultiYType>, MultiYType, AType, BType>(
7475
carpetId: carpetId,
7576
Name: Name.ToOption(),
76-
ShowLegend: ShowLegend.ToOptionV(),
77-
Opacity: Opacity.ToOptionV(),
77+
ShowLegend: ShowLegend.ToOption(),
78+
Opacity: Opacity.ToOption(),
7879
X: X.ToOption(),
7980
MultiX: MultiX.ToOption(),
8081
Y: Y.ToOption(),
@@ -86,8 +87,98 @@ public static GenericChart.GenericChart Carpet<XType, MultiXType, YType, MultiYT
8687
XAxis: XAxis.ToOption(),
8788
YAxis: YAxis.ToOption(),
8889
Color: Color.ToOption(),
89-
CheaterSlope: CheaterSlope.ToOptionV(),
90-
UseDefaults: UseDefaults.ToOptionV()
90+
CheaterSlope: CheaterSlope.ToOption(),
91+
UseDefaults: UseDefaults.ToOption()
92+
);
93+
94+
/// <summary>
95+
/// Creates a contour chart that lies on a specified carpet.
96+
///
97+
/// Plots contours on either the first carpet axis or the carpet axis with a matching `carpet` attribute. Data `z` is interpreted as matching that of the corresponding carpet axis.
98+
/// </summary>
99+
/// <param name="carpetAnchorId">The identifier of the carpet that this trace will lie on.</param>
100+
/// <param name="z">Sets the z data.</param>
101+
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
102+
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
103+
/// <param name="Opacity">Sets the opactity of the trace</param>
104+
/// <param name="A">Sets the a coordinates.</param>
105+
/// <param name="B">Sets the b coordinates.</param>
106+
/// <param name="Text">Sets a text associated with each datum</param>
107+
/// <param name="MultiText">Sets individual text for each datum</param>
108+
/// <param name="ColorBar">Sets the colorbar of this trace.</param>
109+
/// <param name="ColorScale">Sets the colorscale of this trace.</param>
110+
/// <param name="ShowScale">Determines whether or not a colorbar is displayed for this trace.</param>
111+
/// <param name="ReverseScale">Reverses the color mapping if true. If true, `zmin` will correspond to the last color in the array and `zmax` will correspond to the first color.</param>
112+
/// <param name="Transpose">Transposes the z data.</param>
113+
/// <param name="ContourLineDash">Sets the contour line dash style</param>
114+
/// <param name="ContourLineColor">Sets the contour line color</param>
115+
/// <param name="ContourLineSmoothing">Sets the amount of smoothing for the contour lines, where "0" corresponds to no smoothing.</param>
116+
/// <param name="ContourLine">Sets the contour lines (use this for more finegrained control than the other contourline-associated arguments).</param>
117+
/// <param name="ContoursColoring">Determines the coloring method showing the contour values. If "fill", coloring is done evenly between each contour level If "heatmap", a heatmap gradient coloring is applied between each contour level. If "lines", coloring is done on the contour lines. If "none", no coloring is applied on this trace.</param>
118+
/// <param name="ContoursOperation">Sets the constraint operation. "=" keeps regions equal to `value` "&lt;" and "&lt;=" keep regions less than `value` "&gt;" and "&gt;=" keep regions greater than `value` "[]", "()", "[)", and "(]" keep regions inside `value[0]` to `value[1]` "][", ")(", "](", ")[" keep regions outside `value[0]` to value[1]` Open vs. closed intervals make no difference to constraint display, but all versions are allowed for consistency with filter transforms.</param>
119+
/// <param name="ContoursType">If `levels`, the data is represented as a contour plot with multiple levels displayed. If `constraint`, the data is represented as constraints with the invalid region shaded as specified by the `operation` and `value` parameters.</param>
120+
/// <param name="ShowContourLabels">Determines whether to label the contour lines with their values.</param>
121+
/// <param name="ContourLabelFont">Sets the font used for labeling the contour levels. The default color comes from the lines, if shown. The default family and size come from `layout.font`.</param>
122+
/// <param name="Contours">Sets the styles of the contours (use this for more finegrained control than the other contour-associated arguments).</param>
123+
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
124+
public static GenericChart.GenericChart ContourCarpet<ZType, AType, BType, TextType>(
125+
IEnumerable<ZType> z,
126+
string carpetAnchorId,
127+
Optional<string> Name = default,
128+
Optional<bool> ShowLegend = default,
129+
Optional<double> Opacity = default,
130+
Optional<IEnumerable<AType>> A = default,
131+
Optional<IEnumerable<BType>> B = default,
132+
Optional<TextType> Text = default,
133+
Optional<IEnumerable<TextType>> MultiText = default,
134+
Optional<ColorBar> ColorBar = default,
135+
Optional<StyleParam.Colorscale> ColorScale = default,
136+
Optional<bool> ShowScale = default,
137+
Optional<bool> ReverseScale = default,
138+
Optional<bool> Transpose = default,
139+
Optional<Color> ContourLineColor = default,
140+
Optional<StyleParam.DrawingStyle> ContourLineDash = default,
141+
Optional<double> ContourLineSmoothing = default,
142+
Optional<Line> ContourLine = default,
143+
Optional<StyleParam.ContourColoring> ContoursColoring = default,
144+
Optional<StyleParam.ConstraintOperation> ContoursOperation = default,
145+
Optional<StyleParam.ContourType> ContoursType = default,
146+
Optional<bool> ShowContourLabels = default,
147+
Optional<Font> ContourLabelFont = default,
148+
Optional<Contours> Contours = default,
149+
Optional<bool> UseDefaults = default
150+
)
151+
where ZType : IConvertible
152+
where AType : IConvertible
153+
where BType : IConvertible
154+
where TextType : IConvertible
155+
=>
156+
Plotly.NET.ChartCarpet.Chart.ContourCarpet<ZType, AType, BType, TextType>(
157+
z: z,
158+
carpetAnchorId: carpetAnchorId,
159+
Name: Name.ToOption(),
160+
ShowLegend: ShowLegend.ToOption(),
161+
Opacity: Opacity.ToOption(),
162+
A: A.ToOption(),
163+
B: B.ToOption(),
164+
Text: Text.ToOption(),
165+
MultiText: MultiText.ToOption(),
166+
ColorBar: ColorBar.ToOption(),
167+
ColorScale: ColorScale.ToOption(),
168+
ShowScale: ShowScale.ToOption(),
169+
ReverseScale: ReverseScale.ToOption(),
170+
Transpose: Transpose.ToOption(),
171+
ContourLineColor: ContourLineColor.ToOption(),
172+
ContourLineDash: ContourLineDash.ToOption(),
173+
ContourLineSmoothing: ContourLineSmoothing.ToOption(),
174+
ContourLine: ContourLine.ToOption(),
175+
ContoursColoring: ContoursColoring.ToOption(),
176+
ContoursOperation: ContoursOperation.ToOption(),
177+
ContoursType: ContoursType.ToOption(),
178+
ShowContourLabels: ShowContourLabels.ToOption(),
179+
ContourLabelFont: ContourLabelFont.ToOption(),
180+
Contours: Contours.ToOption(),
181+
UseDefaults: UseDefaults.ToOption()
91182
);
92183
}
93184
}

0 commit comments

Comments
 (0)