Skip to content

Commit b8e50f5

Browse files
committed
Add Carpet C# bindings
1 parent 8865d4d commit b8e50f5

File tree

5 files changed

+153
-10
lines changed

5 files changed

+153
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.LayoutObjects;
7+
using Plotly.NET.TraceObjects;
8+
9+
namespace Plotly.NET.CSharp
10+
{
11+
public static partial class Chart
12+
{
13+
/// <summary>
14+
/// Creates a carpet in a 2D coordinate system to be used as additional coordinate system in a carpet plot.
15+
///
16+
/// A carpet plot illustrates the interaction between two or more independent variables and one or more dependent variables in a two-dimensional plot.
17+
/// Besides the ability to incorporate more variables, another feature that distinguishes a carpet plot from an equivalent contour plot or 3D surface plot is that a carpet plot can be used to more accurately interpolate data points.
18+
/// A conventional carpet plot can capture the interaction of up to three independent variables and three dependent variables and still be easily read and interpolated.
19+
///
20+
/// Three-variable carpet plot (cheater plot):
21+
///
22+
/// A carpet plot with two independent variables and one dependent variable is often called a cheater plot for the use of a phantom "cheater" axis instead of the horizontal axis. As a result of this missing axis, the values can be shifted horizontally such that the intersections line up vertically. This allows easy interpolation by having fixed horizontal intervals correspond to fixed intervals in both independent variables.
23+
///
24+
/// Four-variable carpet plot (true carpet plot)
25+
///
26+
/// Instead of using the horizontal axis to adjust the plot perspective and align carpet intersections vertically, the horizontal axis can be used to show the effects on an additional dependent variable.[5] In this case the perspective is fixed, and any overlapping cannot be adjusted. Because a true carpet plot represents two independent variables and two dependent variables simultaneously, there is no corresponding way to show the information on a conventional contour plot or 3D surface plot.
27+
///
28+
/// (from https://en.wikipedia.org/wiki/Carpet_plot @ 1/11/2021)
29+
/// </summary>
30+
/// <param name="carpetId">An identifier for this carpet, so that `scattercarpet` and `contourcarpet` traces can specify a carpet plot on which they lie.</param>
31+
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover</param>
32+
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
33+
/// <param name="Opacity">Sets the opactity of the trace</param>
34+
/// <param name="X">A one dimensional array of x coordinates matching the dimensions of `a` and `b`.</param>
35+
/// <param name="MultiX">A two dimensional array of x coordinates at each carpet point. If omitted, the plot is a cheater plot and the xaxis is hidden by default.</param>
36+
/// <param name="Y">A one dimensional array of y coordinates matching the dimensions of `a` and `b`.</param>
37+
/// <param name="MultiY">A two dimensional array of y coordinates at each carpet point.</param>
38+
/// <param name="A">An array containing values of the first parameter value</param>
39+
/// <param name="B">An array containing values of the second parameter value</param>
40+
/// <param name="AAxis">Sets this carpet's a axis.</param>
41+
/// <param name="BAxis">Sets this carpet's b axis.</param>
42+
/// <param name="XAxis">Sets a reference between this trace's x coordinates and a 2D cartesian x axis. If "x" (the default value), the x coordinates refer to `layout.xaxis`. If "x2", the x coordinates refer to `layout.xaxis2`, and so on.</param>
43+
/// <param name="YAxis">Sets a reference between this trace's y coordinates and a 2D cartesian y axis. If "y" (the default value), the y coordinates refer to `layout.yaxis`. If "y2", the y coordinates refer to `layout.yaxis2`, and so on.</param>
44+
/// <param name="Color">Sets default for all colors associated with this axis all at once: line, font, tick, and grid colors. Grid color is lightened by blending this with the plot background Individual pieces can override this.</param>
45+
/// <param name="CheaterSlope">The shift applied to each successive row of data in creating a cheater plot. Only used if `x` is been omitted.</param>
46+
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
47+
public static GenericChart.GenericChart Carpet<XType, MultiXType, YType, MultiYType, AType, BType>(
48+
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
65+
)
66+
where XType : IConvertible
67+
where MultiXType : IConvertible
68+
where YType : IConvertible
69+
where MultiYType : IConvertible
70+
where AType : IConvertible
71+
where BType : IConvertible
72+
=>
73+
Plotly.NET.ChartCarpet.Chart.Carpet<XType, IEnumerable<MultiXType>, MultiXType, YType, IEnumerable<MultiYType>, MultiYType, AType, BType>(
74+
carpetId: carpetId,
75+
Name: Name.ToOption(),
76+
ShowLegend: ShowLegend.ToOptionV(),
77+
Opacity: Opacity.ToOptionV(),
78+
X: X.ToOption(),
79+
MultiX: MultiX.ToOption(),
80+
Y: Y.ToOption(),
81+
MultiY: MultiY.ToOption(),
82+
A: A.ToOption(),
83+
B: B.ToOption(),
84+
AAxis: AAxis.ToOption(),
85+
BAxis: BAxis.ToOption(),
86+
XAxis: XAxis.ToOption(),
87+
YAxis: YAxis.ToOption(),
88+
Color: Color.ToOption(),
89+
CheaterSlope: CheaterSlope.ToOptionV(),
90+
UseDefaults: UseDefaults.ToOptionV()
91+
);
92+
}
93+
}

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

