Skip to content

Commit

Permalink
Merge pull request #30 from JuliaPlots/hw/bump_geo
Browse files Browse the repository at this point in the history
bump GeometryBasics to 0.4
  • Loading branch information
hexaeder authored Sep 13, 2021
2 parents 5175713 + cdfee91 commit 483f0a4
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 104 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
GeometryBasics = "0.3"
GeometryBasics = "0.4"
LightGraphs = "1.3"
Makie = "0.15"
NetworkLayout = "0.4"
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/depgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ In `GraphMakie` the layout always needs to be function. So we're creating a dumm
We will use the [Edge waypoints](@ref) attribute to get the graph with the least crossings.
=#
lay = _ -> Point.(zip(xs,ys))
## create a vector of Point2f0 per edge
wp = [Point2f0.(zip(paths[e]...)) for e in edges(g)]
## create a vector of Point2f per edge
wp = [Point2f.(zip(paths[e]...)) for e in edges(g)]

## manually tweak some of the lable aligns
align = [(:right, :center) for i in 1:N]
Expand All @@ -75,7 +75,7 @@ align[10] = (:left, :bottom) # JuliaInterpreter
align[13] = (:left, :bottom) # Requires

## shift "JuliaInterpreter" node in data space
offset = [Point2f0(0,0) for i in 1:N]
offset = [Point2f(0,0) for i in 1:N]
offset[10] = Point(-0.1, 0.1)

