Skip to content

Commit

Permalink
Update gallery for UnicodePlots (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg authored Apr 4, 2022
1 parent 88d513d commit b847f29
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 67 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ jobs:
PYTHON: ""
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
run: |
export JULIA_DEBUG=Documenter
export JULIA_DEBUG=Documenter,DemoCards
export PLOTDOCS_ANSICOLOR=true
export GKSwstype=nul # Plots.jl/issues/3664
xvfb-run julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd()));
Pkg.instantiate()'
export DOCUMENTER_DEBUG=true # Democards.jl
xvfb-run julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
xvfb-run julia --project=docs/ docs/make.jl
2 changes: 1 addition & 1 deletion docs/gallery/gaston/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gaston

To switch to Gaston backend, you can use:
To switch to the `Gaston` backend, you can use:

```julia
using Plots
Expand Down
2 changes: 1 addition & 1 deletion docs/gallery/gr/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GR

GR is the default backend for Plots. To explicitly specify the GR backend, you can use:
`GR` is the default backend for `Plots`. To explicitly specify the `GR` backend, you can use:

```julia
using Plots
Expand Down
2 changes: 1 addition & 1 deletion docs/gallery/inspectdr/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# InspectDR

To switch to InspectDR backend, you can use:
To switch to the `InspectDR` backend, you can use:

```julia
using Plots
Expand Down
2 changes: 1 addition & 1 deletion docs/gallery/pgfplotsx/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PGFPlotsX

To switch to PGFPlotsX backend, you can use:
To switch to the `PGFPlotsX` backend, you can use:

```julia
using Plots
Expand Down
2 changes: 1 addition & 1 deletion docs/gallery/plotlyjs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PlotlyJS

To switch to PlotlyJS backend, you can use:
To switch to the `PlotlyJS` backend, you can use:

```julia
using Plots
Expand Down
2 changes: 1 addition & 1 deletion docs/gallery/pyplot/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PyPlot

To switch to PyPlot backend, you can use:
To switch to the `PyPlot` backend, you can use:

```julia
using Plots
Expand Down
6 changes: 6 additions & 0 deletions docs/gallery/unicodeplots/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"theme": "bulmagrid",
"properties":{
"notebook": "false"
}
}
12 changes: 12 additions & 0 deletions docs/gallery/unicodeplots/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# UnicodePlots

To switch to the `UnicodePlots` backend, you can use:

```julia
using Plots
unicodeplots()
```

The demos are generated from `Plots._examples`. Empty demos are features that this backend does not support.

{{{democards}}}
10 changes: 2 additions & 8 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ for (bename, be) in [
("GR", :gr),
("PlotlyJS", :plotlyjs),
("PyPlot", :pyplot),
("PGFPlotsX", :pgfplotsx),
("UnicodePlots", :unicodeplots),
("InspectDR", :inspectdr),
("Gaston", :gaston),
("PGFPlotsX", :pgfplotsx),
# ("UnicodePlots", :unicodeplots),
]
generate_cards(be)
gallery_path, postprocess_cb, assets = makedemos("gallery/$be"; src="src/gallery")
Expand Down Expand Up @@ -83,18 +83,12 @@ const PAGES = Any[
"Advanced Topics"=>["Internals" => "pipeline.md"],
"Gallery" => galleries,
"User Gallery" => user_gallery,
"Examples (old)" => [
"UnicodePlots" => "generated/unicodeplots.md",
],
]

generate_attr_markdown()
generate_supported_markdown()
generate_graph_attr_markdown()
generate_colorschemes_markdown()
for be in (:unicodeplots,)
generate_markdown(be)
end

