Skip to content

Commit 04ae091

Browse files
authored
Merge pull request #80 from JuliaRobotics/feature/graphplot
Add GraphPlot.jl plots Issue #78
2 parents 952c23c + e552531 commit 04ae091

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/DFGPlots/DFGPlots.jl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module DFGPlots
2+
3+
using Colors
4+
using LightGraphs
5+
using MetaGraphs
6+
using GraphPlot
7+
import GraphPlot: gplot
8+
9+
using ...DistributedFactorGraphs
10+
11+
export
12+
dfgplot,
13+
DFGPlotProps
14+
15+
struct DFGPlotProps
16+
nodefillc::NamedTuple{(:var,:fac),Tuple{RGB,RGB}}
17+
nodesize::NamedTuple{(:var,:fac),Tuple{Float64,Float64}}
18+
shape::NamedTuple{(:var,:fac),Tuple{Symbol,Symbol}} #not upported yet
19+
20+
layout::Function #spring_layout, spectral_layout
21+
drawlabels::Bool
22+
end
23+
24+
DFGPlotProps() = DFGPlotProps( (var=colorant"seagreen", fac=colorant"cyan3"),
25+
(var=1.0, fac=0.3),
26+
(var=:box, fac=:elipse),
27+
spring_layout,
28+
true)
29+
30+
31+
function dfgplot(dfg::LightGraphsDFG)
32+
33+
nodesize = [has_prop(dfg.g,i,:factor) ? 0.3 : 1.0 for i=vertices(dfg.g)]
34+
nodelabel = [has_prop(dfg.g,i,:factor) ? "" : string(get_prop(dfg.g,i,:label)) for i=vertices(dfg.g)]
35+
nodefillc = [has_prop(dfg.g,i,:factor) ? colorant"seagreen" : colorant"cyan3" for i=vertices(dfg.g)]
36+
37+
gplot(dfg.g, nodelabel=nodelabel, nodesize=nodesize, nodefillc=nodefillc, layout=spectral_layout)
38+
39+
end
40+
41+
function gplot(dfg::LightGraphsDFG; keyargs...)
42+
gplot(dfg.g; keyargs...)
43+
end
44+
45+
function dfgplot(dfg::AbstractDFG)
46+
# TODO implement convert functions
47+
@warn "TODO Implement convert"
48+
ldfg = LightGraphsDFG{AbstractParams}()
49+
DistributedFactorGraphs._copyIntoGraph!(dfg, ldfg, union(getVariableIds(dfg), getFactorIds(dfg)), true)
50+
51+
nodesize = [has_prop(ldfg.g,i,:factor) ? 0.3 : 1.0 for i=vertices(ldfg.g)]
52+
nodelabel = [has_prop(ldfg.g,i,:factor) ? "" : string(get_prop(ldfg.g,i,:label)) for i=vertices(ldfg.g)]
53+
nodefillc = [has_prop(ldfg.g,i,:factor) ? colorant"seagreen" : colorant"cyan3" for i=vertices(ldfg.g)]
54+
55+
gplot(ldfg.g, nodelabel=nodelabel, nodesize=nodesize, nodefillc=nodefillc, layout=spectral_layout)
56+
57+
end
58+
59+
end

src/DistributedFactorGraphs.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ function __init__()
7979
# Include the Cloudgraphs API
8080
include("CloudGraphsDFG/CloudGraphsDFG.jl")
8181
end
82+
83+
@require GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231" begin
84+
include("DFGPlots/DFGPlots.jl")
85+
@reexport using .DFGPlots
86+
end
87+
8288
end
8389

8490
# not sure where to put

0 commit comments

Comments
 (0)