Skip to content

Commit 1e8cce3

Browse files
committed
documenter docs
1 parent 0bb73e7 commit 1e8cce3

File tree

5 files changed

+78
-56
lines changed

5 files changed

+78
-56
lines changed

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ makedocs(
99
),
1010
pages = [
1111
"index.md",
12+
"plotly_basics.md",
1213
"templates.md",
13-
"traces.md"
1414
]
1515
)
1616

docs/src/plotly_basics.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Plotly.js Basics
2+
3+
Plotly.js is a JavaScript library that allows you to create interactive plots in the browser.
4+
5+
PlotlyLight provide a lightweight interface over the Javascript, so it is worthwhile to learn how the Plotly.js library works.
6+
7+
## What is a Plot?
8+
9+
The core JS function that generates a plot is `Plotly.newPlot(data, layout, config)`, where `data` is a JSON array of objects and `layout`/`config` are JSON objects. Each element of `data` is called a **trace** (data along with specifications on how to plot it).
10+
11+
!!! note "Plotly.js Schema"
12+
The Plotly.js specification is available as a [JSON schema](https://json-schema.org) (raw JSON [here](https://api.plot.ly/v2/plot-schema?format=json&sha1=%27%27)).
13+
14+
PlotlyLight includes this schema as `PlotlyLight.plotly.schema` if you wish to investigate it.
15+
16+
## What is a Trace?
17+
18+
- A **trace** is a JSON object that specifies how data should be represented in a plot.
19+
- There are many different trace *types* (e.g. "scatter" for scatterplots, "box" for boxplots).
20+
21+
22+
!!! note "Tab Auto-Complete"
23+
PlotlyLight's `plot` function enables tab-autocomplete for trace types:
24+
```julia
25+
julia> plot.<TAB>
26+
# bar barpolar box candlestick
27+
# carpet choropleth choroplethmapbox cone
28+
# contour contourcarpet densitymapbox funnel
29+
# funnelarea heatmap heatmapgl histogram
30+
# histogram2d histogram2dcontour icicle image
31+
# indicator isosurface mesh3d ohlc
32+
# parcats parcoords pie pointcloud
33+
# sankey scatter scatter3d scattercarpet
34+
# scattergeo scattergl scattermapbox scatterpolar
35+
# scatterpolargl scattersmith scatterternary splom
36+
# streamtube sunburst surface table
37+
# treemap violin volume waterfall
38+
```
39+
Alternatively, you can type e.g. `plot(; type="scatter", kw...)`.
40+
41+
42+
!!! note "Trace Chaining"
43+
PlotlyLight lets you *chain* traces with the dot syntax:
44+
```@example
45+
using PlotlyLight # hide
46+
y = randn(20)
47+
48+
plot.bar(; y).scatter(; y)
49+
```

docs/src/templates.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,75 +20,88 @@ nothing # hide
2020

2121
```@example templates
2222
preset.template.none!()
23-
plt
23+
plt # hide
2424
```
2525

2626
## `ggplot2!()`
2727

2828
```@example templates
2929
preset.template.ggplot2!()
30-
plt
30+
plt # hide
3131
```
3232

3333
## `gridon!()`
3434

3535
```@example templates
3636
preset.template.gridon!()
37-
plt
37+
plt # hide
3838
```
3939

4040
## `plotly!()`
4141

4242
```@example templates
4343
preset.template.plotly!()
44-
plt
44+
plt # hide
4545
```
4646

4747
## `plotly_dark!()`
4848

4949
```@example templates
5050
preset.template.plotly_dark!()
51-
plt
51+
plt # hide
5252
```
5353

5454
## `plotly_white!()`
5555

5656
```@example templates
5757
preset.template.plotly_white!()
58-
plt
58+
plt # hide
5959
```
6060

6161
## `presentation!()`
6262

6363
```@example templates
6464
preset.template.presentation!()
65-
plt
65+
plt # hide
6666
```
6767

6868
## `seaborn!()`
6969

7070
```@example templates
7171
preset.template.seaborn!()
72-
plt
72+
plt # hide
7373
```
7474

7575
## `simple_white!()`
7676

7777
```@example templates
7878
preset.template.simple_white!()
79-
plt
79+
plt # hide
8080
```
8181

8282
## `xgridoff!()`
8383

8484
```@example templates
8585
preset.template.xgridoff!()
86-
plt
86+
plt # hide
8787
```
8888

8989
## `ygridoff!()`
9090

9191
```@example templates
9292
preset.template.ygridoff!()
93-
plt
93+
plt # hide
94+
```
95+
96+
## Custom Template
97+
98+
To create your own template, simply provide any `JSON3`-writeable object to `PlotlyLight.settings.layout.template`. Here's an example:
99+
100+
```@example templates
101+
my_template = Config()
102+
my_template.layout.title.text = "This Title Will be in Every Plot!"
103+
104+
PlotlyLight.settings.layout.template = my_template
105+
106+
plt # hide
94107
```

docs/src/traces.md

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

src/PlotlyLight.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ Base.@kwdef mutable struct Settings
3333
layout::Config = Config()
3434
config::Config = Config(responsive=true)
3535
reuse_preview::Bool = true
36-
height::String = "100%"
37-
width::String = "100%"
38-
style::Dict{String,String} = Dict("display" => "block", "border" => "none", "min-height" => "350px", "min-width" => "350px")
36+
style::Dict{String,String} = Dict("display" => "block", "border" => "none", "min-height" => "350px", "min-width" => "350px", "width" => "100%", "height" => "100%")
3937
end
4038
settings::Settings = Settings()
4139

@@ -95,13 +93,13 @@ function html_page(o::Plot)
9593
h.meta(name="viewport", content="width=device-width, initial-scale=1"),
9694
h.meta(name="description", content="PlotlyLight.jl"),
9795
h.title("PlotlyLight.jl"),
98-
h.style("body { margin: 0px; } /* remove scrollbar in iframe */"),
96+
h.style("body { padding: 0px; margin: 0px; } /* remove scrollbar in iframe */"),
9997
),
10098
h.body(html_div(o))
10199
)
102100
end
103-
function html_iframe(o::Plot; height=settings.height, width=settings.width, style=settings.style)
104-
IFrame(html_page(o); height=height, width=width, style=join(["$k:$v" for (k,v) in style], ';'))
101+
function html_iframe(o::Plot; style=settings.style)
102+
IFrame(html_page(o); style=join(["$k:$v" for (k,v) in style], ';'))
105103
end
106104
Base.show(io::IO, ::MIME"text/html", o::Plot) = show(io, MIME"text/html"(), html_iframe(o))
107105
Base.show(io::IO, ::MIME"juliavscode/html", o::Plot) = show(io, MIME"text/html"(), o)

0 commit comments

Comments
 (0)