|
| 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 |
0 commit comments