Skip to content

Commit

Permalink
Merge pull request #215 from KristofferC/fe/no-forward
Browse files Browse the repository at this point in the history
Make push! and append! return the original object
  • Loading branch information
tpapp authored Feb 12, 2020
2 parents e87e240 + baef596 commit a17a250
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PGFPlotsX"
uuid = "8314cec4-20b6-5062-9cdb-752b83310925"
version = "1.2.2"
version = "1.2.3"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
2 changes: 1 addition & 1 deletion src/PGFPlotsX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Dates
using DataStructures: OrderedDict
using DefaultApplication: DefaultApplication
using DocStringExtensions: SIGNATURES, TYPEDEF
using MacroTools: prewalk, @capture, @forward
using MacroTools: prewalk, @capture
using Parameters: @unpack
using Requires: @require
using StatsBase: midpoints
Expand Down
3 changes: 2 additions & 1 deletion src/axiselements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ end
Plot(is3d::Bool, incremental::Bool, options::Options, data::PlotData,
trailing::Tuple) = Plot(is3d, incremental, options, data, collect(trailing))

@forward Plot.trailing Base.push!, Base.append!
Base.push!(p::Plot, args...; kwargs...) = (push!(p.trailing, args...; kwargs...); p)
Base.append!(p::Plot, args...; kwargs...) = (append!(p.trailing, args...; kwargs...); p)

"""
Plot([options::Options], data, trailing...)
Expand Down
3 changes: 2 additions & 1 deletion src/axislike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Return the corresponding LaTeX environment name.
"""
function axislike_environment end

@forward AxisLike.contents Base.push!, Base.append!
Base.push!(a::AxisLike, args...; kwargs...) = (push!(a.contents, args...; kwargs...); a)
Base.append!(a::AxisLike, args...; kwargs...) = (append!(a.contents, args...; kwargs...); a)

(T::Type{<:AxisLike})(contents...) = T(Options(), contents...)

Expand Down
8 changes: 6 additions & 2 deletions src/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ When `print_empty = false` (the default), empty options are not printed. Use
Options(pairs::Pair...; print_empty::Bool = false) =
Options(OrderedDict(pairs), print_empty)

@forward Options.dict Base.getindex, Base.setindex!, Base.delete!
Base.getindex(o::Options, args...; kwargs...) = getindex(o.dict, args...; kwargs...)
Base.setindex!(o::Options, args...; kwargs...) = (setindex!(o.dict, args...; kwargs...); o)
Base.delete!(o::Options, args...; kwargs...) = (delete!(o.dict, args...; kwargs...); o)

Base.copy(options::Options) = deepcopy(options)

Expand Down Expand Up @@ -95,7 +97,9 @@ Subtypes have an `options::Options` field.
"""
abstract type OptionType end

@forward OptionType.options Base.getindex, Base.setindex!, Base.delete!
Base.getindex(o::OptionType, args...; kwargs...) = getindex(o.options, args...; kwargs...)
Base.setindex!(o::OptionType, args...; kwargs...) = (setindex!(o.options, args...; kwargs...); o)
Base.delete!(o::OptionType, args...; kwargs...) = (delete!(o.options, args...; kwargs...); o)

Base.copy(a::OptionType) = deepcopy(a)

Expand Down
3 changes: 2 additions & 1 deletion src/tikzdocument.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ struct TikzDocument
end
end

@forward TikzDocument.elements Base.push!, Base.append!
Base.push!(t::TikzDocument, args...; kwargs...) = (push!(t.elements, args...; kwargs...); t)
Base.append!(t::TikzDocument, args...; kwargs...) = (append!(t.elements, args...; kwargs...); t)

"""
$SIGNATURES
Expand Down
3 changes: 2 additions & 1 deletion src/tikzpicture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ end

TikzPicture(elements::TikzElementOrStr...) = TikzPicture(Options(), elements...)

@forward TikzPicture.elements Base.push!, Base.append!
Base.push!(t::TikzPicture, args...; kwargs...) = (push!(t.elements, args...; kwargs...); t)
Base.append!(t::TikzPicture, args...; kwargs...) = (append!(t.elements, args...; kwargs...); t)

function print_tex(io::IO, tp::TikzPicture)
@unpack options, elements = tp
Expand Down
16 changes: 8 additions & 8 deletions test/test_elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,20 @@ end

@testset "push! and append!" begin
plot = Plot(Expression("x"))
push!(plot, "a")
append!(plot, ["b", "c"])
push!(plot, "a")::Plot
append!(plot, ["b", "c"])::Plot
@test plot.trailing == ["a", "b", "c"]
axis = Axis()
push!(axis, plot)
append!(axis, ["non", "sense"])
push!(axis, plot)::Axis
append!(axis, ["non", "sense"])::Axis
@test axis.contents == [plot, "non", "sense"]
picture = TikzPicture()
push!(picture, axis)
append!(picture, ["some", "thing"])
push!(picture, axis)::TikzPicture
append!(picture, ["some", "thing"])::TikzPicture
@test picture.elements == [axis, "some", "thing"]
document = TikzDocument()
push!(document, picture)
append!(document, ["stuff"])
push!(document, picture)::TikzDocument
append!(document, ["stuff"])::TikzDocument
@test document.elements == [picture, "stuff"]
end

Expand Down
4 changes: 2 additions & 2 deletions test/test_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ end
@testset "options push! and append!" begin
opt1 = "color" => "red"
opt2 = "dashed"
@test @pgf(push!({}, opt1, opt2)).dict == Dict([opt1, opt2 => nothing])
@test @pgf(append!({}, [opt1, opt2])).dict == Dict([opt1, opt2 => nothing])
@test @pgf(push!({}, opt1, opt2)::Options).dict == Dict([opt1, opt2 => nothing])
@test @pgf(append!({}, [opt1, opt2])::Options).dict == Dict([opt1, opt2 => nothing])
end

2 comments on commit a17a250

@tpapp
Copy link
Collaborator Author

@tpapp tpapp commented on a17a250 Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/9355

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.3 -m "<description of version>" a17a25059ac6e93a395abb68ee7ee6289309c19a
git push origin v1.2.3

Please sign in to comment.