From b1ea6c81f61e2b0217d09f40485331c4ad91ebbf Mon Sep 17 00:00:00 2001 From: t-bltg Date: Tue, 12 Nov 2024 10:24:16 +0100 Subject: [PATCH] enhance cleanup of `tmp` files - format (#5022) --- .github/workflows/format_check.yml | 23 ++-- PlotThemes/src/PlotThemes.jl | 19 ++-- PlotThemes/src/boxed.jl | 37 ++++--- PlotThemes/src/dao.jl | 40 +++---- PlotThemes/src/dark.jl | 29 ++--- PlotThemes/src/dracula.jl | 26 ++--- PlotThemes/src/ggplot2.jl | 67 ++++++------ PlotThemes/src/gruvbox.jl | 144 +++++++++++++++---------- PlotThemes/src/juno.jl | 23 ++-- PlotThemes/src/lime.jl | 34 +++--- PlotThemes/src/orange.jl | 24 +++-- PlotThemes/src/rose_pine.jl | 40 +++---- PlotThemes/src/sand.jl | 22 ++-- PlotThemes/src/sheet.jl | 36 ++++--- PlotThemes/src/solarized.jl | 78 ++++++++------ PlotThemes/src/wong.jl | 40 ++++--- PlotsBase/ext/FileIOExt.jl | 5 + PlotsBase/ext/GRExt.jl | 4 +- PlotsBase/ext/GastonExt.jl | 4 +- PlotsBase/src/Commons/layouts.jl | 2 +- PlotsBase/src/DataSeries.jl | 2 +- PlotsBase/src/PlotsBase.jl | 2 - PlotsBase/src/Shapes.jl | 4 +- PlotsBase/src/animation.jl | 75 +++++++------ PlotsBase/src/examples.jl | 2 +- PlotsBase/src/recipes.jl | 2 +- PlotsBase/src/utils.jl | 9 +- PlotsBase/src/web.jl | 6 +- PlotsBase/test/test_reference.jl | 3 +- RecipesBase/src/RecipesBase.jl | 12 +-- RecipesBase/test/runtests.jl | 2 +- RecipesPipeline/src/RecipesPipeline.jl | 2 +- RecipesPipeline/src/api.jl | 10 +- RecipesPipeline/src/group.jl | 22 ++-- RecipesPipeline/src/plot_recipe.jl | 2 +- RecipesPipeline/src/series.jl | 8 +- RecipesPipeline/src/series_recipe.jl | 6 +- RecipesPipeline/src/user_recipe.jl | 4 +- RecipesPipeline/src/utils.jl | 14 +-- RecipesPipeline/test/test_group.jl | 8 +- src/Plots.jl | 12 ++- 41 files changed, 498 insertions(+), 406 deletions(-) diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index e97bcf6c4..337100005 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -16,27 +16,22 @@ jobs: steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@latest - - name: Install dependencies + - name: format Julia files run: | - using Pkg - Pkg.add("JuliaFormatter") - shell: julia --color=yes {0} - - - name: Format Julia files - run: | - using JuliaFormatter - format(["RecipesBase", "RecipesPipeline", "PlotsBase", "src", "test", "GraphRecipes", "StatsPlots"]) - shell: julia --color=yes --compile=min -O0 {0} - - - name: suggester / JuliaFormatter - if: success() && github.ref == 'refs/heads/master' + julia --color=yes --compile=min -O0 -e ' + using Pkg; Pkg.add("JuliaFormatter") + using JuliaFormatter + format(["RecipesBase", "RecipesPipeline", "PlotsBase", "src", "test", "GraphRecipes", "StatsPlots", "PlotThemes"]) + ' + - name: suggester + if: success() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/v2' ) uses: reviewdog/action-suggester@v1 with: tool_name: JuliaFormatter fail_on_error: true # reviewdog/action-suggester not using `cleanup` flag? - - name: Cleanup + - name: cleanup if: success() || failure() run: | git checkout -- . diff --git a/PlotThemes/src/PlotThemes.jl b/PlotThemes/src/PlotThemes.jl index f00cdc48b..8a5488f88 100644 --- a/PlotThemes/src/PlotThemes.jl +++ b/PlotThemes/src/PlotThemes.jl @@ -4,8 +4,8 @@ using PlotUtils export add_theme, theme_palette, PlotTheme -_255_to_1(c::Symbol, colors) = RGBA(map(x-> x/255,colors[c])...) -RGB255(r,g,b) = RGB(r/255, g/255, b/255) +_255_to_1(c::Symbol, colors) = RGBA(map(x -> x / 255, colors[c])...) +RGB255(r, g, b) = RGB(r / 255, g / 255, b / 255) function expand_palette(bg, cs; kwargs...) colors = palette(cs).colors.colors @@ -13,7 +13,7 @@ function expand_palette(bg, cs; kwargs...) return palette(c) end -const KW = Dict{Symbol, Any} +const KW = Dict{Symbol,Any} struct PlotTheme defaults::KW @@ -33,7 +33,6 @@ function theme_palette(s::Symbol) end end - # add themes include("dark.jl") include("ggplot2.jl") @@ -50,8 +49,7 @@ include("dao.jl") include("dracula.jl") include("rose_pine.jl") - -const _themes = Dict{Symbol, PlotTheme}([ +const _themes = Dict{Symbol,PlotTheme}([ :default => PlotTheme(), :dao => _dao, :dark => _dark, @@ -72,14 +70,9 @@ const _themes = Dict{Symbol, PlotTheme}([ :orange => _orange, :dracula => _dracula, :rose_pine => _rose_pine, - :rose_pine_dawn => _rose_pine_dawn - + :rose_pine_dawn => _rose_pine_dawn, ]) - -function add_theme(s::Symbol, thm::PlotTheme) - _themes[s] = thm -end - +add_theme(s::Symbol, thm::PlotTheme) = _themes[s] = thm end # module diff --git a/PlotThemes/src/boxed.jl b/PlotThemes/src/boxed.jl index 664febb48..cd1063f8e 100644 --- a/PlotThemes/src/boxed.jl +++ b/PlotThemes/src/boxed.jl @@ -1,16 +1,21 @@ -const _boxed = PlotTheme(Dict([ - :minorticks => true, - :grid => false, - :frame => :box, - :guidefontvalign => :top, - :guidefonthalign => :right, - :foreground_color_legend => nothing, - :legendfontsize => 9, - :legend => :topright, - :xlim => (:auto,:auto), - :ylim => (:auto,:auto), - :label => "", - :palette => expand_palette(colorant"white", [RGB(0,0,0); wong_palette]; - lchoices = [57], - cchoices = [100]) - ])) +const _boxed = PlotTheme( + Dict([ + :minorticks => true, + :grid => false, + :frame => :box, + :guidefontvalign => :top, + :guidefonthalign => :right, + :foreground_color_legend => nothing, + :legendfontsize => 9, + :legend => :topright, + :xlim => (:auto, :auto), + :ylim => (:auto, :auto), + :label => "", + :palette => expand_palette( + colorant"white", + [RGB(0, 0, 0); wong_palette]; + lchoices = [57], + cchoices = [100], + ), + ]), +) diff --git a/PlotThemes/src/dao.jl b/PlotThemes/src/dao.jl index c17cc01d0..816ee530c 100644 --- a/PlotThemes/src/dao.jl +++ b/PlotThemes/src/dao.jl @@ -4,25 +4,27 @@ const dao_palette = [ colorant"#707070", colorant"#21ab74", colorant"#ba3030", - colorant"#9467bd" + colorant"#9467bd", ] -const _dao = PlotTheme(Dict([ - :background => :white, - :framestyle => :box, - :grid => true, - :gridalpha => 0.4, - :linewidth => 1.4, - :markerstrokewidth => 0, - :fontfamily => "Computer Modern", - :colorgradient => :magma, - :guidefontsize => 12, - :titlefontsize => 12, - :tickfontsize => 8, - :palette => dao_palette, - :minorgrid => true, - :minorticks => 5, - :gridlinewidth => 0.7, - :minorgridalpha => 0.06, - :legend => :outertopright]) +const _dao = PlotTheme( + Dict([ + :background => :white, + :framestyle => :box, + :grid => true, + :gridalpha => 0.4, + :linewidth => 1.4, + :markerstrokewidth => 0, + :fontfamily => "Computer Modern", + :colorgradient => :magma, + :guidefontsize => 12, + :titlefontsize => 12, + :tickfontsize => 8, + :palette => dao_palette, + :minorgrid => true, + :minorticks => 5, + :gridlinewidth => 0.7, + :minorgridalpha => 0.06, + :legend => :outertopright, + ]), ) diff --git a/PlotThemes/src/dark.jl b/PlotThemes/src/dark.jl index 6946ece1b..22d2e4479 100644 --- a/PlotThemes/src/dark.jl +++ b/PlotThemes/src/dark.jl @@ -3,20 +3,23 @@ const dark_palette = [ colorant"#FE4365", # red colorant"#eca25c", # orange colorant"#3f9778", # green - colorant"#005D7F" # blue + colorant"#005D7F", # blue ] const dark_bg = colorant"#363D46" -const _dark = PlotTheme(Dict([ - :bg => dark_bg, - :bginside => colorant"#30343B", - :fg => colorant"#ADB2B7", - :fgtext => colorant"#FFFFFF", - :fgguide => colorant"#FFFFFF", - :fglegend => colorant"#FFFFFF", - :legendfontcolor => colorant"#FFFFFF", - :legendtitlefontcolor => colorant"#FFFFFF", - :titlefontcolor => colorant"#FFFFFF", - :palette => expand_palette(dark_bg, dark_palette; lchoices = [57], cchoices = [100]), - :colorgradient => :fire]) +const _dark = PlotTheme( + Dict([ + :bg => dark_bg, + :bginside => colorant"#30343B", + :fg => colorant"#ADB2B7", + :fgtext => colorant"#FFFFFF", + :fgguide => colorant"#FFFFFF", + :fglegend => colorant"#FFFFFF", + :legendfontcolor => colorant"#FFFFFF", + :legendtitlefontcolor => colorant"#FFFFFF", + :titlefontcolor => colorant"#FFFFFF", + :palette => + expand_palette(dark_bg, dark_palette; lchoices = [57], cchoices = [100]), + :colorgradient => :fire, + ]), ) diff --git a/PlotThemes/src/dracula.jl b/PlotThemes/src/dracula.jl index 1ea16ea87..a1ddd1422 100644 --- a/PlotThemes/src/dracula.jl +++ b/PlotThemes/src/dracula.jl @@ -13,16 +13,18 @@ const dracula_palette = [ const dracula_bg = colorant"#282a36" const dracula_fg = colorant"#f8f8f2" -const _dracula = PlotTheme(Dict([ - :bg => dracula_bg, - :bginside => colorant"#30343B", - :fg => dracula_fg, - :fgtext => dracula_fg, - :fgguide => dracula_fg, - :fglegend => dracula_fg, - :legendfontcolor => dracula_fg, - :legendtitlefontcolor => dracula_fg, - :titlefontcolor => dracula_fg, - :palette => expand_palette(dracula_bg, dracula_palette), - :colorgradient => :viridis]) +const _dracula = PlotTheme( + Dict([ + :bg => dracula_bg, + :bginside => colorant"#30343B", + :fg => dracula_fg, + :fgtext => dracula_fg, + :fgguide => dracula_fg, + :fglegend => dracula_fg, + :legendfontcolor => dracula_fg, + :legendtitlefontcolor => dracula_fg, + :titlefontcolor => dracula_fg, + :palette => expand_palette(dracula_bg, dracula_palette), + :colorgradient => :viridis, + ]), ) diff --git a/PlotThemes/src/ggplot2.jl b/PlotThemes/src/ggplot2.jl index a6856488c..36f989874 100644 --- a/PlotThemes/src/ggplot2.jl +++ b/PlotThemes/src/ggplot2.jl @@ -26,39 +26,40 @@ const _ggplot_colors = Dict( :gray92 => RGB(fill(0.92, 3)...), :gray20 => RGB(fill(0.2, 3)...), - :gray30 => RGB(fill(0.3, 3)...) - ) - + :gray30 => RGB(fill(0.3, 3)...), +) -const _ggplot2 = PlotTheme(Dict([ - ## Background etc - :bg => :white, - :bginside => _ggplot_colors[:gray92], - :bglegend => _ggplot_colors[:gray92], - :fglegend => :white, - :fgguide => :black, - :widen=>true, - ## Axes / Ticks - #framestyle => :grid, - #foreground_color_tick => _ggplot_colors[:gray20], # tick color not yet implemented - :foreground_color_axis => _ggplot_colors[:gray20], # tick color - :tick_direction=>:out, - :foreground_color_border =>:white, # axis color - :foreground_color_text => _ggplot_colors[:gray30], # tick labels - :gridlinewidth => 1, - #tick label size => *0.8, - ### Grid - :foreground_color_grid => :white, - :gridalpha => 1, - ### Minor Grid - :minorgrid => true, - :minorgridalpha => 1, - :minorgridlinewidth=>0.5, # * 0.5 - :foreground_color_minor_grid=>:white, - #foreground_color_minortick=>:white, ## not yet implemented - :minorticks => 2, - ## Lines and markers - :markerstrokealpha => 0, - :markerstrokewidth => 0 ]) +const _ggplot2 = PlotTheme( + Dict([ + ## Background etc + :bg => :white, + :bginside => _ggplot_colors[:gray92], + :bglegend => _ggplot_colors[:gray92], + :fglegend => :white, + :fgguide => :black, + :widen => true, + ## Axes / Ticks + #framestyle => :grid, + #foreground_color_tick => _ggplot_colors[:gray20], # tick color not yet implemented + :foreground_color_axis => _ggplot_colors[:gray20], # tick color + :tick_direction => :out, + :foreground_color_border => :white, # axis color + :foreground_color_text => _ggplot_colors[:gray30], # tick labels + :gridlinewidth => 1, + #tick label size => *0.8, + ### Grid + :foreground_color_grid => :white, + :gridalpha => 1, + ### Minor Grid + :minorgrid => true, + :minorgridalpha => 1, + :minorgridlinewidth => 0.5, # * 0.5 + :foreground_color_minor_grid => :white, + #foreground_color_minortick=>:white, ## not yet implemented + :minorticks => 2, + ## Lines and markers + :markerstrokealpha => 0, + :markerstrokewidth => 0, + ]), #showaxis=> :false ) diff --git a/PlotThemes/src/gruvbox.jl b/PlotThemes/src/gruvbox.jl index d822e2c1f..31de14616 100644 --- a/PlotThemes/src/gruvbox.jl +++ b/PlotThemes/src/gruvbox.jl @@ -1,68 +1,94 @@ # https://github.com/morhetz/gruvbox -const _gruvbox_dark_palette = (:bright_green, :bright_yellow, :bright_blue, :bright_aqua, :bright_purple, :bright_red, :bright_orange) +const _gruvbox_dark_palette = ( + :bright_green, + :bright_yellow, + :bright_blue, + :bright_aqua, + :bright_purple, + :bright_red, + :bright_orange, +) -const _gruvbox_light_palette = (:faded_green, :faded_yellow, :faded_blue, :faded_aqua, :faded_purple, :faded_red, :faded_orange) +const _gruvbox_light_palette = ( + :faded_green, + :faded_yellow, + :faded_blue, + :faded_aqua, + :faded_purple, + :faded_red, + :faded_orange, +) const _gruvbox_colors = Dict( - :dark0_hard => RGB255(29,32,33), - :dark0 => RGB255(40,40,40), - :dark0_soft => RGB255(50,48,47), - :dark1 => RGB255(60,56,54), - :dark2 => RGB255(80,73,69), - :dark3 => RGB255(102,92,84), - :dark4 => RGB255(124,111,100), - :dark4_256 => RGB255(124,111,100), - :gray_245 => RGB255(146,131,116), - :gray_244 => RGB255(146,131,116), - :light0_hard => RGB255(249,245,215), - :light0 => RGB255(253,244,193), - :light0_soft => RGB255(242,229,188), - :light1 => RGB255(235,219,178), - :light2 => RGB255(213,196,161), - :light3 => RGB255(189,174,147), - :light4 => RGB255(168,153,132), - :light4_256 => RGB255(168,153,132), - :bright_red => RGB255(251,73,52), - :bright_green => RGB255(184,187,38), - :bright_yellow => RGB255(250,189,47), - :bright_blue => RGB255(131,165,152), - :bright_purple => RGB255(211,134,155), - :bright_aqua => RGB255(142,192,124), - :bright_orange => RGB255(254,128,25), - :neutral_red => RGB255(204,36,29), - :neutral_green => RGB255(152,151,26), - :neutral_yellow => RGB255(215,153,33), - :neutral_blue => RGB255(69,133,136), - :neutral_purple => RGB255(177,98,134), - :neutral_aqua => RGB255(104,157,106), - :neutral_orange => RGB255(214,93,14), - :faded_red => RGB255(157,0,6), - :faded_green => RGB255(121,116,14), - :faded_yellow => RGB255(181,118,20), - :faded_blue => RGB255(7,102,120), - :faded_purple => RGB255(143,63,113), - :faded_aqua => RGB255(66,123,88), - :faded_orange => RGB255(175,58,3), + :dark0_hard => RGB255(29, 32, 33), + :dark0 => RGB255(40, 40, 40), + :dark0_soft => RGB255(50, 48, 47), + :dark1 => RGB255(60, 56, 54), + :dark2 => RGB255(80, 73, 69), + :dark3 => RGB255(102, 92, 84), + :dark4 => RGB255(124, 111, 100), + :dark4_256 => RGB255(124, 111, 100), + :gray_245 => RGB255(146, 131, 116), + :gray_244 => RGB255(146, 131, 116), + :light0_hard => RGB255(249, 245, 215), + :light0 => RGB255(253, 244, 193), + :light0_soft => RGB255(242, 229, 188), + :light1 => RGB255(235, 219, 178), + :light2 => RGB255(213, 196, 161), + :light3 => RGB255(189, 174, 147), + :light4 => RGB255(168, 153, 132), + :light4_256 => RGB255(168, 153, 132), + :bright_red => RGB255(251, 73, 52), + :bright_green => RGB255(184, 187, 38), + :bright_yellow => RGB255(250, 189, 47), + :bright_blue => RGB255(131, 165, 152), + :bright_purple => RGB255(211, 134, 155), + :bright_aqua => RGB255(142, 192, 124), + :bright_orange => RGB255(254, 128, 25), + :neutral_red => RGB255(204, 36, 29), + :neutral_green => RGB255(152, 151, 26), + :neutral_yellow => RGB255(215, 153, 33), + :neutral_blue => RGB255(69, 133, 136), + :neutral_purple => RGB255(177, 98, 134), + :neutral_aqua => RGB255(104, 157, 106), + :neutral_orange => RGB255(214, 93, 14), + :faded_red => RGB255(157, 0, 6), + :faded_green => RGB255(121, 116, 14), + :faded_yellow => RGB255(181, 118, 20), + :faded_blue => RGB255(7, 102, 120), + :faded_purple => RGB255(143, 63, 113), + :faded_aqua => RGB255(66, 123, 88), + :faded_orange => RGB255(175, 58, 3), ) -const _gruvbox_dark = PlotTheme(Dict([ - :bg => _gruvbox_colors[:dark2], - :bginside => _gruvbox_colors[:dark0], - :fg => _gruvbox_colors[:light3], - :fgtext => _gruvbox_colors[:light3], - :fgguide => _gruvbox_colors[:dark1], - :fglegend => _gruvbox_colors[:light3], - :palette => expand_palette(_gruvbox_colors[:dark3], [_gruvbox_colors[c] for c in _gruvbox_dark_palette]), - :colorgradient => cgrad(:YlOrRd, rev = true) ]) +const _gruvbox_dark = PlotTheme( + Dict([ + :bg => _gruvbox_colors[:dark2], + :bginside => _gruvbox_colors[:dark0], + :fg => _gruvbox_colors[:light3], + :fgtext => _gruvbox_colors[:light3], + :fgguide => _gruvbox_colors[:dark1], + :fglegend => _gruvbox_colors[:light3], + :palette => expand_palette( + _gruvbox_colors[:dark3], + [_gruvbox_colors[c] for c ∈ _gruvbox_dark_palette], + ), + :colorgradient => cgrad(:YlOrRd, rev = true), + ]), ) -const _gruvbox_light = PlotTheme(Dict([ - :bg => _gruvbox_colors[:light1], - :bginside => _gruvbox_colors[:light0], - :fg => _gruvbox_colors[:dark1], - :fgtext => _gruvbox_colors[:dark1], - :fgguide => _gruvbox_colors[:dark1], - :fglegend => _gruvbox_colors[:dark1], - :palette => expand_palette(_gruvbox_colors[:light3], [_gruvbox_colors[c] for c in _gruvbox_light_palette]), - :colorgradient => cgrad(:YlOrRd, rev = true) ]) +const _gruvbox_light = PlotTheme( + Dict([ + :bg => _gruvbox_colors[:light1], + :bginside => _gruvbox_colors[:light0], + :fg => _gruvbox_colors[:dark1], + :fgtext => _gruvbox_colors[:dark1], + :fgguide => _gruvbox_colors[:dark1], + :fglegend => _gruvbox_colors[:dark1], + :palette => expand_palette( + _gruvbox_colors[:light3], + [_gruvbox_colors[c] for c ∈ _gruvbox_light_palette], + ), + :colorgradient => cgrad(:YlOrRd, rev = true), + ]), ) diff --git a/PlotThemes/src/juno.jl b/PlotThemes/src/juno.jl index ddb36bd00..07ca2b233 100644 --- a/PlotThemes/src/juno.jl +++ b/PlotThemes/src/juno.jl @@ -3,18 +3,21 @@ const juno_palette = [ colorant"#FE4365", # red colorant"#eca25c", # orange colorant"#3f9778", # green - colorant"#005D7F" # blue + colorant"#005D7F", # blue ] const juno_bg = colorant"#282C34" -const _juno = PlotTheme(Dict([ - :bg => juno_bg, - :bginside => colorant"#21252B", - :fg => colorant"#ADB2B7", - :fgtext => colorant"#9EB1BE", - :fgguide => colorant"#9EB1BE", - :fglegend => colorant"#9EB1BE", - :palette => expand_palette(juno_bg, juno_palette; lchoices = [57], cchoices = [100]), - :colorgradient => :fire ]) +const _juno = PlotTheme( + Dict([ + :bg => juno_bg, + :bginside => colorant"#21252B", + :fg => colorant"#ADB2B7", + :fgtext => colorant"#9EB1BE", + :fgguide => colorant"#9EB1BE", + :fglegend => colorant"#9EB1BE", + :palette => + expand_palette(juno_bg, juno_palette; lchoices = [57], cchoices = [100]), + :colorgradient => :fire, + ]), ) diff --git a/PlotThemes/src/lime.jl b/PlotThemes/src/lime.jl index ba21d6bf0..48050d190 100644 --- a/PlotThemes/src/lime.jl +++ b/PlotThemes/src/lime.jl @@ -1,20 +1,24 @@ # a blue/green/yellow theme of no specific origin -const lime_palette = reverse([colorant"#271924", # dark blue - colorant"#394256", # semi dark blue - colorant"#30727F", # green blue - colorant"#36A58F", # turqoise - colorant"#80D584", # green, - colorant"#EBFB73"]) # yellow +const lime_palette = reverse([ + colorant"#271924", # dark blue + colorant"#394256", # semi dark blue + colorant"#30727F", # green blue + colorant"#36A58F", # turqoise + colorant"#80D584", # green, + colorant"#EBFB73", +]) # yellow const black = lime_palette[6] -const _lime = PlotTheme(Dict([ - :bg => black, - :bginside => black, - :fg => lime_palette[1], - :fgtext => lime_palette[2], - :fgguide => lime_palette[2], - :fglegend => lime_palette[2], - :palette => expand_palette(black, lime_palette[1:4]), - :colorgradient => :viridis]) +const _lime = PlotTheme( + Dict([ + :bg => black, + :bginside => black, + :fg => lime_palette[1], + :fgtext => lime_palette[2], + :fgguide => lime_palette[2], + :fglegend => lime_palette[2], + :palette => expand_palette(black, lime_palette[1:4]), + :colorgradient => :viridis, + ]), ) diff --git a/PlotThemes/src/orange.jl b/PlotThemes/src/orange.jl index c57df73fa..c358a3f01 100644 --- a/PlotThemes/src/orange.jl +++ b/PlotThemes/src/orange.jl @@ -1,21 +1,23 @@ #252634,#234B57,#207269,#4F9866,#9BB858,#FACF5A # a blue/green/yellow theme of no specific origin -const orange_palette = reverse([ +const orange_palette = reverse([ colorant"#271924", # dark blue colorant"#20545D", # semi dark blue colorant"#32856A", # green blue colorant"#86B15B", # green, - colorant"#FACF5A" # yellow + colorant"#FACF5A", # yellow ]) const _black = orange_palette[5] -const _orange = PlotTheme(Dict([ - :bg => _black, - :bginside => _black, - :fg => orange_palette[1], - :fgtext => orange_palette[2], - :fgguide => orange_palette[2], - :fglegend => orange_palette[2], - :palette => expand_palette(black, orange_palette[1:4]), - :colorgradient => :viridis]) +const _orange = PlotTheme( + Dict([ + :bg => _black, + :bginside => _black, + :fg => orange_palette[1], + :fgtext => orange_palette[2], + :fgguide => orange_palette[2], + :fglegend => orange_palette[2], + :palette => expand_palette(black, orange_palette[1:4]), + :colorgradient => :viridis, + ]), ) diff --git a/PlotThemes/src/rose_pine.jl b/PlotThemes/src/rose_pine.jl index b597560bf..c9519e494 100644 --- a/PlotThemes/src/rose_pine.jl +++ b/PlotThemes/src/rose_pine.jl @@ -11,15 +11,17 @@ const rose_pine_palette = [ const rose_pine_bg = colorant"#191724" -const _rose_pine = PlotTheme(Dict([ - :bg => rose_pine_bg, - :bginside => colorant"#1f1d2e", - :fg => colorant"#e0def4", - :fgtext => colorant"#e0def4", - :fgguide => colorant"#e0def4", - :fglegend => colorant"#e0def4", - :palette => expand_palette(rose_pine_bg, rose_pine_palette), - :colorgradient => cgrad(rose_pine_palette)]) +const _rose_pine = PlotTheme( + Dict([ + :bg => rose_pine_bg, + :bginside => colorant"#1f1d2e", + :fg => colorant"#e0def4", + :fgtext => colorant"#e0def4", + :fgguide => colorant"#e0def4", + :fglegend => colorant"#e0def4", + :palette => expand_palette(rose_pine_bg, rose_pine_palette), + :colorgradient => cgrad(rose_pine_palette), + ]), ) const rose_pine_dawn_palette = [ @@ -34,13 +36,15 @@ const rose_pine_dawn_palette = [ const rose_pine_dawn_bg = colorant"#faf4ed" -const _rose_pine_dawn = PlotTheme(Dict([ - :bg => rose_pine_dawn_bg, - :bginside => colorant"#fffaf3", - :fg => colorant"#575279", - :fgtext => colorant"#575279", - :fgguide => colorant"#575279", - :fglegend => colorant"#575279", - :palette => expand_palette(rose_pine_dawn_bg, rose_pine_dawn_palette), - :colorgradient => cgrad(rose_pine_dawn_palette)]) +const _rose_pine_dawn = PlotTheme( + Dict([ + :bg => rose_pine_dawn_bg, + :bginside => colorant"#fffaf3", + :fg => colorant"#575279", + :fgtext => colorant"#575279", + :fgguide => colorant"#575279", + :fglegend => colorant"#575279", + :palette => expand_palette(rose_pine_dawn_bg, rose_pine_dawn_palette), + :colorgradient => cgrad(rose_pine_dawn_palette), + ]), ) diff --git a/PlotThemes/src/sand.jl b/PlotThemes/src/sand.jl index cc3d2b9c6..f3071452d 100644 --- a/PlotThemes/src/sand.jl +++ b/PlotThemes/src/sand.jl @@ -5,18 +5,20 @@ const sand_palette = [ colorant"#E2C08D", # brown colorant"#FF6347", # red colorant"#2E2C29", # dark, - colorant"#4B4844" # medium + colorant"#4B4844", # medium ] const sand_bg = colorant"#F7F3EE" -const _sand = PlotTheme(Dict([ - :bg => sand_bg, - :bginside => colorant"#E2DCD4", - :fg => colorant"#CBBFAF", - :fgtext => colorant"#725B61", - :fgguide => colorant"#725B61", - :fglegend => colorant"#725B61", - :palette => expand_palette(sand_bg, sand_palette), - :colorgradient => :dense]) +const _sand = PlotTheme( + Dict([ + :bg => sand_bg, + :bginside => colorant"#E2DCD4", + :fg => colorant"#CBBFAF", + :fgtext => colorant"#725B61", + :fgguide => colorant"#725B61", + :fglegend => colorant"#725B61", + :palette => expand_palette(sand_bg, sand_palette), + :colorgradient => :dense, + ]), ) diff --git a/PlotThemes/src/sheet.jl b/PlotThemes/src/sheet.jl index a8456f81e..a9770795c 100644 --- a/PlotThemes/src/sheet.jl +++ b/PlotThemes/src/sheet.jl @@ -1,4 +1,4 @@ -const sheet_args = Dict{Symbol, Any}([ +const sheet_args = Dict{Symbol,Any}([ :fglegend => plot_color(colorant"#225", 0.1), :bglegend => plot_color(:white, 0.9), :gridcolor => colorant"#225", @@ -7,7 +7,8 @@ const sheet_args = Dict{Symbol, Any}([ :minorgrid => true, :linewidth => 1.2, :markersize => 6, - :markerstrokewidth => 0]) + :markerstrokewidth => 0, +]) #= NOTE ======================================================================== Colors are taken from https://personal.sron.nl/~pault/ @@ -56,10 +57,14 @@ const ylorbr_gradient = [ colorant"#46353a", ] -const _mute = PlotTheme(merge!(Dict{Symbol,Any}([ - :palette => mute_palette, - :colorgradient => reverse(ylorbr_gradient)]), - sheet_args) +const _mute = PlotTheme( + merge!( + Dict{Symbol,Any}([ + :palette => mute_palette, + :colorgradient => reverse(ylorbr_gradient), + ]), + sheet_args, + ), ) # ------------------------------------------------------------------------------ @@ -90,11 +95,8 @@ const sunset_gradient = [ colorant"#a50026", ] -const _vibrant = PlotTheme(; - palette = vibrant_palette, - colorgradient = sunset_gradient, - sheet_args... -) +const _vibrant = + PlotTheme(; palette = vibrant_palette, colorgradient = sunset_gradient, sheet_args...) # ------------------------------------------------------------------------------ # Bright @@ -122,8 +124,12 @@ const iridescent_gradient = [ colorant"#662506", ] -const _bright = PlotTheme(merge!(Dict{Symbol,Any}([ - :palette => bright_palette, - :colorgradient => reverse(iridescent_gradient)]), - sheet_args) +const _bright = PlotTheme( + merge!( + Dict{Symbol,Any}([ + :palette => bright_palette, + :colorgradient => reverse(iridescent_gradient), + ]), + sheet_args, + ), ) diff --git a/PlotThemes/src/solarized.jl b/PlotThemes/src/solarized.jl index fe1d0ba93..89ac9cfdb 100644 --- a/PlotThemes/src/solarized.jl +++ b/PlotThemes/src/solarized.jl @@ -2,42 +2,52 @@ const _solarized_palette = (:red, :yellow, :blue, :green, :orange, :magenta, :violet, :cyan) const _solarized_colors = Dict([ - :base03 => RGB255(0, 43, 54), - :base02 => RGB255(7, 54, 66), - :base01 => RGB255(88, 110, 117), - :base00 => RGB255(101, 123, 131), - :base0 => RGB255(131, 148, 150), - :base1 => RGB255(147, 161, 161), - :base2 => RGB255(238, 232, 213), - :base3 => RGB255(253, 246, 227), - :blue => RGB255(38, 139, 210), - :orange => RGB255(203, 75, 22), - :red => RGB255(220, 50, 47), - :green => RGB255(133, 153, 0), - :yellow => RGB255(181, 137, 0), - :magenta=> RGB255(211, 54, 130), - :violet => RGB255(108, 113, 196), - :cyan => RGB255(42, 161, 152) + :base03 => RGB255(0, 43, 54), + :base02 => RGB255(7, 54, 66), + :base01 => RGB255(88, 110, 117), + :base00 => RGB255(101, 123, 131), + :base0 => RGB255(131, 148, 150), + :base1 => RGB255(147, 161, 161), + :base2 => RGB255(238, 232, 213), + :base3 => RGB255(253, 246, 227), + :blue => RGB255(38, 139, 210), + :orange => RGB255(203, 75, 22), + :red => RGB255(220, 50, 47), + :green => RGB255(133, 153, 0), + :yellow => RGB255(181, 137, 0), + :magenta => RGB255(211, 54, 130), + :violet => RGB255(108, 113, 196), + :cyan => RGB255(42, 161, 152), ]) -const _solarized = PlotTheme(Dict([ - :bg => _solarized_colors[:base03], - :bginside => _solarized_colors[:base02], - :fg => _solarized_colors[:base00], - :fgtext => _solarized_colors[:base01], - :fgguide => _solarized_colors[:base01], - :fglegend => _solarized_colors[:base01], - :palette => expand_palette(_solarized_colors[:base03], [_solarized_colors[c] for c in _solarized_palette]), - :colorgradient => :YlOrRd]) +const _solarized = PlotTheme( + Dict([ + :bg => _solarized_colors[:base03], + :bginside => _solarized_colors[:base02], + :fg => _solarized_colors[:base00], + :fgtext => _solarized_colors[:base01], + :fgguide => _solarized_colors[:base01], + :fglegend => _solarized_colors[:base01], + :palette => expand_palette( + _solarized_colors[:base03], + [_solarized_colors[c] for c ∈ _solarized_palette], + ), + :colorgradient => :YlOrRd, + ]), ) -const _solarized_light = PlotTheme(Dict([ - :bg => _solarized_colors[:base3], - :bginside => _solarized_colors[:base2], - :fg => _solarized_colors[:base0], - :fgtext => _solarized_colors[:base1], - :fgguide => _solarized_colors[:base1], - :fglegend => _solarized_colors[:base1], - :palette => expand_palette(_solarized_colors[:base3], [_solarized_colors[c] for c in _solarized_palette]), - :colorgradient => cgrad(:YlOrRd, rev = true)]) +const _solarized_light = PlotTheme( + Dict([ + :bg => _solarized_colors[:base3], + :bginside => _solarized_colors[:base2], + :fg => _solarized_colors[:base0], + :fgtext => _solarized_colors[:base1], + :fgguide => _solarized_colors[:base1], + :fglegend => _solarized_colors[:base1], + :palette => expand_palette( + _solarized_colors[:base3], + [_solarized_colors[c] for c ∈ _solarized_palette], + ), + :colorgradient => cgrad(:YlOrRd, rev = true), + ]), ) diff --git a/PlotThemes/src/wong.jl b/PlotThemes/src/wong.jl index df3a956b7..5175aa1f7 100644 --- a/PlotThemes/src/wong.jl +++ b/PlotThemes/src/wong.jl @@ -1,21 +1,35 @@ # colors chosen by according to https://www.nature.com/articles/nmeth.1618?WT.ec_id=NMETH-201106 # as proposed by @tpoisot in https://github.com/JuliaPlots/Plots.jl/issues/1144 const wong_palette = [ - RGB(([230, 159, 0] / 255)...), # orange - RGB(([ 86, 180, 233] / 255)...), # sky blue - RGB(([ 0, 158, 115] / 255)...), # blueish green - RGB(([240, 228, 66] / 255)...), # yellow - RGB(([ 0, 114, 178] / 255)...), # blue - RGB(([213, 94, 0] / 255)...), # vermillion + RGB(([230, 159, 0] / 255)...), # orange + RGB(([86, 180, 233] / 255)...), # sky blue + RGB(([0, 158, 115] / 255)...), # blueish green + RGB(([240, 228, 66] / 255)...), # yellow + RGB(([0, 114, 178] / 255)...), # blue + RGB(([213, 94, 0] / 255)...), # vermillion RGB(([204, 121, 167] / 255)...), # reddish purple - ] +] -const _wong = PlotTheme(Dict([ - :palette => expand_palette(colorant"white", wong_palette; lchoices = [57], cchoices = [100]), - :colorgradient => cgrad(:viridis).colors]) +const _wong = PlotTheme( + Dict([ + :palette => expand_palette( + colorant"white", + wong_palette; + lchoices = [57], + cchoices = [100], + ), + :colorgradient => cgrad(:viridis).colors, + ]), ) -const _wong2 = PlotTheme(Dict([ - :palette => expand_palette(colorant"white", [RGB(0,0,0); wong_palette]; lchoices = [57], cchoices = [100]), - :colorgradient => :viridis]) +const _wong2 = PlotTheme( + Dict([ + :palette => expand_palette( + colorant"white", + [RGB(0, 0, 0); wong_palette]; + lchoices = [57], + cchoices = [100], + ), + :colorgradient => :viridis, + ]), ) diff --git a/PlotsBase/ext/FileIOExt.jl b/PlotsBase/ext/FileIOExt.jl index 19c022a49..ca5019c89 100644 --- a/PlotsBase/ext/FileIOExt.jl +++ b/PlotsBase/ext/FileIOExt.jl @@ -23,6 +23,11 @@ function _show_pdfbackends(io::IO, ::MIME"image/png", plt::Plot) # now write from the file write(io, read(open(pngfn), String)) + + # cleanup + rm("$fn.pdf") + rm("$fn.png") + nothing end # Possibly need to create another extension that has both pgfplotsx and showio diff --git a/PlotsBase/ext/GRExt.jl b/PlotsBase/ext/GRExt.jl index 9fb0294d7..a972fd50f 100644 --- a/PlotsBase/ext/GRExt.jl +++ b/PlotsBase/ext/GRExt.jl @@ -823,9 +823,7 @@ alignment(symb) = end # -------------------------------------------------------------------------------------- -function gr_get_markershape(s::Symbol) - s in gr_marker_keys ? s : Shape(s) -end +gr_get_markershape(s::Symbol) = s in gr_marker_keys ? s : Shape(s) function gr_set_gradient(c) grad = _as_gradient(c) diff --git a/PlotsBase/ext/GastonExt.jl b/PlotsBase/ext/GastonExt.jl index bf46e3f91..d3f17e56c 100644 --- a/PlotsBase/ext/GastonExt.jl +++ b/PlotsBase/ext/GastonExt.jl @@ -180,8 +180,8 @@ for (mime, term) ∈ ( ) @eval function PlotsBase._show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{GastonBackend}) term = String($term) - tmpfile = tempname() * ".$term" if plt.o ≢ nothing + tmpfile = tempname() * ".$term" ret = Gaston.save(; saveopts = gaston_saveopts(plt), handle = plt.o.handle, @@ -192,8 +192,8 @@ for (mime, term) ∈ ( while !isfile(tmpfile) end # avoid race condition with read in next line write(io, read(tmpfile)) - rm(tmpfile, force = true) end + isfile(tmpfile) && rm(tmpfile, force = true) end nothing end diff --git a/PlotsBase/src/Commons/layouts.jl b/PlotsBase/src/Commons/layouts.jl index e9b5d0647..aba10e409 100644 --- a/PlotsBase/src/Commons/layouts.jl +++ b/PlotsBase/src/Commons/layouts.jl @@ -150,7 +150,7 @@ function GridLayout( heights = zeros(dims[1]) end if widths ≢ nothing - sum(widths) ≈ 1 || error("The widths provided ($(widths)) must sum to 1.") + sum(widths) ≈ 1 || error("The widths provided ($(widths)) must sum to 1.") all_between_one(widths) || error("The widths provided ($(widths)) must be in the range (0, 1).") else diff --git a/PlotsBase/src/DataSeries.jl b/PlotsBase/src/DataSeries.jl index 507c05c6e..b6d0422d1 100644 --- a/PlotsBase/src/DataSeries.jl +++ b/PlotsBase/src/DataSeries.jl @@ -35,7 +35,7 @@ mutable struct Series end @recipe function f(s::Series) - for (k, v) in s.plotattributes + for (k, v) ∈ s.plotattributes k in (:subplot, :yerror, :xerror, :zerror) && continue plotattributes[k] = v end diff --git a/PlotsBase/src/PlotsBase.jl b/PlotsBase/src/PlotsBase.jl index d4f7995dc..9b3914601 100644 --- a/PlotsBase/src/PlotsBase.jl +++ b/PlotsBase/src/PlotsBase.jl @@ -165,7 +165,6 @@ include("users.jl") n = length(_examples) imports = sizehint!(Expr[], n) examples = sizehint!(Expr[], 10n) - scratch_dir = mktempdir() for i ∈ setdiff(1:n, _backend_skips[backend_name()], _animation_examples) _examples[i].external && continue (imp = _examples[i].imports) ≡ nothing || push!(imports, imp) @@ -174,7 +173,6 @@ include("users.jl") $func() = begin # evaluate each example in a local scope $(_examples[i].exprs) $i == 1 || return # trigger display only for one example - fn = joinpath(scratch_dir, tempname()) show(devnull, current()) nothing end diff --git a/PlotsBase/src/Shapes.jl b/PlotsBase/src/Shapes.jl index 7d5bd92aa..e00a68654 100644 --- a/PlotsBase/src/Shapes.jl +++ b/PlotsBase/src/Shapes.jl @@ -138,8 +138,8 @@ const _shapes = KW( :star6 => makestar(6), :star7 => makestar(7), :star8 => makestar(8), - :uparrow => Shape([(-1.3,-1), (0, 1.5), (0,-1.5), (0, 1.5), (1.3,-1)]), - :downarrow => Shape([(-1.3, 1), (0, -1.5), (0,1.5), (0, -1.5),(1.3, 1)]), + :uparrow => Shape([(-1.3, -1), (0, 1.5), (0, -1.5), (0, 1.5), (1.3, -1)]), + :downarrow => Shape([(-1.3, 1), (0, -1.5), (0, 1.5), (0, -1.5), (1.3, 1)]), ) Shape(k::Symbol) = deepcopy(_shapes[k]) diff --git a/PlotsBase/src/animation.jl b/PlotsBase/src/animation.jl index cdcec84d8..64fd3dcf1 100644 --- a/PlotsBase/src/animation.jl +++ b/PlotsBase/src/animation.jl @@ -13,6 +13,8 @@ struct Animation frames::Vector{String} end +const ANIM_PATTERN = "plots-anim-%06d.png" + Animation(dir = convert(String, mktempdir())) = Animation(dir, String[]) """ @@ -21,17 +23,23 @@ Animation(dir = convert(String, mktempdir())) = Animation(dir, String[]) Add a plot (the current plot if not specified) to an existing animation """ function frame(anim::Animation, plt::P = current()) where {P<:AbstractPlot} - i = length(anim.frames) + 1 - filename = @sprintf "%06d.png" i + filename = Printf.format(Printf.Format(ANIM_PATTERN), length(anim.frames) + 1) png(plt, joinpath(anim.dir, filename)) push!(anim.frames, filename) end -giffn() = isijulia() ? "tmp.gif" : tempname() * ".gif" -movfn() = isijulia() ? "tmp.mov" : tempname() * ".mov" -mp4fn() = isijulia() ? "tmp.mp4" : tempname() * ".mp4" -webmfn() = isijulia() ? "tmp.webm" : tempname() * ".webm" -apngfn() = isijulia() ? "tmp.png" : tempname() * ".png" +anim_filename(ext, parent = nothing) = + if isijulia() + "tmp" + else + tempname(parent ≡ nothing ? tempdir() : parent) + end * ext + +giffn(parent = nothing) = anim_filename(".gif", parent) +movfn(parent = nothing) = anim_filename(".mov", parent) +mp4fn(parent = nothing) = anim_filename(".mp4", parent) +webmfn(parent = nothing) = anim_filename(".webm", parent) +apngfn(parent = nothing) = anim_filename(".png", parent) mutable struct FrameIterator itr @@ -88,32 +96,34 @@ file_extension(fn) = Base.Filesystem.splitext(fn)[2][2:end] gif(animation[, filename]; fps=20, loop=0, variable_palette=false, verbose=false, show_msg=true) Creates an animated .gif-file from an `Animation` object. """ -gif(anim::Animation, fn = giffn(); kw...) = buildanimation(anim, fn; kw...) +gif(anim::Animation, fn = giffn(anim.dir); kw...) = build_animation(anim, fn; kw...) """ mov(animation[, filename]; fps=20, loop=0, verbose=false, show_msg=true) Creates an .mov-file from an `Animation` object. """ -mov(anim::Animation, fn = movfn(); kw...) = buildanimation(anim, fn, false; kw...) +mov(anim::Animation, fn = movfn(anim.dir); kw...) = build_animation(anim, fn, false; kw...) """ mp4(animation[, filename]; fps=20, loop=0, verbose=false, show_msg=true) Creates an .mp4-file from an `Animation` object. """ -mp4(anim::Animation, fn = mp4fn(); kw...) = buildanimation(anim, fn, false; kw...) +mp4(anim::Animation, fn = mp4fn(anim.dir); kw...) = build_animation(anim, fn, false; kw...) """ webm(animation[, filename]; fps=20, loop=0, verbose=false, show_msg=true) Creates an .webm-file from an `Animation` object. """ -webm(anim::Animation, fn = webmfn(); kw...) = buildanimation(anim, fn, false; kw...) +webm(anim::Animation, fn = webmfn(anim.dir); kw...) = + build_animation(anim, fn, false; kw...) """ apng(animation[, filename]; fps=20, loop=0, verbose=false, show_msg=true) Creates an animated .apng-file from an `Animation` object. """ -apng(anim::Animation, fn = apngfn(); kw...) = buildanimation(anim, fn, false; kw...) +apng(anim::Animation, fn = apngfn(anim.dir); kw...) = + build_animation(anim, fn, false; kw...) ffmpeg_framerate(fps) = "$fps" ffmpeg_framerate(fps::Rational) = "$(fps.num)/$(fps.den)" -function buildanimation( +function build_animation( anim::Animation, fn::AbstractString, is_animated_gif::Bool = true; @@ -126,30 +136,30 @@ function buildanimation( length(anim.frames) == 0 && throw(ArgumentError("Cannot build empty animations")) fn = abspath(expanduser(fn)) - animdir = anim.dir framerate = ffmpeg_framerate(fps) - verbose_level = (verbose isa Int ? verbose : verbose ? 32 : 16) # "error" - + verbose_level = (verbose isa Int ? verbose : verbose ? 32 : 16) # "error" + pattern = joinpath(anim.dir, ANIM_PATTERN) + palette = joinpath(anim.dir, "palette.bmp") if is_animated_gif if variable_palette # generate a colorpalette for each frame for highest quality, but larger filesize palette = "palettegen=stats_mode=single[pal],[0:v][pal]paletteuse=new=1" - `-v $verbose_level -framerate $framerate -i $animdir/%06d.png -lavfi "$palette" -loop $loop -y $fn` |> + `-v $verbose_level -framerate $framerate -i $pattern -lavfi "$palette" -loop $loop -y $fn` |> ffmpeg_exe else # generate a colorpalette first so ffmpeg does not have to guess it - `-v $verbose_level -i $animdir/%06d.png -vf "palettegen=stats_mode=full" -y "$animdir/palette.bmp"` |> + `-v $verbose_level -i $pattern -vf "palettegen=stats_mode=full" -y "$palette"` |> ffmpeg_exe # then apply the palette to get better results - `-v $verbose_level -framerate $framerate -i $animdir/%06d.png -i "$animdir/palette.bmp" -lavfi "paletteuse=dither=sierra2_4a" -loop $loop -y $fn` |> + `-v $verbose_level -framerate $framerate -i $pattern -i "$palette" -lavfi "paletteuse=dither=sierra2_4a" -loop $loop -y $fn` |> ffmpeg_exe end elseif file_extension(fn) in ("png", "apng") # FFMPEG specific command for APNG (Animated PNG) animations - `-v $verbose_level -framerate $framerate -i $animdir/%06d.png -plays $loop -f apng -y $fn` |> + `-v $verbose_level -framerate $framerate -i $pattern -plays $loop -f apng -y $fn` |> ffmpeg_exe else - `-v $verbose_level -framerate $framerate -i $animdir/%06d.png -vf format=yuv420p -loop $loop -y $fn` |> + `-v $verbose_level -framerate $framerate -i $pattern -vf format=yuv420p -loop $loop -y $fn` |> ffmpeg_exe end @@ -169,7 +179,6 @@ function Base.show(io::IO, ::MIME"text/html", agif::AnimatedGif) else error("Cannot show animation with extension $ext: $agif") end - write(io, html) nothing end @@ -199,7 +208,7 @@ function _animate(forloop::Expr, args...; type::Symbol = :none) freqassert = :() block = forloop.args[2] - animationsKwargs = Any[] + kw = Any[] filterexpr = true n = length(args) @@ -213,14 +222,14 @@ function _animate(forloop::Expr, args...; type::Symbol = :none) filterexpr == true || error("Can only specify one filterexpression (one of 'when' or 'every')") - filterexpr = # when every + filterexpr = # when every arg == :when ? args[i + 1] : :(mod1($countersym, $(args[i + 1])) == 1) i += 1 elseif arg isa Expr && arg.head == Symbol("=") - #specification of type = + # specification of type = lhs, rhs = arg.args - push!(animationsKwargs, :($lhs = $rhs)) + push!(kw, :($lhs = $rhs)) else error("Parameter specification not understood: $(arg)") end @@ -236,21 +245,21 @@ function _animate(forloop::Expr, args...; type::Symbol = :none) # add a final call to `gif(anim)`? retval = if type ≡ :gif - :(PlotsBase.gif($animsym; $(animationsKwargs...))) + :(PlotsBase.gif($animsym; $(kw...))) elseif type ≡ :apng - :(PlotsBase.apng($animsym; $(animationsKwargs...))) + :(PlotsBase.apng($animsym; $(kw...))) else animsym end # full expression: quote - $freqassert # if filtering, check frequency is an Integer > 0 - $animsym = PlotsBase.Animation() # init animation object - let $countersym = 1 # init iteration counter - $forloop # for loop, saving a frame after each iteration + $freqassert # if filtering, check frequency is an Integer > 0 + $animsym = PlotsBase.Animation() # init animation object + let $countersym = 1 # init iteration counter + $forloop # for loop, saving a frame after each iteration end - $retval # return the animation object, or the gif + $retval # return the animation object, or the gif end |> esc end diff --git a/PlotsBase/src/examples.jl b/PlotsBase/src/examples.jl index aa1d6e916..a72bcac0d 100644 --- a/PlotsBase/src/examples.jl +++ b/PlotsBase/src/examples.jl @@ -1313,7 +1313,7 @@ _backend_skips = Dict( ) _backend_skips[:plotly] = _backend_skips[:plotlyjs] # 25 and 30 require StatsPlots, which doesn't support Plots v2 yet -for backend in keys(_backend_skips) +for backend ∈ keys(_backend_skips) append!(_backend_skips[backend], [25, 30]) end diff --git a/PlotsBase/src/recipes.jl b/PlotsBase/src/recipes.jl index f054fd738..5647453d3 100644 --- a/PlotsBase/src/recipes.jl +++ b/PlotsBase/src/recipes.jl @@ -333,7 +333,7 @@ end primary := false @series begin markershape := if plotattributes[:markershape] === :arrow - [isless(yi, 0.0) ? :downarrow : :uparrow for yi in y] + [isless(yi, 0.0) ? :downarrow : :uparrow for yi ∈ y] else plotattributes[:markershape] end diff --git a/PlotsBase/src/utils.jl b/PlotsBase/src/utils.jl index 8884d31d8..ce078b5e5 100644 --- a/PlotsBase/src/utils.jl +++ b/PlotsBase/src/utils.jl @@ -106,9 +106,14 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) elseif plotattributes[:markerstrokecolor] ≡ :auto get_series_color(plotattributes[:markercolor], sp, plotIndex, stype) else - get_series_color(something(plotattributes[:markerstrokecolor], plotattributes[:seriescolor]), sp, plotIndex, stype) + get_series_color( + something(plotattributes[:markerstrokecolor], plotattributes[:seriescolor]), + sp, + plotIndex, + stype, + ) end - + # if marker_z, fill_z or line_z are set, ensure we have a gradient if plotattributes[:marker_z] ≢ nothing Commons.ensure_gradient!(plotattributes, :markercolor, :markeralpha) diff --git a/PlotsBase/src/web.jl b/PlotsBase/src/web.jl index 4197f1a94..2061e988c 100644 --- a/PlotsBase/src/web.jl +++ b/PlotsBase/src/web.jl @@ -68,6 +68,8 @@ function show_png_from_html(io::IO, plt::AbstractPlot) html_to_png(html_fn, png_fn, w, h) # now read that file data into io - pngdata = readall(png_fn) - write(io, pngdata) + write(io, readall(png_fn)) + rm(html_fn) + rm(png_fn) + nothing end diff --git a/PlotsBase/test/test_reference.jl b/PlotsBase/test/test_reference.jl index 650add787..2cc734ee2 100644 --- a/PlotsBase/test/test_reference.jl +++ b/PlotsBase/test/test_reference.jl @@ -18,7 +18,8 @@ reference_dir(args...) = else joinpath(homedir(), ".julia", "dev", "PlotReferenceImages.jl", args...) end -reference_path(backend, version) = reference_dir("PlotsBase", string(backend), string(version)) +reference_path(backend, version) = + reference_dir("PlotsBase", string(backend), string(version)) function checkout_reference_dir(dn::AbstractString) mkpath(dn) diff --git a/RecipesBase/src/RecipesBase.jl b/RecipesBase/src/RecipesBase.jl index aa5103caa..987bacc83 100644 --- a/RecipesBase/src/RecipesBase.jl +++ b/RecipesBase/src/RecipesBase.jl @@ -110,7 +110,7 @@ function create_kw_body(func_signature::Expr) kw_body, cleanup_body = map(_ -> Expr(:block), 1:2) arg1 = args[1] if isa(arg1, Expr) && arg1.head ≡ :parameters - for kwpair in arg1.args + for kwpair ∈ arg1.args k, v = kwpair.args if isa(k, Expr) && k.head ≡ :(::) k = k.args[1] @@ -143,13 +143,13 @@ end # and we push this block onto the series_blocks list. # then at the end we push the main body onto the series list function process_recipe_body!(expr::Expr) - for (i, e) in enumerate(expr.args) + for (i, e) ∈ enumerate(expr.args) if isa(e, Expr) # process trailing flags, like: # a --> b, :quiet, :force quiet, require, force = false, false, false if _is_arrow_tuple(e) - for flag in e.args + for flag ∈ e.args if _equals_symbol(flag, :quiet) quiet = true elseif _equals_symbol(flag, :require) @@ -506,9 +506,9 @@ function create_grid_vcat(expr::Expr) nr = length(expr.args) nc = rmin body = Expr(:block) - for r in 1:nr + for r ∈ 1:nr if (arg = expr.args[r]) |> isrow - for (c, item) in enumerate(arg.args) + for (c, item) ∈ enumerate(arg.args) push!(body.args, :(cell[$r, $c] = $(create_grid(item)))) end else @@ -535,7 +535,7 @@ end function create_grid_curly(expr::Expr) kw = KW() - for (i, arg) in enumerate(expr.args[2:end]) + for (i, arg) ∈ enumerate(expr.args[2:end]) add_layout_pct!(kw, arg, i, length(expr.args) - 1) end s = expr.args[1] diff --git a/RecipesBase/test/runtests.jl b/RecipesBase/test/runtests.jl index 2dae4af67..8dd467495 100644 --- a/RecipesBase/test/runtests.jl +++ b/RecipesBase/test/runtests.jl @@ -9,7 +9,7 @@ const KW = Dict{Symbol,Any} RB.is_key_supported(k::Symbol) = true -for t in map(i -> Symbol(:T, i), 1:5) +for t ∈ map(i -> Symbol(:T, i), 1:5) @eval struct $t end end diff --git a/RecipesPipeline/src/RecipesPipeline.jl b/RecipesPipeline/src/RecipesPipeline.jl index 2a2342cbb..38ffdadc0 100644 --- a/RecipesPipeline/src/RecipesPipeline.jl +++ b/RecipesPipeline/src/RecipesPipeline.jl @@ -127,7 +127,7 @@ using PrecompileTools mats = (Int[1 2; 3 4], Float64[1 2; 3 4]) surfs = Surface.(mats) vols = Volume(ones(Int, 1, 2, 3)), Volume(ones(Float64, 1, 2, 3)) - for pl_attrs in plotattributes + for pl_attrs ∈ plotattributes _series_data_vector(1, pl_attrs) _series_data_vector([1], pl_attrs) _series_data_vector(["a"], pl_attrs) diff --git a/RecipesPipeline/src/api.jl b/RecipesPipeline/src/api.jl index f79ee9a23..62df9d193 100644 --- a/RecipesPipeline/src/api.jl +++ b/RecipesPipeline/src/api.jl @@ -20,7 +20,7 @@ function warn_on_recipe_aliases!( recipe_type::Symbol, @nospecialize(args) ) - for x in v + for x ∈ v warn_on_recipe_aliases!(plt, x, recipe_type, args) end end @@ -55,7 +55,7 @@ Select the proper indices from `val` for attribute `key`. split_attribute(plt, key, val::AbstractArray, indices) = val[indices, fill(Colon(), ndims(val) - 1)...] split_attribute(plt, key, val::Tuple, indices) = - Tuple(split_attribute(plt, key, v, indices) for v in val) + Tuple(split_attribute(plt, key, v, indices) for v ∈ val) # ## Preprocessing attributes @@ -93,10 +93,10 @@ Preprocessing of axis attributes. Prepends the axis letter to axis attributes by default. """ function preprocess_axis_attrs!(plt, plotattributes) - for (k, v) in plotattributes + for (k, v) ∈ plotattributes is_axis_attribute(plt, k) || continue pop!(plotattributes, k) - for letter in (:x, :y, :z) + for letter ∈ (:x, :y, :z) get!(plotattributes, Symbol(letter, k), v) end end @@ -121,7 +121,7 @@ Removes the `:letter` key from `plotattributes` and does the same prepending of function postprocess_axis_attrs!(plt, plotattributes, letter) pop!(plotattributes, :letter) letter in (:x, :y, :z) || return - for (k, v) in plotattributes + for (k, v) ∈ plotattributes is_axis_attribute(plt, k) || continue pop!(plotattributes, k) get!(plotattributes, Symbol(letter, k), v) diff --git a/RecipesPipeline/src/group.jl b/RecipesPipeline/src/group.jl index 33d70f725..583ceff14 100644 --- a/RecipesPipeline/src/group.jl +++ b/RecipesPipeline/src/group.jl @@ -9,7 +9,7 @@ end # this is when given a vector-type of values to group by function _extract_group_attributes(v::AVec, args...; legend_entry = string) res = Dict{eltype(v),Vector{Int}}() - for (i, label) in enumerate(v) + for (i, label) ∈ enumerate(v) if haskey(res, label) push!(res[label], i) else @@ -31,7 +31,7 @@ function _extract_group_attributes(vs::Tuple, args...) end # allow passing NamedTuples for a named legend entry -legend_entry_from_tuple(ns::NamedTuple) = join(["$k = $v" for (k, v) in pairs(ns)], ", ") +legend_entry_from_tuple(ns::NamedTuple) = join(["$k = $v" for (k, v) ∈ pairs(ns)], ", ") function _extract_group_attributes(vs::NamedTuple, args...) isempty(vs) && return GroupBy([""], [axes(args[1], 1)]) @@ -42,7 +42,7 @@ end # expecting a mapping of "group label" to "group indices" function _extract_group_attributes(idxmap::Dict{T,V}, args...) where {T,V<:AVec{Int}} group_labels = (sort ∘ collect ∘ keys)(idxmap) - group_indices = Vector{Int}[collect(idxmap[k]) for k in group_labels] + group_indices = Vector{Int}[collect(idxmap[k]) for k ∈ group_labels] GroupBy(group_labels, group_indices) end @@ -50,7 +50,7 @@ filter_data(v::AVec, idxfilter::AVec{Int}) = v[idxfilter] filter_data(v, idxfilter) = v function filter_data!(plotattributes::AKW, idxfilter) - for s in (:x, :y, :z, :xerror, :yerror, :zerror) + for s ∈ (:x, :y, :z, :xerror, :yerror, :zerror) plotattributes[s] = filter_data(get(plotattributes, s, nothing), idxfilter) end end @@ -67,7 +67,7 @@ function groupedvec2mat(x_ind, x, y::AbstractArray, groupby, def_val = y[1]) length(groupby.group_labels), ) fill!(y_mat, def_val) - for i in eachindex(groupby.group_labels) + for i ∈ eachindex(groupby.group_labels) xi = x[groupby.group_indices[i]] yi = y[groupby.group_indices[i]] y_mat[getindex.(Ref(x_ind), xi), i] = yi @@ -76,7 +76,7 @@ function groupedvec2mat(x_ind, x, y::AbstractArray, groupby, def_val = y[1]) end groupedvec2mat(x_ind, x, y::Tuple, groupby) = - Tuple(groupedvec2mat(x_ind, x, v, groupby) for v in y) + Tuple(groupedvec2mat(x_ind, x, v, groupby) for v ∈ y) group_as_matrix(t) = false # used in `StatsPlots` @@ -85,11 +85,11 @@ group_as_matrix(t) = false # used in `StatsPlots` plt = plotattributes[:plot_object] group_length = maximum(union(groupby.group_indices...)) if !group_as_matrix(args[1]) - for (i, glab) in enumerate(groupby.group_labels) + for (i, glab) ∈ enumerate(groupby.group_labels) @series begin label --> string(glab) idxfilter --> groupby.group_indices[i] - for (key, val) in plotattributes + for (key, val) ∈ plotattributes if splittable_attribute(plt, key, val, group_length) :($key) := split_attribute(plt, key, val, groupby.group_indices[i]) end @@ -101,7 +101,7 @@ group_as_matrix(t) = false # used in `StatsPlots` g = args[1] if length(g.args) == 1 x = zeros(Int, group_length) - for indexes in groupby.group_indices + for indexes ∈ groupby.group_indices x[indexes] = eachindex(indexes) end last_attrs = g.args @@ -110,7 +110,7 @@ group_as_matrix(t) = false # used in `StatsPlots` end x_u = unique(sort(x)) x_ind = Dict(zip(x_u, eachindex(x_u))) - for (key, val) in plotattributes + for (key, val) ∈ plotattributes if splittable_attribute(plt, key, val, group_length) :($key) := groupedvec2mat(x_ind, x, val, groupby) end @@ -118,7 +118,7 @@ group_as_matrix(t) = false # used in `StatsPlots` label --> reshape(groupby.group_labels, 1, :) typeof(g)(( x_u, - (groupedvec2mat(x_ind, x, arg, groupby, NaN) for arg in last_attrs)..., + (groupedvec2mat(x_ind, x, arg, groupby, NaN) for arg ∈ last_attrs)..., )) end end diff --git a/RecipesPipeline/src/plot_recipe.jl b/RecipesPipeline/src/plot_recipe.jl index 8cddfbd70..97c490565 100644 --- a/RecipesPipeline/src/plot_recipe.jl +++ b/RecipesPipeline/src/plot_recipe.jl @@ -31,7 +31,7 @@ function _process_plotrecipe(plt, kw, kw_list, still_to_process) datalist = RecipesBase.apply_recipe(kw, Val{st}, plt) if !isnothing(datalist) warn_on_recipe_aliases!(plt, datalist, :plot, st) - for data in datalist + for data ∈ datalist preprocess_attributes!(plt, data.plotattributes) if data.plotattributes[:seriestype] == st error( diff --git a/RecipesPipeline/src/series.jl b/RecipesPipeline/src/series.jl index 08d7d40ec..29f222476 100644 --- a/RecipesPipeline/src/series.jl +++ b/RecipesPipeline/src/series.jl @@ -36,7 +36,7 @@ _prepare_series_data(v::Volume) = _series_data_vector(x, plotattributes) = [_prepare_series_data(x)] # fixed number of blank series -_series_data_vector(n::Integer, plotattributes) = [zeros(0) for i in 1:n] +_series_data_vector(n::Integer, plotattributes) = [zeros(0) for i ∈ 1:n] # vector of data points is a single series _series_data_vector(v::AVec{<:DataPoint}, plotattributes) = [_prepare_series_data(v)] @@ -48,7 +48,7 @@ function _series_data_vector(v::AVec, plotattributes) elseif all(x -> x isa MaybeString, v) _series_data_vector(Vector{MaybeString}(v), plotattributes) else - vcat((_series_data_vector(vi, plotattributes) for vi in v)...) + vcat((_series_data_vector(vi, plotattributes) for vi ∈ v)...) end end @@ -57,7 +57,7 @@ function _series_data_vector(v::AMat{<:DataPoint}, plotattributes) if is3d(plotattributes) [_prepare_series_data(Surface(v))] else - [_prepare_series_data(v[:, i]) for i in axes(v, 2)] + [_prepare_series_data(v[:, i]) for i ∈ axes(v, 2)] end end @@ -133,7 +133,7 @@ struct SliceIt end my = length(ys) mz = length(zs) if mx > 0 && my > 0 && mz > 0 - for i in 1:max(mx, my, mz) + for i ∈ 1:max(mx, my, mz) # add a new series di = copy(plotattributes) xi, yi, zi = xs[mod1(i, mx)], ys[mod1(i, my)], zs[mod1(i, mz)] diff --git a/RecipesPipeline/src/series_recipe.jl b/RecipesPipeline/src/series_recipe.jl index 5c770c3d3..b97763fb4 100644 --- a/RecipesPipeline/src/series_recipe.jl +++ b/RecipesPipeline/src/series_recipe.jl @@ -8,13 +8,13 @@ Recursively apply series recipes until the backend supports the seriestype """ function _process_seriesrecipes!(plt, kw_list) - for kw in kw_list + for kw ∈ kw_list # in series attributes given as vector with one element per series, # select the value for current series slice_series_attributes!(plt, kw_list, kw) end process_sliced_series_attributes!(plt, kw_list) - for kw in kw_list + for kw ∈ kw_list series_attrs = DefaultsDict(kw, series_defaults(plt)) # now we have a fully specified series, with colors chosen. we must recursively # handle series recipes, which dispatch on seriestype. If a backend does not @@ -51,7 +51,7 @@ function _process_seriesrecipe(plt, plotattributes) warn_on_recipe_aliases!(plt, datalist, :series, st) # assuming there was no error, recursively apply the series recipes - for data in datalist + for data ∈ datalist if isa(data, RecipeData) preprocess_attributes!(plt, data.plotattributes) if data.plotattributes[:seriestype] == st diff --git a/RecipesPipeline/src/user_recipe.jl b/RecipesPipeline/src/user_recipe.jl index be650cce6..9e38e299b 100644 --- a/RecipesPipeline/src/user_recipe.jl +++ b/RecipesPipeline/src/user_recipe.jl @@ -66,7 +66,7 @@ function _recipedata_vector(plt, plotattributes, args) # remove subplot and axis args from plotattributes... # they will be passed through in the kw_list - isempty(args) || for (k, v) in plotattributes + isempty(args) || for (k, v) ∈ plotattributes if is_subplot_attribute(plt, k) || is_axis_attribute(plt, k) reset_kw!(plotattributes, k) end @@ -81,7 +81,7 @@ function _expand_seriestype_array(plotattributes, args) if typeof(sts) <: AbstractArray reset_kw!(plotattributes, :seriestype) rd = Vector{RecipeData}(undef, size(sts, 1)) - for r in axes(sts, 1) + for r ∈ axes(sts, 1) dc = copy(plotattributes) dc[:seriestype] = sts[r:r, :] rd[r] = RecipeData(dc, args) diff --git a/RecipesPipeline/src/utils.jl b/RecipesPipeline/src/utils.jl index 682b91d01..b02ac17ad 100644 --- a/RecipesPipeline/src/utils.jl +++ b/RecipesPipeline/src/utils.jl @@ -81,11 +81,11 @@ struct Surface{M<:AMat} <: AbstractSurface surf::M end -Surface(f::Function, x, y) = Surface(Float64[f(xi, yi) for yi in y, xi in x]) +Surface(f::Function, x, y) = Surface(Float64[f(xi, yi) for yi ∈ y, xi ∈ x]) Base.Array(surf::Surface) = surf.surf -for f in (:length, :size, :axes, :iterate) +for f ∈ (:length, :size, :axes, :iterate) @eval Base.$f(surf::Surface, args...) = $f(surf.surf, args...) end Base.copy(surf::Surface) = Surface(copy(surf.surf)) @@ -110,7 +110,7 @@ function Volume( end Base.Array(vol::Volume) = vol.v -for f in (:length, :size, :axes, :iterate) +for f ∈ (:length, :size, :axes, :iterate) @eval Base.$f(vol::Volume, args...) = $f(vol.v, args...) end Base.copy(vol::Volume{T}) where {T} = @@ -138,7 +138,7 @@ end Returns `true` if `myseriestype` represents a 3D series, `false` otherwise. """ is3d(st) = false -for st in ( +for st ∈ ( :contour, :contourf, :contour3d, @@ -162,7 +162,7 @@ is3d(plotattributes::AbstractDict) = is3d(get(plotattributes, :seriestype, :path Returns `true` if `myseriestype` represents a surface series, `false` otherwise. """ is_surface(st) = false -for st in (:contour, :contourf, :contour3d, :image, :heatmap, :surface, :wireframe) +for st ∈ (:contour, :contourf, :contour3d, :image, :heatmap, :surface, :wireframe) @eval is_surface(::Type{Val{Symbol($(string(st)))}}) = true end is_surface(st::Symbol) = is_surface(Val{st}) @@ -175,7 +175,7 @@ is_surface(plotattributes::AbstractDict) = Returns `true` if `myseriestype` needs 3d axes, `false` otherwise. """ needs_3d_axes(st) = false -for st in (:contour3d, :path3d, :scatter3d, :surface, :volume, :wireframe, :mesh3d) +for st ∈ (:contour3d, :path3d, :scatter3d, :surface, :volume, :wireframe, :mesh3d) @eval needs_3d_axes(::Type{Val{Symbol($(string(st)))}}) = true end needs_3d_axes(st::Symbol) = needs_3d_axes(Val{st}) @@ -209,7 +209,7 @@ unzip(v::AVec{<:Tuple}) = map(x -> getfield.(v, x), fieldnames(eltype(v))) # -------------------------------- _map_funcs(f::Function, u::AVec) = map(f, u) -_map_funcs(fs::AVec{F}, u::AVec) where {F<:Function} = [map(f, u) for f in fs] +_map_funcs(fs::AVec{F}, u::AVec) where {F<:Function} = [map(f, u) for f ∈ fs] # -------------------------------- # ## Signature strings diff --git a/RecipesPipeline/test/test_group.jl b/RecipesPipeline/test/test_group.jl index 98bc58b3e..66f5b9528 100644 --- a/RecipesPipeline/test/test_group.jl +++ b/RecipesPipeline/test/test_group.jl @@ -6,7 +6,7 @@ function _extract_group_attributes_old_slow_known_good_implementation( group_labels = collect(unique(sort(v))) n = length(group_labels) group_indices = - Vector{Int}[filter(i -> v[i] == glab, eachindex(v)) for glab in group_labels] + Vector{Int}[filter(i -> v[i] == glab, eachindex(v)) for glab ∈ group_labels] RecipesPipeline.GroupBy(map(legend_entry, group_labels), group_indices) end @@ -49,12 +49,12 @@ lp = map(i -> "xx" * "$(i % 599)", 1:2_000) @testset "_filter_input_data!" begin filtered_keys = [:x, :y, :z, :xerror, :yerror, :zerror] - orig_akw = Dict{Symbol,Any}(k => rand(10) for k in filtered_keys) - orig_akw[:idxfilter] = [1,4,10] + orig_akw = Dict{Symbol,Any}(k => rand(10) for k ∈ filtered_keys) + orig_akw[:idxfilter] = [1, 4, 10] akw = deepcopy(orig_akw) RecipesPipeline._filter_input_data!(akw) - for k in filtered_keys + for k ∈ filtered_keys @test akw[k] == orig_akw[k][orig_akw[:idxfilter]] end end diff --git a/src/Plots.jl b/src/Plots.jl index 4a1a613e1..e25843b7d 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -57,17 +57,19 @@ if PlotsBase.DEFAULT_BACKEND == "gr" # FIXME: Creating a new global in closed m $func() = begin # evaluate each example in a local scope $(PlotsBase._examples[i].exprs) $i == 1 || return # trigger display only for one example - fn = joinpath(scratch_dir, tempname()) + fn = tempname(scratch_dir) pl = current() show(devnull, pl) - # FIXME: pgfplotsx requires bug - backend_name() ≡ :pgfplotsx && return if backend_name() ≡ :unicodeplots savefig(pl, "$fn.txt") return end - showable(MIME"image/png"(), pl) && savefig(pl, "$fn.png") - showable(MIME"application/pdf"(), pl) && savefig(pl, "$fn.pdf") + if showable(MIME"image/png"(), pl) + savefig(pl, "$fn.png") + end + if showable(MIME"application/pdf"(), pl) + savefig(pl, "$fn.pdf") + end if showable(MIME"image/svg+xml"(), pl) show(PipeBuffer(), MIME"image/svg+xml"(), pl) end