Skip to content

Commit

Permalink
Close MakieOrg#80: use Graphs.jl API for edge src and dst
Browse files Browse the repository at this point in the history
  • Loading branch information
hdavid16 committed Jan 21, 2023
1 parent 664e46e commit 441691e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions docs/examples/interactions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ function (action::EdgeDragAction)(state, idx, event, axis)
if state == true
if action.src===action.dst===action.init===nothing
action.init = event.data
action.src = p[:node_pos][][edge.src]
action.dst = p[:node_pos][][edge.dst]
action.src = p[:node_pos][][src(edge)]
action.dst = p[:node_pos][][dst(edge)]
end
offset = event.data - action.init
p[:node_pos][][edge.src] = action.src + offset
p[:node_pos][][edge.dst] = action.dst + offset
p[:node_pos][][src(edge)] = action.src + offset
p[:node_pos][][dst(edge)] = action.dst + offset
p[:node_pos][] = p[:node_pos][] # trigger change
elseif state == false
action.src = action.dst = action.init = nothing
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/truss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function get_load(u, p, t=0.0)
for (i,e) in enumerate(edges(g))
edgeval = get_edge(gd_nd, i)
fvec = Point(edgeval[1], edgeval[2])
dir = pos[e.dst] .- pos[e.src]
dir = pos[dst(e)] .- pos[src(e)]
force[i] = sign(fvec dir) * norm(fvec)
end
return force
Expand All @@ -116,7 +116,7 @@ gc = [9.81 for i in 1:nv(g)] # gravitational constant
γ = [200.0 for i in 1:nv(g)] # damping parameter
γ[end] = 100.0

L = [norm(pos0[e.src] - pos0[e.dst]) for e in edges(g)] # length of edges
L = [norm(pos0[src(e)] - pos0[dst(e)]) for e in edges(g)] # length of edges
K = [0.5e6 for i in 1:ne(g)] # spring constant of edges

## bundle parameters for NetworkDynamics
Expand Down
8 changes: 4 additions & 4 deletions src/interaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ function (action::EdgeDragAction)(state, idx, event, _)
if state == true
if action.src === action.dst === action.init === nothing
action.init = event.data
action.src = action.p[:node_pos][][edge.src]
action.dst = action.p[:node_pos][][edge.dst]
action.src = action.p[:node_pos][][src(edge)]
action.dst = action.p[:node_pos][][dst(edge)]
end
offset = event.data - action.init
action.p[:node_pos][][edge.src] = action.src + offset
action.p[:node_pos][][edge.dst] = action.dst + offset
action.p[:node_pos][][src(edge)] = action.src + offset
action.p[:node_pos][][dst(edge)] = action.dst + offset
action.p[:node_pos][] = action.p[:node_pos][] # trigger change
elseif state == false
action.src = action.dst = action.init = nothing
Expand Down
8 changes: 4 additions & 4 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,13 @@ function find_edge_paths(g, attr, pos::AbstractVector{PT}) where {PT}
paths = Vector{AbstractPath{PT}}(undef, ne(g))

for (i, e) in enumerate(edges(g))
if e.src == e.dst # selfedge
if src(e) == dst(e) # selfedge
size = getattr(attr.selfedge_size, i)
direction = getattr(attr.selfedge_direction, i)
width = getattr(attr.selfedge_width, i)
paths[i] = selfedge_path(g, pos, e.src, size, direction, width)
paths[i] = selfedge_path(g, pos, src(e), size, direction, width)
else # no selfedge
p1, p2 = pos[e.src], pos[e.dst]
p1, p2 = pos[src(e)], pos[dst(e)]
tangents = getattr(attr.tangents, i)
tfactor = getattr(attr.tfactor, i)
waypoints::Vector{PT} = getattr(attr.waypoints, i, PT[])
Expand All @@ -373,7 +373,7 @@ function find_edge_paths(g, attr, pos::AbstractVector{PT}) where {PT}
elseif cdu === false
curve_distance = 0.0
elseif cdu === automatic
if is_directed(g) && has_edge(g, e.dst, e.src)
if is_directed(g) && has_edge(g, dst(e), src(e))
curve_distance = getattr(attr.curve_distance, i, 0.0)
else
curve_distance = 0.0
Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ end
if state == true
if action.src===action.dst===action.init===nothing
action.init = event.data
action.src = p[:node_pos][][edge.src]
action.dst = p[:node_pos][][edge.dst]
action.src = p[:node_pos][][src(edge)]
action.dst = p[:node_pos][][dst(edge)]
end
offset = event.data - action.init
p[:node_pos][][edge.src] = action.src + offset
p[:node_pos][][edge.dst] = action.dst + offset
p[:node_pos][][src(edge)] = action.src + offset
p[:node_pos][][dst(edge)] = action.dst + offset
p[:node_pos][] = p[:node_pos][] # trigger change
elseif state == false
action.src = action.dst = action.init = nothing
Expand Down

0 comments on commit 441691e

Please sign in to comment.