Skip to content

Commit 58d270c

Browse files
committed
port trace2d to dynobj v4
- adjust some Dynobj usage - fix some unused function args
1 parent 266779c commit 58d270c

File tree

17 files changed

+865
-911
lines changed

17 files changed

+865
-911
lines changed

docs/index.fsx

+13-13
Original file line numberDiff line numberDiff line change
@@ -290,25 +290,25 @@ double[] x = new double[] { 1, 2 };
290290
double[] y = new double[] { 5, 10 };
291291
292292
LinearAxis xAxis = new LinearAxis();
293-
xAxis.SetValue("title", "xAxis");
294-
xAxis.SetValue("showgrid", false);
295-
xAxis.SetValue("showline", true);
293+
xAxis.SetProperty("title", "xAxis");
294+
xAxis.SetProperty("showgrid", false);
295+
xAxis.SetProperty("showline", true);
296296
297297
LinearAxis yAxis = new LinearAxis();
298-
yAxis.SetValue("title", "yAxis");
299-
yAxis.SetValue("showgrid", false);
300-
yAxis.SetValue("showline", true);
298+
yAxis.SetProperty("title", "yAxis");
299+
yAxis.SetProperty("showgrid", false);
300+
yAxis.SetProperty("showline", true);
301301
302302
Layout layout = new Layout();
303-
layout.SetValue("xaxis", xAxis);
304-
layout.SetValue("yaxis", yAxis);
305-
layout.SetValue("showlegend", true);
303+
layout.SetProperty("xaxis", xAxis);
304+
layout.SetProperty("yaxis", yAxis);
305+
layout.SetProperty("showlegend", true);
306306
307307
Trace trace = new Trace("scatter");
308-
trace.SetValue("x", x);
309-
trace.SetValue("y", y);
310-
trace.SetValue("mode", "markers");
311-
trace.SetValue("name", "Hello from C#");
308+
trace.SetProperty("x", x);
309+
trace.SetProperty("y", y);
310+
trace.SetProperty("mode", "markers");
311+
trace.SetProperty("name", "Hello from C#");
312312
313313
GenericChart
314314
.ofTraceObject(true, trace)

src/Plotly.NET.ImageExport/PuppeteerSharpRenderer.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ type PuppeteerSharpRenderer() =
3131

3232
gChart
3333
|> GenericChart.mapConfig (fun c ->
34-
DynObj.setValue c "responsive" true
34+
DynObj.SetProperty c "responsive" true
3535
c)
3636
|> GenericChart.mapLayout (fun l ->
37-
DynObj.setValue l "width" "100%"
38-
DynObj.setValue l "height" "100%"
37+
DynObj.SetProperty l "width" "100%"
38+
DynObj.SetProperty l "height" "100%"
3939
l)
4040
|> GenericChart.toEmbeddedHTML
4141
// this should be done via regex, as this only captures the default width and height.

src/Plotly.NET/Layout/ObjectAbstractions/3D/Scene.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ type Scene() =
125125
/// <param name="xAxis">The new x axis object</param>
126126
static member setXAxis(xAxis: LinearAxis) =
127127
(fun (scene: Scene) ->
128-
scene.SetValue("xaxis", xAxis)
128+
scene.SetProperty("xaxis", xAxis)
129129
scene)
130130

131131
/// <summary>
@@ -143,7 +143,7 @@ type Scene() =
143143
/// <param name="yAxis">The new y axis object</param>
144144
static member setYAxis(yAxis: LinearAxis) =
145145
(fun (scene: Scene) ->
146-
scene.SetValue("yaxis", yAxis)
146+
scene.SetProperty("yaxis", yAxis)
147147
scene)
148148

149149
/// <summary>
@@ -161,5 +161,5 @@ type Scene() =
161161
/// <param name="zAxis">The new z axis object</param>
162162
static member setZAxis(zAxis: LinearAxis) =
163163
(fun (scene: Scene) ->
164-
scene.SetValue("zaxis", zAxis)
164+
scene.SetProperty("zaxis", zAxis)
165165
scene)

src/Plotly.NET/Layout/ObjectAbstractions/Polar/Polar.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ type Polar() =
106106
/// <param name="angularAxis">The new AngularAxis object</param>
107107
static member setAngularAxis(angularAxis: AngularAxis) =
108108
(fun (polar: Polar) ->
109-
polar.SetValue("angularaxis", angularAxis)
109+
polar.SetProperty("angularaxis", angularAxis)
110110
polar)
111111

