Skip to content

Commit c54d526

Browse files
authored
WIP rewrite (#40)
* copy paste PlotlyX over here * wip * update project.toml * change generate_traces.jl and add a schema object * update artifacts * rework traces * bye bye Julai 1.6 * wip trace * add plot, which is way smarter than auto-generated trace functions * new readme * readme * add save, some readme stuff * readme * readme and bump version
1 parent 04f89af commit c54d526

File tree

15 files changed

+272
-574
lines changed

15 files changed

+272
-574
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: CI
22
on:
33
push:
4-
branches: [master]
54
tags: ["*"]
65
pull_request:
76
jobs:
@@ -12,7 +11,6 @@ jobs:
1211
fail-fast: false
1312
matrix:
1413
version:
15-
- '1.6'
1614
- '1' # automatically expands to the latest stable 1.x release of Julia
1715
- 'nightly'
1816
os:

.github/workflows/CompatHelper.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CompatHelper
2+
on:
3+
schedule:
4+
- cron: 0 0 * * *
5+
workflow_dispatch:
6+
jobs:
7+
CompatHelper:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Pkg.add("CompatHelper")
11+
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
12+
- name: CompatHelper.main()
13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
16+
run: julia -e 'using CompatHelper; CompatHelper.main()'

Artifacts.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ git-tree-sha1 = "454cd11f76e34fb3c8163fdef1e071633f1ece18"
44
[[PlotlyLight.download]]
55
sha256 = "af56c1871c5ccdb6b51022b378b023dce3df56c18d6b2d21f78c25d1d0b9b486"
66
url = "https://gist.github.com/joshday/6454da06baf6d0ca532c08ba04b76855/raw/454cd11f76e34fb3c8163fdef1e071633f1ece18.tar.gz"
7+
8+
[plotly_artifacts]
9+
git-tree-sha1 = "732abe4f42a5631b96e7b7a003161af12b0a4178"
10+
11+
[[plotly_artifacts.download]]
12+
sha256 = "2682c0da29cf273ef89ba58e04b38c9fc69e664e6e968d6e8e7b4e9bff8f9727"
13+
url = "https://gist.github.com/joshday/8312806ce405dbc529e9381d4d92f14c/raw/732abe4f42a5631b96e7b7a003161af12b0a4178.tar.gz"

Project.toml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
name = "PlotlyLight"
22
uuid = "ca7969ec-10b3-423e-8d99-40f33abb42bf"
33
authors = ["joshday <[email protected]>"]
4-
version = "0.7.5"
4+
version = "0.8.0"
55

66
[deps]
77
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
88
Cobweb = "ec354790-cf28-43e8-bb59-b484409b7bad"
9-
DefaultApplication = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85"
109
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
1110
EasyConfig = "acab07b0-f158-46d4-8913-50acef6d41fe"
1211
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
12+
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
1313
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
14-
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
1514
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
1615

1716
[compat]
18-
Cobweb = "0.5.1"
19-
DefaultApplication = "1"
20-
EasyConfig = "0.1.11"
21-
JSON3 = "1.8"
22-
Scratch = "1.2"
23-
StructTypes = "1"
24-
julia = "^1.6"
17+
Artifacts = "1.3"
18+
Aqua = "0.8"
19+
Cobweb = "0.6"
20+
Downloads = "1.6"
21+
EasyConfig = "0.1"
22+
JSON3 = "1.14"
23+
StructTypes = "1.10"
24+
julia = "1.7"
2525

2626
[extras]
27+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2728
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2829

2930
[targets]
30-
test = ["Test"]
31+
test = ["Test", "Aqua"]

README.md

Lines changed: 56 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@
77

88
<br><br>
99

10-
# Features
10+
## Features
1111

1212
- 🚀 Fastest time-to-first-plot in Julia!
1313
- 🌐 Use the [Plotly.js Javascript documentation](https://plotly.com/javascript/) directly. No magic syntax: Just [`JSON3.write`](https://github.com/quinnj/JSON3.jl).
14-
- Set deeply-nested keys easily with [`EasyConfig.jl`](https://github.com/joshday/EasyConfig.jl).
15-
- e.g. `myplot.layout.xaxis.title.font.family = "Arial"`
16-
- 🕸️ Plays nicely with [Cobweb.jl](https://github.com/joshday/Cobweb.jl) to display or save plots as HTML.
17-
- 🎈 Plots will appear in `MIME"text/html"` environments (like [Pluto.jl](https://github.com/fonsp/Pluto.jl)).
14+
- 📂 Set deeply-nested keys easily, e.g. `myplot.layout.xaxis.title.font.family = "Arial"`.
1815
- 📊 The Same [built-in themes](https://plotly.com/python/templates/) as Plotly's python package.
1916

2017
<br><br>
2118

22-
# 🚀 Quickstart
19+
## 🚀 Quickstart
2320

2421
```julia
2522
using PlotlyLight
2623

27-
Preset.Template.plotly_dark!() # Change template
24+
preset.template.plotly_dark!() # Change template
2825

29-
p = Plot(x = 1:20, y = cumsum(randn(20)), type="scatter", mode="lines+markers") # Make plot
26+
p = plot(x = 1:20, y = cumsum(randn(20)), type="scatter", mode="lines+markers") # Make plot
3027

3128
p.layout.title.text = "My Title!" # Make changes
3229

@@ -38,133 +35,99 @@ p # `display(p)` to see the updated plot
3835
<img width=650 src="https://user-images.githubusercontent.com/8075494/213164013-3ba1a108-122a-4339-a0a2-fa2175fa06e3.png">
3936
</p>
4037

41-
#### Adding Traces
38+
## 📈 Traces
4239

43-
- Calling a `Plot` object will add a trace:
40+
- A core concept in Plotly is that of a *trace*, which is the data along with specifications on how to plot it.
41+
- There are many different trace *types* (e.g. "scatter" for scatterplots, "box" for boxplots).
4442

45-
```julia
46-
Plot()(
47-
x = 1:10, y = randn(10), name = "trace 1"
48-
)(
49-
x = 3:12, y = randn(10), name = "trace 2"
50-
)
51-
```
52-
53-
<br><br>
54-
55-
# 📄 Saving Plots
5643

57-
## Save HTML files with [Cobweb.jl](https://github.com/joshday/Cobweb.jl)
44+
PlotlyLight does some simple "tricks" with the `plot` function so that:
5845

5946
```julia
60-
using Cobweb
61-
62-
page = Cobweb.Page(p)
63-
64-
Cobweb.save(page, "myplot.html")
47+
plot.trace(; kw...) == plot(; type=trace, kw...)
6548
```
6649

67-
## Save images with [PlotlyKaleido.jl](https://github.com/JuliaPlots/PlotlyKaleido.jl)
50+
**This lets you tab-autocomplete the trace type:**
6851

6952
```julia
70-
using PlotlyKaleido
71-
72-
PlotlyKaleido.savefig(p, "myplot.png")
53+
julia> plot.<TAB>
54+
# bar barpolar box candlestick carpet choropleth choroplethmapbox
55+
# cone contour contourcarpet densitymapbox funnel funnelarea heatmap
56+
# heatmapgl histogram histogram2d histogram2dcontour icicle image indicator
57+
# isosurface mesh3d ohlc parcats parcoords pie pointcloud
58+
# sankey scatter scatter3d scattercarpet scattergeo scattergl scattermapbox
59+
# scatterpolar scatterpolargl scattersmith scatterternary splom streamtube sunburst
60+
# surface table treemap violin volume waterfall
7361
```
7462

75-
<br><br>
76-
77-
# `?Plot`
63+
**You can chain the dot syntax to add traces to a plot, e.g.**
7864

7965
```julia
80-
Plot(data, layout=Config(), config=Config())
81-
Plot(;layout=Config(), config=Config(), kw...)
66+
y = randn(20)
67+
68+
plot.bar(; y).scatter(; y)
8269
```
8370

84-
Create a Plotly plot with the given `data` (`Config` or `Vector{Config}`), `layout`, and `config`.
85-
Alternatively, you can create a plot with a single trace by providing the `data` as keyword arguments.
71+
<br><br>
8672

87-
For more info, read the Plotly.js docs: [https://plotly.com/javascript/](https://plotly.com/javascript/).
73+
## 📄 Saving Plots
8874

89-
### Examples
75+
### Saving Plots As HTML
9076

9177
```julia
92-
p = Plot(Config(x=1:10, y=randn(10)))
78+
p = plot(y=rand(10))
9379

94-
p = Plot(; x=1:10, y=randn(10))
80+
PlotlyLight.save(p, "myplot.html")
9581
```
9682

97-
<br><br>
83+
- Note: call `preset.source.standalone!()` first if you want the html file to contain the entire plotly.js script. This enables you to view the plot even without internet access.
9884

99-
# ⚙️ Presets and Settings
10085

101-
- There are several presets that can make your life easier, located in the `Preset` module.
102-
- Each preset is a function that you set via `Preset.[Template|Source|PlotContainer].<preset!>`
86+
### Save Plots as Image via [PlotlyKaleido.jl](https://github.com/JuliaPlots/PlotlyKaleido.jl)
10387

88+
```julia
89+
using PlotlyKaleido
10490

105-
## `Preset.Template`
91+
PlotlyKaleido.start()
10692

107-
- The template/theme of the plot.
93+
(;data, layout, config) = p
10894

109-
```julia
110-
ggplot2!
111-
gridon!
112-
none!
113-
plotly!
114-
plotly_dark!
115-
plotly_white!
116-
presentation!
117-
seaborn!
118-
simple_white!
119-
xgridoff!
120-
ygridoff!
95+
PlotlyKaleido.savefig((; data, layout, config), "myplot.png")
12196
```
12297

98+
<br><br>
12399

124-
## `Preset.Source`
100+
## 🎛️ Presets
125101

126-
- How the Plotly.js library gets loaded when the plot is displayed in a browser.
102+
### Theme Presets
103+
104+
Set a theme/template via `preset.template.<option>!()`. Note that options are tab-autocomplete-able. These are borrowed from the [built-in themes](https://plotly.com/python/templates/) in the plotly python package.
127105

128106
```julia
129-
cdn! # Use https://cdn.plot.ly/plotly-<version>.min.js to load Plotly.js.
130-
local! # Use a local copy of Plotly.
131-
none! # Do not load Plotly.js
132-
standalone! # Create a standalone html file that hard-codes Plotly.js into it.
107+
preset.template.ggplot2!()
133108
```
134109

135-
## `Preset.PlotContainer`
110+
### Source Presets
136111

137-
- The HTML `<div>` that the plot will be inserted into.
112+
Change how the plotly.js script gets loaded in the produced html via `preset.source.<option>!()`.
138113

139114
```julia
140-
auto! # Automatically choose one of the above based on `stdout`.
141-
fillwindow! # Fill the height/width of the page (REPL default).
142-
iframe! # Wrap the Plot inside an <iframe> (Jupyter[lab] default).
143-
pluto! # Use the full width of a Pluto cell (Pluto default).
144-
responsive! # Fill whatever container the plot lives in.
115+
preset.source.none!() # Don't include the script.
116+
preset.source.cdn!() # Use the official plotly.js CDN.
117+
preset.source.local!() # Use a local version of the plotly.js script.
118+
preset.source.standalone!() # Copy-paste the plotly.js script into the html output.
145119
```
146120

147-
## Manual Settings
148-
149-
If the available `Preset`s aren't enough to satisfy your use case, you can override the settings to your own preferences via the `settings!(; kw...)` function.
150-
151-
- `load_plotlyjs`
152-
- A function that returns a `MIME("text/html")`-representable object that will load the Plotly.js library.
153-
- Default value:
154-
```julia
155-
() -> Cobweb.h.script(src=PlotlyLight.cdn_url[], charset="utf-8")
156-
```
157-
- `make_container = (id::String) -> Cobweb.h.div(; id=id)`
158-
- A function of an identifier that returns a `MIME("text/html")`-representable object that will write the `<div>` to be populated with the plot.
159-
- `layout = Config()` and `config = Config()`
160-
- The default `layout` and `config`. They will be merged with the `Plot`'s `layout`/`config` (conflicting values will taken from the `Plot`).
161-
- `iframe::Union{Nothing, Cobweb.IFrame} = nothing`
162-
- A `Cobweb.IFrame` to use as a template to wrap the plot in, e.g. `Cobweb.IFrame(""; height="500px", width="600px")`.
121+
## ⚙️ Settings
163122

164-
# Update/Change the Version of Plotly.js
123+
Occasionally `preset`s aren't enough. Lower level user-configurable settings are available in `PlotlyLight.settings`:
165124

166125
```julia
167-
PlotlyLight.update!() # update to latest released version
168-
169-
PlotlyLight.update!(v"2.24.2") # update to specific release.
126+
PlotlyLight.settings.src::Cobweb.Node # plotly.js script loader
127+
PlotlyLight.settings.div::Cobweb.Node # The plot-div
128+
PlotlyLight.settings.layout::EasyConfig.Config # default `layout` for all plots
129+
PlotlyLight.settings.config::EasyConfig.Config # default `config` for all plots
130+
PlotlyLight.settings.reuse_preview::Bool # In the REPL, open plots in same page (true, the default) or different pages.
170131
```
132+
133+
Check out e.g. `PlotlyLight.Settings().src` to examine default values.

deps/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[deps]
2+
ArtifactUtils = "8b73e784-e7d8-4ea5-973d-377fed4e3bce"
3+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
4+
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"

deps/artifacts.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Pkg
2+
Pkg.activate(@__DIR__)
3+
4+
using ArtifactUtils, JSON3
5+
6+
version = JSON3.read(download("https://api.github.com/repos/plotly/plotly.js/releases/latest")).name
7+
8+
9+
#-----------------------------------------------------------------------------# get urls
10+
plotly_url = "https://github.com/plotly/plotly.js/raw/$version/dist/plotly.min.js"
11+
12+
schema_url = "https://github.com/plotly/plotly.js/raw/$version/dist/plot-schema.json"
13+
14+
template_urls = Dict(
15+
t => "https://raw.githubusercontent.com/plotly/plotly.py/master/packages/python/plotly/plotly/package_data/templates/$t.json" for t in
16+
(:ggplot2, :gridon, :plotly, :plotly_dark, :plotly_white, :presentation, :seaborn, :simple_white, :xgridoff, :ygridoff)
17+
)
18+
19+
#-----------------------------------------------------------------------------# make tempdir
20+
dir = mktempdir()
21+
mkdir(joinpath(dir, "templates"))
22+
23+
#-----------------------------------------------------------------------------# download
24+
open(io -> println(io, version), joinpath(dir, "version.txt"), "w")
25+
download(plotly_url, joinpath(dir, "plotly.min.js"))
26+
download(schema_url, joinpath(dir, "plot-schema.json"))
27+
for (k,v) in template_urls
28+
download(v, joinpath(dir, "templates", "$k.json"))
29+
end
30+
31+
#-----------------------------------------------------------------------------# make artifact
32+
artifact_id = artifact_from_directory(dir)
33+
gist = upload_to_gist(artifact_id)
34+
add_artifact!("Artifacts.toml", "plotly_artifacts", gist; force=true)

quarto/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

quarto/Project.toml

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

quarto/_quarto.yml

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

0 commit comments

Comments
 (0)