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

add Aqua.jl tests #169

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,30 @@ SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
Aqua = "0.8"
CairoMakie = "0.11"
DataStructures = "0.17, 0.18"
FileIO = "1"
GeometryBasics = "0.4"
Graphs = "1.4"
LinearAlgebra="1"
Literate = "2"
Makie = "0.20"
NetworkLayout = "0.4.3"
PolynomialRoots = "1"
ReferenceTests = "0.10"
SimpleTraits = "0.9"
StaticArrays = "1.2"
Test = "1"
julia = "1"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["CairoMakie", "FileIO", "Literate", "ReferenceTests", "Test"]
test = ["Aqua", "CairoMakie", "FileIO", "Literate", "ReferenceTests", "Test"]
10 changes: 2 additions & 8 deletions src/beziercurves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Method: Calculates the square distance between `pt` and path `p` and minimizes (
let a = p0 - pt, b = p - p0
t = -(a[1]*b[1] + a[2]*b[2]) / (b[1]^2 + b[2]^2)
"""
function inverse_interpolate(p::BezierPath{<:Point2}, pt)
function inverse_interpolate(p::BezierPath{<:Point2}, pt::Point2)
p0 = p.commands[end-1].p
c = p.commands[end]
N = length(p.commands) - 1
Expand All @@ -103,19 +103,13 @@ function inverse_interpolate(p::BezierPath{<:Point2}, pt)
return t
end

function inverse_interpolate(l::Line{PT}, pt) where PT
function inverse_interpolate(l::Line{<:Point2}, pt::Point2)
a = l.p0 - pt
b = l.p - l.p0
t = -(a[1]*b[1] + a[2]*b[2]) / (b[1]^2 + b[2]^2)
return t
end

function inverse_interpolate(p, pt::Point3)
# TODO: is this the right place to throw an error when trying to shift arrows to destination nodes?
@warn "arrow_shift = :end will not display properly for 3D plots."
nothing
end

_inverse_interpolate(c::LineTo{<:Point2}, p0, pt) = inverse_interpolate(Line(p0, c.p), pt)
function _inverse_interpolate(c::CurveTo{<:Point2}, p0, pt)
p1, p2, p3 = c.c1, c.c2, c.p
Expand Down
44 changes: 28 additions & 16 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -753,30 +753,42 @@ lands on the surface of the destination node.
function update_arrow_shift(g, gp, edge_paths::Vector{<:AbstractPath{PT}}, to_px, node_markers, node_sizes, shift) where {PT}
arrow_shift = Vector{Float32}(undef, ne(g))

warn_nan = false
warn_3d = false
for (i,e) in enumerate(edges(g))
t = getattr(shift, i, 0.5)
if t === :end
j = dst(e)
p0 = getattr(gp.node_pos, j)
node_marker = getattr(node_markers, j)
node_size = getattr(node_sizes, j)
arrow_marker = getattr(gp.arrow_marker, i)
arrow_size = getattr(gp.arrow_size, i)
d = distance_between_markers(node_marker, node_size, arrow_marker, arrow_size)
p1 = point_near_dst(edge_paths[i], p0, d, to_px)
t = inverse_interpolate(edge_paths[i], p1)
if isnan(t)
@warn """
Shifting arrowheads to destination nodes failed.
This can happen when the markers are inadequately scaled (e.g., when zooming out too far).
Arrow shift has been reset to 0.5.
"""
if PT <: Point2
j = dst(e)
p0 = getattr(gp.node_pos, j)
node_marker = getattr(node_markers, j)
node_size = getattr(node_sizes, j)
arrow_marker = getattr(gp.arrow_marker, i)
arrow_size = getattr(gp.arrow_size, i)
d = distance_between_markers(node_marker, node_size, arrow_marker, arrow_size)
p1 = point_near_dst(edge_paths[i], p0, d, to_px)
t = inverse_interpolate(edge_paths[i], p1)
if isnan(t)
warn_nan = true
t = 0.5
end
else
warn_3d = true
t = 0.5
end
end
arrow_shift[i] = t
end

if warn_nan
@warn """
Shifting arrowheads to destination nodes failed.
This can happen when the markers are inadequately scaled (e.g., when zooming out too far).
Arrow shift has been reset to 0.5.
"""
end
if warn_3d
@warn "`arrow_shift=:end` not implemented for 3d plot!"
end
return arrow_shift
end

Expand Down
6 changes: 6 additions & 0 deletions test/Aqua.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Aqua

Aqua.test_ambiguities(GraphMakie)
Aqua.test_all(GraphMakie;
ambiguities=false,
unbound_args=false)
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ using Makie.Colors
using StaticArrays
using Test

include("Aqua.jl")

include("beziercurves_test.jl")

@testset "GraphMakie.jl" begin
Expand Down
Loading