Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding uparrow as a predefined marker and creating unfilled markershapes #4977

Merged
merged 9 commits into from
Oct 9, 2024
4 changes: 4 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,10 @@
"name": "Penelope Yong",
"type": "Other"
},
{
"name": "Leon Becker",
"type": "Other"
},
{
"name": "Patrick Jaap",
"type": "Other"
Expand Down
8 changes: 8 additions & 0 deletions PlotsBase/ext/GRExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions PlotsBase/src/Commons/Commons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ using ..ColorTypes: alpha
using ..RecipesBase
using ..Statistics
using ..NaNMath
using ..Unzip
using ..Printf

const width = Measures.width
Expand Down
4 changes: 3 additions & 1 deletion PlotsBase/src/Commons/attrs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ const _styleAliases = Dict{Symbol,Symbol}(
const _shape_keys = Symbol[
:circle,
:rect,
:star5,
:diamond,
:hexagon,
:cross,
Expand All @@ -157,13 +156,16 @@ const _shape_keys = Symbol[
:heptagon,
:octagon,
:star4,
:star5,
:star6,
:star7,
:star8,
:vline,
:hline,
:+,
:x,
:uparrow,
:downarrow,
]

const _all_markers = vcat(:none, :auto, _shape_keys) # sort(collect(keys(_shapes))))
Expand Down
5 changes: 5 additions & 0 deletions PlotsBase/src/Shapes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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])
Expand Down
5 changes: 5 additions & 0 deletions PlotsBase/src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions PlotsBase/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion PlotsBase/test/test_animations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions PlotsBase/test/test_reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 0 additions & 19 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading