Skip to content

Commit df88bb2

Browse files
committed
Add template and default docs
1 parent 01f9a17 commit df88bb2

File tree

3 files changed

+186
-2
lines changed

3 files changed

+186
-2
lines changed

Plotly.NET.sln

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29709.97
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{BF60BC93-E09B-4E5F-9D85-95A519479D54}"
77
ProjectSection(SolutionItems) = preProject
@@ -44,6 +44,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{7B09CC0A-F
4444
docs\00_1_image-export.fsx = docs\00_1_image-export.fsx
4545
docs\00_2_display-options.fsx = docs\00_2_display-options.fsx
4646
docs\00_3_chart-config.fsx = docs\00_3_chart-config.fsx
47+
docs\00_4_templates.fsx = docs\00_4_templates.fsx
48+
docs\00_5_defaults.fsx = docs\00_5_defaults.fsx
4749
docs\01_0_axis-styling.fsx = docs\01_0_axis-styling.fsx
4850
docs\01_1_errorbars.fsx = docs\01_1_errorbars.fsx
4951
docs\01_2_multiple-charts.fsx = docs\01_2_multiple-charts.fsx

docs/00_4_templates.fsx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
(**
2+
---
3+
title: Chart Templates
4+
category: General
5+
categoryindex: 1
6+
index: 5
7+
---
8+
*)
9+
10+
(*** hide ***)
11+
12+
(*** condition: prepare ***)
13+
#r "nuget: Newtonsoft.JSON, 12.0.3"
14+
#r "nuget: DynamicObj"
15+
#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"
16+
17+
(*** condition: ipynb ***)
18+
#if IPYNB
19+
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
20+
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
21+
#endif // IPYNB
22+
23+
(**
24+
# Chart Templates
25+
26+
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
27+
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
28+
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
29+
30+
## Using premade templates
31+
32+
premade templates can be accessed via the `ChartTemplates` module. In fact, the `ChartTemplates.plotly` template is always active by default (see [global defaults](./005_defaults.html))
33+
*)
34+
open Plotly.NET
35+
36+
let lightMirrored =
37+
Chart.Point([1,2])
38+
|> Chart.withTemplate ChartTemplates.lightMirrored
39+
40+
(*** condition: ipynb ***)
41+
#if IPYNB
42+
lightMirrored
43+
#endif // IPYNB
44+
45+
(***hide***)
46+
lightMirrored |> GenericChart.toChartHTML
47+
(***include-it-raw***)
48+
49+
(**
50+
51+
here are then contents of the template `plotly` which is used by default for all charts:
52+
53+
*)
54+
55+
open DynamicObj
56+
57+
(***include-output***)
58+
ChartTemplates.plotly
59+
|> DynObj.print
60+
61+
(**
62+
63+
## Creating custom templates
64+
65+
Chart Templates consist of a `Layout` object and a collection of `Trace` objects. Both are used to set default values for all possible styling options:
66+
*)
67+
68+
open Plotly.NET.TraceObjects
69+
70+
let myTemplate =
71+
Template.init(
72+
layoutTemplate = Layout.init(
73+
Title = Title.init("I will always be there now!")
74+
),
75+
TraceTemplates = [
76+
Trace2D.initScatter(Trace2DStyle.Scatter(
77+
Marker = Marker.init(Symbol = StyleParam.MarkerSymbol.ArrowLeft, Size = 20)
78+
))
79+
]
80+
)
81+
82+
let myTemplateExampleChart =
83+
Chart.Point([1,2])
84+
|> Chart.withTemplate myTemplate
85+
86+
(*** condition: ipynb ***)
87+
#if IPYNB
88+
myTemplateExampleChart
89+
#endif // IPYNB
90+
91+
(***hide***)
92+
myTemplateExampleChart |> GenericChart.toChartHTML
93+
(***include-it-raw***)

docs/00_5_defaults.fsx

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
(**
2+
---
3+
title: Global default values
4+
category: General
5+
categoryindex: 1
6+
index: 6
7+
---
8+
*)
9+
10+
(*** hide ***)
11+
12+
(*** condition: prepare ***)
13+
#r "nuget: Newtonsoft.JSON, 12.0.3"
14+
#r "nuget: DynamicObj"
15+
#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"
16+
17+
(*** condition: ipynb ***)
18+
#if IPYNB
19+
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
20+
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
21+
#endif // IPYNB
22+
23+
(**
24+
# Global default values
25+
26+
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
27+
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
28+
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
29+
30+
Plotly.NET provides mutable global default values in the `Defaults` module.
31+
32+
These values are always used in Chart generation. The default values are:
33+
34+
|Value name|Value|
35+
|---|---|
36+
| DefaultWidth | `600` |
37+
| DefaultHeight | `600` |
38+
| DefaultConfig | `Config.init(Responsive = true)` |
39+
| DefaultDisplayOptions | `DisplayOptions.init()` |
40+
| DefaultTemplate | `ChartTemplates.plotly` |
41+
42+
## Changing default values
43+
44+
The following code replaces the default template from the global defaults:
45+
*)
46+
open Plotly.NET
47+
48+
let before = Chart.Point([1,2])
49+
50+
(*** condition: ipynb ***)
51+
#if IPYNB
52+
before
53+
#endif // IPYNB
54+
55+
(***hide***)
56+
before |> GenericChart.toChartHTML
57+
(***include-it-raw***)
58+
59+
Defaults.DefaultTemplate <- ChartTemplates.lightMirrored
60+
61+
let after = Chart.Point([1,2])
62+
63+
(*** condition: ipynb ***)
64+
#if IPYNB
65+
after
66+
#endif // IPYNB
67+
68+
(***hide***)
69+
after |> GenericChart.toChartHTML
70+
(***include-it-raw***)
71+
72+
73+
(**
74+
## Ignoring global defaults
75+
76+
All Chart functions have a `UseDefaults` argument, which when set to `false` will ignore all global defaults:
77+
*)
78+
79+
80+
let noDefaults = Chart.Point([1,2], UseDefaults = false)
81+
82+
(*** condition: ipynb ***)
83+
#if IPYNB
84+
noDefaults
85+
#endif // IPYNB
86+
87+
(***hide***)
88+
noDefaults |> GenericChart.toChartHTML
89+
(***include-it-raw***)

0 commit comments

Comments
 (0)