diff --git a/NEWS.md b/NEWS.md index 95cb0df2..362d3db6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/Project.toml b/Project.toml index 57a12c81..a90f652a 100644 --- a/Project.toml +++ b/Project.toml @@ -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" @@ -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" @@ -79,7 +79,7 @@ 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" @@ -87,4 +87,4 @@ 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"] diff --git a/docs/Project.toml b/docs/Project.toml index db1fad78..30f00a88 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -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" diff --git a/docs/make.jl b/docs/make.jl index 698dfac8..72dd708c 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,5 +1,5 @@ using Documenter -using GraphPlot +using GraphMakie using DistributedFactorGraphs makedocs(; diff --git a/docs/src/DrawingGraphs.md b/docs/src/DrawingGraphs.md index d8a841f8..99490c94 100644 --- a/docs/src/DrawingGraphs.md +++ b/docs/src/DrawingGraphs.md @@ -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 ``` @@ -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: @@ -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 diff --git a/docs/src/func_ref.md b/docs/src/func_ref.md index 6554ac56..b6ba5df8 100644 --- a/docs/src/func_ref.md +++ b/docs/src/func_ref.md @@ -44,7 +44,7 @@ Modules = [DistributedFactorGraphs] Pages = ["entities/DFGFactor.jl"] ``` -## DFG Plots [GraphPlot.jl] +## DFG Plots [GraphMakie.jl] ```@autodocs Modules = [DistributedFactorGraphs] diff --git a/ext/DFGPlots.jl b/ext/DFGPlots.jl index 98329291..a2c3c842 100644 --- a/ext/DFGPlots.jl +++ b/ext/DFGPlots.jl @@ -2,13 +2,13 @@ module DFGPlots 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 @@ -17,40 +17,77 @@ struct DFGPlotProps 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 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()) @@ -60,8 +97,8 @@ function plotDFG(dfg::AbstractDFG, p::DFGPlotProps = DFGPlotProps()) 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...) end end diff --git a/src/weakdeps_prototypes.jl b/src/weakdeps_prototypes.jl index 04ae5fef..67ba8455 100644 --- a/src/weakdeps_prototypes.jl +++ b/src/weakdeps_prototypes.jl @@ -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 diff --git a/test/consol_DataEntryBlobTests.jl b/test/consol_DataEntryBlobTests.jl index 0e8acf8b..1bc9938e 100644 --- a/test/consol_DataEntryBlobTests.jl +++ b/test/consol_DataEntryBlobTests.jl @@ -1,6 +1,6 @@ if false using Test - using GraphPlot + using GraphMakie using DistributedFactorGraphs using Pkg using Dates diff --git a/test/interfaceTests.jl b/test/interfaceTests.jl index ac7011ca..77954088 100644 --- a/test/interfaceTests.jl +++ b/test/interfaceTests.jl @@ -1,6 +1,6 @@ if false using Test - using GraphPlot + using GraphMakie using DistributedFactorGraphs using Pkg using Dates diff --git a/test/plottingTest.jl b/test/plottingTest.jl index 3f8d8544..0099defa 100644 --- a/test/plottingTest.jl +++ b/test/plottingTest.jl @@ -1,4 +1,4 @@ -using GraphPlot +using GraphMakie using DistributedFactorGraphs # using DistributedFactorGraphs.DFGPlots using Test @@ -27,7 +27,7 @@ map( ## -# Using GraphPlot plotting +# Using GraphMakie plotting plot = plotDFG(dfg) @test plot !== nothing diff --git a/test/runtests.jl b/test/runtests.jl index fff2680b..3e2b9432 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using Test -using GraphPlot # For plotting tests +using GraphMakie # For plotting tests using DistributedFactorGraphs using Pkg using Dates