112112
/// <summary>
@@ -124,5 +124,5 @@ type Polar() =
124124
/// <param name="radialAxis">The new RadialAxis object</param>
125125
static member setRadialAxis(radialAxis: RadialAxis) =
126126
(fun (polar: Polar) ->
127-
polar.SetValue("radialaxis", radialAxis)
127+
polar.SetProperty("radialaxis", radialAxis)
128128
polar)

src/Plotly.NET/Layout/ObjectAbstractions/Smith/Smith.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type Smith() =
7777
/// <param name="imaginaryAxis">The new ImaginaryAxis object</param>
7878
static member setImaginaryAxis(imaginaryAxis: ImaginaryAxis) =
7979
(fun (smith: Smith) ->
80-
smith.SetValue("imaginaryaxis", imaginaryAxis)
80+
smith.SetProperty("imaginaryaxis", imaginaryAxis)
8181
smith)
8282

8383
/// <summary>
@@ -95,5 +95,5 @@ type Smith() =
9595
/// <param name="realAxis">The new RealAxis object</param>
9696
static member setRealAxis(realAxis: RealAxis) =
9797
(fun (smith: Smith) ->
98-
smith.SetValue("realaxis", realAxis)
98+
smith.SetProperty("realaxis", realAxis)
9999
smith)

src/Plotly.NET/Layout/ObjectAbstractions/Ternary/Ternary.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type Ternary() =
8888
/// <param name="aAxis">The new a axis object</param>
8989
static member setAAxis(aAxis: LinearAxis) =
9090
(fun (ternary: Ternary) ->
91-
ternary.SetValue("aaxis", aAxis)
91+
ternary.SetProperty("aaxis", aAxis)
9292
ternary)
9393

9494
/// <summary>
@@ -106,7 +106,7 @@ type Ternary() =
106106
/// <param name="bAxis">The new b axis object</param>
107107
static member setBAxis(bAxis: LinearAxis) =
108108
(fun (ternary: Ternary) ->
109-
ternary.SetValue("baxis", bAxis)
109+
ternary.SetProperty("baxis", bAxis)
110110
ternary)
111111

112112
/// <summary>
@@ -124,5 +124,5 @@ type Ternary() =
124124
/// <param name="cAxis">The new c axis object</param>
125125
static member setCAxis(cAxis: LinearAxis) =
126126
(fun (ternary: Ternary) ->
127-
ternary.SetValue("caxis", cAxis)
127+
ternary.SetProperty("caxis", cAxis)
128128
ternary)

src/Plotly.NET/Traces/Trace.fs