+32
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,38 @@ namespace Plotly.NET.CSharp
1010
{
1111
public static partial class Chart
1212
{
13+
/// <summary>
14+
/// Creates a Scatter plot on a ternary coordinate system
15+
///
16+
/// In general, ScatterTernary creates a barycentric plot on three variables which sum to a constant, graphically depicting the ratios of the three variables as positions in an equilateral triangle.
17+
///
18+
/// ScatterTernary charts are the basis of PointTernary, LineTernary, and BubbleTernary Charts, and can be customized as such. We also provide abstractions for those: Chart.LineTernary, Chart.PointTernary, Chart.BubbleTernary
19+
/// </summary>
20+
/// <param name="A">Sets the quantity of component `a` in each data point. If `a`, `b`, and `c` are all provided, they need not be normalized, only the relative values matter. If only two arrays are provided they must be normalized to match `ternary&lt;i&gt;.sum`.</param>
21+
/// <param name="B">Sets the quantity of component `b` in each data point. If `a`, `b`, and `c` are all provided, they need not be normalized, only the relative values matter. If only two arrays are provided they must be normalized to match `ternary&lt;i&gt;.sum`.</param>
22+
/// <param name="C">Sets the quantity of component `c` in each data point. If `a`, `b`, and `c` are all provided, they need not be normalized, only the relative values matter. If only two arrays are provided they must be normalized to match `ternary&lt;i&gt;.sum`.</param>
23+
/// <param name="Sum">The number each triplet should sum to, if only two of `a`, `b`, and `c` are provided. This overrides `ternary&lt;i&gt;.sum` to normalize this specific trace, but does not affect the values displayed on the axes. 0 (or missing) means to use `ternary&lt;i&gt;.sum`</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="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
1345
public static GenericChart.GenericChart Scatterternary<AType, BType, CType, SumType, TextType>(
1446
IEnumerable<AType>? A = null,
1547
IEnumerable<BType>? B = null,

src/Plotly.NET.CSharp/GenericChartExtensions.cs

+15-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class GenericChartExtensions
1717
public static void SaveHtml(
1818
this GenericChart.GenericChart gChart,
1919
string path,
20-
bool? OpenInBrowser
20+
bool? OpenInBrowser = null
2121
) =>
2222
Plotly.NET.Chart.SaveHtml(
2323
path: path,
@@ -41,12 +41,12 @@ public static void SaveHtml(
4141
/// <param name="LegendGroupTitle">Sets the title for the chart's trace legend group </param>
4242
public static GenericChart.GenericChart WithTraceInfo(
4343
this GenericChart.GenericChart gChart,
44-
string? Name,
45-
StyleParam.Visible? Visible,
46-
bool? ShowLegend,
47-
int? LegendRank,
48-
string? LegendGroup,
49-
Title? LegendGroupTitle
44+
string? Name = null,
45+
StyleParam.Visible? Visible = null,
46+
bool? ShowLegend = null,
47+
int? LegendRank = null,
48+
string? LegendGroup = null,
49+
Title? LegendGroupTitle = null
5050
) =>
5151
Plotly.NET.Chart.WithTraceInfo(
5252
Name: Name,
@@ -56,6 +56,14 @@ public static GenericChart.GenericChart WithTraceInfo(
5656
LegendGroup: LegendGroup,
5757
LegendGroupTitle: LegendGroupTitle
5858
).Invoke(gChart);
59+
60+
/// Sets the size of a Chart (in pixels)
61+
public static GenericChart.GenericChart WithSize(
62+
this GenericChart.GenericChart gChart,
63+
int? Width = null,
64+
int? Height = null
65+
) =>
66+
Plotly.NET.Chart.WithSize(Width: Width, Height: Height).Invoke(gChart);
5967
}
6068

6169

src/Plotly.NET/ChartAPI/Chart.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2638,7 +2638,7 @@ type Chart =
26382638
GenericChart.addLayout layout ch)
26392639

26402640

2641-
// Set the size of a Chart
2641+
/// Sets the size of a Chart (in pixels)
26422642
[<CompiledName("WithSize")>]
26432643
static member withSize
26442644
(

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Program
1010
static void Main(string[] args)
1111
{
1212
Chart.Grid(
13-
nRows: 5,
13+
nRows: 6,
1414
nCols: 3,
1515
gCharts:
1616
new GenericChart []
@@ -57,8 +57,18 @@ static void Main(string[] args)
5757
),
5858
Chart.Invisible(),
5959
Chart.Invisible(),
60+
Chart.Carpet<double,double,double,double,double,double>(
61+
carpetId: "testCarpet",
62+
A: new double [] {4.0, 4.0, 4.0, 4.5, 4.5, 4.5, 5.0, 5.0, 5.0, 6.0, 6.0, 6.0},
63+
B: new double [] {1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0},
64+
Y: new double [] {2.0, 3.5, 4.0, 3.0, 4.5, 5.0, 5.5, 6.5, 7.5, 8.0, 8.5, 10.0}
65+
),
66+
Chart.Invisible(),
67+
Chart.Invisible(),
6068
}
61-
).Show();
69+
)
70+
.WithSize(750,2000)
71+
.Show();
6272
}
6373
}
6474
}

0 commit comments

Comments
 (0)