forked from plotly/Plotly.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericChartExtensions.cs
More file actions
277 lines (266 loc) · 20.1 KB
/
GenericChartExtensions.cs
File metadata and controls
277 lines (266 loc) · 20.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
using Plotly.NET;
using Plotly.NET.LayoutObjects;
using Plotly.NET.TraceObjects;
namespace Plotly.NET.CSharp
{
public static class GenericChartExtensions
{
public static Layout GetLayout(this GenericChart.GenericChart gChart) => GenericChart.getLayout(gChart);
public static Trace [] GetTraces(this GenericChart.GenericChart gChart) => GenericChart.getTraces(gChart).ToArray();
/// <summary>
/// Saves the given Chart as html file at the given path (.html file extension is added if not present).
/// Optionally opens the generated file in the browser.
/// </summary>
/// <param name="path">The path to save the chart html at.</param>
/// <param name="OpenInBrowser">Wether or not to open the generated file in the browser (default: false)</param>
public static void SaveHtml(
this GenericChart.GenericChart gChart,
string path,
bool? OpenInBrowser = null
) =>
Plotly.NET.Chart.SaveHtml(
path: path,
OpenInBrowser: OpenInBrowser.ToOptionV()
).Invoke(gChart);
/// <summary>
/// Saves the given chart as a temporary html file and opens it in the browser.
/// </summary>
/// <param name="ch">The chart to show in the browser</param>
public static void Show(this GenericChart.GenericChart gChart) => Plotly.NET.Chart.Show(gChart);
/// <summary>
/// Sets trace information on the given chart.
/// </summary>
/// <param name="Name">Sets the name of the chart's trace(s). When the chart is a multichart (it contains multiple traces), the name is suffixed by '_%i' where %i is the index of the trace.</param>
/// <param name="Visible">Wether or not the chart's traces are visible</param>
/// <param name="ShowLegend">Determines whether or not item(s) corresponding to this chart's trace(s) is/are shown in the legend.</param>
/// <param name="LegendRank">Sets the legend rank for the chart's trace(s). Items and groups with smaller ranks are presented on top/left side while with `"reversed" `legend.traceorder` they are on bottom/right side. The default legendrank is 1000, so that you can use ranks less than 1000 to place certain items before all unranked items, and ranks greater than 1000 to go after all unranked items.</param>
/// <param name="LegendGroup">Sets the legend group for the chart's trace(s). Traces part of the same legend group hide/show at the same time when toggling legend items.</param>
/// <param name="LegendGroupTitle">Sets the title for the chart's trace legend group </param>
public static GenericChart.GenericChart WithTraceInfo(
this GenericChart.GenericChart gChart,
string? Name = null,
StyleParam.Visible? Visible = null,
bool? ShowLegend = null,
int? LegendRank = null,
string? LegendGroup = null,
Title? LegendGroupTitle = null
) =>
Plotly.NET.Chart.WithTraceInfo(
Name: Name.ToOption(),
Visible: Visible.ToOption(),
ShowLegend: ShowLegend.ToOptionV(),
LegendRank: LegendRank.ToOptionV(),
LegendGroup: LegendGroup.ToOption(),
LegendGroupTitle: LegendGroupTitle.ToOption()
).Invoke(gChart);
/// Sets the size of a Chart (in pixels)
public static GenericChart.GenericChart WithSize(
this GenericChart.GenericChart gChart,
int? Width = null,
int? Height = null
) =>
Plotly.NET.Chart.WithSize(Width: Width.ToOptionV(), Height: Height.ToOptionV()).Invoke(gChart);
/// <summary>
/// Sets the given x axis styles on the input chart's layout.
///
/// If there is already an axis set at the given id, the styles are applied to it. If there is no axis present, a new LinearAxis object with the given styles will be set.
/// </summary>
/// <param name="TitleText">Sets the text of the axis title.</param>
/// <param name="TitleFont">Sets the font of the axis title.</param>
/// <param name="TitleStandoff">Sets the standoff distance (in px) between the axis labels and the title text.</param>
/// <param name="Title">Sets the Title (use this for more finegrained control than the other title-associated arguments)</param>
/// <param name="Color">Sets default for all colors associated with this axis all at once: line, font, tick, and grid colors.</param>
/// <param name="AxisType">Sets the axis type. By default, plotly attempts to determined the axis type by looking into the data of the traces that referenced the axis in question.</param>
/// <param name="MinMax">Tuple of (Min*Max value). Sets the range of this axis (the axis will go from Min to Max). If the axis `type` is "log", then you must take the log of your desired range (e.g. to set the range from 1 to 100, set the range from 0 to 2).</param>
/// <param name="Mirror">Determines if and how the axis lines or/and ticks are mirrored to the opposite side of the plotting area.</param>
/// <param name="ShowSpikes">Determines whether or not spikes (aka droplines) are drawn for this axis.</param>
/// <param name="SpikeColor">Sets the spike color. If not set, will use the series color</param>
/// <param name="SpikeThickness">Sets the width (in px) of the zero line.</param>
/// <param name="ShowLine">Determines whether or not a line bounding this axis is drawn.</param>
/// <param name="LineColor">Sets the axis line color.</param>
/// <param name="ShowGrid">Determines whether or not grid lines are drawn. If "true", the grid lines are drawn at every tick mark.</param>
/// <param name="GridColor">Sets the color of the grid lines.</param>
/// <param name="ZeroLine">Determines whether or not a line is drawn at along the 0 value of this axis. If "true", the zero line is drawn on top of the grid lines.</param>
/// <param name="ZeroLineColor">Sets the line color of the zero line.</param>
/// <param name="Anchor">If set to an opposite-letter axis id (e.g. `x2`, `y`), this axis is bound to the corresponding opposite-letter axis. If set to "free", this axis' position is determined by `position`.</param>
/// <param name="Side">Determines whether a x (y) axis is positioned at the "bottom" ("left") or "top" ("right") of the plotting area.</param>
/// <param name="Overlaying">If set a same-letter axis id, this axis is overlaid on top of the corresponding same-letter axis, with traces and axes visible for both axes. If "false", this axis does not overlay any same-letter axes. In this case, for axes with overlapping domains only the highest-numbered axis will be visible.</param>
/// <param name="Domain">Tuple of (X*Y fractions). Sets the domain of this axis (in plot fraction).</param>
/// <param name="Position">Sets the position of this axis in the plotting space (in normalized coordinates). Only has an effect if `anchor` is set to "free".</param>
/// <param name="CategoryOrder">Specifies the ordering logic for the case of categorical variables. By default, plotly uses "trace", which specifies the order that is present in the data supplied. Set `categoryorder` to "category ascending" or "category descending" if order should be determined by the alphanumerical order of the category names. Set `categoryorder` to "array" to derive the ordering from the attribute `categoryarray`. If a category is not found in the `categoryarray` array, the sorting behavior for that attribute will be identical to the "trace" mode. The unspecified categories will follow the categories in `categoryarray`. Set `categoryorder` to "total ascending" or "total descending" if order should be determined by the numerical order of the values. Similarly, the order can be determined by the min, max, sum, mean or median of all the values.</param>
/// <param name="CategoryArray">Sets the order in which categories on this axis appear. Only has an effect if `categoryorder` is set to "array". Used with `categoryorder`.</param>
/// <param name="RangeSlider">Sets a range slider for this axis</param>
/// <param name="RangeSelector">Sets a range selector for this axis. This object contains toggable presets for the rangeslider.</param>
/// <param name="BackgroundColor">Sets the background color of this axis' wall. (Only has an effect on 3D scenes)</param>
/// <param name="ShowBackground">Sets whether or not this axis' wall has a background color. (Only has an effect on 3D scenes)</param>
/// <param name="Id">The target axis id on which the styles should be applied. Default is 1.</param>
public static GenericChart.GenericChart WithXAxisStyle<MinType, MaxType, CategoryArrayType>(
this GenericChart.GenericChart gChart,
string? TitleText = null,
Font? TitleFont = null,
int? TitleStandoff = null,
Title? Title = null,
Color? Color = null,
StyleParam.AxisType? AxisType = null,
Tuple<MinType, MaxType>? MinMax = null,
StyleParam.Mirror? Mirror = null,
bool? ShowSpikes = null,
Color? SpikeColor = null,
int? SpikeThickness = null,
bool? ShowLine = null,
Color? LineColor = null,
bool? ShowGrid = null,
Color? GridColor = null,
bool? ZeroLine = null,
Color? ZeroLineColor = null,
StyleParam.LinearAxisId? Anchor = null,
StyleParam.Side? Side = null,
StyleParam.LinearAxisId? Overlaying = null,
Tuple<double, double>? Domain = null,
double? Position = null,
StyleParam.CategoryOrder? CategoryOrder = null,
IEnumerable<CategoryArrayType>? CategoryArray = null,
RangeSlider? RangeSlider = null,
RangeSelector? RangeSelector = null,
Color? BackgroundColor = null,
bool? ShowBackground = null,
StyleParam.SubPlotId? Id = null
)
where MinType : IConvertible
where MaxType : IConvertible
where CategoryArrayType : class, IConvertible
=>
Plotly.NET.Chart.WithXAxisStyle<MinType, MaxType, CategoryArrayType>(
TitleText: TitleText.ToOption(),
TitleFont: TitleFont.ToOption(),
TitleStandoff: TitleStandoff.ToOptionV(),
Title: Title.ToOption(),
Color: Color.ToOption(),
AxisType: AxisType.ToOption(),
MinMax: MinMax.ToOption(),
Mirror: Mirror.ToOption(),
ShowSpikes: ShowSpikes.ToOptionV(),
SpikeColor: SpikeColor.ToOption(),
SpikeThickness: SpikeThickness.ToOptionV(),
ShowLine: ShowLine.ToOptionV(),
LineColor: LineColor.ToOption(),
ShowGrid: ShowGrid.ToOptionV(),
GridColor: GridColor.ToOption(),
ZeroLine: ZeroLine.ToOptionV(),
ZeroLineColor: ZeroLineColor.ToOption(),
Anchor: Anchor.ToOption(),
Side: Side.ToOption(),
Overlaying: Overlaying.ToOption(),
Domain: Domain.ToOption(),
Position: Position.ToOptionV(),
CategoryOrder: CategoryOrder.ToOption(),
CategoryArray: CategoryArray.ToOption(),
RangeSlider: RangeSlider.ToOption(),
RangeSelector: RangeSelector.ToOption(),
BackgroundColor: BackgroundColor.ToOption(),
ShowBackground: ShowBackground.ToOptionV(),
Id: Id.ToOption()
).Invoke(gChart);
/// <summary>
/// Sets the given y axis styles on the input chart's layout.
///
/// If there is already an axis set at the given id, the styles are applied to it. If there is no axis present, a new LinearAxis object with the given styles will be set.
/// </summary>
/// <param name="TitleText">Sets the text of the axis title.</param>
/// <param name="TitleFont">Sets the font of the axis title.</param>
/// <param name="TitleStandoff">Sets the standoff distance (in px) between the axis labels and the title text.</param>
/// <param name="Title">Sets the Title (use this for more finegrained control than the other title-associated arguments)</param>
/// <param name="Color">Sets default for all colors associated with this axis all at once: line, font, tick, and grid colors.</param>
/// <param name="AxisType">Sets the axis type. By default, plotly attempts to determined the axis type by looking into the data of the traces that referenced the axis in question.</param>
/// <param name="MinMax">Tuple of (Min*Max value). Sets the range of this axis (the axis will go from Min to Max). If the axis `type` is "log", then you must take the log of your desired range (e.g. to set the range from 1 to 100, set the range from 0 to 2).</param>
/// <param name="Mirror">Determines if and how the axis lines or/and ticks are mirrored to the opposite side of the plotting area.</param>
/// <param name="ShowSpikes">Determines whether or not spikes (aka droplines) are drawn for this axis.</param>
/// <param name="SpikeColor">Sets the spike color. If not set, will use the series color</param>
/// <param name="SpikeThickness">Sets the width (in px) of the zero line.</param>
/// <param name="ShowLine">Determines whether or not a line bounding this axis is drawn.</param>
/// <param name="LineColor">Sets the axis line color.</param>
/// <param name="ShowGrid">Determines whether or not grid lines are drawn. If "true", the grid lines are drawn at every tick mark.</param>
/// <param name="GridColor">Sets the color of the grid lines.</param>
/// <param name="ZeroLine">Determines whether or not a line is drawn at along the 0 value of this axis. If "true", the zero line is drawn on top of the grid lines.</param>
/// <param name="ZeroLineColor">Sets the line color of the zero line.</param>
/// <param name="Anchor">If set to an opposite-letter axis id (e.g. `x2`, `y`), this axis is bound to the corresponding opposite-letter axis. If set to "free", this axis' position is determined by `position`.</param>
/// <param name="Side">Determines whether a x (y) axis is positioned at the "bottom" ("left") or "top" ("right") of the plotting area.</param>
/// <param name="Overlaying">If set a same-letter axis id, this axis is overlaid on top of the corresponding same-letter axis, with traces and axes visible for both axes. If "false", this axis does not overlay any same-letter axes. In this case, for axes with overlapping domains only the highest-numbered axis will be visible.</param>
/// <param name="Domain">Tuple of (X*Y fractions). Sets the domain of this axis (in plot fraction).</param>
/// <param name="Position">Sets the position of this axis in the plotting space (in normalized coordinates). Only has an effect if `anchor` is set to "free".</param>
/// <param name="CategoryOrder">Specifies the ordering logic for the case of categorical variables. By default, plotly uses "trace", which specifies the order that is present in the data supplied. Set `categoryorder` to "category ascending" or "category descending" if order should be determined by the alphanumerical order of the category names. Set `categoryorder` to "array" to derive the ordering from the attribute `categoryarray`. If a category is not found in the `categoryarray` array, the sorting behavior for that attribute will be identical to the "trace" mode. The unspecified categories will follow the categories in `categoryarray`. Set `categoryorder` to "total ascending" or "total descending" if order should be determined by the numerical order of the values. Similarly, the order can be determined by the min, max, sum, mean or median of all the values.</param>
/// <param name="CategoryArray">Sets the order in which categories on this axis appear. Only has an effect if `categoryorder` is set to "array". Used with `categoryorder`.</param>
/// <param name="RangeSlider">Sets a range slider for this axis</param>
/// <param name="RangeSelector">Sets a range selector for this axis. This object contains toggable presets for the rangeslider.</param>
/// <param name="BackgroundColor">Sets the background color of this axis' wall. (Only has an effect on 3D scenes)</param>
/// <param name="ShowBackground">Sets whether or not this axis' wall has a background color. (Only has an effect on 3D scenes)</param>
/// <param name="Id">The target axis id on which the styles should be applied. Default is 1.</param>
public static GenericChart.GenericChart WithYAxisStyle<MinType, MaxType, CategoryArrayType>(
this GenericChart.GenericChart gChart,
string? TitleText = null,
Font? TitleFont = null,
int? TitleStandoff = null,
Title? Title = null,
Color? Color = null,
StyleParam.AxisType? AxisType = null,
Tuple<MinType, MaxType>? MinMax = null,
StyleParam.Mirror? Mirror = null,
bool? ShowSpikes = null,
Color? SpikeColor = null,
int? SpikeThickness = null,
bool? ShowLine = null,
Color? LineColor = null,
bool? ShowGrid = null,
Color? GridColor = null,
bool? ZeroLine = null,
Color? ZeroLineColor = null,
StyleParam.LinearAxisId? Anchor = null,
StyleParam.Side? Side = null,
StyleParam.LinearAxisId? Overlaying = null,
Tuple<double, double>? Domain = null,
double? Position = null,
StyleParam.CategoryOrder? CategoryOrder = null,
IEnumerable<CategoryArrayType>? CategoryArray = null,
RangeSlider? RangeSlider = null,
RangeSelector? RangeSelector = null,
Color? BackgroundColor = null,
bool? ShowBackground = null,
StyleParam.SubPlotId? Id = null
)
where MinType : IConvertible
where MaxType : IConvertible
where CategoryArrayType : class, IConvertible
=>
Plotly.NET.Chart.WithYAxisStyle<MinType, MaxType, CategoryArrayType>(
TitleText: TitleText.ToOption(),
TitleFont: TitleFont.ToOption(),
TitleStandoff: TitleStandoff.ToOptionV(),
Title: Title.ToOption(),
Color: Color.ToOption(),
AxisType: AxisType.ToOption(),
MinMax: MinMax.ToOption(),
Mirror: Mirror.ToOption(),
ShowSpikes: ShowSpikes.ToOptionV(),
SpikeColor: SpikeColor.ToOption(),
SpikeThickness: SpikeThickness.ToOptionV(),
ShowLine: ShowLine.ToOptionV(),
LineColor: LineColor.ToOption(),
ShowGrid: ShowGrid.ToOptionV(),
GridColor: GridColor.ToOption(),
ZeroLine: ZeroLine.ToOptionV(),
ZeroLineColor: ZeroLineColor.ToOption(),
Anchor: Anchor.ToOption(),
Side: Side.ToOption(),
Overlaying: Overlaying.ToOption(),
Domain: Domain.ToOption(),
Position: Position.ToOptionV(),
CategoryOrder: CategoryOrder.ToOption(),
CategoryArray: CategoryArray.ToOption(),
RangeSlider: RangeSlider.ToOption(),
RangeSelector: RangeSelector.ToOption(),
BackgroundColor: BackgroundColor.ToOption(),
ShowBackground: ShowBackground.ToOptionV(),
Id: Id.ToOption()
).Invoke(gChart);
}
}