Skip to content

Commit aad6184

Browse files
committed
Rename WithTraceName -> WithTraceInfo, additional improvements of that functionality
1 parent f09ce38 commit aad6184

File tree

4 files changed

+57
-33
lines changed

4 files changed

+57
-33
lines changed

src/Plotly.NET/CSharpLayer/GenericChartExtensions.fs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@ module GenericChartExtensions =
1616

1717
type GenericChart with
1818

19-
[<CompiledName("WithTraceName")>]
19+
[<CompiledName("WithTraceInfo")>]
2020
[<Extension>]
21-
member this.WithTraceName
21+
member this.WithTraceInfo
2222
(
23-
[<Optional; DefaultParameterValue(null)>] ?Name,
24-
[<Optional; DefaultParameterValue(null)>] ?ShowLegend,
25-
[<Optional; DefaultParameterValue(null)>] ?LegendGroup,
26-
[<Optional; DefaultParameterValue(null)>] ?Visible
23+
[<Optional; DefaultParameterValue(null)>] ?Name: string,
24+
[<Optional; DefaultParameterValue(null)>] ?Visible: StyleParam.Visible,
25+
[<Optional; DefaultParameterValue(null)>] ?ShowLegend: bool,
26+
[<Optional; DefaultParameterValue(null)>] ?LegendRank: int,
27+
[<Optional; DefaultParameterValue(null)>] ?LegendGroup: string,
28+
[<Optional; DefaultParameterValue(null)>] ?LegendGroupTitle: Title
2729
) =
2830
this
29-
|> Chart.withTraceName (
31+
|> Chart.withTraceInfo (
3032
?Name = Name,
33+
?Visible = Visible,
3134
?ShowLegend = ShowLegend,
35+
?LegendRank = LegendRank,
3236
?LegendGroup = LegendGroup,
33-
?Visible = Visible
37+
?LegendGroupTitle = LegendGroupTitle
3438
)
3539

3640
/// Set the axis anchor id the trace is belonging to

src/Plotly.NET/ChartAPI/Chart.fs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ open System.IO
1010
open GenericChart
1111
open System.Runtime.InteropServices
1212

13-
// ###########
14-
// Copied from FSharp.Care.Collections to remove dependancies
13+
// Copied from FSharp.Care.Collections to remove dependencies
1514
[<AutoOpen>]
16-
module Seq =
15+
module internal Seq =
1716

1817
/// Splits a sequence of pairs into two sequences
1918
let unzip (input: seq<_>) =
@@ -46,7 +45,7 @@ module internal ChartIO =
4645
else
4746
invalidOp "Not supported OS platform"
4847

49-
/// Provides a set of static methods for creating charts.
48+
/// Provides a set of static methods for creating and styling charts.
5049
type Chart =
5150

5251
/// <summary>Creates a chart that is completely invisible when rendered. The Chart object however is NOT empty! Combining this chart with other charts will have unforseen consequences (it has for example invisible axes that can override other axes if used in Chart.Combine)</summary>
@@ -65,14 +64,24 @@ type Chart =
6564
|> Layout.AddLinearAxis(StyleParam.SubPlotId.YAxis 1, hiddenAxis ()))
6665

6766

68-
/// Set the name related properties of a trace
69-
[<CompiledName("WithTraceName")>]
70-
static member withTraceName
67+
/// <summary>
68+
/// Sets trace information on the given chart.
69+
/// </summary>
70+
/// <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>
71+
/// <param name="Visible">Wether or not the chart's traces are visible</param>
72+
/// <param name="ShowLegend">Determines whether or not item(s) corresponding to this chart's trace(s) is/are shown in the legend.</param>
73+
/// <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>
74+
/// <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>
75+
/// <param name="LegendGroupTitle">Sets the title for the chart's trace legend group </param>
76+
[<CompiledName("WithTraceInfo")>]
77+
static member withTraceInfo
7178
(
72-
[<Optional; DefaultParameterValue(null)>] ?Name,
73-
[<Optional; DefaultParameterValue(null)>] ?ShowLegend,
74-
[<Optional; DefaultParameterValue(null)>] ?LegendGroup,
75-
[<Optional; DefaultParameterValue(null)>] ?Visible
79+
[<Optional; DefaultParameterValue(null)>] ?Name: string,
80+
[<Optional; DefaultParameterValue(null)>] ?Visible: StyleParam.Visible,
81+
[<Optional; DefaultParameterValue(null)>] ?ShowLegend: bool,
82+
[<Optional; DefaultParameterValue(null)>] ?LegendRank: int,
83+
[<Optional; DefaultParameterValue(null)>] ?LegendGroup: string,
84+
[<Optional; DefaultParameterValue(null)>] ?LegendGroupTitle: Title
7685
) =
7786
fun (ch: GenericChart) ->
7887
ch
@@ -84,9 +93,12 @@ type Chart =
8493
trace
8594
|> TraceStyle.TraceInfo(
8695
?Name = (naming i Name),
96+
?Visible = Visible,
8797
?ShowLegend = ShowLegend,
98+
?LegendRank = LegendRank,
8899
?LegendGroup = LegendGroup,
89-
?Visible = Visible
100+
?LegendGroupTitle = LegendGroupTitle
101+
90102
))
91103

