forked from plotly/Plotly.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayOptions.fs
More file actions
72 lines (56 loc) · 2.31 KB
/
DisplayOptions.fs
File metadata and controls
72 lines (56 loc) · 2.31 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
namespace Plotly.NET
open DynamicObj
open System.Runtime.InteropServices
type ChartDescription =
{
Heading: string
Text: string
}
static member create heading text = { Heading = heading; Text = text }
//to-do: when finally using a html dsl, adapt to return XMLNode
static member toHtml(d: ChartDescription) =
let html =
"""<div class=container>
<h3>[DESCRIPTIONHEADING]</h3>
<p>[DESCRIPTIONTEXT]</p>
</div>"""
html
.Replace("[DESCRIPTIONHEADING]", d.Heading)
.Replace("[DESCRIPTIONTEXT]", d.Text)
type DisplayOptions() =
inherit DynamicObj()
static member init
(
[<Optional; DefaultParameterValue(null)>] ?AdditionalHeadTags: seq<string>,
[<Optional; DefaultParameterValue(null)>] ?Description: ChartDescription
) =
DisplayOptions() |> DisplayOptions.style (?AdditionalHeadTags = AdditionalHeadTags, ?Description = Description)
// Applies the styles to Font()
static member style
(
[<Optional; DefaultParameterValue(null)>] ?AdditionalHeadTags: seq<string>,
[<Optional; DefaultParameterValue(null)>] ?Description: ChartDescription
) =
(fun (displayOptions: DisplayOptions) ->
AdditionalHeadTags |> DynObj.setValueOpt displayOptions "AdditionalHeadTags"
Description |> DynObj.setValueOpt displayOptions "Description"
displayOptions)
static member getReplacements(displayOptions: DisplayOptions) =
[
"[ADDITIONAL_HEAD_TAGS]",
(displayOptions.TryGetTypedValue<seq<string>>("AdditionalHeadTags")
|> Option.map (String.concat "\r\n")
|> Option.defaultValue "")
"[DESCRIPTION]",
(displayOptions.TryGetTypedValue<ChartDescription>("Description")
|> Option.map ChartDescription.toHtml
|> Option.defaultValue "")
]
static member replaceHtmlPlaceholders (displayOptions: DisplayOptions) (html: string) =
displayOptions
|> DisplayOptions.getReplacements
|> List.fold
(fun (html: string) (placeholder, replacement) ->
//printfn $"replacing {placeholder} {replacement}"
html.Replace(placeholder, replacement))
html