f, ax, p = graphplot(g; layout=lay,
Expand Down
18 changes: 9 additions & 9 deletions docs/examples/interactions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ nhover = NodeHoverHandler(node_hover_action)
register_interaction!(ax, :nhover, nhover)

function set_cursor!(p) #hide
direction = Point2f0(-0.1, 0.2) #hide
direction = Point2f(-0.1, 0.2) #hide
arrows!([p-direction], [direction], linewidth=3, arrowsize=20, lengthscale=0.8) #hide
end #hide
nodepos = copy(p[:node_pos][]) #hide
set_cursor!(nodepos[5] + Point2f0(0.05, 0)) #hide
set_cursor!(nodepos[5] + Point2f(0.05, 0)) #hide
p.node_size[][5] = 20; p.node_size[] = p.node_size[] #hide
f #hide

Expand Down Expand Up @@ -105,9 +105,9 @@ end
ndrag = NodeDragHandler(node_drag_action)
register_interaction!(ax, :ndrag, ndrag)

p[:node_pos][][1] = nodepos[1] + Point2f0(1.0,0.5) #hide
p[:node_pos][][1] = nodepos[1] + Point2f(1.0,0.5) #hide
p[:node_pos][] = p[:node_pos][] #hide
set_cursor!(p[:node_pos][][1] + Point2f0(0.05, 0)) #hide
set_cursor!(p[:node_pos][][1] + Point2f(0.05, 0)) #hide
p.node_size[][1] = 20; p.node_size[] = p.node_size[] #hide
f # hide

Expand All @@ -117,9 +117,9 @@ f # hide
pop!(ax.scene.plots) #hide
p.node_size[][1] = 10; p.node_size[] = p.node_size[] #hide
mutable struct EdgeDragAction
init::Union{Nothing, Point2f0} # save click position
src::Union{Nothing, Point2f0} # save src vertex position
dst::Union{Nothing, Point2f0} # save dst vertex position
init::Union{Nothing, Point2f} # save click position
src::Union{Nothing, Point2f} # save src vertex position
dst::Union{Nothing, Point2f} # save dst vertex position
EdgeDragAction() = new(nothing, nothing, nothing)
end
function (action::EdgeDragAction)(state, idx, event, axis)
Expand All @@ -141,8 +141,8 @@ end
edrag = EdgeDragHandler(EdgeDragAction())
register_interaction!(ax, :edrag, edrag)

p[:node_pos][][9] = nodepos[9] + Point2f0(0.9,1.0) #hide
p[:node_pos][][10] = nodepos[10] + Point2f0(0.9,1.0) #hide
p[:node_pos][][9] = nodepos[9] + Point2f(0.9,1.0) #hide
p[:node_pos][][10] = nodepos[10] + Point2f(0.9,1.0) #hide
p[:node_pos][] = p[:node_pos][] #hide
pm = (p[:node_pos][][9] + p[:node_pos][][10])/2 #hide
set_cursor!(pm) #hide
Expand Down
12 changes: 6 additions & 6 deletions docs/examples/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ f # hide
# This is not very nice, lets change the offsets based on the `node_positions`

offsets = 0.15 * (p[:node_pos][] .- p[:node_pos][][1])
offsets[1] = Point2f0(0, 0.3)
offsets[1] = Point2f(0, 0.3)
p.nlabels_offset[] = offsets
autolimits!(ax)
f # hide
Expand Down Expand Up @@ -120,8 +120,8 @@ in pixels using the `elabels_distance` argument.
=#
p.elabels_opposite[] = [1,2,8,6]

p.elabels_offset[] = [Point2f0(0.0, 0.0) for i in 1:ne(g)]
p.elabels_offset[][5] = Point2f0(-0.4,0)
p.elabels_offset[] = [Point2f(0.0, 0.0) for i in 1:ne(g)]
p.elabels_offset[][5] = Point2f(-0.4,0)
p.elabels_offset[] = p.elabels_offset[]

p.elabels_shift[] = [0.5 for i in 1:ne(g)]
Expand Down Expand Up @@ -168,7 +168,7 @@ f # hide

# It is possible to change the appearance using the `selfedge_` attributes:
p.selfedge_size = Dict(1=>Makie.automatic, 4=>3.6, 6=>0.5) #idx as in edges(g)
p.selfedge_direction = Point2f0(0.3, 1)
p.selfedge_direction = Point2f(0.3, 1)
p.selfedge_width = Any[Makie.automatic for i in 1:ne(g)]
p.selfedge_width[][4] = 0.6*π; notify(p.selfedge_width)
autolimits!(ax)
Expand Down Expand Up @@ -221,8 +221,8 @@ waypoint_radius = Dict(1 => nothing,
f = Figure(); f[1,1] = ax = Axis(f)
using Makie.Colors # hide
for i in 3:4 #hide
poly!(ax, Circle(Point2f0(waypoints[i][1]), waypoint_radius[i]), color=RGBA(0.0,0.44705883,0.69803923,0.2)) #hide
poly!(ax, Circle(Point2f0(waypoints[i][2]), waypoint_radius[i]), color=RGBA(0.0,0.44705883,0.69803923,0.2)) #hide
poly!(ax, Circle(Point2f(waypoints[i][1]), waypoint_radius[i]), color=RGBA(0.0,0.44705883,0.69803923,0.2)) #hide
poly!(ax, Circle(Point2f(waypoints[i][2]), waypoint_radius[i]), color=RGBA(0.0,0.44705883,0.69803923,0.2)) #hide
end #hide

p = graphplot!(ax, g; layout=SquareGrid(cols=2, dy=-0.5),
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/truss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ for i in 1:N
end
end
add_edge!(g, 2N, 2N+1)
pos0 = zeros(Point2f0, 2N + 1)
pos0 = zeros(Point2f, 2N + 1)
pos0[1:N] = [Point((i-1)dx,0) for i in 1:N]
pos0[N+1:2*N] = [Point(i*dx + shift, 1) for i in 1:N]
pos0[2N+1] = Point(N*dx + 1, -1)
Expand Down Expand Up @@ -85,7 +85,7 @@ end

"Extract vector of Points from dgl state `u`"
function to_pos(u)
pos = Vector{Point2f0}(undef, nv(g))
pos = Vector{Point2f}(undef, nv(g))
for (i, idx) in enumerate(x_idxs)
pos[i] = Point(u[idx], u[idx+1])
end
Expand Down
4 changes: 2 additions & 2 deletions src/beziercurves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ function Path(P::Vararg{PT, 2}; tangents=nothing, tfactor=.5) where {PT<:Abstrac
if tangents === nothing
return Line(p1, p2)
else
t1 = normalize(Pointf0(tangents[1]))
t2 = normalize(Pointf0(tangents[2]))
t1 = normalize(Pointf(tangents[1]))
t2 = normalize(Pointf(tangents[2]))
len = norm(p2 - p1)
return BezierPath([MoveTo(p1),
CurveTo(PT(p1+len*tf1*t1),
Expand Down
6 changes: 3 additions & 3 deletions src/interaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ end

mutable struct EdgeDragAction{PT<:GraphPlot}
p::PT
init::Union{Nothing,Point2f0} # save click position
src::Union{Nothing,Point2f0} # save src vertex position
dst::Union{Nothing,Point2f0} # save dst vertex position
init::Union{Nothing,Point2f} # save click position
src::Union{Nothing,Point2f} # save src vertex position
dst::Union{Nothing,Point2f} # save dst vertex position
EdgeDragAction(p::T) where {T} = new{T}(p, nothing, nothing, nothing)
end

Expand Down
6 changes: 3 additions & 3 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function Makie.plot!(gp::GraphPlot)

# create initial vertex positions, will be updated on changes to graph or layout
# make node_position-Observable available as named attribute from the outside
gp[:node_pos] = @lift [Pointf0(p) for p in ($(gp.layout))($graph)]
gp[:node_pos] = @lift [Pointf(p) for p in ($(gp.layout))($graph)]

node_pos = gp[:node_pos]

Expand Down Expand Up @@ -393,8 +393,8 @@ function selfedge_path(g, pos::AbstractVector{<:Point2}, v, size, direction, wid

# the actual length of the tagent vectors, magic number from `CurveTo`
l = Float32( size/(cos/2) * 2*0.375) )
t1 = vp + l * Point2f0(cos-Δ/2), sin-Δ/2))
t2 = vp + l * Point2f0(cos+Δ/2), sin+Δ/2))
t1 = vp + l * Point2f(cos-Δ/2), sin-Δ/2))
t2 = vp + l * Point2f(cos+Δ/2), sin+Δ/2))

