forked from plotly/Plotly.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTML.fs
More file actions
95 lines (84 loc) · 2.91 KB
/
HTML.fs
File metadata and controls
95 lines (84 loc) · 2.91 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
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, plotlyReference: PlotlyJSReference, ?AdditionalHeadTags, ?Description) =
let additionalHeadTags =
defaultArg AdditionalHeadTags []
let description = defaultArg Description []
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
yield! additionalHeadTags
]
body [] [ yield! chart; yield! description ]
]
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
]