Skip to content

Add C# bindings for statistical charts, improve optional argument APIs #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 26, 2022
41 changes: 21 additions & 20 deletions src/Plotly.NET.CSharp/ChartAPI/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Plotly.NET;
using Plotly.NET.LayoutObjects;
using Plotly.NET.TraceObjects;
using System.Runtime.InteropServices;

namespace Plotly.NET.CSharp
{
Expand Down Expand Up @@ -36,30 +37,30 @@ public static GenericChart.GenericChart Grid(
IEnumerable<GenericChart.GenericChart> gCharts,
int nRows,
int nCols,
Tuple<StyleParam.LinearAxisId, StyleParam.LinearAxisId>[][]? 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
Optional<Tuple<StyleParam.LinearAxisId, StyleParam.LinearAxisId>[][]> SubPlots = default,
Optional<StyleParam.LinearAxisId[]> XAxes = default,
Optional<StyleParam.LinearAxisId[]> YAxes = default,
Optional<StyleParam.LayoutGridRowOrder> RowOrder = default,
Optional<StyleParam.LayoutGridPattern> Pattern = default,
Optional<double> XGap = default,
Optional<double> YGap = default,
Optional<Domain> Domain = default,
Optional<StyleParam.LayoutGridXSide> XSide = default,
Optional<StyleParam.LayoutGridYSide> YSide = default
) =>
Plotly.NET.Chart.Grid<IEnumerable<GenericChart.GenericChart>>(
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)
SubPlots: SubPlots.ToOption(),
XAxes: XAxes.ToOption(),
YAxes: YAxes.ToOption(),
RowOrder: RowOrder.ToOption(),
Pattern: Pattern.ToOption(),
XGap: XGap.ToOption(),
YGap: YGap.ToOption(),
Domain: Domain.ToOption(),
XSide: XSide.ToOption(),
YSide: YSide.ToOption()
).Invoke(gCharts);
}
}
931 changes: 733 additions & 198 deletions src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs

Large diffs are not rendered by default.

104 changes: 53 additions & 51 deletions src/Plotly.NET.CSharp/ChartAPI/Chart3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Plotly.NET;
using Plotly.NET.LayoutObjects;
using Plotly.NET.TraceObjects;
using System.Runtime.InteropServices;


namespace Plotly.NET.CSharp
{
Expand Down Expand Up @@ -43,64 +45,64 @@ public static partial class Chart
/// <param name="Line">Sets the line (use this for more finegrained control than the other line-associated arguments)</param>
/// <param name="Projection">Sets the projection of this trace.</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
public static GenericChart.GenericChart Scatter3D<XData, YData, ZData, TextData>(
IEnumerable<XData> x,
IEnumerable<YData> y,
IEnumerable<ZData> z,
public static GenericChart.GenericChart Scatter3D<XType, YType, ZType, TextType>(
IEnumerable<XType> x,
IEnumerable<YType> y,
IEnumerable<ZType> z,
StyleParam.Mode mode,
string? Name = null,
bool? ShowLegend = null,
double? Opacity = null,
IEnumerable<double>? MultiOpacity = null,
TextData? Text = null,
IEnumerable<TextData>? MultiText = null,
StyleParam.TextPosition? TextPosition = null,
IEnumerable<StyleParam.TextPosition>? MultiTextPosition = null,
Color? MarkerColor = null,
StyleParam.Colorscale? MarkerColorScale = null,
Line? MarkerOutline = null,
StyleParam.MarkerSymbol3D? MarkerSymbol = null,
IEnumerable<StyleParam.MarkerSymbol3D>? 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
Optional<string> Name = default,
Optional<bool> ShowLegend = default,
Optional<double> Opacity = default,
Optional<IEnumerable<double>> MultiOpacity = default,
Optional<TextType> Text = default,
Optional<IEnumerable<TextType>> MultiText = default,
Optional<StyleParam.TextPosition> TextPosition = default,
Optional<IEnumerable<StyleParam.TextPosition>> MultiTextPosition = default,
Optional<Color> MarkerColor = default,
Optional<StyleParam.Colorscale> MarkerColorScale = default,
Optional<Line> MarkerOutline = default,
Optional<StyleParam.MarkerSymbol3D> MarkerSymbol = default,
Optional<IEnumerable<StyleParam.MarkerSymbol3D>> MultiMarkerSymbol = default,
Optional<Marker> Marker = default,
Optional<Color> LineColor = default,
Optional<StyleParam.Colorscale> LineColorScale = default,
Optional<double> LineWidth = default,
Optional<StyleParam.DrawingStyle> LineDash = default,
Optional<Line> Line = default,
Optional<Projection> Projection = default,
Optional<bool> UseDefaults = default
)
where XData: IConvertible
where YData: IConvertible
where ZData: IConvertible
where TextData: class, IConvertible
where XType: IConvertible
where YType: IConvertible
where ZType : IConvertible
where TextType : IConvertible

=> Plotly.NET.Chart3D.Chart.Scatter3D<XData, YData, ZData, TextData>(
=> Plotly.NET.Chart3D.Chart.Scatter3D<XType, YType, ZType, TextType>(
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)
Name: Name.ToOption(),
ShowLegend: ShowLegend.ToOption(),
Opacity: Opacity.ToOption(),
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.ToOption(),
LineDash: LineDash.ToOption(),
Line: Line.ToOption(),
Projection: Projection.ToOption(),
UseDefaults: UseDefaults.ToOption()
);
}
}
131 changes: 111 additions & 20 deletions src/Plotly.NET.CSharp/ChartAPI/ChartCarpet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Plotly.NET.LayoutObjects;
using Plotly.NET.TraceObjects;
using System.Runtime.InteropServices;

