Skip to content

Commit 7e6e50b

Browse files
committed
Finish Trace module refactor, add tests
1 parent 31e74b8 commit 7e6e50b

File tree

4 files changed

+234
-185
lines changed

4 files changed

+234
-185
lines changed

src/Plotly.NET/ChartAPI/Chart.fs

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

13-
// Copied from FSharp.Care.Collections to remove dependencies
14-
[<AutoOpen>]
15-
module internal Seq =
16-
17-
/// Splits a sequence of pairs into two sequences
18-
let unzip (input: seq<_>) =
19-
let (lstA, lstB) =
20-
Seq.foldBack (fun (a, b) (accA, accB) -> a :: accA, b :: accB) input ([], [])
21-
22-
(Seq.ofList lstA, Seq.ofList lstB)
23-
24-
/// Splits a sequence of triples into three sequences
25-
let unzip3 (input: seq<_>) =
26-
let (lstA, lstB, lstC) =
27-
Seq.foldBack (fun (a, b, c) (accA, accB, accC) -> a :: accA, b :: accB, c :: accC) input ([], [], [])
28-
29-
(Seq.ofList lstA, Seq.ofList lstB, Seq.ofList lstC)
30-
31-
[<AutoOpen>]
32-
module internal ChartIO =
33-
34-
///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)
35-
let openOsSpecificFile path =
36-
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
37-
let psi =
38-
new System.Diagnostics.ProcessStartInfo(FileName = path, UseShellExecute = true)
39-
40-
System.Diagnostics.Process.Start(psi) |> ignore
41-
elif RuntimeInformation.IsOSPlatform(OSPlatform.Linux) then
42-
System.Diagnostics.Process.Start("xdg-open", path) |> ignore
43-
elif RuntimeInformation.IsOSPlatform(OSPlatform.OSX) then
44-
System.Diagnostics.Process.Start("open", path) |> ignore
45-
else
46-
invalidOp "Not supported OS platform"
47-
4813
/// Provides a set of static methods for creating and styling charts.
4914
type Chart =
5015

@@ -135,10 +100,10 @@ type Chart =
135100
/// <summary>
136101
/// Sets the color axis id for the chart's trace(s).
137102
/// </summary>
138-
/// <param name="Id">The new color axis id for the chart's trace(s)</param>
103+
/// <param name="id">The new color axis id for the chart's trace(s)</param>
139104
[<CompiledName("WithColorAxisAnchor")>]
140-
static member withColorAxisAnchor([<Optional; DefaultParameterValue(null)>] ?Id: int) =
141-
fun (ch: GenericChart) -> ch |> mapTrace (TraceStyle.setColorAxisAnchor (?ColorAxisId = Id))
105+
static member withColorAxisAnchor(id: int) =
106+
fun (ch: GenericChart) -> ch |> mapTrace (Trace.setColorAxisAnchor id)
142107

143108
/// <summary>
144109
/// Sets the marker for the chart's trace(s).
@@ -310,7 +275,7 @@ type Chart =
310275
/// Apply styling to the xError(s) of the chart as Object
311276
[<CompiledName("WithXError")>]
312277
static member withXError(xError: Error) =
313-
(fun (ch: GenericChart) -> ch |> mapTrace (Trace.SetXError(xError)))
278+
(fun (ch: GenericChart) -> ch |> mapTrace (Trace.setXError (xError)))
314279

315280
/// Apply styling to the xError(s) of the chart as Object
316281
[<CompiledName("WithXErrorStyle")>]
@@ -338,7 +303,7 @@ type Chart =
338303
/// Apply styling to the yError(s) of the chart as Object
339304
[<CompiledName("WithYError")>]
340305
static member withYError(yError: Error) =
341-
(fun (ch: GenericChart) -> ch |> mapTrace (Trace.SetYError(yError)))
306+
(fun (ch: GenericChart) -> ch |> mapTrace (Trace.setYError (yError)))
342307

343308
/// Apply styling to the yError(s) of the chart as Object
344309
[<CompiledName("WithYErrorStyle")>]
@@ -366,7 +331,7 @@ type Chart =
366331
/// Apply styling to the zError(s) of the chart as Object
367332
[<CompiledName("WithZError")>]
368333
static member withZError(zError: Error) =
369-
(fun (ch: GenericChart) -> ch |> mapTrace (Trace.SetZError(zError)))
334+
(fun (ch: GenericChart) -> ch |> mapTrace (Trace.setZError (zError)))
370335

