Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #469 from JuliaPlots/sd/rng_tests
Browse files Browse the repository at this point in the history
rng tests
  • Loading branch information
SimonDanisch authored Jul 11, 2020
2 parents 5f7ef01 + 9a41e14 commit 46d50f5
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 125 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ GeometryBasics = "0.2.6"
GridLayoutBase = "0.3"
ImageIO = "0.2"
IntervalSets = "0.3, 0.4, 0.5"
MakieGallery = "0.2.9"
MakieGallery = "0.2.13"
Match = "1.1"
Observables = "0.3.1"
Packing = "0.4"
Expand Down
1 change: 1 addition & 0 deletions src/AbstractPlotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ include("camera/camera3d.jl")
include("basic_recipes/basic_recipes.jl")
include("basic_recipes/multiple.jl")
include("basic_recipes/errorbars.jl")
include("basic_recipes/pie.jl")
# layouting of plots
include("layouting/transformation.jl")
include("layouting/data_limits.jl")
Expand Down
61 changes: 61 additions & 0 deletions src/basic_recipes/pie.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@recipe(Pie, values) do scene
Theme(
normalize = true,
color = :gray,
strokecolor = :black,
strokewidth = 1,
vertex_per_deg = 1,
radius = 1,
inner_radius = 0,
offset = 0,
)
end

function plot!(plot::Pie)

values = plot[1]

polys = lift(values, plot.vertex_per_deg, plot.radius, plot.inner_radius, plot.offset, plot.normalize) do vals, vertex_per_deg, radius, inner_radius, offset, normalize

T = eltype(vals)

# find start and end angles of all pie pieces
summed = cumsum([zero(T); vals])
boundaries = if normalize
summed ./ summed[end] .* 2pi
else
summed
end

# create vector of a vector of points for each piece
vertex_arrays = map(boundaries[1:end-1], boundaries[2:end]) do sta, en
distance = en - sta
# how many vertices are needed for the curve?
nvertices = max(2, ceil(Int, rad2deg(distance) * vertex_per_deg))

# curve points
points = map(LinRange(sta, en, nvertices)) do rad
Point2f0(cos(rad + offset), sin(rad + offset)) .* radius
end

# add inner points (either curve or one point)
if inner_radius != 0
inner_points = map(LinRange(en, sta, nvertices)) do rad
Point2f0(cos(rad + offset), sin(rad + offset)) .* inner_radius
end

append!(points, inner_points)
else
push!(points, Point2f0(0, 0))
end

points
end
end

# plot pieces as polys
poly!(plot, polys, color = plot.color, strokewidth = plot.strokewidth,
strokecolor = plot.strokecolor)

plot
end
10 changes: 5 additions & 5 deletions src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ $(ATTRIBUTES)
@recipe(Scatter, positions) do scene
Attributes(;
default_theme(scene)...,
color = :black,
color = :gray65,
colormap = :viridis,
marker = Circle,
markersize = 0.1,
markersize = 10,

strokecolor = RGBA(0, 0, 0, 0),
strokewidth = 0.0,
strokecolor = :black,
strokewidth = 1.0,
glowcolor = RGBA(0, 0, 0, 0),
glowwidth = 0.0,

Expand All @@ -215,7 +215,7 @@ $(ATTRIBUTES)
transform_marker = false, # Applies the plots transformation to marker
uv_offset_width = Vec4f0(0),
distancefield = nothing,
markerspace = automatic,
markerspace = Pixel,
fxaa = false,
)
end
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/quaternions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function Base.show(io::IO, q::Quaternion)
print(io, q[4], pm(q[1]), "im", pm(q[2]), "jm", pm(q[3]), "km")
end

Random.rand(mt::MersenneTwister, ::Random.SamplerType{Quaternion}) = rand(mt, Quaternion{Float64})
Random.rand(mt::MersenneTwister, ::Random.SamplerType{Quaternion{T}}) where T = Quaternion(rand(mt, T), rand(mt, T), rand(mt, T), 1.0)
Random.rand(mt::AbstractRNG, ::Random.SamplerType{Quaternion}) = rand(mt, Quaternion{Float64})
Random.rand(mt::AbstractRNG, ::Random.SamplerType{Quaternion{T}}) where T = Quaternion(rand(mt, T), rand(mt, T), rand(mt, T), 1.0)