namespace Plotly.NET.CSharp
{
Expand Down Expand Up @@ -46,22 +47,22 @@ public static partial class Chart
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
public static GenericChart.GenericChart Carpet<XType, MultiXType, YType, MultiYType, AType, BType>(
string carpetId,
string? Name = null,
bool? ShowLegend = null,
double? Opacity = null,
IEnumerable<XType>? X = null,
IEnumerable<IEnumerable<MultiXType>>? MultiX = null,
IEnumerable<YType>? Y = null,
IEnumerable<IEnumerable<MultiYType>>? MultiY = null,
IEnumerable<AType>? A = null,
IEnumerable<BType>? 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
Optional<string> Name = default,
Optional<bool> ShowLegend = default,
Optional<double> Opacity = default,
Optional<IEnumerable<XType>> X = default,
Optional<IEnumerable<IEnumerable<MultiXType>>> MultiX = default,
Optional<IEnumerable<YType>> Y = default,
Optional<IEnumerable<IEnumerable<MultiYType>>> MultiY = default,
Optional<IEnumerable<AType>> A = default,
Optional<IEnumerable<BType>> B = default,
Optional<LinearAxis> AAxis = default,
Optional<LinearAxis> BAxis = default,
Optional<StyleParam.LinearAxisId> XAxis = default,
Optional<StyleParam.LinearAxisId> YAxis = default,
Optional<Color> Color = default,
Optional<double> CheaterSlope = default,
Optional<bool> UseDefaults = default
)
where XType : IConvertible
where MultiXType : IConvertible
Expand All @@ -73,8 +74,8 @@ public static GenericChart.GenericChart Carpet<XType, MultiXType, YType, MultiYT
Plotly.NET.ChartCarpet.Chart.Carpet<XType, IEnumerable<MultiXType>, MultiXType, YType, IEnumerable<MultiYType>, MultiYType, AType, BType>(
carpetId: carpetId,
Name: Name.ToOption(),
ShowLegend: ShowLegend.ToOptionV(),
Opacity: Opacity.ToOptionV(),
ShowLegend: ShowLegend.ToOption(),
Opacity: Opacity.ToOption(),
X: X.ToOption(),
MultiX: MultiX.ToOption(),
Y: Y.ToOption(),
Expand All @@ -86,8 +87,98 @@ public static GenericChart.GenericChart Carpet<XType, MultiXType, YType, MultiYT
XAxis: XAxis.ToOption(),
YAxis: YAxis.ToOption(),
Color: Color.ToOption(),
CheaterSlope: CheaterSlope.ToOptionV(),
UseDefaults: UseDefaults.ToOptionV()
CheaterSlope: CheaterSlope.ToOption(),
UseDefaults: UseDefaults.ToOption()
);

/// <summary>
/// Creates a contour chart that lies on a specified carpet.
///
/// 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.
/// </summary>
/// <param name="carpetAnchorId">The identifier of the carpet that this trace will lie on.</param>
/// <param name="z">Sets the z data.</param>
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
/// <param name="Opacity">Sets the opactity of the trace</param>
/// <param name="A">Sets the a coordinates.</param>
/// <param name="B">Sets the b coordinates.</param>
/// <param name="Text">Sets a text associated with each datum</param>
/// <param name="MultiText">Sets individual text for each datum</param>
/// <param name="ColorBar">Sets the colorbar of this trace.</param>
/// <param name="ColorScale">Sets the colorscale of this trace.</param>
/// <param name="ShowScale">Determines whether or not a colorbar is displayed for this trace.</param>
/// <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>
/// <param name="Transpose">Transposes the z data.</param>
/// <param name="ContourLineDash">Sets the contour line dash style</param>
/// <param name="ContourLineColor">Sets the contour line color</param>
/// <param name="ContourLineSmoothing">Sets the amount of smoothing for the contour lines, where "0" corresponds to no smoothing.</param>
/// <param name="ContourLine">Sets the contour lines (use this for more finegrained control than the other contourline-associated arguments).</param>
/// <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>
/// <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>
/// <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>
/// <param name="ShowContourLabels">Determines whether to label the contour lines with their values.</param>
/// <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>
/// <param name="Contours">Sets the styles of the contours (use this for more finegrained control than the other contour-associated arguments).</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
public static GenericChart.GenericChart ContourCarpet<ZType, AType, BType, TextType>(
IEnumerable<ZType> z,
string carpetAnchorId,
Optional<string> Name = default,
Optional<bool> ShowLegend = default,
Optional<double> Opacity = default,
Optional<IEnumerable<AType>> A = default,
Optional<IEnumerable<BType>> B = default,
Optional<TextType> Text = default,
Optional<IEnumerable<TextType>> MultiText = default,
Optional<ColorBar> ColorBar = default,
Optional<StyleParam.Colorscale> ColorScale = default,
Optional<bool> ShowScale = default,
Optional<bool> ReverseScale = default,
Optional<bool> Transpose = default,
Optional<Color> ContourLineColor = default,
Optional<StyleParam.DrawingStyle> ContourLineDash = default,
Optional<double> ContourLineSmoothing = default,
Optional<Line> ContourLine = default,
Optional<StyleParam.ContourColoring> ContoursColoring = default,
Optional<StyleParam.ConstraintOperation> ContoursOperation = default,
Optional<StyleParam.ContourType> ContoursType = default,
Optional<bool> ShowContourLabels = default,
Optional<Font> ContourLabelFont = default,
Optional<Contours> Contours = default,
Optional<bool> UseDefaults = default
)
where ZType : IConvertible
where AType : IConvertible
where BType : IConvertible
where TextType : IConvertible
=>
Plotly.NET.ChartCarpet.Chart.ContourCarpet<ZType, AType, BType, TextType>(
z: z,
carpetAnchorId: carpetAnchorId,
Name: Name.ToOption(),
ShowLegend: ShowLegend.ToOption(),
Opacity: Opacity.ToOption(),
A: A.ToOption(),
B: B.ToOption(),
Text: Text.ToOption(),
MultiText: MultiText.ToOption(),
ColorBar: ColorBar.ToOption(),
ColorScale: ColorScale.ToOption(),
ShowScale: ShowScale.ToOption(),
ReverseScale: ReverseScale.ToOption(),
Transpose: Transpose.ToOption(),
ContourLineColor: ContourLineColor.ToOption(),
ContourLineDash: ContourLineDash.ToOption(),
ContourLineSmoothing: ContourLineSmoothing.ToOption(),
ContourLine: ContourLine.ToOption(),
ContoursColoring: ContoursColoring.ToOption(),
ContoursOperation: ContoursOperation.ToOption(),
ContoursType: ContoursType.ToOption(),
ShowContourLabels: ShowContourLabels.ToOption(),
ContourLabelFont: ContourLabelFont.ToOption(),
Contours: Contours.ToOption(),
UseDefaults: UseDefaults.ToOption()
);
}
}
Loading