Skip to content

Commit 31a5ba3

Browse files
committed
Add C# bindings for Chart.Grid and Chart.Scatter3D
1 parent a9d1a11 commit 31a5ba3

File tree

3 files changed

+181
-17
lines changed

3 files changed

+181
-17
lines changed

Diff for: src/Plotly.NET.CSharp/ChartAPI/Chart.cs

+49
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,62 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using Plotly.NET;
7+
using Plotly.NET.LayoutObjects;
8+
using Plotly.NET.TraceObjects;
79

810
namespace Plotly.NET.CSharp
911
{
1012
public static partial class Chart
1113
{
1214
public static GenericChart.GenericChart Combine(IEnumerable<GenericChart.GenericChart> gCharts) => Plotly.NET.Chart.Combine(gCharts);
1315

16+
1417
public static GenericChart.GenericChart Invisible() => Plotly.NET.Chart.Invisible();
18+
19+
/// <summary>
20+
/// Creates a subplot grid with the given dimensions (nRows x nCols) for the input charts.
21+
/// </summary>
22+
/// <param name ="gCharts">The charts to display on the grid.</param>
23+
/// <param name ="nRows">The number of rows in the grid. If you provide a 2D `subplots` array or a `yaxes` array, its length is used as the default. But it's also possible to have a different length, if you want to leave a row at the end for non-cartesian subplots.</param>
24+
/// <param name ="nCols">The number of columns in the grid. If you provide a 2D `subplots` array, the length of its longest row is used as the default. If you give an `xaxes` array, its length is used as the default. But it's also possible to have a different length, if you want to leave a row at the end for non-cartesian subplots.</param>
25+
/// <param name ="SubPlots">Used for freeform grids, where some axes may be shared across subplots but others are not. Each entry should be a cartesian subplot id, like "xy" or "x3y2", or "" to leave that cell empty. You may reuse x axes within the same column, and y axes within the same row. Non-cartesian subplots and traces that support `domain` can place themselves in this grid separately using the `gridcell` attribute.</param>
26+
/// <param name ="XAxes">Used with `yaxes` when the x and y axes are shared across columns and rows. Each entry should be an y axis id like "y", "y2", etc., or "" to not put a y axis in that row. Entries other than "" must be unique. Ignored if `subplots` is present. If missing but `xaxes` is present, will generate consecutive IDs.</param>
27+
/// <param name ="YAxes">Used with `yaxes` when the x and y axes are shared across columns and rows. Each entry should be an x axis id like "x", "x2", etc., or "" to not put an x axis in that column. Entries other than "" must be unique. Ignored if `subplots` is present. If missing but `yaxes` is present, will generate consecutive IDs.</param>
28+
/// <param name ="RowOrder">Is the first row the top or the bottom? Note that columns are always enumerated from left to right.</param>
29+
/// <param name ="Pattern">If no `subplots`, `xaxes`, or `yaxes` are given but we do have `rows` and `columns`, we can generate defaults using consecutive axis IDs, in two ways: "coupled" gives one x axis per column and one y axis per row. "independent" uses a new xy pair for each cell, left-to-right across each row then iterating rows according to `roworder`.</param>
30+
/// <param name ="XGap">Horizontal space between grid cells, expressed as a fraction of the total width available to one cell. Defaults to 0.1 for coupled-axes grids and 0.2 for independent grids.</param>
31+
/// <param name ="YGap">Vertical space between grid cells, expressed as a fraction of the total height available to one cell. Defaults to 0.1 for coupled-axes grids and 0.3 for independent grids.</param>
32+
/// <param name ="Domain">Sets the domains of this grid subplot (in plot fraction). The first and last cells end exactly at the domain edges, with no grout around the edges.</param>
33+
/// <param name ="XSide">Sets where the x axis labels and titles go. "bottom" means the very bottom of the grid. "bottom plot" is the lowest plot that each x axis is used in. "top" and "top plot" are similar.</param>
34+
/// <param name ="YSide">Sets where the y axis labels and titles go. "left" means the very left edge of the grid. "left plot" is the leftmost plot that each y axis is used in. "right" and "right plot" are similar.</param>
35+
public static GenericChart.GenericChart Grid(
36+
IEnumerable<GenericChart.GenericChart> gCharts,
37+
int nRows,
38+
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
49+
) =>
50+
Plotly.NET.Chart.Grid<IEnumerable<GenericChart.GenericChart>>(
51+
nRows: nRows,
52+
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)
63+
).Invoke(gCharts);
1564
}
1665
}