return BezierPath([MoveTo(vp),
CurveTo(t1, t2, vp)])
Expand Down
8 changes: 4 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ function getattr(o::Observable, idx, default=nothing)
end

"""
Pointf0(p::Point{N, T})
Pointf(p::Point{N, T})
Convert Point{N, T} or NTuple{N, T} to Point{N, Float32}.
"""
Pointf0(p::Union{Point{N,T}, NTuple{N,T}}) where {N,T} = Point{N, Float32}(p)
Pointf0(p::Vararg{T,N}) where {N,T} = Point{N, Float32}(p)
Pointf(p::Union{Point{N,T}, NTuple{N,T}}) where {N,T} = Point{N, Float32}(p)
Pointf(p::Vararg{T,N}) where {N,T} = Point{N, Float32}(p)

"""
align_to_dir(align::Tuple{Symbol, Symbol})
Expand All @@ -87,7 +87,7 @@ function align_to_dir(align::Tuple{Symbol, Symbol})
y = 1.0
end
norm = x==y==0.0 ? 1 : sqrt(x^2 + y^2)
return Point2f0(x/norm, y/norm)
return Point2f(x/norm, y/norm)
end

"""
Expand Down
112 changes: 56 additions & 56 deletions test/beziercurves_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ using GraphMakie: BezierPath, MoveTo, LineTo, CurveTo, interpolate, discretize,

@testset "interpolation and tangets" begin
path = BezierPath([
MoveTo(Point2f0(0,0)),
LineTo(Point2f0(0.5,0.5)),
CurveTo(Point2f0(1,0),
Point2f0(1,0),
Point2f0(1,1)),
CurveTo(Point2f0(1,2),
Point2f0(0,2),
Point2f0(0,1))])
MoveTo(Point2f(0,0)),
LineTo(Point2f(0.5,0.5)),
CurveTo(Point2f(1,0),
Point2f(1,0),
Point2f(1,1)),
CurveTo(Point2f(1,2),
Point2f(0,2),
Point2f(0,1))])

lines(discretize(path))

Expand All @@ -25,11 +25,11 @@ using GraphMakie: BezierPath, MoveTo, LineTo, CurveTo, interpolate, discretize,
arrows!(pos, tan; lengthscale=0.1)

path = BezierPath([
MoveTo(Point3f0(0,0,0)),
LineTo(Point3f0(1,0,0)),
LineTo(Point3f0(1,1,1)),
LineTo(Point3f0(0,1,1)),
LineTo(Point3f0(0,0,1))])
MoveTo(Point3f(0,0,0)),
LineTo(Point3f(1,0,0)),
LineTo(Point3f(1,1,1)),
LineTo(Point3f(0,1,1)),
LineTo(Point3f(0,0,1))])
ts = 0:0.1:1.0
pos = map(t->interpolate(path,t), ts)
tan = map(t->tangent(path,t), ts)
Expand All @@ -38,85 +38,85 @@ using GraphMakie: BezierPath, MoveTo, LineTo, CurveTo, interpolate, discretize,
end

@testset "natural spline constructor" begin
path = Path(Point2f0(0.0,0.0), Point2f0(0.0,1.0))
path = Path(Point2f(0.0,0.0), Point2f(0.0,1.0))
@test path isa GraphMakie.Line

path = Path(Point2f0(0.0,0.0),
Point2f0(0.0,1.0),
Point2f0(1.0,1.0))
path = Path(Point2f(0.0,0.0),
Point2f(0.0,1.0),
Point2f(1.0,1.0))
lines(discretize(path))
scatter!(waypoints(path))

