update tests

This commit is contained in:
Simon Christ 2019-11-20 15:20:33 +01:00
parent faf905a932
commit a2bdc4c3ef
2 changed files with 16 additions and 13 deletions

View File

@ -5,6 +5,8 @@ Base.@kwdef mutable struct PGFPlotsXPlot
the_plot::PGFPlotsX.TikzDocument = PGFPlotsX.TikzDocument() the_plot::PGFPlotsX.TikzDocument = PGFPlotsX.TikzDocument()
end end
pgfx_axes(pgfx_plot::PGFPlotsXPlot) = pgfx_plot.the_plot.elements[1].elements[1].contents
function Base.show(io::IO, mime::MIME, pgfx_plot::PGFPlotsXPlot) function Base.show(io::IO, mime::MIME, pgfx_plot::PGFPlotsXPlot)
show(io::IO, mime, pgfx_plot.the_plot) show(io::IO, mime, pgfx_plot.the_plot)
end end
@ -31,7 +33,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
a = alpha(cstr) a = alpha(cstr)
title_cstr = plot_color(sp[:titlefontcolor]) title_cstr = plot_color(sp[:titlefontcolor])
title_a = alpha(cstr) title_a = alpha(cstr)
# TODO: aspect ratio
axis_opt = PGFPlotsX.Options( axis_opt = PGFPlotsX.Options(
"height" => string(height(bb)), "height" => string(height(bb)),
"width" => string(width(bb)), "width" => string(width(bb)),
@ -575,7 +576,7 @@ end
function _show(io::IO, mime::MIME"application/x-tex", plt::Plot{PGFPlotsXBackend}) function _show(io::IO, mime::MIME"application/x-tex", plt::Plot{PGFPlotsXBackend})
_update_plot_object(plt) _update_plot_object(plt)
PGFPlotsX.print_tex(plt.o) PGFPlotsX.print_tex(plt.o.the_plot)
end end
function _display(plt::Plot{PGFPlotsXBackend}) function _display(plt::Plot{PGFPlotsXBackend})

View File

@ -12,34 +12,37 @@ function create_plot!( args...; kwargs... )
end end
@testset "PGFPlotsX" begin @testset "PGFPlotsX" begin
pgfx_plot, pgfx_tex = create_plot(1:5) pgfx_plot = plot(1:5)
Plots._update_plot_object(pgfx_plot)
@test pgfx_plot.o.the_plot isa PGFPlotsX.TikzDocument
@test pgfx_plot.o isa PGFPlotsX.GroupPlot @testset "3D docs example" begin
@testset "3D docs example" begin
n = 100 n = 100
ts = range(0, stop=8π, length=n) ts = range(0, stop=8π, length=n)
x = ts .* map(cos, ts) x = ts .* map(cos, ts)
y = (0.1ts) .* map(sin, ts) y = (0.1ts) .* map(sin, ts)
z = 1:n z = 1:n
pl = plot(x, y, z, zcolor=reverse(z), m=(10, 0.8, :blues, Plots.stroke(0)), leg=false, cbar=true, w=5) pl = plot(x, y, z, zcolor=reverse(z), m=(10, 0.8, :blues, Plots.stroke(0)), leg=false, cbar=true, w=5)
pgfx_plot, pgfx_tex = create_plot!(pl, zeros(n), zeros(n), 1:n, w=10) pgfx_plot = plot!(pl, zeros(n), zeros(n), 1:n, w=10)
if @test_nowarn(haskey(pgfx_plot.o.contents[1].options.dict, "colorbar") == true) Plots._update_plot_object(pgfx_plot)
@test pgfx_plot.o.contents[1]["colorbar"] === nothing if @test_nowarn(haskey(Plots.pgfx_axes(pgfx_plot.o)[1].options.dict, "colorbar") == true)
@test Plots.pgfx_axes(pgfx_plot.o)[1]["colorbar"] === nothing
end end
end # testset end # testset
@testset "Color docs example" begin @testset "Color docs example" begin
y = rand(100) y = rand(100)
plot(0:10:100, rand(11, 4), lab="lines", w=3, palette=:grays, fill=0, α=0.6) plot(0:10:100, rand(11, 4), lab="lines", w=3, palette=:grays, fill=0, α=0.6)
scatter!(y, zcolor=abs.(y .- 0.5), m=(:heat, 0.8, Plots.stroke(1, :green)), ms=10 * abs.(y .- 0.5) .+ 4, lab="grad") pl = scatter!(y, zcolor=abs.(y .- 0.5), m=(:heat, 0.8, Plots.stroke(1, :green)), ms=10 * abs.(y .- 0.5) .+ 4, lab="grad")
Plots._update_plot_object(pl)
axis = Plots.pgfx_axes(pl.o)[1]
@test count( x->x isa PGFPlotsX.LegendEntry, axis.contents ) == 5
@test count( x->x isa PGFPlotsX.Plot, axis.contents ) == 5
# TODO: marker size does not adjust # TODO: marker size does not adjust
# TODO: marker stroke is incorrect # TODO: marker stroke is incorrect
# TODO: fill legends
# TODO: adjust colorbar limits to data
end # testset end # testset
@testset "Plot in pieces" begin @testset "Plot in pieces" begin
plot(rand(100) / 3, reg=true, fill=(0, :green)) plot(rand(100) / 3, reg=true, fill=(0, :green))
scatter!(rand(100), markersize=6, c=:orange) scatter!(rand(100), markersize=6, c=:orange)
# TODO: legends should be different
end # testset end # testset
@testset "Marker types" begin @testset "Marker types" begin
markers = filter((m->begin markers = filter((m->begin
@ -50,7 +53,6 @@ end
x = (range(0, stop=10, length=n + 2))[2:end - 1] x = (range(0, stop=10, length=n + 2))[2:end - 1]
y = repeat(reshape(reverse(x), 1, :), n, 1) y = repeat(reshape(reverse(x), 1, :), n, 1)
scatter(x, y, m=(8, :auto), lab=map(string, markers), bg=:linen, xlim=(0, 10), ylim=(0, 10)) scatter(x, y, m=(8, :auto), lab=map(string, markers), bg=:linen, xlim=(0, 10), ylim=(0, 10))
#TODO: fix markers that show up as circles
end # testset end # testset
@testset "Layout" begin @testset "Layout" begin
plot(Plots.fakedata(100, 10), layout=4, palette=[:grays :blues :heat :lightrainbow], bg_inside=[:orange :pink :darkblue :black]) plot(Plots.fakedata(100, 10), layout=4, palette=[:grays :blues :heat :lightrainbow], bg_inside=[:orange :pink :darkblue :black])