-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathInternalUtils.fs
More file actions
105 lines (85 loc) · 3.41 KB
/
InternalUtils.fs
File metadata and controls
105 lines (85 loc) · 3.41 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
[<AutoOpen>]
module internal InternalUtils
open DynamicObj
open System.Runtime.InteropServices
open System.IO
open System.Reflection
let combineOptSeqs (first: seq<'A> option) (second: seq<'A> option) =
match first, second with
| Some f, Some s -> Some(Seq.append f s)
| Some f, None -> Some f
| None, Some s -> Some s
| _ -> None
let combineOptLists (first: List<'A> option) (second: List<'A> option) =
match first, second with
| Some f, Some s -> Some(List.append f s)
| Some f, None -> Some f
| None, Some s -> Some s
| _ -> None
let getFullPlotlyJS () =
let assembly =
Assembly.GetExecutingAssembly()
use str =
assembly.GetManifestResourceStream("Plotly.NET.plotly-2.18.1.min.js")
use r = new StreamReader(str)
r.ReadToEnd()
[<AutoOpen>]
module DynObj =
let setSingleOrMultiOpt (dyn: #DynamicObj) (propName: string) (single: 'A option, multi: seq<'A> option) =
if multi.IsSome then
multi |> DynObj.setValueOpt dyn propName
else
single |> DynObj.setValueOpt dyn propName
let setSingleOrMultiOptBy
(dyn: #DynamicObj)
(propName: string)
(f: 'A -> 'B)
(single: 'A option, multi: seq<'A> option)
=
if multi.IsSome then
multi |> DynObj.setValueOptBy dyn propName (Seq.map f)
else
single |> DynObj.setValueOptBy dyn propName f
let setSingleOrAnyOpt (dyn: #DynamicObj) (propName: string) (single: 'A option, any: 'B option) =
if any.IsSome then
any |> DynObj.setValueOpt dyn propName
else
single |> DynObj.setValueOpt dyn propName
let setSingleOrAnyOptBy
(dyn: #DynamicObj)
(propName: string)
(singleF: 'A -> 'C)
(anyF: 'B -> 'D)
(single: 'A option, any: 'B option)
=
if any.IsSome then
any |> DynObj.setValueOptBy dyn propName anyF
else
single |> DynObj.setValueOptBy dyn propName singleF
// Copied from FSharp.Care.Collections to remove dependencies
[<AutoOpen>]
module internal Seq =
/// Splits a sequence of pairs into two sequences
let unzip (input: seq<_>) =
let (lstA, lstB) =
Seq.foldBack (fun (a, b) (accA, accB) -> a :: accA, b :: accB) input ([], [])
(Seq.ofList lstA, Seq.ofList lstB)
/// Splits a sequence of triples into three sequences
let unzip3 (input: seq<_>) =
let (lstA, lstB, lstC) =
Seq.foldBack (fun (a, b, c) (accA, accB, accC) -> a :: accA, b :: accB, c :: accC) input ([], [], [])
(Seq.ofList lstA, Seq.ofList lstB, Seq.ofList lstC)
[<AutoOpen>]
module internal ChartIO =
///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)
let openOsSpecificFile path =
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
let psi =
new System.Diagnostics.ProcessStartInfo(FileName = path, UseShellExecute = true)
System.Diagnostics.Process.Start(psi) |> ignore
elif RuntimeInformation.IsOSPlatform(OSPlatform.Linux) then
System.Diagnostics.Process.Start("xdg-open", path) |> ignore
elif RuntimeInformation.IsOSPlatform(OSPlatform.OSX) then
System.Diagnostics.Process.Start("open", path) |> ignore
else
invalidOp "Not supported OS platform"