Quaternion{T}(x1, x2, x3, s) where T = Quaternion{T}((x1, x2, x3, s))
Base.convert(T::Type{<: Quaternion}, x::NTuple{4, Any}) = T(x)
Expand Down
8 changes: 4 additions & 4 deletions test/glmakie_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ database = MakieGallery.load_database(joinpath.(example_dir, readdir(example_dir
examples = MakieGallery.record_examples(test_record_path);

@test length(examples) == length(database)

# Download test images manually, so we can specify the folder
# TODO, refactor makiegallery
path = MakieGallery.download_reference("v0.6.0")
#
# # Download test images manually, so we can specify the folder
# # TODO, refactor makiegallery
path = MakieGallery.download_reference("v0.6.3")

MakieGallery.run_comparison(test_record_path, tested_diff_path, joinpath(dirname(path), "test_recordings"))
2 changes: 1 addition & 1 deletion test/quaternions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# @test angle(qrotation([0, 0, 1], pi / 2)) ≈ pi / 2
#
# let # test numerical stability of angle
# ax = randn(3)
# ax = RNG.randn(3)
# for θ in [1e-9, π - 1e-9]
# q = qrotation(ax, θ)
# @test angle(q) ≈ θ
Expand Down
12 changes: 6 additions & 6 deletions test/reference_image_tests/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


@cell "align" [scatter, text, align, "2d"] begin
scene = scatter(rand(10), color=:red)
scene = scatter(RNG.rand(10), color=:red)
text!(scene,"adding text",textsize = 0.6, align = (:center, :center))
end

Expand All @@ -15,12 +15,12 @@

@cell "font" [text, scatter, font, "2d"] begin
scene = Scene()
scatter!(scene, rand(10), color=:red)
scatter!(scene, RNG.rand(10), color=:red)
text!(scene,"adding text",textsize = 0.6, align = (:center, :center), font = "Blackchancery")
end

@cell "glowcolor, glowwidth" [scatter, glowcolor, glowwidth, "2d"] begin
scatter(randn(10),color=:blue, glowcolor = :orange, glowwidth = 10)
scatter(RNG.randn(10),color=:blue, glowcolor = :orange, glowwidth = 10)
end

@cell "isorange, isovalue" [volume, algorithm, isorange, isovalue] begin
Expand All @@ -39,7 +39,7 @@

@cell "position" [scatter, text, position, "2d"] begin
scene = Scene()
scatter!(scene, rand(10), color=:red)
scatter!(scene, RNG.rand(10), color=:red)
text!(scene,"adding text",textsize = 0.6, position = (5.0, 1.1))
end

Expand All @@ -54,8 +54,8 @@

@cell "visible" [scatter, visible, "2d"] begin
vbox(
scatter(randn(20), color = to_colormap(:deep, 20), markersize = 1, visible = true),
scatter(randn(20), color = to_colormap(:deep, 20), markersize = 1, visible = false)
scatter(RNG.randn(20), color = to_colormap(:deep, 20), markersize = 10, visible = true),
scatter(RNG.randn(20), color = to_colormap(:deep, 20), markersize = 10, visible = false)
)
end
end
6 changes: 3 additions & 3 deletions test/reference_image_tests/documentation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
scene = Scene(resolution = (500, 500))
x = map([:dot, :dash, :dashdot], [2, 3, 4]) do ls, lw
linesegments!(
range(1, stop = 5, length = 100), rand(100), rand(100),
range(1, stop = 5, length = 100), RNG.rand(100), RNG.rand(100),
linestyle = ls, linewidth = lw,
color = rand(RGBAf0)
color = RNG.rand(RGBAf0)
)[end]
end
x = [x..., scatter!(range(1, stop=5, length=100), rand(100), rand(100))[end]]
x = [x..., scatter!(range(1, stop=5, length=100), RNG.rand(100), RNG.rand(100))[end]]
center!(scene)
ls = AbstractPlotting.legend(x, ["attribute $i" for i in 1:4], camera = campixel!, raw = true)
l = ls[end]
Expand Down
72 changes: 46 additions & 26 deletions test/reference_image_tests/examples2d.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@block SimonDanisch ["2d"] begin

@cell "Test heatmap + image overlap" [image, heatmap, transparency] begin
heatmap(rand(32, 32))
image!(map(x->RGBAf0(x,0.5, 0.5, 0.8), rand(32,32)))
heatmap(RNG.rand(32, 32))
image!(map(x->RGBAf0(x,0.5, 0.5, 0.8), RNG.rand(32,32)))
end

@cell "poly and colormap" [poly, colormap, colorrang] begin
Expand All @@ -17,7 +17,7 @@
end
@cell "quiver" [quiver, arrows, vectorfield, gradient] begin
x = range(-2, stop = 2, length = 21)
arrows(x, x, rand(21, 21), rand(21, 21), arrowsize = 0.05)
arrows(x, x, RNG.rand(21, 21), RNG.rand(21, 21), arrowsize = 0.05)
end
@cell "Arrows on hemisphere" [arrows, quiver, mesh] begin
using GeometryBasics
Expand All @@ -30,7 +30,7 @@
@cell "image" [image] begin
vbox(
image(AbstractPlotting.logo(), scale_plot = false),
image(rand(100, 500), scale_plot = false),
image(RNG.rand(100, 500), scale_plot = false),
)
end
@cell "FEM polygon 2D" [fem, poly] begin
Expand Down Expand Up @@ -98,10 +98,10 @@
)
end
@cell "Subscenes" [image, scatter, subscene] begin
img = rand(RGBAf0, 100, 100)
img = RNG.rand(RGBAf0, 100, 100)
scene = image(img, show_axis = false)
subscene = Scene(scene, IRect(100, 100, 300, 300))
scatter!(subscene, rand(100) * 200, rand(100) * 200, markersize = 4)
scatter!(subscene, RNG.rand(100) * 200, RNG.rand(100) * 200, markersize = 4)
scene
end

Expand Down Expand Up @@ -136,8 +136,8 @@
end
@cell "Hbox" [lines, scatter, hbox] begin
t = range(-122277.9, stop=-14798.0, length=29542)
x = -42 .- randn(length(t))
sc1 = scatter(t, x, color=:black, markersize=sqrt(length(t)/20))
x = -42 .- RNG.randn(length(t))
sc1 = scatter(t, x, color=:black, markersize=1.0)
sc2 = lines(t[1:end-1], diff(x), color = :blue)
hbox(sc2, sc1)
end
Expand All @@ -150,7 +150,7 @@
end
@cell "contour" [contour] begin
y = range(-0.997669, stop = 0.997669, length = 23)
contour(range(-0.99, stop = 0.99, length = 23), y, rand(23, 23), levels = 10)
contour(range(-0.99, stop = 0.99, length = 23), y, RNG.rand(23, 23), levels = 10)
end

@cell "Text Annotation" [text, align, annotation] begin
Expand Down Expand Up @@ -187,7 +187,7 @@
using Statistics
n, m = 100, 101
t = range(0, 1, length=m)
X = cumsum(randn(n, m), dims = 2)
X = cumsum(RNG.randn(n, m), dims = 2)
X = X .- X[:, 1]
μ = vec(mean(X, dims=1)) # mean
lines(t, μ) # plot mean line
Expand All @@ -213,7 +213,7 @@ end
@block AnshulSinghvi ["colors"] begin

@cell "Line changing colour" [colors, lines, animation] begin
scene = lines(rand(10); linewidth=10)
scene = lines(RNG.rand(10); linewidth=10)

record(scene, @replace_with_a_path(mp4), 1:255; framerate = 60) do i
scene.plots[2][:color] = RGBf0(i/255, (255 - i)/255, 0) # animate scene
Expand Down Expand Up @@ -280,43 +280,63 @@ end

@block JuliusKrumbiegel ["2d"] begin
@cell "Errorbars x y low high" [errorbars] begin
using Random
Random.seed!(2)

x = 1:10
y = sin.(x)
scene = scatter(x, y)
errorbars!(scene, x, y, rand(10) .+ 0.5, rand(10) .+ 0.5)
errorbars!(scene, x, y, rand(10) .* 0.3 .+ 0.1, rand(10) .* 0.3 .+ 0.1,
errorbars!(scene, x, y, RNG.rand(10) .+ 0.5, RNG.rand(10) .+ 0.5)
errorbars!(scene, x, y, RNG.rand(10) .* 0.3 .+ 0.1, RNG.rand(10) .* 0.3 .+ 0.1,
color = :red, direction = :x)
scene
end

@cell "Errorbars xy low high" [errorbars] begin
using Random
Random.seed!(2)

x = 1:10
y = sin.(x)
xy = Point2f0.(x, y)
scene = scatter(xy)
errorbars!(scene, xy, rand(10) .+ 0.5, rand(10) .+ 0.5)
errorbars!(scene, xy, rand(10) .* 0.3 .+ 0.1, rand(10) .* 0.3 .+ 0.1,
errorbars!(scene, xy, RNG.rand(10) .+ 0.5, RNG.rand(10) .+ 0.5)
errorbars!(scene, xy, RNG.rand(10) .* 0.3 .+ 0.1, RNG.rand(10) .* 0.3 .+ 0.1,
color = :red, direction = :x)
scene
end

@cell "Errorbars xy error" [errorbars] begin
using Random
Random.seed!(2)

x = 1:10
y = sin.(x)
xy = Point2f0.(x, y)
scene = scatter(xy)
errorbars!(scene, xy, rand(10) .+ 0.5)
errorbars!(scene, xy, rand(10) .* 0.3 .+ 0.1,
errorbars!(scene, xy, RNG.rand(10) .+ 0.5)
errorbars!(scene, xy, RNG.rand(10) .* 0.3 .+ 0.1,
color = :red, direction = :x)
scene
end

@cell "Simple pie chart" [pie] begin
using AbstractPlotting.MakieLayout
scene, layout = layoutscene(resolution = (800, 800))
ax = layout[1, 1] = LAxis(scene, autolimitaspect = 1)

pie!(ax, 1:5, color = 1:5)

scene
end

@cell "Hollow pie chart" [pie] begin
using AbstractPlotting.MakieLayout
scene, layout = layoutscene(resolution = (800, 800))
ax = layout[1, 1] = LAxis(scene, autolimitaspect = 1)

pie!(ax, 1:5, color = 1:5, radius = 2, inner_radius = 1)

scene
end

@cell "Open pie chart" [pie] begin
using AbstractPlotting.MakieLayout
scene, layout = layoutscene(resolution = (800, 800))
ax = layout[1, 1] = LAxis(scene, autolimitaspect = 1)

pie!(ax, 0.1:0.1:1.0, normalize = false)
scene
end
end
Loading

0 comments on commit 46d50f5

Please sign in to comment.