From f137efb6c7e97032a9b8913d2159441a3878cf14 Mon Sep 17 00:00:00 2001 From: leckerbeon Date: Thu, 10 Oct 2024 01:35:29 +0200 Subject: [PATCH] Adding uparrow as a predefined marker and creating unfilled markershapes (#4977) * :uparrow and :downarrow markershapes are now defined as well as markercolor=nothing creates an unfilled open arrow shape * Changes to update markerstrokecolor * Added myself to .zenodo.json * add special :arrow markershape for sticks * improve arrowshape * update tests * fix custom markershapes * remove extensions from Plots project file --------- Co-authored-by: Simon Christ Co-authored-by: Simon Christ --- .zenodo.json | 4 ++++ PlotsBase/ext/GRExt.jl | 8 ++++++++ PlotsBase/src/Commons/Commons.jl | 1 + PlotsBase/src/Commons/attrs.jl | 4 +++- PlotsBase/src/Shapes.jl | 5 +++++ PlotsBase/src/recipes.jl | 5 +++++ PlotsBase/src/utils.jl | 4 ++-- PlotsBase/test/test_animations.jl | 2 +- PlotsBase/test/test_reference.jl | 4 ++-- Project.toml | 19 ------------------- 10 files changed, 31 insertions(+), 25 deletions(-) diff --git a/.zenodo.json b/.zenodo.json index 8362504a4..fec2e5ead 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -782,6 +782,10 @@ "name": "Penelope Yong", "type": "Other" }, + { + "name": "Leon Becker", + "type": "Other" + }, { "name": "Patrick Jaap", "type": "Other" diff --git a/PlotsBase/ext/GRExt.jl b/PlotsBase/ext/GRExt.jl index c354d17ce..86b9b0056 100644 --- a/PlotsBase/ext/GRExt.jl +++ b/PlotsBase/ext/GRExt.jl @@ -227,6 +227,7 @@ const gr_markertypes = ( vline = -30, hline = -31, ) +const gr_marker_keys = keys(gr_markertypes) const gr_haligns = ( left = GR.TEXT_HALIGN_LEFT, hcenter = GR.TEXT_HALIGN_CENTER, @@ -822,6 +823,9 @@ alignment(symb) = end # -------------------------------------------------------------------------------------- +function gr_get_markershape(s::Symbol) + s in gr_marker_keys ? s : Shape(s) +end function gr_set_gradient(c) grad = _as_gradient(c) @@ -1263,6 +1267,7 @@ function gr_add_legend(sp, leg, viewport_area) if (msh = series[:markershape]) ≢ :none msz = max(first(series[:markersize]), 0) + msh = gr_get_markershape.(msh) msw = max(first(series[:markerstrokewidth]), 0) mfac = 0.8 * lfps / (msz + 0.5 * msw + 1e-20) gr_draw_marker( @@ -2047,6 +2052,9 @@ function gr_draw_markers( ms = get_thickness_scaling(series) * _cycle(msize, i) msw = get_thickness_scaling(series) * _cycle(strokewidth, i) shape = _cycle(shapes, i) + if !(shape isa Shape) + shape = gr_get_markershape.(shape) + end for j ∈ rng gr_draw_marker( series, diff --git a/PlotsBase/src/Commons/Commons.jl b/PlotsBase/src/Commons/Commons.jl index 573953f9a..50dd564bf 100644 --- a/PlotsBase/src/Commons/Commons.jl +++ b/PlotsBase/src/Commons/Commons.jl @@ -61,6 +61,7 @@ using ..ColorTypes: alpha using ..RecipesBase using ..Statistics using ..NaNMath +using ..Unzip using ..Printf const width = Measures.width diff --git a/PlotsBase/src/Commons/attrs.jl b/PlotsBase/src/Commons/attrs.jl index 48da09c12..6b16d2c02 100644 --- a/PlotsBase/src/Commons/attrs.jl +++ b/PlotsBase/src/Commons/attrs.jl @@ -144,7 +144,6 @@ const _styleAliases = Dict{Symbol,Symbol}( const _shape_keys = Symbol[ :circle, :rect, - :star5, :diamond, :hexagon, :cross, @@ -157,6 +156,7 @@ const _shape_keys = Symbol[ :heptagon, :octagon, :star4, + :star5, :star6, :star7, :star8, @@ -164,6 +164,8 @@ const _shape_keys = Symbol[ :hline, :+, :x, + :uparrow, + :downarrow, ] const _all_markers = vcat(:none, :auto, _shape_keys) # sort(collect(keys(_shapes)))) diff --git a/PlotsBase/src/Shapes.jl b/PlotsBase/src/Shapes.jl index 1feef553e..7d5bd92aa 100644 --- a/PlotsBase/src/Shapes.jl +++ b/PlotsBase/src/Shapes.jl @@ -47,6 +47,9 @@ function Shape(x::AVec{X}, y::AVec{Y}) where {X,Y} return Shape(convert(Vector{X}, x), convert(Vector{Y}, y)) end +# make it broadcast like a scalar +Base.Broadcast.broadcastable(shape::Shape) = Ref(shape) + get_xs(shape::Shape) = shape.x get_ys(shape::Shape) = shape.y vertices(shape::Shape) = collect(zip(shape.x, shape.y)) @@ -135,6 +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)]), ) Shape(k::Symbol) = deepcopy(_shapes[k]) diff --git a/PlotsBase/src/recipes.jl b/PlotsBase/src/recipes.jl index 597977e0a..3e2db37c2 100644 --- a/PlotsBase/src/recipes.jl +++ b/PlotsBase/src/recipes.jl @@ -332,6 +332,11 @@ end if plotattributes[:markershape] ≢ :none primary := false @series begin + markershape := if plotattributes[:markershape] === :arrow + [isless(yi, 0.0) ? :downarrow : :uparrow for yi in y] + else + plotattributes[:markershape] + end seriestype := :scatter x := x y := y diff --git a/PlotsBase/src/utils.jl b/PlotsBase/src/utils.jl index fb266145e..ec24b35ae 100644 --- a/PlotsBase/src/utils.jl +++ b/PlotsBase/src/utils.jl @@ -108,9 +108,9 @@ 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(plotattributes[:markerstrokecolor], 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/test/test_animations.jl b/PlotsBase/test/test_animations.jl index ca22cf6db..a988ac3c9 100644 --- a/PlotsBase/test/test_animations.jl +++ b/PlotsBase/test/test_animations.jl @@ -54,7 +54,7 @@ end circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines) end when i % 5 == 0 fps = 10 - @test_throws LoadError macroexpand( + @test_throws ErrorException macroexpand( @__MODULE__, quote @gif for i ∈ 1:n diff --git a/PlotsBase/test/test_reference.jl b/PlotsBase/test/test_reference.jl index 4e3133af0..650add787 100644 --- a/PlotsBase/test/test_reference.jl +++ b/PlotsBase/test/test_reference.jl @@ -18,7 +18,7 @@ reference_dir(args...) = else joinpath(homedir(), ".julia", "dev", "PlotReferenceImages.jl", args...) end -reference_path(backend, version) = reference_dir("Plots", string(backend), string(version)) +reference_path(backend, version) = reference_dir("PlotsBase", string(backend), string(version)) function checkout_reference_dir(dn::AbstractString) mkpath(dn) @@ -54,7 +54,7 @@ end function reference_file(backend, version, i) # NOTE: keep ref[...].png naming consistent with `PlotDocs` - refdir = reference_dir("Plots", string(backend)) + refdir = mkpath(reference_dir("PlotsBase", string(backend))) fn = ref_name(i) * ".png" reffn = joinpath(refdir, string(version), fn) for ver ∈ sort(VersionNumber.(readdir(refdir)), rev = true) diff --git a/Project.toml b/Project.toml index 976ad1d92..e8d70b3e9 100644 --- a/Project.toml +++ b/Project.toml @@ -9,30 +9,11 @@ PlotsBase = "c52230a3-c5da-43a3-9e85-260fcdfdc737" PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" -[weakdeps] -FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" -GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" -IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" -ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" -Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" - -[extensions] -FileIOExt = "FileIO" -GeometryBasicsExt = "GeometryBasics" -IJuliaExt = "IJulia" -ImageInTerminalExt = "ImageInTerminal" -UnitfulExt = "Unitful" - [compat] -FileIO = "1" GR = "0.73, 1" -ImageInTerminal = "0.5" -GeometryBasics = "0.4" -IJulia = "1" PlotsBase = "0.1" PrecompileTools = "1" Reexport = "1" -Unitful = "1" julia = "1.10" [extras]