-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathHTML.fs
More file actions
112 lines (101 loc) · 3.44 KB
/
HTML.fs
File metadata and controls
112 lines (101 loc) · 3.44 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
106
107
108
109
110
111
112
namespace Plotly.NET
open Giraffe.ViewEngine
open System
type HTML() =
static member CreateChartScript
(
data: string,
layout: string,
config: string,
plotlyReference: PlotlyJSReference,
guid: string
) =
match plotlyReference with
| Require r ->
script
[ _type "text/javascript" ]
[
rawText (
Globals.REQUIREJS_SCRIPT_TEMPLATE
.Replace("[REQUIRE_SRC]", r)
.Replace("[SCRIPTID]", guid.Replace("-", ""))
.Replace("[ID]", guid)
.Replace("[DATA]", data)
.Replace("[LAYOUT]", layout)
.Replace("[CONFIG]", config)
)
]
| _ ->
script
[ _type "text/javascript" ]
[
rawText (
Globals.SCRIPT_TEMPLATE
.Replace("[SCRIPTID]", guid.Replace("-", ""))
.Replace("[ID]", guid)
.Replace("[DATA]", data)
.Replace("[LAYOUT]", layout)
.Replace("[CONFIG]", config)
)
]
static member Doc(
chart,
documentTitle: string,
documentDescription: string,
documentCharset: string,
documentFavicon: XmlNode,
plotlyReference: PlotlyJSReference,
?AdditionalHeadTags,
?ChartDescription
) =
let additionalHeadTags =
defaultArg AdditionalHeadTags []
let chartDescription = defaultArg ChartDescription []
let plotlyScriptRef =
match plotlyReference with
| CDN cdn -> script [ _src cdn; _charset "utf-8"] []
| Full ->
script
[ _type "text/javascript"; _charset "utf-8"]
[
rawText (InternalUtils.getFullPlotlyJS ())
]
| NoReference
| Require _ -> rawText ""
html
[]
[
head
[]
[
plotlyScriptRef
title [] [ str documentTitle ]
meta [ _charset documentCharset ]
meta
[
_name "description"
_content documentDescription
]
documentFavicon
yield! additionalHeadTags
]
body [] [ yield! chart; yield! chartDescription ]
]
static member CreateChartHTML(data: string, layout: string, config: string, plotlyReference: PlotlyJSReference) =
let guid = Guid.NewGuid().ToString()
let chartScript =
HTML.CreateChartScript(
data = data,
layout = layout,
config = config,
plotlyReference = plotlyReference,
guid = guid
)
[
div
[ _id guid ]
[
comment "Plotly chart will be drawn inside this DIV"
]
chartScript
]