1- # oneliner fast build PLOTDOCS_PACKAGES='UnicodePlots' PLOTDOCS_EXAMPLES=1 julia --project make.jl
1+ # oneliner fast build PLOTDOCS_SUFFIX='' PLOTDOCS_PACKAGES='UnicodePlots' PLOTDOCS_EXAMPLES='1' julia --project make.jl
22import Pkg; Pkg. precompile()
33
44using RecipesBase, RecipesPipeline, PlotsBase, Plots
@@ -109,7 +109,7 @@ function generate_cards(
109109 )
110110 @show backend
111111 # create folder: for each backend we generate a DemoSection "generated" under "gallery"
112- cards_path = let dn = joinpath(prefix, " $ backend" , " generated" )
112+ cards_path = let dn = joinpath(prefix, string( backend) , " generated" * suffix )
113113 isdir(dn) && rm(dn; recursive = true )
114114 mkpath(dn)
115115 end
@@ -118,22 +118,26 @@ function generate_cards(
118118 needs_rng_fix = Dict{Int, Bool}()
119119
120120 for (i, example) in enumerate(PlotsBase. _examples)
121+ i ∈ skip && continue
121122 (slice ≢ nothing && i ∉ slice) && continue
122123 # write out the header, description, code block, and image link
123124 jlname = " $backend -$(PlotsBase. ref_name(i)) .jl"
124125 jl = PipeBuffer()
126+ # DemoCards YAML frontmatter
127+ # https://johnnychen94.github.io/DemoCards.jl/stable/quickstart/usage_example/julia_demos/1.julia_demo/#juliademocard_example
128+ asset_name = " $(backend) _$(PlotsBase. ref_name(i)) "
129+ asset_path = asset_name * if i ∈ PlotsBase. _animation_examples
130+ " .gif"
131+ elseif backend ∈ (:gr, :pythonplot, :gaston)
132+ " .svg"
133+ else
134+ " .png"
135+ end
125136 if ! isempty(example. header)
126137 push!(sec_config[" order" ], jlname)
127138 # start a new demo file
128139 @debug " generate demo \" $(example. header) \" - writing `$jlname `"
129140
130- # DemoCards YAML frontmatter
131- # https://johnnychen94.github.io/DemoCards.jl/stable/quickstart/usage_example/julia_demos/1.julia_demo/#juliademocard_example
132- asset = if i ∈ PlotsBase. _animation_examples
133- " anim_$(backend) _$(PlotsBase. ref_name(i)) .gif"
134- else
135- " $(backend) _$(PlotsBase. ref_name(i)) .png"
136- end
137141 extra = if backend ≡ :unicodeplots
138142 " import FileIO, FreeType #hide" # weak deps for png export
139143 else
@@ -143,21 +147,18 @@ function generate_cards(
143147 jl, """
144148 # ---
145149 # title: $(example. header)
146- # id: $(backend) _$(PlotsBase. ref_name(i)) $(i ∈ skip ? " " : " \n # cover: assets/$asset " )
150+ # id: $asset_name
151+ # cover: $asset_path
147152 # author: "$(author()) "
148153 # description: ""
149154 # date: $(Dates. now())
150155 # ---
151156
152157 using Plots
158+ const PlotsBase = Plots.PlotsBase #hide
153159 $backend ()
154160 $extra
155- """
156- )
157161
158- i ∈ skip && @goto write_file
159- write(
160- jl, """
161162 PlotsBase.reset_defaults() #hide
162163 using StableRNGs #hide
163164 rng = StableRNG($(PlotsBase. SEED) ) #hide
@@ -175,23 +176,20 @@ function generate_cards(
175176 # from the docs: """
176177 # #src and #hide are quite similar. The only difference is that #src lines are filtered out before execution (if execute=true) and #hide lines are filtered out after execution.
177178 # """
178- asset = if i ∈ PlotsBase. _animation_examples
179- " gif(anim, \" assets/anim_$(backend) _$(PlotsBase. ref_name(i)) .gif\" )\n " # NOTE: must not be hidden, for appearance in the rendered `html`
180- else
181- " png(\" assets/$(backend) _$(PlotsBase. ref_name(i)) .png\" ) #src\n "
182- end
183- write(
184- jl, """
185- mkpath("assets") #src
186- $asset
179+ asset_cmd = if i ∈ PlotsBase. _animation_examples
180+ " PlotsBase.gif(anim, \" $asset_path \" )\n " # NOTE: must not be hidden, for appearance in the rendered `html`
181+ elseif backend ∈ (:gr, :pythonplot, :gaston)
182+ " PlotsBase.svg(\" $asset_path \" ) #src\n "
183+ elseif backend ≡ :plotlyjs
187184 """
188- )
189- backend ≡ :plotlyjs && write(
190- jl, """
185+ PlotsBase.png(\" $asset_path \" ) #src
191186 nothing #hide
192- #  _ $(PlotsBase . ref_name(i)) .png )
187+ # 
193188 """
194- )
189+ else
190+ " PlotsBase.png(\" $asset_path \" ) #src\n "
191+ end
192+ write(jl, """ mkpath("assets") #src\n $asset_cmd \n """ )
195193
196194 @label write_file
197195 fn, mode = if isempty(example. header)
@@ -201,9 +199,7 @@ function generate_cards(
201199 end
202200 card = joinpath(cards_path, fn)
203201 # @info "writing" card
204- open(card, mode) do io
205- write(io, read(jl, String))
206- end
202+ open(io -> write(io, read(jl, String)), card, mode)
207203 # DEBUG: sometimes the generated file is still empty when passing to `DemoCards.makedemos`
208204 sleep(0.01 )
209205 end
@@ -482,29 +478,28 @@ function generate_graph_attr_markdown()
482478 # [Graph Attributes](@id graph_attributes)
483479
484480 Where possible, GraphRecipes will adopt attributes from Plots.jl to format visualizations.
485- For example, the `linewidth` attribute from Plots.jl has the same effect in GraphRecipes.
486- In order to give the user control over the layout of the graph visualization, GraphRecipes
487- provides a number of keyword arguments (attributes). Here we describe those attributes
488- alongside their default values.
481+ For example, the `linewidth` attribute from Plots.jl has the same effect in ` GraphRecipes` .
482+ In order to give the user control over the layout of the graph visualization,
483+ `GraphRecipes` provides a number of keyword arguments (attributes).
484+ Here we describe those attributes alongside their default values.
489485
490486 ```@raw html
491487 $(to_html(df))
492488 ```
493489 \n
494490 ## Aliases
495- Certain keyword arguments have aliases, so GraphRecipes "does what you mean, not
496- what you say".
491+ Certain keyword arguments have aliases, so `GraphRecipes` does "what you mean, not what you say".
497492
498- So for example, `nodeshape=:rect` and `node_shape=:rect` are equivalent. To see the
499- available aliases, type `GraphRecipes.graph_aliases`. If you are unhappy with the provided
500- aliases, then you can add your own:
493+ So for example, `nodeshape=:rect` and `node_shape=:rect` are equivalent.
494+ To see the available aliases, type `GraphRecipes.graph_aliases`.
495+ If you are unhappy with the provided aliases, then you can add your own:
501496 ```julia
502497 using GraphRecipes, Plots
503498
504499 push!(GraphRecipes.graph_aliases[:nodecolor],:nc)
505500
506501 # These two calls produce the same plot, modulo some randomness in the layout.
507- plot(graphplot([0 1; 0 0], nodecolor=:red), graphplot([0 1; 0 0], nc=:red))
502+ plot(graphplot([0 1; 0 0]; nodecolor=:red), graphplot([0 1; 0 0]; nc=:red))
508503 ```
509504
510505 $(autogenerated())
@@ -521,9 +516,7 @@ generate_colorschemes_markdown() = open(joinpath(GEN_DIR, "colorschemes.md"), "w
521516 ```
522517 """
523518 )
524- for line in readlines(joinpath(SRC_DIR, " colorschemes.md" ))
525- write(md, line * ' \n ' )
526- end
519+ foreach(line -> write(md, line * ' \n ' ), readlines(joinpath(SRC_DIR, " colorschemes.md" )))
527520 write(
528521 md, """
529522 ## misc
@@ -616,10 +609,10 @@ function main(args)
616609 gaston()
617610
618611 # NOTE: for a faster representative test build use `PLOTDOCS_PACKAGES='GR' PLOTDOCS_EXAMPLES='1'`
619- default_packages = " GR, PythonPlot, PlotlyJS, PGFPlotsX, UnicodePlots, Gaston"
620- packages = get(ENV , " PLOTDOCS_PACKAGES" , default_packages )
621- packages = let val = packages == " ALL" ? default_packages : packages
622- Symbol.(filter(! isempty, strip.(split(val, " , " ))))
612+ all_packages = " GR PythonPlot PlotlyJS PGFPlotsX UnicodePlots Gaston"
613+ packages = get(ENV , " PLOTDOCS_PACKAGES" , " ALL " )
614+ packages = let val = packages == " ALL" ? all_packages : packages
615+ Symbol.(filter(! isempty, strip.(split(val))))
623616 end
624617 packages_backends = NamedTuple(p => Symbol(lowercase(string(p))) for p in packages)
625618 backends = values(packages_backends) |> collect
@@ -659,13 +652,13 @@ function main(args)
659652 @time " gallery" for pkg in packages
660653 be = packages_backends[pkg]
661654 needs_rng_fix[pkg] = generate_cards(joinpath(@__DIR__, " gallery" ), be, slice)
662- let (path, cb, assets ) = makedemos(
663- joinpath(" gallery" , string(be));
655+ let (path, cb, asset ) = makedemos(
656+ joinpath(@__DIR__, " gallery" , string(be));
664657 root = @__DIR__, src = joinpath(work, " gallery" ), edit_branch = BRANCH
665658 )
666659 push!(gallery, string(pkg) => joinpath(" gallery" , path))
667660 push!(gallery_callbacks, cb)
668- push!(gallery_assets, assets )
661+ push!(gallery_assets, asset )
669662 end
670663 end
671664 if ! debug
@@ -835,7 +828,7 @@ function main(args)
835828 # [1, 4, 5, 7:12, 14:21, 25:27, 29:30, 33:34, 36, 38:39, 41, 43, 45:46, 48, 52, 54, 62]
836829 @time " post-process `rng`" for pkg in packages
837830 be = packages_backends[pkg]
838- prefix = joinpath(BLD_DIR, " gallery" , string(be), " generated" )
831+ prefix = joinpath(BLD_DIR, " gallery" , string(be), " generated" * suffix )
839832 must_fix = needs_rng_fix[pkg]
840833 for file in Glob. glob(" */index.html" , prefix)
841834 (m = match(r" -ref(\d +)" , file)) ≡ nothing && continue
@@ -894,7 +887,7 @@ function main(args)
894887 root = @__DIR__,
895888 target = build,
896889 versions = [" stable" => " v^" , " v#.#" , " dev" => " dev" , " latest" => " dev" ],
897- # devbranch = BRANCH,
890+ devbranch = BRANCH,
898891 deploy_repo = " github.com/JuliaPlots/PlotDocs.jl" , # see https://documenter.juliadocs.org/stable/man/hosting/#Out-of-repo-deployment
899892 repo_previews = " github.com/JuliaPlots/PlotDocs.jl" ,
900893 push_preview = Base. get_bool_env(" PLOTDOCS_PUSH_PREVIEW" , false ),
0 commit comments