371336
/// Apply styling to the zError(s) of the chart as Object
372337
[<CompiledName("WithZErrorStyle")>]
@@ -759,39 +724,6 @@ type Chart =
759724
)
760725

761726
Chart.withColorBar (colorbar)
762-
//// Sets second x-Axis of 2D- Charts
763-
//static member withX_Axis2(xAxis2:Axis.LinearAxis) =
764-
// (fun (ch:GenericChart) ->
765-
// let layout =
766-
// GenericChart.getLayout ch
767-
// |> Layout.style (xAxis2=xAxis2)
768-
// GenericChart.setLayout layout ch
769-
// )
770-
771-
772-
// // Sets second x-Axis of 2D- Charts
773-
//static member withX_Axis2Style(title,?MinMax,?Showgrid,?Showline) =
774-
// let range = if MinMax.IsSome then Some (StyleParam.Range.MinMax (MinMax.Value)) else None
775-
// let xaxis = Axis.LinearAxis.init(Title=title,?Range=range,?Showgrid=Showgrid,?Showline=Showline,Side=StyleParam.Side.Top)
776-
// Chart.withX_Axis2(xaxis)
777-
778-
779-
//// Sets second y-Axis of 2D- Charts
780-
//static member withY_Axis2(yAxis2:Axis.LinearAxis) =
781-
// (fun (ch:GenericChart) ->
782-
// let layout =
783-
// GenericChart.getLayout ch
784-
// |> Layout.style (yAxis2=yAxis2)
785-
// GenericChart.setLayout layout ch
786-
// )
787-
788-
789-
// // Sets second x-Axis of 2D- Charts
790-
//static member withY_Axis2Style(title,?MinMax,?Showgrid,?Showline) =
791-
// let range = if MinMax.IsSome then Some (StyleParam.Range.MinMax (MinMax.Value)) else None
792-
// let yaxis = Axis.LinearAxis.init(Title=title,?Range=range,?Showgrid=Showgrid,?Showline=Showline,Side=StyleParam.Side.Right)
793-
// Chart.withY_Axis2(yaxis)
794-
795727

796728
// Set the Layout of a Chart
797729
[<CompiledName("WithLayout")>]

src/Plotly.NET/InternalUtils.fs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
module internal InternalUtils
33

44
open DynamicObj
5+
open System.Runtime.InteropServices
56

67
[<AutoOpen>]
78
module DynObj =
@@ -40,3 +41,38 @@ module DynObj =
4041
any |> DynObj.setValueOptBy dyn propName anyF
4142
else
4243
single |> DynObj.setValueOptBy dyn propName singleF
44+
45+
// Copied from FSharp.Care.Collections to remove dependencies
46+
[<AutoOpen>]
47+
module internal Seq =
48+
49+
/// Splits a sequence of pairs into two sequences
50+
let unzip (input: seq<_>) =
51+
let (lstA, lstB) =
52+
Seq.foldBack (fun (a, b) (accA, accB) -> a :: accA, b :: accB) input ([], [])
53+
54+
(Seq.ofList lstA, Seq.ofList lstB)
55+
56+
/// Splits a sequence of triples into three sequences
57+
let unzip3 (input: seq<_>) =
58+
let (lstA, lstB, lstC) =
59+
Seq.foldBack (fun (a, b, c) (accA, accB, accC) -> a :: accA, b :: accB, c :: accC) input ([], [], [])
60+
61+
(Seq.ofList lstA, Seq.ofList lstB, Seq.ofList lstC)
62+
63+
[<AutoOpen>]
64+
module internal ChartIO =
65+
66+
///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)
67+
let openOsSpecificFile path =
68+
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
69+
let psi =
70+
new System.Diagnostics.ProcessStartInfo(FileName = path, UseShellExecute = true)
71+
72+
System.Diagnostics.Process.Start(psi) |> ignore
73+
elif RuntimeInformation.IsOSPlatform(OSPlatform.Linux) then
74+
System.Diagnostics.Process.Start("xdg-open", path) |> ignore
75+
elif RuntimeInformation.IsOSPlatform(OSPlatform.OSX) then
76+
System.Diagnostics.Process.Start("open", path) |> ignore
77+
else
78+
invalidOp "Not supported OS platform"

0 commit comments

Comments
 (0)