path = Path(Point2f0(0.0,0.0),
Point2f0(-0.5,1.0),
Point2f0(0.5,1.0),
Point2f0(0.0,0.0))
path = Path(Point2f(0.0,0.0),
Point2f(-0.5,1.0),
Point2f(0.5,1.0),
Point2f(0.0,0.0))
lines(discretize(path))
scatter!(waypoints(path))

path = Path(Point2f0(0.0,0.0),
Point2f0(-0.5,1.0),
Point2f0(1.5,1.0),
Point2f0(2.0,0.0))
path = Path(Point2f(0.0,0.0),
Point2f(-0.5,1.0),
Point2f(1.5,1.0),
Point2f(2.0,0.0))
lines(discretize(path))
scatter!(waypoints(path))

path = Path(Point2f0(0.0,0.0),
Point2f0(-0.5,1.0),
Point2f0(1.5,1.0),
Point2f0(2.0,0.0);
tangents=(Point2f0(-1,0),
Point2f0(-1,0)))
path = Path(Point2f(0.0,0.0),
Point2f(-0.5,1.0),
Point2f(1.5,1.0),
Point2f(2.0,0.0);
tangents=(Point2f(-1,0),
Point2f(-1,0)))
lines(discretize(path), linewidth=10)
scatter!(waypoints(path))
end

@testset "two points and tangets" begin
p1 = Point2f0(0,0)
t1 = Point2f0(0,1)
p2 = Point2f0(1,1)
t2 = Point2f0(0,1)
p1 = Point2f(0,0)
t1 = Point2f(0,1)
p2 = Point2f(1,1)
t2 = Point2f(0,1)
path = Path(p1, p2; tangents=(t1, t2))
lines(discretize(path))
scatter!(waypoints(path))

p1 = Point2f0(0,0)
t1 = Point2f0(1,0)*10
p2 = Point2f0(1,1)
t2 = Point2f0(0,1)*5
p1 = Point2f(0,0)
t1 = Point2f(1,0)*10
p2 = Point2f(1,1)
t2 = Point2f(0,1)*5
path = Path(p1, p2; tangents=(t1, t2))
lines(discretize(path))
scatter!(waypoints(path))

p1 = Point2f0(0,0)
t1 = Point2f0(-1,0)
p2 = Point2f0(1,1)
t2 = Point2f0(0,1)
p1 = Point2f(0,0)
t1 = Point2f(-1,0)
p2 = Point2f(1,1)
t2 = Point2f(0,1)
path = Path(p1, p2; tangents=(t1, t2))
lines(discretize(path))
scatter!(waypoints(path))

p1 = Point2f0(0,0)
t1 = Point2f0(-.5,.5)
p2 = Point2f0(0,0)
t2 = Point2f0(-.5,-.5)
p1 = Point2f(0,0)
t1 = Point2f(-.5,.5)
p2 = Point2f(0,0)
t2 = Point2f(-.5,-.5)
path = Path(p1, p2; tangents=(t1, t2))
lines(discretize(path))
scatter!(waypoints(path))

p1 = Point2f0(0,0)
p2 = Point2f0(1,0)
midp = Point2f0[]
p1 = Point2f(0,0)
p2 = Point2f(1,0)
midp = Point2f[]
path = Path(p1, midp..., p2)
lines(discretize(path))
end

@testset "straight lines with radi" begin
using GraphMakie: plot_controlpoints!
p1 = Point2f0(0,0)
p2 = Point2f0(1,-.5)
p3 = Point2f0(2,.5)
p4 = Point2f0(3,0)
p1 = Point2f(0,0)
p2 = Point2f(1,-.5)
p3 = Point2f(2,.5)
p4 = Point2f(3,0)
path = Path(0.5, p1, p2, p3, p4)
fig, ax, p = lines(discretize(path))
plot_controlpoints!(ax, path)
Expand All @@ -128,7 +128,7 @@ end

@testset "test beziersegments recipe" begin
using GraphMakie: beziersegments
paths = [Path(rand(Point2f0, 4)...) for _ in 1:4]
paths = [Path(rand(Point2f, 4)...) for _ in 1:4]
fig, ax, p = beziersegments(paths; linewidth=[2,4,6,8], color=[1,2,3,4])
p.attributes
end
Expand All @@ -143,5 +143,5 @@ end

g = star_graph(10)
add_edge!(g, 1, 1)
@test_throws ErrorException graphplot(g; layout=_->rand(Point3f0, 10))
@test_throws ErrorException graphplot(g; layout=_->rand(Point3f, 10))
end
Loading

0 comments on commit 483f0a4

Please sign in to comment.