-
Notifications
You must be signed in to change notification settings - Fork 81
/
1_4_display-options.fsx
141 lines (101 loc) · 3.69 KB
/
1_4_display-options.fsx
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
(**
---
title: Display Options
category: Chart Layout
categoryindex: 2
index: 5
---
*)
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 12.0.3"
#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
#endif // IPYNB
(**
# Display Options
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
*Summary:* This example shows how to alter the display options that control the html document that contains plotly charts
You can control the html document that gets created via `Chart.Show` with various functions that change a chart's `DisplayOptions`.
Naturally, these full html documents can not be embedded in this documentation page, so images have to suffice in this case.
let's first create some data for the purpose of creating example charts:
*)
open Plotly.NET
let x = [1.; 2.; 3.; 4.; 5.; 6.; 7.; 8.; 9.; 10.; ]
let y = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
(**
## Chart description
To create a chart description to put below the chart, use `ChartDescription.create` to create the description, and `Chart.WithDescription`
to add the description to the chart's display options:
*)
let description1 =
ChartDescription.create "Hello" "F#"
(***do-not-eval***)
let desc1 =
Chart.Point(x,y,Name="desc1")
|> Chart.WithDescription(description1)
|> Chart.Show
(**
![]({{root}}img/desc1.png)
The `ChartDescription` type is a bit barebones for now, but you can contain any valid html in both `Heading` and `Text` fields:
*)
let description2 =
ChartDescription.create "<h1>I am heading</h1>" "<ol><li>Hi</li><li>there</li></ol>"
(***do-not-eval***)
let desc2 =
Chart.Point(x,y,Name="desc1")
|> Chart.WithDescription(description2)
|> Chart.Show
(**
![]({{root}}img/desc2.png)
## Adding additional head tags
You can add any number of additional html tags to the documents `<head>` tag using `Chart.WithAdditionalHeadTags`.
For example, you can load external css libraries to style the chart description:
*)
//html for description containing bulma classes such as "hero"
let bulmaHero = """<section class="hero is-primary is-bold">
<div class="hero-body">
<p class="title">
Hero title
</p>
<p class="subtitle">
Hero subtitle
</p>
</div>
</section>
"""
// chart description containing bulma classes
let description3 =
ChartDescription.create
"""<h1 class="title">I am heading</h1>"""
bulmaHero
(***do-not-eval***)
let desc3 =
Chart.Point(x,y,Name="desc3")
|> Chart.WithDescription description3
// Add reference to the bulma css framework
|> Chart.WithAdditionalHeadTags ["""<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.2/css/bulma.min.css">"""]
|> Chart.Show
(**
![]({{root}}img/desc3.png)
## Using MathTeX
By popular request, `Chart.WithMathTex` is a prebuilt function to enable MathTeX for your generated plotly chart documents:
*)
(***do-not-eval***)
[
Chart.Point([(1.,2.)],@"$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$")
Chart.Point([(2.,4.)],@"$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$")
]
|> Chart.Combine
|> Chart.withTitle @"$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$"
// include mathtex tags in <head>. pass true to append these scripts, false to ONLY include MathTeX.
|> Chart.WithMathTex(true)
|> Chart.Show
(**
![]({{root}}img/desc4.png)
*)