Diff for: src/Plotly.NET.CSharp/ChartAPI/Chart3D.cs

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
10+
namespace Plotly.NET.CSharp
11+
{
12+
public static partial class Chart
13+
{
14+
/// <summary>
15+
/// Creates a Scatter3D plot.
16+
///
17+
/// In general, Scatter3D Plots plot three-dimensional data on 3 cartesian position scales in the X, Y, and Z dimension.
18+
///
19+
/// Scatter3D charts are the basis of Point3D, Line3D, and Bubble3D Charts, and can be customized as such. We also provide abstractions for those: Chart.Line3D, Chart.Point3D, Chart.Bubble3D
20+
/// </summary>
21+
/// <param name="x">Sets the x coordinates of the plotted data.</param>
22+
/// <param name="y">Sets the y coordinates of the plotted data.</param>
23+
/// <param name="z">Sets the z coordinates of the plotted data.</param>
24+
/// <param name="mode">Determines the drawing mode for this scatter trace.</param>
25+
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
26+
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
27+
/// <param name="Opacity">Sets the opactity of the trace</param>
28+
/// <param name="MultiOpacity">Sets the opactity of individual datum markers</param>
29+
/// <param name="Text">Sets a text associated with each datum</param>
30+
/// <param name="MultiText">Sets individual text for each datum</param>
31+
/// <param name="TextPosition">Sets the position of text associated with each datum</param>
32+
/// <param name="MultiTextPosition">Sets the position of text associated with individual datum</param>
33+
/// <param name="MarkerColor">Sets the color of the marker</param>
34+
/// <param name="MarkerColorScale">Sets the colorscale of the marker</param>
35+
/// <param name="MarkerOutline">Sets the outline of the marker</param>
36+
/// <param name="MarkerSymbol">Sets the marker symbol for each datum</param>
37+
/// <param name="MultiMarkerSymbol">Sets the marker symbol for each individual datum</param>
38+
/// <param name="Marker">Sets the marker (use this for more finegrained control than the other marker-associated arguments)</param>
39+
/// <param name="LineColor">Sets the color of the line</param>
40+
/// <param name="LineColorScale">Sets the colorscale of the line</param>
41+
/// <param name="LineWidth">Sets the width of the line</param>
42+
/// <param name="LineDash">sets the drawing style of the line</param>
43+
/// <param name="Line">Sets the line (use this for more finegrained control than the other line-associated arguments)</param>
44+
/// <param name="Projection">Sets the projection of this trace.</param>
45+
/// <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,
50+
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
72+
)
73+
where XData: IConvertible
74+
where YData: IConvertible
75+
where ZData: IConvertible
76+
where TextData: class, IConvertible
77+
78+
=> Plotly.NET.Chart3D.Chart.Scatter3D<XData, YData, ZData, TextData>(
79+
x: x,
80+
y: y,
81+
z: z,
82+
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)
104+
);
105+
}
106+
}

Diff for: tests/Plotly.NET.Tests.CSharpConsole/Program.cs

+26-17
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,32 @@ class Program
99
{
1010
static void Main(string[] args)
1111
{
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-
}
12+
Chart.Grid(
13+
nRows: 2,
14+
nCols: 3,
15+
gCharts:
16+
new GenericChart []
17+
{
18+
Chart.Scatter<int,int,string>(
19+
x: new int [] { 1, 2 },
20+
y: new int [] { 3, 4 },
21+
mode: Mode.Markers
22+
),
23+
Chart.Point<int,int,string>(
24+
x: new int [] { 5, 6 },
25+
y: new int [] { 7, 8 }
26+
),
27+
Chart.Line<int,int,string>(
28+
x: new int [] { 9, 10 },
29+
y: new int [] { 11, 12 }
30+
),
31+
Chart.Scatter3D<int,int,int,string>(
32+
x: new int[] { 12, 13 },
33+
y: new int [] { 13, 14 },
34+
z: new int [] { 14, 15 },
35+
mode: Mode.Markers
36+
)
37+
}
2938
).Show();
3039
}
3140
}

0 commit comments

Comments
 (0)