+39-48
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Trace(traceTypeName: string) =
3939
/// <param name="marker">The new marker object</param>
4040
static member setMarker(marker: Marker) =
4141
(fun (trace: ('T :> Trace)) ->
42-
trace.SetValue("marker", marker)
42+
trace.SetProperty("marker", marker)
4343
trace)
4444

4545
/// <summary>
@@ -49,7 +49,7 @@ type Trace(traceTypeName: string) =
4949
static member updateMarker(marker: Marker) =
5050
(fun (trace: #Trace) ->
5151
let combined =
52-
(DynObj.combine (trace |> Trace.getMarker) marker) :?> Marker
52+
(DynObj.combine (trace |> Trace.getMarker) marker)
5353

5454
trace |> Trace.setMarker combined)
5555

@@ -68,7 +68,7 @@ type Trace(traceTypeName: string) =
6868
/// <param name="line">The new line object</param>
6969
static member setLine(line: Line) =
7070
(fun (trace: #Trace) ->
71-
trace.SetValue("line", line)
71+
trace.SetProperty("line", line)
7272
trace)
7373

7474
/// <summary>
@@ -78,7 +78,7 @@ type Trace(traceTypeName: string) =
7878
static member updateLine(line: Line) =
7979
(fun (trace: #Trace) ->
8080
let combined =
81-
(DynObj.combine (trace |> Trace.getLine) line) :?> Line
81+
(DynObj.combine (trace |> Trace.getLine) line)
8282

8383
trace |> Trace.setLine combined)
8484

@@ -97,7 +97,7 @@ type Trace(traceTypeName: string) =
9797
/// <param name="error">The new error object</param>
9898
static member setXError(error: Error) =
9999
(fun (trace: #Trace) ->
100-
trace.SetValue("error_x", error)
100+
trace.SetProperty("error_x", error)
101101
trace)
102102

103103
/// <summary>
@@ -107,7 +107,7 @@ type Trace(traceTypeName: string) =
107107
static member updateXError(error: Error) =
108108
(fun (trace: #Trace) ->
109109
let combined =
110-
(DynObj.combine (trace |> Trace.getXError) error) :?> Error
110+
(DynObj.combine (trace |> Trace.getXError) error)
111111

112112
trace |> Trace.setXError combined)
113113

@@ -126,7 +126,7 @@ type Trace(traceTypeName: string) =
126126
/// <param name="error">The new error object</param>
127127
static member setYError(error: Error) =
128128
(fun (trace: #Trace) ->
129-
trace.SetValue("error_y", error)
129+
trace.SetProperty("error_y", error)
130130
trace)
131131

132132
/// <summary>
@@ -136,7 +136,7 @@ type Trace(traceTypeName: string) =
136136
static member updateYError(error: Error) =
137137
(fun (trace: #Trace) ->
138138
let combined =
139-
(DynObj.combine (trace |> Trace.getYError) error) :?> Error
139+
(DynObj.combine (trace |> Trace.getYError) error)
140140

141141
trace |> Trace.setYError combined)
142142

@@ -155,7 +155,7 @@ type Trace(traceTypeName: string) =
155155
/// <param name="error">The new error object</param>
156156
static member setZError(error: Error) =
157157
(fun (trace: #Trace) ->
158-
trace.SetValue("error_z", error)
158+
trace.SetProperty("error_z", error)
159159
trace)
160160

161161
/// <summary>
@@ -165,7 +165,7 @@ type Trace(traceTypeName: string) =
165165
static member updateZError(error: Error) =
166166
(fun (trace: #Trace) ->
167167
let combined =
168-
(DynObj.combine (trace |> Trace.getZError) error) :?> Error
168+
(DynObj.combine (trace |> Trace.getZError) error)
169169

170170
trace |> Trace.setZError combined)
171171

@@ -193,7 +193,7 @@ type Trace(traceTypeName: string) =
193193
StyleParam.SubPlotId.ColorAxis colorAxisId
194194

195195
(fun (trace: #Trace) ->
196-
trace.SetValue("coloraxis", StyleParam.SubPlotId.convert id)
196+
trace.SetProperty("coloraxis", StyleParam.SubPlotId.convert id)
197197
trace)
198198

199199
/// <summary>
@@ -220,7 +220,7 @@ type Trace(traceTypeName: string) =
220220
StyleParam.SubPlotId.Legend legendId
221221

222222
(fun (trace: #Trace) ->
223-
trace.SetValue("legend", StyleParam.SubPlotId.convert id)
223+
trace.SetProperty("legend", StyleParam.SubPlotId.convert id)
224224
trace)
225225

226226
/// <summary>
@@ -238,7 +238,7 @@ type Trace(traceTypeName: string) =
238238
/// <param name="domain">The new domain</param>
239239
static member setDomain(domain: Domain) =
240240
(fun (trace: ('T :> Trace)) ->
241-
trace.SetValue("domain", domain)
241+
trace.SetProperty("domain", domain)
242242
trace)
243243

244244
/// <summary>
@@ -248,7 +248,7 @@ type Trace(traceTypeName: string) =
248248
static member updateDomain(domain: Domain) =
249249
(fun (trace: #Trace) ->
250250
let combined =
251-
(DynObj.combine (trace |> Trace.getDomain) domain) :?> Domain
251+
(DynObj.combine (trace |> Trace.getDomain) domain)
252252

253253
trace |> Trace.setDomain combined)
254254

@@ -267,7 +267,7 @@ type Trace(traceTypeName: string) =
267267
/// <param name="stackgroup">The new stackgroup</param>
268268
static member setStackGroup(stackgroup: string) =
269269
(fun (trace: ('T :> Trace)) ->
270-
trace.SetValue("stackgroup", stackgroup)
270+
trace.SetProperty("stackgroup", stackgroup)
271271
trace)
272272

273273
/// <summary>
@@ -286,7 +286,7 @@ type Trace(traceTypeName: string) =
286286
static member setColorBar(colorBar: ColorBar) =
287287
(fun (trace: ('T :> Trace)) ->
288288

289-
trace.SetValue("colorbar", colorBar)
289+
trace.SetProperty("colorbar", colorBar)
290290
trace)
291291

292292
/// <summary>
@@ -296,7 +296,7 @@ type Trace(traceTypeName: string) =
296296
static member updateColorBar(colorBar: ColorBar) =
297297
(fun (trace: #Trace) ->
298298
let combined =
299-
(DynObj.combine (trace |> Trace.getColorBar) colorBar) :?> ColorBar
299+
DynObj.combine (trace |> Trace.getColorBar) colorBar
300300

301301
trace |> Trace.setColorBar combined)
302302

@@ -327,16 +327,14 @@ type TraceStyle() =
327327
[<Optional; DefaultParameterValue(null)>] ?LegendGroup: string,
328328
[<Optional; DefaultParameterValue(null)>] ?LegendGroupTitle: Title
329329
) =
330-
(fun (trace: ('T :> Trace)) ->
331-
332-
Name |> DynObj.setOptionalProperty trace "name"
333-
Visible |> DynObj.setOptionalPropertyBy trace "visible" StyleParam.Visible.convert
334-
ShowLegend |> DynObj.setOptionalProperty trace "showlegend"
335-
LegendRank |> DynObj.setOptionalProperty trace "legendrank"
336-
LegendGroup |> DynObj.setOptionalProperty trace "legendgroup"
337-
LegendGroupTitle |> DynObj.setOptionalProperty trace "legendgrouptitle"
338-
339-
trace)
330+
fun (trace: #Trace) ->
331+
trace
332+
|> DynObj.withOptionalProperty "name" Name
333+
|> DynObj.withOptionalPropertyBy "visible" Visible StyleParam.Visible.convert
334+
|> DynObj.withOptionalProperty "showlegend" ShowLegend
335+
|> DynObj.withOptionalProperty "legendrank" LegendRank
336+
|> DynObj.withOptionalProperty "legendgroup" LegendGroup
337+
|> DynObj.withOptionalProperty "legendgrouptitle" LegendGroupTitle
340338

341339
/// <summary>
342340
/// Returns a function that applies the given styles to the trace's marker object. Overwrites attributes with the same name that are already set.
@@ -704,13 +702,11 @@ type TraceStyle() =
704702
[<Optional; DefaultParameterValue(null)>] ?Selected: TraceSelection,
705703
[<Optional; DefaultParameterValue(null)>] ?Unselected: TraceSelection
706704
) =
707-
(fun (trace: ('T :> Trace)) ->
708-
709-
SelectedPoints |> DynObj.setOptionalProperty trace "selectedpoints"
710-
Selected |> DynObj.setOptionalProperty trace "selected"
711-
Unselected |> DynObj.setOptionalProperty trace "unselected"
712-
713-
trace)
705+
fun (trace: #Trace) ->
706+
trace
707+
|> DynObj.withOptionalProperty "selectedpoints" SelectedPoints
708+
|> DynObj.withOptionalProperty "selected" Selected
709+
|> DynObj.withOptionalProperty "unselected" Unselected
714710

715711
/// <summary>
716712
/// Returns a function that applies the given styles to the trace's text items.
@@ -742,20 +738,15 @@ type TraceStyle() =
742738
[<Optional; DefaultParameterValue(null)>] ?MultiHoverTemplate: seq<string>,
743739
[<Optional; DefaultParameterValue(null)>] ?TextFont: Font
744740
) =
745-
(fun (trace: ('T :> Trace)) ->
746-
(Text, MultiText) |> DynObj.setOptionalSingleOrMultiProperty trace "text"
747-
748-
(TextPosition, MultiTextPosition)
749-
|> DynObj.setSingleOrMultiOptBy trace "textposition" StyleParam.TextPosition.convert
750-
751-
(TextTemplate, MultiTextTemplate) |> DynObj.setOptionalSingleOrMultiProperty trace "texttemplate"
752-
(HoverText, MultiHoverText) |> DynObj.setOptionalSingleOrMultiProperty trace "hovertext"
753-
HoverInfo |> DynObj.setOptionalPropertyBy trace "hoverinfo" StyleParam.HoverInfo.convert
754-
(HoverTemplate, MultiHoverTemplate) |> DynObj.setOptionalSingleOrMultiProperty trace "hovertemplate"
755-
756-
TextFont |> DynObj.setOptionalProperty trace "textfont"
757-
758-
trace)
741+
fun (trace: #Trace) ->
742+
trace
743+
|> DynObj.withOptionalSingleOrMultiProperty "text" (Text, MultiText)
744+
|> DynObj.withOptionalSingleOrMultiPropertyBy "textposition" (TextPosition, MultiTextPosition) StyleParam.TextPosition.convert
745+
|> DynObj.withOptionalSingleOrMultiProperty "texttemplate" (TextTemplate, MultiTextTemplate)
746+
|> DynObj.withOptionalSingleOrMultiProperty "hovertext" (HoverText, MultiHoverText)
747+
|> DynObj.withOptionalPropertyBy "hoverinfo" HoverInfo StyleParam.HoverInfo.convert
748+
|> DynObj.withOptionalSingleOrMultiProperty "hovertemplate" (HoverTemplate, MultiHoverTemplate)
749+
|> DynObj.withOptionalProperty "textfont" TextFont
759750

760751
// <summary>
761752
/// Returns a function that applies the given styles to the trace's domain object.

0 commit comments

Comments
 (0)