Skip to content

Commit d4c2ea8

Browse files
authored
Update docs for v5 (#458)
* use fsdocs 20.0.1 * add docs for legends * add temporary fix for multi legend regression bug in docs * finish update existing docs to 5.0.0 * Add subplot title docs * add docs minimal theme customization
1 parent 98a4d18 commit d4c2ea8

13 files changed

+321
-13855
lines changed

.config/dotnet-tools.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
"version": "5.2.2",
77
"commands": [
88
"fantomas"
9-
]
9+
],
10+
"rollForward": false
1011
},
1112
"fsdocs-tool": {
12-
"version": "19.1.1",
13+
"version": "20.0.1",
1314
"commands": [
1415
"fsdocs"
15-
]
16+
],
17+
"rollForward": false
1618
}
1719
}
1820
}

Plotly.NET.sln

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{7B09CC0A-F
4242
docs\Dockerfile = docs\Dockerfile
4343
docs\index.fsx = docs\index.fsx
4444
docs\NuGet.config = docs\NuGet.config
45-
docs\_template.html = docs\_template.html
45+
docs\_head.html = docs\_head.html
4646
docs\_template.ipynb = docs\_template.ipynb
4747
EndProjectSection
4848
EndProject
4949
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "reference", "reference", "{5219BAC7-ACE6-435F-A983-BC63DD7B745E}"
50-
ProjectSection(SolutionItems) = preProject
51-
docs\reference\_template.html = docs\reference\_template.html
52-
EndProjectSection
5350
EndProject
5451
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{60FB82C0-F472-494E-BCF7-7B3C54212406}"
5552
ProjectSection(SolutionItems) = preProject
@@ -153,6 +150,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01_chart-layout", "01_chart
153150
docs\chart-layout\axis-styling.fsx = docs\chart-layout\axis-styling.fsx
154151
docs\chart-layout\errorbars.fsx = docs\chart-layout\errorbars.fsx
155152
docs\chart-layout\layout_images.fsx = docs\chart-layout\layout_images.fsx
153+
docs\chart-layout\legends.fsx = docs\chart-layout\legends.fsx
156154
docs\chart-layout\multiple-charts.fsx = docs\chart-layout\multiple-charts.fsx
157155
docs\chart-layout\shapes.fsx = docs\chart-layout\shapes.fsx
158156
docs\chart-layout\sliders.fsx = docs\chart-layout\sliders.fsx

docs/_head.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<meta charset="utf-8">
2+
<title>{{fsdocs-page-title}}</title>
3+
<meta name="author" content="{{fsdocs-authors}}">
4+
<meta name="description" content="Plotly.NET documentation for: {{fsdocs-page-title}}. Plotly.NET is an Interactive charting library for .NET programming languages.">
5+
6+
<!-- Opengraph properties (https://ogp.me/) -->
7+
<meta property="og:title" content="Plotly.NET documentation for: {{fsdocs-page-title}}" />
8+
<meta property="og:url" content="{{root}}{{fsdocs-source-basename}}.html">
9+
<meta property="og:type" content="website" />
10+
<meta property="og:site_name" content="Plotly.NET" />
11+
<meta property="og:description" content="Plotly.NET documentation for: {{fsdocs-page-title}}. Plotly.NET is an Interactive charting library for .NET programming languages.">
12+
<meta property="og:image" content="{{root}}img/logo_meta_tags.png">
13+
14+
<!-- Twitter cards -->
15+
<meta name="twitter:card" content="summary_large_image">
16+
<meta property="twitter:domain" content="{{root}}{{fsdocs-source-basename}}.html">
17+
<meta property="twitter:url" content="https://plotly.net">
18+
<meta name="twitter:title" content="Plotly.NET documentation for: {{fsdocs-page-title}}">
19+
<meta name="twitter:description" content="Plotly.NET documentation for: {{fsdocs-page-title}}. Plotly.NET is an Interactive charting library for .NET programming languages.">
20+
<meta name="twitter:image" content="{{root}}img/logo_meta_tags.png">
21+
22+
<link rel="shortcut icon" type="image/x-icon" href="{{root}}/img/favicon.ico">
23+
<script src="https://cdn.plot.ly/plotly-2.27.1.min.js"></script>
24+
<script>MathJax = { tex: { inlineMath: [['$', '$'], ['\\(', '\\)']] } };</script>
25+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-svg.js"></script>

docs/_template.html

Lines changed: 0 additions & 103 deletions
This file was deleted.

docs/chart-layout/legends.fsx

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
(**
2+
---
3+
title: Legends
4+
category: Chart Layout
5+
categoryindex: 2
6+
index: 9
7+
---
8+
*)
9+
10+
(*** hide ***)
11+
12+
(*** condition: prepare ***)
13+
#r "nuget: Newtonsoft.JSON, 13.0.1"
14+
#r "nuget: DynamicObj, 2.0.0"
15+
#r "nuget: Giraffe.ViewEngine.StrongName, 2.0.0-alpha1"
16+
#r "../../src/Plotly.NET/bin/Release/netstandard2.0/Plotly.NET.dll"
17+
18+
Plotly.NET.Defaults.DefaultDisplayOptions <-
19+
Plotly.NET.DisplayOptions.init (PlotlyJSReference = Plotly.NET.PlotlyJSReference.NoReference)
20+
21+
(*** condition: ipynb ***)
22+
#if IPYNB
23+
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
24+
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
25+
#endif // IPYNB
26+
27+
(**
28+
# Legends
29+
30+
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/plotly.net/gh-pages?urlpath=/tree/home/jovyan/{{fsdocs-source-basename}}.ipynb)&emsp;
31+
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
32+
33+
*Summary:* This example shows how to create Legends and add them to the Charts in F#.
34+
35+
Let's first create some data for the purpose of creating example charts:
36+
37+
*)
38+
39+
open Plotly.NET
40+
41+
let x = [ 1.; 2.; 3.; 4.; 5.; 6.; 7.; 8.; 9.; 10. ]
42+
let y = [ 2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1. ]
43+
44+
// note that legends are not shown on charts with only one trace,
45+
// which is why we need to set the trace to visible manually on this chart
46+
let simple_chart = Chart.Point(x, y, ShowLegend = true, Name = "test_chart")
47+
48+
(**
49+
## Creating a legend
50+
51+
Legends are `LayoutObjects` that can be added to a chart's `Layout`. The `LayoutLegend.init` function is used to create a legend object, which can then be added to a chart using the `Chart.withLegend` function:
52+
*)
53+
open Plotly.NET.LayoutObjects
54+
55+
let my_legend =
56+
Legend.init (
57+
Title = Title.init("my first legend!"),
58+
BorderColor = Color.fromString "black",
59+
BorderWidth = 1
60+
)
61+
62+
let first_legend_chart =
63+
simple_chart
64+
|> Chart.withLegend my_legend
65+
66+
(*** condition: ipynb ***)
67+
#if IPYNB
68+
first_legend_chart
69+
#endif // IPYNB
70+
71+
(***hide***)
72+
first_legend_chart |> GenericChart.toChartHTML
73+
(***include-it-raw***)
74+
75+
(**
76+
## Styling existing legends
77+
78+
The `Chart.withLegendStyle` function can be used to update the style of an existing legend.
79+
The following code will move the existing legend to the center bottom of the chart:
80+
*)
81+
82+
let styled_legend_chart =
83+
first_legend_chart
84+
|> Chart.withLegendStyle(
85+
Orientation = StyleParam.Orientation.Horizontal,
86+
X = 0.5,
87+
XAnchor = StyleParam.XAnchorPosition.Center
88+
)
89+
90+
(*** condition: ipynb ***)
91+
#if IPYNB
92+
styled_legend_chart
93+
#endif // IPYNB
94+
95+
(***hide***)
96+
styled_legend_chart |> GenericChart.toChartHTML
97+
(***include-it-raw***)
98+
99+
(**
100+
## Grouping legend items
101+
102+
You can group multiple traces as a single legend item by setting the `LegendGroup` property of the individual traces to the same value:
103+
*)
104+
105+
let grouped_legend_chart =
106+
[
107+
Chart.Point(x, y)
108+
|> GenericChart.mapTrace (
109+
Trace2DStyle.Scatter(
110+
LegendGroup = "Group A",
111+
LegendGroupTitle = (Title.init (Text = "Group A"))
112+
)
113+
)
114+
Chart.Point(y, x)
115+
|> GenericChart.mapTrace (
116+
Trace2DStyle.Scatter(
117+
LegendGroup = "Group A"
118+
)
119+
)
120+
Chart.Point(y, y)
121+
|> GenericChart.mapTrace (
122+
Trace2DStyle.Scatter(
123+
LegendGroup = "Group B",
124+
LegendGroupTitle = (Title.init (Text = "Group B"))
125+
)
126+
)
127+
]
128+
|> Chart.combine
129+
130+
(*** condition: ipynb ***)
131+
#if IPYNB
132+
grouped_legend_chart
133+
#endif // IPYNB
134+
135+
(***hide***)
136+
grouped_legend_chart |> GenericChart.toChartHTML
137+
(***include-it-raw***)
138+
139+
(**
140+
## Multiple legends
141+
142+
Starting with Plotly.NET 5.0.0, the multiple legends feature from plotl.js v2.22+ is supported.
143+
144+
However, plotly.js has a [regression bug starting from 2.24.3](https://github.com/plotly/plotly.js/issues/7023), which causes multiple legends to not display correctly
145+
146+
This means that the referenced plotly.js version has to be changed to <2.24.3 to use this feature. Note that features introduced in plotly.js/.NET after this version will not work on a chart using that reference.
147+
Future versions of plotly.js will hopefully fix this issue.
148+
149+
Similarily to how multiple axes are handled, multiple legends are added by providing an additional `Id` argument when using the `Chart.withLegend` function:
150+
151+
To select which legend a trace should belong to, use `Chart.withLegendAnchor` with the corresponding `id` argument.
152+
*)
153+
154+
155+
let multi_legend_chart =
156+
[
157+
Chart.Point(x, y)
158+
|> Chart.withLegendAnchor 1
159+
Chart.Point(y, x)
160+
|> Chart.withLegendAnchor 2
161+
]
162+
|> Chart.combine
163+
|> Chart.withLegend(
164+
Legend.init(
165+
BorderColor = Color.fromKeyword Blue,
166+
BorderWidth = 2,
167+
Title = Title.init(
168+
Text = "Legend 1"
169+
)
170+
)
171+
)
172+
|> Chart.withLegend(
173+
Legend.init(
174+
X = 0.75,
175+
Y = 0.75,
176+
BorderColor = Color.fromKeyword Red,
177+
BorderWidth = 2,
178+
Title = Title.init(
179+
Text = "Legend 2"
180+
)
181+
),
182+
Id = 2
183+
)
184+
// set lower plotly.js version to avoid regression bug
185+
|> Chart.withDisplayOptionsStyle(
186+
PlotlyJSReference = Plotly.NET.PlotlyJSReference.CDN "https://cdn.plot.ly/plotly-2.23.0.min.js"
187+
)
188+
189+
(*** condition: ipynb ***)
190+
#if IPYNB
191+
multi_legend_chart
192+
#endif // IPYNB
193+
194+
(***hide***)
195+
multi_legend_chart |> GenericChart.toEmbeddedHTML
196+
(***include-it-raw***)

0 commit comments

Comments
 (0)