Skip to content
Merged
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Listing news on any major breaking changes in DFG. For regular changes, see integrated Github.com project milestones for DFG.

# v0.26
- Graph structure plotting now uses GraphMakie.jl instead of GraphPlot.jl. Update by replacing `using GraphPlot` with `using GraphMakie`.

# v0.25
- Deprecated nouns:
SessionBlobEntry -> GraphBlobEntry
Expand Down
12 changes: 6 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[weakdeps]
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"

[extensions]
DFGPlots = "GraphPlot"
BlobArrow = "Arrow"
DFGPlots = "GraphMakie"

[compat]
Aqua = "0.8"
Expand All @@ -51,13 +51,13 @@ Dates = "1.10"
Distributions = "0.23, 0.24, 0.25"
DocStringExtensions = "0.8, 0.9"
FileIO = "1"
GraphPlot = "0.5.0, 0.6"
GraphMakie = "0.5.14"
Graphs = "1.4"
InteractiveUtils = "1.10"
JSON3 = "1"
LinearAlgebra = "1.10"
Manifolds = "0.9, 0.10"
ManifoldsBase = "0.14, 0.15"
ManifoldsBase = "0.14, 0.15, 1"
OrderedCollections = "1.4"
Pkg = "1.4, 1.5"
ProgressMeter = "1"
Expand All @@ -79,12 +79,12 @@ julia = "1.10"
[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Manifolds = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test", "DataStructures", "GraphPlot", "LinearAlgebra", "Manifolds", "Pkg", "Statistics"]
test = ["Aqua", "Test", "DataStructures", "GraphMakie", "LinearAlgebra", "Manifolds", "Pkg", "Statistics"]
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
DistributedFactorGraphs = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"

[compat]
Documenter = "1"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Documenter
using GraphPlot
using GraphMakie
using DistributedFactorGraphs

makedocs(;
Expand Down
18 changes: 9 additions & 9 deletions docs/src/DrawingGraphs.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Drawing Graphs

Graphs can be visualized by using either `GraphPlot` or rendering to .dot files (which can be viewed using xdot).
Graphs can be visualized by using either `GraphMakie` or rendering to .dot files (which can be viewed using xdot).

## GraphPlot
## GraphMakie

`GraphPlot` plotting is available if `GraphPlot` is imported before DFG is imported. Install `GraphPlot` using the following command:
`GraphMakie` plotting is available if `GraphMakie` is imported before DFG is imported. Install `GraphMakie` using the following command:

```julia
using Pkg
Pkg.add("GraphPlot")
Pkg.add("GraphMakie")
```

Then bring `GraphPlot` in before DFG:
Then bring `GraphMakie` in before DFG:

```julia
using GraphPlot
using GraphMakie
using DistributedFactorGraphs
```

Expand All @@ -38,7 +38,7 @@ f1 = addFactor!(dfg, [:l0; :x1], LinearRelative(Normal(-10.0,5.0)), solvable=1)
plotDFG(dfg)
```

### Rendering GraphPlot to PDF
### Rendering GraphMakie to PDF

The graph can be rendered to PDF, SVG or JPG in the following way by including compose:

Expand All @@ -57,12 +57,12 @@ FIXME show graph.svg

### More Information

More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
More information at [GraphMakie.jl](https://github.com/MakieOrg/GraphMakie.jl)

## Dot Files

Dot files are a standard format for visualizing graphs and applications such as
xdot are available to view the files. Dot plotting does not require `GraphPlot`
xdot are available to view the files. Dot plotting does not require `GraphMakie`
and can be drawn by either:
- Calling [`toDot`](@ref) on any graph to produce a string of the graph
- Calling [`toDotFile`](@ref) on any graph to save it directly to a dotfile
Expand Down
2 changes: 1 addition & 1 deletion docs/src/func_ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Modules = [DistributedFactorGraphs]
Pages = ["entities/DFGFactor.jl"]
```

## DFG Plots [GraphPlot.jl]
## DFG Plots [GraphMakie.jl]

```@autodocs
Modules = [DistributedFactorGraphs]
Expand Down
73 changes: 55 additions & 18 deletions ext/DFGPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

using Colors
using Graphs
using GraphPlot
using DocStringExtensions
import GraphPlot: gplot
using GraphMakie

using DistributedFactorGraphs

import DistributedFactorGraphs.plotDFG
import DistributedFactorGraphs: plotDFG
import GraphMakie: graphplot

export plotDFG, DFGPlotProps

Expand All @@ -17,40 +17,77 @@
nodesize::NamedTuple{(:var, :fac), Tuple{Float64, Float64}}
shape::NamedTuple{(:var, :fac), Tuple{Symbol, Symbol}} #not upported yet

layout::Function #spring_layout, spectral_layout
layout::Any #FIXME add layout type
drawlabels::Bool
end

function DFGPlotProps()
return DFGPlotProps(
(var = colorant"seagreen", fac = colorant"cyan3"),
(var = 1.0, fac = 0.3),
(var = :box, fac = :elipse),
spring_layout,
(var = colorant"lightgreen", fac = colorant"cyan3"),
(var = 40.0, fac = 20.0),
(var = :circle, fac = :rect),
GraphMakie.Stress(),
true,
)
end

function plotDFG(dfg::GraphsDFG, p::DFGPlotProps = DFGPlotProps())
function plotDFG(dfg::GraphsDFG; p::DFGPlotProps = DFGPlotProps(), interactive::Bool = true)
nodetypes = [haskey(dfg.g.variables, s) for s in dfg.g.labels]

nodesize = [isVar ? p.nodesize.var : p.nodesize.fac for isVar in nodetypes]
# nodelabel = [isVar ? string(get_prop(dfg.g,i,:label)) : "" for (i,isVar) in enumerate(nodetypes)]
if p.drawlabels
nodelabel = [nodetypes[i] ? string(s) : "" for (i, s) in enumerate(dfg.g.labels)]
ilabels = [nodetypes[i] ? string(s) : "" for (i, s) in enumerate(dfg.g.labels)]
else
nodelabel = nothing
ilabels = nothing

Check warning on line 42 in ext/DFGPlots.jl

View check run for this annotation

Codecov / codecov/patch

ext/DFGPlots.jl#L42

Added line #L42 was not covered by tests
end

nodefillc = [isVar ? p.nodefillc.var : p.nodefillc.fac for isVar in nodetypes]
node_color = [isVar ? p.nodefillc.var : p.nodefillc.fac for isVar in nodetypes]
marker = [isVar ? p.shape.var : p.shape.fac for isVar in nodetypes]

return gplot(
figaxpl = graphplot(
dfg.g;
nodelabel = nodelabel,
nodesize = nodesize,
nodefillc = nodefillc,
ilabels,
layout = p.layout,
node_size = nodesize,
node_color,
node_attr = (marker = marker,),
)

(f, ax, p) = figaxpl

label_text = GraphMakie.text!(
ax,
0,
0;
text = "",
font = :bold,
fontsize = 30,
glowcolor = (:white, 1),
glowwidth = 3,
)

ax.aspect = GraphMakie.DataAspect()
if interactive
function node_drag_action(state, idx, event, axis)
p[:node_pos][][idx] = event.data
return p[:node_pos][] = p[:node_pos][]
end
GraphMakie.hidedecorations!(ax)
GraphMakie.hidespines!(ax)
ndrag = NodeDragHandler(node_drag_action)
GraphMakie.deregister_interaction!(ax, :rectanglezoom)
GraphMakie.register_interaction!(ax, :ndrag, ndrag)

function node_hover_action(state, idx, event, axis)
label = dfg.g.labels[idx]
label_text.text[] = state ? string(label) : ""
return label_text.transformation.translation[] = (event.data..., 0)
end
nhover = NodeHoverHandler(node_hover_action)
GraphMakie.register_interaction!(ax, :nhover, nhover)
end
return figaxpl
end

function plotDFG(dfg::AbstractDFG, p::DFGPlotProps = DFGPlotProps())
Expand All @@ -60,8 +97,8 @@
return plotDFG(ldfg, p)
end

function gplot(dfg::GraphsDFG; keyargs...)
return gplot(dfg.g; keyargs...)
function graphplot(dfg::GraphsDFG; keyargs...)
return graphplot(dfg.g; keyargs...)

Check warning on line 101 in ext/DFGPlots.jl

View check run for this annotation

Codecov / codecov/patch

ext/DFGPlots.jl#L100-L101

Added lines #L100 - L101 were not covered by tests
end

end
13 changes: 4 additions & 9 deletions src/weakdeps_prototypes.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
"""
$(SIGNATURES)
Plots the structure of the factor graph. GraphPlot must be imported before DistributedFactorGraphs for these functions to be available.
Plots the structure of the factor graph. GraphMakie must be imported before DistributedFactorGraphs for these functions to be available.
Returns the plot context.

E.g.
```
using GraphPlot
using DistributedFactorGraphs, DistributedFactorGraphs.DFGPlots
using GraphMakie
using DistributedFactorGraphs
# ... Make graph...
# Using GraphViz plotting
plotDFG(fg)
# Save to PDF
using Compose
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), plotDFG(fg))
```

More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
More information at [GraphMakie.jl](https://github.com/MakieOrg/GraphMakie.jl)
"""
function plotDFG end
2 changes: 1 addition & 1 deletion test/consol_DataEntryBlobTests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if false
using Test
using GraphPlot
using GraphMakie
using DistributedFactorGraphs
using Pkg
using Dates
Expand Down
2 changes: 1 addition & 1 deletion test/interfaceTests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if false
using Test
using GraphPlot
using GraphMakie
using DistributedFactorGraphs
using Pkg
using Dates
Expand Down
4 changes: 2 additions & 2 deletions test/plottingTest.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GraphPlot
using GraphMakie
using DistributedFactorGraphs
# using DistributedFactorGraphs.DFGPlots
using Test
Expand Down Expand Up @@ -27,7 +27,7 @@ map(

##

# Using GraphPlot plotting
# Using GraphMakie plotting
plot = plotDFG(dfg)
@test plot !== nothing

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Test
using GraphPlot # For plotting tests
using GraphMakie # For plotting tests
using DistributedFactorGraphs
using Pkg
using Dates
Expand Down
Loading