From 076de033fde711909cf2c48c1f6fc01193adf676 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 29 Mar 2020 15:39:44 +0200 Subject: [PATCH 1/4] fix `default` with axis args --- src/args.jl | 101 +++++++++++++++++++----------------------------- src/axes.jl | 3 ++ src/pipeline.jl | 10 +---- src/series.jl | 4 +- 4 files changed, 47 insertions(+), 71 deletions(-) diff --git a/src/args.jl b/src/args.jl index cebc5344..9a19211c 100644 --- a/src/args.jl +++ b/src/args.jl @@ -450,38 +450,33 @@ const _initial_fontsizes = Dict(:titlefontsize => _subplot_defaults[:titlefonts :tickfontsize => _axis_defaults[:tickfontsize], :guidefontsize => _axis_defaults[:guidefontsize]) -const _all_args = sort(collect(union(map(keys, _all_defaults)...))) - -is_subplot_attr(k) = haskey(_subplot_defaults, k) -is_series_attr(k) = haskey(_series_defaults, k) -#is_axis_attr(k) = haskey(_axis_defaults_byletter, k) -is_axis_attr(k) = haskey(_axis_defaults, Symbol(chop(string(k); head=1, tail=0))) -is_axis_attr_noletter(k) = haskey(_axis_defaults, k) - -RecipesBase.is_key_supported(k::Symbol) = is_attr_supported(k) - const _internal_args = [:plot_object, :series_plotindex, :markershape_to_add, :letter, :idxfilter] -const _magic_axis_args = [:axis, :tickfont, :guidefont] + +const _axis_args = sort(union(collect(keys(_axis_defaults)))) +const _series_args = sort(union(collect(keys(_series_defaults)))) +const _subplot_args = sort(union(collect(keys(_subplot_defaults)))) +const _plot_args = sort(union(collect(keys(_plot_defaults)))) + +const _magic_axis_args = [:axis, :tickfont, :guidefont, :grid, :minorgrid] const _magic_subplot_args = [:titlefont, :legendfont, :legendtitlefont, ] const _magic_series_args = [:line, :marker, :fill] -function is_noletter_attribute(k) - is_axis_attr_noletter(k) && return true - k in _magic_axis_args && return true - return false -end +const _all_axis_args = sort(union([_axis_args; _magic_axis_args])) +const _all_subplot_args = sort(union([_subplot_args; _magic_subplot_args])) +const _all_series_args = sort(union([_series_args; _magic_series_args])) +const _all_plot_args = _plot_args -function is_default_attribute(k) - k in _internal_args && return true - k in _all_args && return true - is_axis_attr(k) && return true - is_noletter_attribute(k) && return true - k in _magic_subplot_args && return true - k in _magic_series_args && return true - Symbol(chop(string(k); head = 1, tail = 0)) in _magic_axis_args && return true - return false -end +const _all_args = + sort([_all_axis_args; _all_subplot_args; _all_series_args; _all_plot_args]) + +is_subplot_attr(k) = k in _all_subplot_args +is_series_attr(k) = k in _all_series_args +is_axis_attr(k) = Symbol(chop(string(k); head=1, tail=0)) in _all_axis_args +is_axis_attr_noletter(k) = k in _all_axis_args + +RecipesBase.is_key_supported(k::Symbol) = is_attr_supported(k) +is_default_attribute(k) = k in _internal_args || k in _all_args || is_axis_attr_noletter(k) # ----------------------------------------------------------------------------- @@ -942,22 +937,6 @@ end function preprocessArgs!(plotattributes::AKW) replaceAliases!(plotattributes, _keyAliases) - # clear all axis stuff - # if haskey(plotattributes, :axis) && plotattributes[:axis] in (:none, nothing, false) - # plotattributes[:ticks] = nothing - # plotattributes[:foreground_color_border] = RGBA(0,0,0,0) - # plotattributes[:foreground_color_axis] = RGBA(0,0,0,0) - # plotattributes[:grid] = false - # delete!(plotattributes, :axis) - # end - # for letter in (:x, :y, :z) - # asym = Symbol(letter, :axis) - # if haskey(plotattributes, asym) || plotattributes[asym] in (:none, nothing, false) - # plotattributes[Symbol(letter, :ticks)] = nothing - # plotattributes[Symbol(letter, :foreground_color_border)] = RGBA(0,0,0,0) - # end - # end - # handle axis args common to all axis args = pop_kw!(plotattributes, :axis, ()) for arg in wraptuple(args) @@ -1015,13 +994,6 @@ function preprocessArgs!(plotattributes::AKW) processMinorGridArg!(plotattributes, arg, letter) end end - # fonts - for fontname in (:titlefont, :legendfont, :legendtitlefont) - args = pop_kw!(plotattributes, fontname, ()) - for arg in wraptuple(args) - processFontArg!(plotattributes, fontname, arg) - end - end # handle font args common to all axes for fontname in (:tickfont, :guidefont) args = pop_kw!(plotattributes, fontname, ()) @@ -1040,17 +1012,27 @@ function preprocessArgs!(plotattributes::AKW) end end end - # handle axes guides - if haskey(plotattributes, :guide) - guide = pop!(plotattributes, :guide) - for letter in (:x, :y, :z) - guide_sym = Symbol(letter, :guide) - if !is_explicit(plotattributes, guide_sym) - plotattributes[guide_sym] = guide + # handle axes args + for k in _axis_args + if haskey(plotattributes, k) + v = plotattributes[k] + for letter in (:x, :y, :z) + lk = Symbol(letter, k) + if !is_explicit(plotattributes, lk) + plotattributes[lk] = v + end end end end + # fonts + for fontname in (:titlefont, :legendfont, :legendtitlefont) + args = pop_kw!(plotattributes, fontname, ()) + for arg in wraptuple(args) + processFontArg!(plotattributes, fontname, arg) + end + end + # handle line args for arg in wraptuple(pop_kw!(plotattributes, :line, ())) processLineArg(plotattributes, arg) @@ -1504,12 +1486,9 @@ function _update_axis(plt::Plot, sp::Subplot, plotattributes_in::AKW, letter::Sy end function _update_axis(axis::Axis, plotattributes_in::AKW, letter::Symbol, subplot_index::Int) - # grab magic args (for example `xaxis = (:flip, :log)`) - args = wraptuple(get(plotattributes_in, Symbol(letter, :axis), ())) - # build the KW of arguments from the letter version (i.e. xticks --> ticks) kw = KW() - for k in keys(_axis_defaults) + for k in _all_axis_args # first get the args without the letter: `tickfont = font(10)` # note: we don't pop because we want this to apply to all axes! (delete after all have finished) if haskey(plotattributes_in, k) @@ -1524,7 +1503,7 @@ function _update_axis(axis::Axis, plotattributes_in::AKW, letter::Symbol, subplo end # update the axis - attr!(axis, args...; kw...) + attr!(axis; kw...) return end diff --git a/src/axes.jl b/src/axes.jl index 702ff5ba..822de875 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -84,6 +84,9 @@ function attr!(axis::Axis, args...; kw...) process_axis_arg!(plotattributes, arg) end + # then preprocess keyword arguments + preprocessArgs!(KW(kw)) + # then override for any keywords... only those keywords that already exists in plotattributes for (k,v) in kw if haskey(plotattributes, k) diff --git a/src/pipeline.jl b/src/pipeline.jl index ef846dd1..2659b74c 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -62,14 +62,8 @@ function _preprocess_args(plotattributes::AKW, args, still_to_process::Vector{Re # remove subplot and axis args from plotattributes... they will be passed through in the kw_list if !isempty(args) for (k,v) in plotattributes - for defdict in (_subplot_defaults, - _axis_defaults, - _axis_defaults_byletter[:x], - _axis_defaults_byletter[:y], - _axis_defaults_byletter[:z]) - if haskey(defdict, k) - reset_kw!(plotattributes, k) - end + if k in _all_subplot_args || k in _all_axis_args + reset_kw!(plotattributes, k) end end end diff --git a/src/series.jl b/src/series.jl index bbb49469..a2799d9e 100644 --- a/src/series.jl +++ b/src/series.jl @@ -227,7 +227,7 @@ _apply_type_recipe(plotattributes, v::AbstractArray{<:DataPoint}, letter) = v # axis args before type recipes should still be mapped to all axes function _preprocess_axis_args!(plotattributes) for (k, v) in plotattributes - if is_noletter_attribute(k) + if is_axis_attr_noletter(k) pop!(plotattributes, k) for l in (:x, :y, :z) lk = Symbol(l, k) @@ -246,7 +246,7 @@ function _postprocess_axis_args!(plotattributes, letter) pop!(plotattributes, :letter) if letter in (:x, :y, :z) for (k, v) in plotattributes - if is_noletter_attribute(k) + if is_axis_attr_noletter(k) pop!(plotattributes, k) lk = Symbol(letter, k) haskey(plotattributes, lk) || (plotattributes[lk] = v) From a5b6c27beca81bebba5c626058c65d0cf4040841 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 29 Mar 2020 16:25:23 +0200 Subject: [PATCH 2/4] add new test --- src/examples.jl | 30 ++++++++++++++++++++++++++++++ test/runtests.jl | 1 + 2 files changed, 31 insertions(+) diff --git a/src/examples.jl b/src/examples.jl index f17832a5..5ae70450 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -889,6 +889,36 @@ const _examples = PlotExample[ end, ], ), + PlotExample( + "Setting defaults and font arguments", + "", + [ + quote + begin + using Plots, LaTeXStrings + default( + titlefont = (20, "times"), + legendfontsize = 18, + guidefont = (18, :darkgreen), + tickfont = (12, :orange), + guide = L"x", + framestyle = :zerolines, + yminorgrid = true + ) + plot( + [sin, cos], + -2π, + 2π, + label = [L"sin(\theta)" L"cos(\theta)"], + title = "Trigonometric Functions", + xlabel = L"\theta", + linewidth = 2, + legend = :outertopleft, + ) + end + end, + ], + ), ] # Some constants for PlotDocs and PlotReferenceImages diff --git a/test/runtests.jl b/test/runtests.jl index 9b36f097..e5c74b58 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,6 +8,7 @@ using Gtk using LibGit2 using GeometryTypes using Dates +using LaTeXStrings include("test_hdf5plots.jl") include("test_pgfplotsx.jl") From 9243de6ce9055e1840707cc39ea7fd4c8a2a58d8 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 29 Mar 2020 17:00:57 +0200 Subject: [PATCH 3/4] add texlive-base --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a4ca0ed6..da45839a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ addons: packages: - at-spi2-core - libgtk-3-dev + - texlive-base - xauth - xvfb From 246632abca06eeb5a5688875d712a640c639bda2 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 29 Mar 2020 17:39:56 +0200 Subject: [PATCH 4/4] ok, don't use latex in tests --- .travis.yml | 4 +++- Project.toml | 3 +-- src/examples.jl | 8 ++++---- test/runtests.jl | 1 - 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index da45839a..abf00122 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,10 +17,12 @@ addons: packages: - at-spi2-core - libgtk-3-dev - - texlive-base - xauth - xvfb +env: + - GKS_ENCODING="utf8" + cache: directories: - $HOME/.julia/artifacts diff --git a/Project.toml b/Project.toml index 26d82018..1b164cc1 100644 --- a/Project.toml +++ b/Project.toml @@ -55,7 +55,6 @@ GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb" Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44" ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" -LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925" @@ -69,4 +68,4 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92" [targets] -test = ["FileIO", "GeometryTypes", "Gtk", "ImageMagick", "Images", "LaTeXStrings", "LibGit2", "OffsetArrays", "PGFPlotsX", "HDF5", "Random", "RDatasets", "StaticArrays", "StatsPlots", "Test", "UnicodePlots", "VisualRegressionTests"] +test = ["FileIO", "GeometryTypes", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "HDF5", "Random", "RDatasets", "StaticArrays", "StatsPlots", "Test", "UnicodePlots", "VisualRegressionTests"] diff --git a/src/examples.jl b/src/examples.jl index 5ae70450..a1592df8 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -895,13 +895,13 @@ const _examples = PlotExample[ [ quote begin - using Plots, LaTeXStrings + using Plots default( titlefont = (20, "times"), legendfontsize = 18, guidefont = (18, :darkgreen), tickfont = (12, :orange), - guide = L"x", + guide = "x", framestyle = :zerolines, yminorgrid = true ) @@ -909,9 +909,9 @@ const _examples = PlotExample[ [sin, cos], -2π, 2π, - label = [L"sin(\theta)" L"cos(\theta)"], + label = ["sin(θ)" "cos(θ)"], title = "Trigonometric Functions", - xlabel = L"\theta", + xlabel = "θ", linewidth = 2, legend = :outertopleft, ) diff --git a/test/runtests.jl b/test/runtests.jl index e5c74b58..9b36f097 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,7 +8,6 @@ using Gtk using LibGit2 using GeometryTypes using Dates -using LaTeXStrings include("test_hdf5plots.jl") include("test_pgfplotsx.jl")