ansicolor = get(ENV, "PLOTDOCS_ANSICOLOR", "true") == "true"
@show ansicolor
Expand Down
86 changes: 36 additions & 50 deletions src/PlotDocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ markdown_symbols_to_string(arr) = isempty(arr) ? "" : markdown_code_to_string(ar
# ----------------------------------------------------------------------

function generate_cards(pkgname::Symbol; skip = get(Plots._backend_skips, pkgname, Int[]), gendir = "gallery")

# create folder: for each backend we generate a DemoSection "generated" under "gallery"
cardspath = mkpath(joinpath("docs", gendir, "$pkgname", "generated"))
sec_config = Dict{String, Any}("order" => [])

for (i,example) in enumerate(_examples)
for (i, example) in enumerate(_examples)
# write out the header, description, code block, and image link
jlname = "$(pkgname)-ref$i.jl"
jl = IOBuffer()
jl = PipeBuffer()
if !isempty(example.header)
push!(sec_config["order"], jlname)
# start a new demo file
Expand All @@ -66,56 +65,45 @@ function generate_cards(pkgname::Symbol; skip = get(Plots._backend_skips, pkgnam
write(jl, """
# ---
# title: $(example.header)
# id: $(pkgname)_demo_$(i) $(i in skip ? "" : "\n# cover: assets/$(i in (2, 31) ? string("anim_", pkgname, "_ex", i, ".gif") : string(pkgname, "_ex", i, ".png"))")
# id: $(pkgname)_demo_$(i) $(i in skip ? "" : "\n# cover: assets/$(i in (2, 31) ? "anim_$(pkgname)_ex$(i).gif" : "$(pkgname)_ex$(i).png")")
# author: "[PlotDocs.jl](https://github.com/JuliaPlots/PlotDocs.jl/)"
# description: ""
# date: $(now())
# ---
""")
# backend initialization
write(jl,
"""
using Plots
$(pkgname)()
""")

i in skip && @goto write_file
# generate animations only for GR
i in (2, 31) && pkgname != :gr && @goto write_file
write(jl, """
Plots.reset_defaults() #hide
""")
write(jl, "Plots.reset_defaults() # hide\n")
end
# DemoCards use Literate.jl syntax with extra leading `#` as markdown lines
write(jl, "# $(replace(example.desc, "\n" => "\n # "))\n")
write(jl, "# $(replace(example.desc, "\n" => "\n # hide"))\n")

if pkgname (:unicodeplots, :inspectdr, :gaston)
write(jl, "using Logging; Logging.disable_logging(Logging.Warn) #src\n")
write(jl, "using Logging; Logging.disable_logging(Logging.Warn) # hide\n")
end
for expr in example.exprs
pretty_print_expr(jl, expr)
end
write(jl, "\nmkpath(\"assets\") #src\n")
if pkgname == :unicodeplots
write(jl, "show(current()) #src\n")
elseif pkgname == :gaston
write(jl, "png(\"assets/$(pkgname)_ex$i\") #hide\n")
write(jl, "# ![](assets/$(pkgname)_ex$i.png)\n")
elseif i in (2, 31)
write(jl, "gif(anim, \"assets/anim_$(pkgname)_ex$i.gif\")\n")
write(jl, "\nmkpath(\"assets\") # hide\n")
if i in (2, 31)
write(jl, "gif(anim, \"assets/anim_$(pkgname)_ex$i.gif\") # hide\n")
else
write(jl, "png(\"assets/$(pkgname)_ex$i\") #src\n")
write(jl, "png(\"assets/$(pkgname)_ex$i\") # hide\n")
end

@label write_file
if !isempty(example.header)
open(joinpath(cardspath, jlname), "w") do io
write(io, take!(jl))
write(io, read(jl, String))
end
else
open(joinpath(cardspath, "$(pkgname)-ref$(i-1).jl"), "a") do io
write(io, take!(jl))
write(io, read(jl, String))
end
end
# DEBUG: sometimes the generated file is still empty when passing to `DemoCards.makedemos`
Expand All @@ -126,34 +114,31 @@ function generate_cards(pkgname::Symbol; skip = get(Plots._backend_skips, pkgnam
attr_name = string(pkgname, ".jl")
open(joinpath(cardspath, attr_name), "w") do jl
pkg = Plots._backend_instance(pkgname)
write(jl, """
# ---
# title: Supported attribute values
# id: $(pkgname)_attributes
# hidden: true
# author: "[PlotDocs.jl](https://github.com/JuliaPlots/PlotDocs.jl/)"
# date: $(now())
# ---
""")
write(jl, "# - Supported arguments: $(markdown_code_to_string(collect(Plots.supported_attrs(pkg))))\n")
write(jl, "# - Supported values for linetype: $(markdown_symbols_to_string(Plots.supported_seriestypes(pkg)))\n")
write(jl, "# - Supported values for linestyle: $(markdown_symbols_to_string(Plots.supported_styles(pkg)))\n")
write(jl, "# - Supported values for marker: $(markdown_symbols_to_string(Plots.supported_markers(pkg)))\n")
write(jl, """
# ---
# title: Supported attribute values
# id: $(pkgname)_attributes
# hidden: true
# author: "[PlotDocs.jl](https://github.com/JuliaPlots/PlotDocs.jl/)"
# date: $(now())
# ---
# - Supported arguments: $(markdown_code_to_string(collect(Plots.supported_attrs(pkg))))
# - Supported values for linetype: $(markdown_symbols_to_string(Plots.supported_seriestypes(pkg)))
# - Supported values for linestyle: $(markdown_symbols_to_string(Plots.supported_styles(pkg)))
# - Supported values for marker: $(markdown_symbols_to_string(Plots.supported_markers(pkg)))
""")
end
open(joinpath(cardspath, "config.json"), "w") do config
sec_config["description"] = "[Supported attributes](@ref $(pkgname)_attributes)"
push!(sec_config["order"], attr_name)
write(config, json(sec_config)
)
write(config, json(sec_config))
end
end

function generate_markdown(pkgname::Symbol; skip = get(Plots._backend_skips, pkgname, Int[]), gendir = GENDIR)
pkg = Plots._backend_instance(pkgname)

# open the markdown file
md = open(joinpath(gendir, "$(pkgname).md"), "w")

md = open(joinpath(gendir, "$(pkgname).md"), "w") # open the markdown file
write(md, """
```@meta
EditURL = "$PLOT_DOCS_URL"
Expand All @@ -178,8 +163,8 @@ function generate_markdown(pkgname::Symbol; skip = get(Plots._backend_skips, pkg
if !isempty(example.header)
write(md, "### [$(example.header)](@id $pkgname-ref$i)\n")
end
write(md, "$(example.desc)\n")
write(md, """
$(example.desc)
```@example $pkgname
Plots.reset_defaults() # hide
""")
Expand All @@ -205,12 +190,13 @@ function generate_markdown(pkgname::Symbol; skip = get(Plots._backend_skips, pkg
end
end

write(md, "- Supported arguments: $(markdown_code_to_string(collect(Plots.supported_attrs(pkg))))\n")
write(md, "- Supported values for linetype: $(markdown_symbols_to_string(Plots.supported_seriestypes(pkg)))\n")
write(md, "- Supported values for linestyle: $(markdown_symbols_to_string(Plots.supported_styles(pkg)))\n")
write(md, "- Supported values for marker: $(markdown_symbols_to_string(Plots.supported_markers(pkg)))\n")

write(md, "(Automatically generated: $(now()))")
write(md, """
- Supported arguments: $(markdown_code_to_string(collect(Plots.supported_attrs(pkg))))
- Supported values for linetype: $(markdown_symbols_to_string(Plots.supported_seriestypes(pkg)))
- Supported values for linestyle: $(markdown_symbols_to_string(Plots.supported_styles(pkg)))
- Supported values for marker: $(markdown_symbols_to_string(Plots.supported_markers(pkg)))
(Automatically generated: $(now()))
""")
close(md)
end

Expand Down

0 comments on commit b847f29

Please sign in to comment.