92104
/// Set the axis anchor id the trace is belonging to

src/Plotly.NET/ChartAPI/Chart2D.fs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,6 +3107,7 @@ module Chart2D =
31073107
Trace2DStyle.Histogram(
31083108
?X = X,
31093109
?Y = Y,
3110+
?Opacity = Opacity,
31103111
?Text = Text,
31113112
?MultiText = MultiText,
31123113
?Orientation = Orientation,
@@ -3128,7 +3129,7 @@ module Chart2D =
31283129
)
31293130
)
31303131
|> TraceStyle.Marker(?Color = MarkerColor)
3131-
|> TraceStyle.TraceInfo(?Name = Name, ?ShowLegend = ShowLegend, ?Opacity = Opacity)
3132+
|> TraceStyle.TraceInfo(?Name = Name, ?ShowLegend = ShowLegend)
31323133
|> GenericChart.ofTraceObject useDefaults
31333134

31343135

@@ -3198,6 +3199,7 @@ module Chart2D =
31983199
let histChart =
31993200
Trace2D.initHistogram (
32003201
Trace2DStyle.Histogram(
3202+
?Opacity = Opacity,
32013203
?Text = Text,
32023204
?MultiText = MultiText,
32033205
Orientation = orientation,
@@ -3219,7 +3221,7 @@ module Chart2D =
32193221
)
32203222
)
32213223
|> TraceStyle.Marker(?Color = MarkerColor)
3222-
|> TraceStyle.TraceInfo(?Name = Name, ?ShowLegend = ShowLegend, ?Opacity = Opacity)
3224+
|> TraceStyle.TraceInfo(?Name = Name, ?ShowLegend = ShowLegend)
32233225
|> GenericChart.ofTraceObject useDefaults
32243226

32253227
match orientation with
@@ -3285,6 +3287,7 @@ module Chart2D =
32853287
Y = y,
32863288
?YGap = YGap,
32873289
?Z = Z,
3290+
?Opacity = Opacity,
32883291
?HistFunc = HistFunc,
32893292
?HistNorm = HistNorm,
32903293
?NBinsX = NBinsX,
@@ -3298,7 +3301,7 @@ module Chart2D =
32983301
?ZSmooth = ZSmooth
32993302
)
33003303
)
3301-
|> TraceStyle.TraceInfo(?Name = Name, ?ShowLegend = ShowLegend, ?Opacity = Opacity)
3304+
|> TraceStyle.TraceInfo(?Name = Name, ?ShowLegend = ShowLegend)
33023305
|> GenericChart.ofTraceObject useDefaults
33033306

33043307
/// <summary>

src/Plotly.NET/Traces/Trace.fs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,34 @@ type Trace(traceTypeName: string) =
2020
/// These functions are used internally to style traces of Chart objects. Users are usually pointed
2121
/// to the API layer provided by the `Chart` module/object
2222
type TraceStyle() =
23-
/// Applies the given TraceInfo style parameters to a Trace object.
23+
24+
/// <summary>
25+
/// Sets trace information on the given trace.
26+
/// </summary>
27+
/// <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>
28+
/// <param name="Visible">Wether or not the chart's traces are visible</param>
29+
/// <param name="ShowLegend">Determines whether or not item(s) corresponding to this chart's trace(s) is/are shown in the legend.</param>
30+
/// <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>
31+
/// <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>
32+
/// <param name="LegendGroupTitle">Sets the title for the chart's trace legend group </param>
2433
static member TraceInfo
2534
(
2635
[<Optional; DefaultParameterValue(null)>] ?Name: string,
2736
[<Optional; DefaultParameterValue(null)>] ?Visible: StyleParam.Visible,
2837
[<Optional; DefaultParameterValue(null)>] ?ShowLegend: bool,
38+
[<Optional; DefaultParameterValue(null)>] ?LegendRank: int,
2939
[<Optional; DefaultParameterValue(null)>] ?LegendGroup: string,
30-
[<Optional; DefaultParameterValue(null)>] ?Opacity: float,
31-
[<Optional; DefaultParameterValue(null)>] ?Uid: string,
32-
[<Optional; DefaultParameterValue(null)>] ?Hoverinfo: string
40+
[<Optional; DefaultParameterValue(null)>] ?LegendGroupTitle: Title
3341
) =
3442
(fun (trace: ('T :> Trace)) ->
43+
3544
Name |> DynObj.setValueOpt trace "name"
3645
Visible |> DynObj.setValueOptBy trace "visible" StyleParam.Visible.toObject
3746
ShowLegend |> DynObj.setValueOpt trace "showlegend"
47+
LegendRank |> DynObj.setValueOpt trace "legendrank"
3848
LegendGroup |> DynObj.setValueOpt trace "legendgroup"
39-
Opacity |> DynObj.setValueOpt trace "opacity"
40-
Uid |> DynObj.setValueOpt trace "uid"
41-
Hoverinfo |> DynObj.setValueOpt trace "hoverinfo"
42-
// Update
43-
//Stream: Stream
49+
LegendGroupTitle |> DynObj.setValueOpt trace "legendgrouptitle"
4450

45-
// out ->
4651
trace)
4752

4853
/// Sets selection of data points on a Trace object.

0 commit comments

Comments
 (0)