Skip to content

Commit c1ed1be

Browse files
committed
#52: Add member extensions to GenericChart to enable fluent interface 🚀
1 parent 918adc2 commit c1ed1be

File tree

7 files changed

+723
-15
lines changed

7 files changed

+723
-15
lines changed

Diff for: src/Plotly.NET/Axis.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Axis =
1111
static member init
1212
(
1313
?AxisType ,
14-
?Title ,
14+
?Title : string ,
1515
?Titlefont ,
1616
?Autorange ,
1717
?Rangemode ,
@@ -157,10 +157,10 @@ module Axis =
157157
?Exponentformat,
158158
?Tickformat,
159159
?Hoverformat,
160-
?Showline,
160+
?Showline: bool,
161161
?Linecolor,
162162
?Linewidth,
163-
?Showgrid,
163+
?Showgrid: bool,
164164
?Gridcolor,
165165
?Gridwidth,
166166
?Zeroline : bool,

Diff for: src/Plotly.NET/ChartExtensions.fs

+16-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ open System.IO
66
open GenericChart
77
open ChartDescription
88
open System.Runtime.InteropServices
9+
open System.Runtime.CompilerServices
910

1011
/// Extensions methods for Charts supporting the fluent pipeline style 'Chart.WithXYZ(...)'.
1112
[<AutoOpen>]
13+
1214
module ChartExtensions =
1315

1416
///Choose process to open plots with depending on OS. Thanks to @zyzhu for hinting at a solution (https://github.com/plotly/Plotly.NET/issues/31)
15-
let private openOsSpecificFile path =
17+
let internal openOsSpecificFile path =
1618
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
1719
let psi = new System.Diagnostics.ProcessStartInfo(FileName = path, UseShellExecute = true)
1820
System.Diagnostics.Process.Start(psi) |> ignore
@@ -46,8 +48,7 @@ module ChartExtensions =
4648
trace
4749
|> TraceStyle.TraceInfo(?Name=(naming i Name),?Showlegend=Showlegend,?Legendgroup=Legendgroup,?Visible=Visible)
4850
)
49-
50-
51+
5152
/// Set the axis anchor id the trace is belonging to
5253
[<CompiledName("WithAxisAnchor")>]
5354
static member withAxisAnchor
@@ -65,7 +66,15 @@ module ChartExtensions =
6566
trace
6667
|> TraceStyle.SetAxisAnchor(?X=idx,?Y=idy,?Z=idz)
6768
)
68-
69+
[<CompiledName("WithAxisAnchor")>]
70+
static member withAxisAnchor
71+
(
72+
(ch:GenericChart),
73+
[<Optional;DefaultParameterValue(null)>] ?X,
74+
[<Optional;DefaultParameterValue(null)>] ?Y,
75+
[<Optional;DefaultParameterValue(null)>] ?Z
76+
) =
77+
ch |> Chart.withAxisAnchor(?X=X,?Y=Y,?Z=Z)
6978

7079
/// Apply styling to the Marker(s) of the chart as Object.
7180
[<CompiledName("WithMarker")>]
@@ -620,11 +629,11 @@ module ChartExtensions =
620629

621630
// Set the size of a Chart
622631
[<CompiledName("WithSize")>]
623-
static member withSize(width,heigth) =
632+
static member withSize(width,height) =
624633
(fun (ch:GenericChart) ->
625634
let layout =
626635
GenericChart.getLayout ch
627-
|> Layout.style (Width=width,Height=heigth)
636+
|> Layout.style (Width=width,Height=height)
628637
GenericChart.setLayout layout ch
629638
)
630639

@@ -963,5 +972,4 @@ module ChartExtensions =
963972
let file = sprintf "%s.html" guid
964973
let path = Path.Combine(tempPath, file)
965974
File.WriteAllText(path, html)
966-
path |> openOsSpecificFile
967-
975+
path |> openOsSpecificFile

Diff for: src/Plotly.NET/GenericChart.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Plotly.NET
22

33
open System
44
open Newtonsoft.Json
5-
5+
open System.Runtime.CompilerServices
66

77
/// HTML template for Plotly.js
88
module HTML =
@@ -134,6 +134,7 @@ module ChartDescription =
134134
.Replace("[DESCRIPTIONTEXT]",d.Text)
135135

136136
/// Module to represent a GenericChart
137+
[<Extension>]
137138
module GenericChart =
138139

139140
open Trace
@@ -181,7 +182,6 @@ module GenericChart =
181182
| Chart (t,_,c) -> Chart (t,layout,c)
182183
| MultiChart (t,_,c) -> MultiChart (t,layout,c)
183184

184-
185185
// Adds a Layout function to the GenericChart
186186
let addLayout layout gChart =
187187
match gChart with

0 commit comments

Comments
 (0)