Skip to content

Commit 3e77289

Browse files
committed
include simple doctest for plot
ref #492
1 parent 2f4e1a1 commit 3e77289

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[deps]
2+
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
3+
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
24
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
35
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
46
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"

docs/src/DrawingGraphs.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ Pkg.add("GraphPlot")
1313

1414
Then bring `GraphPlot` in before DFG:
1515

16-
```julia
16+
```@example plots; continued = true
1717
using GraphPlot
1818
using DistributedFactorGraphs
1919
```
2020

21-
Any factor graph can then be drawn by calling `dfgplot`:
21+
Any factor graph can then be drawn by calling [`dfgplot`](@ref):
2222

23-
```julia
23+
```@example plots
24+
using Cairo # hide
2425
# Construct graph using IIF
2526
using IncrementalInference
2627
# Create graph
27-
dfg = LightDFG{SolverParams}(params=SolverParams())
28+
dfg = LightDFG{SolverParams}(solverParams=SolverParams())
2829
v1 = addVariable!(dfg, :x0, ContinuousScalar, labels = [:POSE], solvable=1)
2930
v2 = addVariable!(dfg, :x1, ContinuousScalar, labels = [:POSE], solvable=1)
3031
v3 = addVariable!(dfg, :l0, ContinuousScalar, labels = [:LANDMARK], solvable=1)
@@ -37,19 +38,22 @@ f1 = addFactor!(dfg, [:l0; :x1], LinearConditional(Normal(-10.0,5.0)), solvable=
3738
dfgplot(dfg)
3839
```
3940

40-
![imgs/initialgraph.jpg](imgs/initialgraph.jpg)
41-
42-
- [`dfgplot`](@ref)
43-
4441
### Rendering GraphPlot to PDF
4542

46-
The graph can be rendered to PDF or JPG in the following way:
43+
The graph can be rendered to PDF, SVG or JPG in the following way by including compose:
4744

48-
```julia
49-
# Save to PDF
45+
```@example plots
5046
using Compose
51-
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(dfg))
47+
# lets add another variable and factor and plot it
48+
dfg.solverParams.graphinit = false # hide
49+
addVariable!(dfg, :x2, ContinuousScalar);
50+
addFactor!(dfg, [:x1; :x2], LinearConditional(Normal(50.0,2.0)));
51+
# Save to SVG
52+
draw(SVG("graph.svg", 10cm, 10cm), dfgplot(dfg));
53+
nothing # hide
5254
```
55+
![](graph.svg)
56+
5357

5458
### More Information
5559

@@ -63,12 +67,12 @@ and can be drawn by either:
6367
- Calling [`toDot`](@ref) on any graph to produce a string of the graph
6468
- Calling [`toDotFile`](@ref) on any graph to save it directly to a dotfile
6569

66-
```julia
70+
```@example
6771
using DistributedFactorGraphs
6872
# Construct graph using IIF
6973
using IncrementalInference
7074
# Create graph
71-
dfg = GraphsDFG{SolverParams}(params=SolverParams())
75+
dfg = LightDFG{SolverParams}(solverParams=SolverParams())
7276
v1 = addVariable!(dfg, :x0, ContinuousScalar, labels = [:POSE], solvable=1)
7377
v2 = addVariable!(dfg, :x1, ContinuousScalar, labels = [:POSE], solvable=1)
7478
v3 = addVariable!(dfg, :l0, ContinuousScalar, labels = [:LANDMARK], solvable=1)
@@ -79,5 +83,6 @@ f1 = addFactor!(dfg, [:l0; :x1], LinearConditional(Normal(-10.0,5.0)), solvable=
7983
# Save to dot file
8084
toDotFile(dfg, "/tmp/test.dot")
8185
# Open with xdot
82-
run(`xdot /tmp/test.dot`)
86+
# run(`xdot /tmp/test.dot`)
87+
# nothing # hide
8388
```

0 commit comments

Comments
 (0)