Skip to content

Commit

Permalink
tests, docs, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed May 23, 2022
1 parent 8ae184d commit 47f4a79
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## [v0.3.0] -
## [v0.3.0] - 2022-05-23

### Added

Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Documenter = "0.27"
Graphs = "1.6"
julia = "^1.5"
Luxor = "3"
NetworkLayout = "0.4"
NetworkLayout = "0.4.4"
2 changes: 0 additions & 2 deletions docs/src/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,6 @@ julia> adjacency_matrix(wg)

For a directed graph, each edge can have two weights, one from `src` to `dst`, the other from `dst` to `src`.

Note that `a_star()` doesn't work with weighted graphs yet.

## Spanning trees

A spanning tree is a set of edges that connect all the vertices of a graph together, without forming any cycles. There are various functions for finding spanning trees in Graphs.jl, including algorithms by Otakar Borůvka (`boruvka_mst()`), Joseph Kruskal (`kruskal_mst()`), and Robert Prim (`prim_mst()`). (Immortality can be attained by inventing a new graph-spanning algorithm.)
Expand Down
27 changes: 19 additions & 8 deletions docs/src/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ The two keyword arguments `vertexfunction` and `edgefunction` allow you to pass

!!! note

If you define these functions, all the separate vertex/edge keywords are ignored.
If you define these functions, all the other vertex/edge keywords are ignored.

```
vertexfunction = my_vertexfunction(vertex, coordinates)
Expand Down Expand Up @@ -243,9 +243,9 @@ end
end 800 600
```

## Functions
## Functions as keyword arguments

Some keywords accept functions:
The following keyword arguments accept functions:

- `edgelabelrotations`
- `edgelabels`
Expand All @@ -263,6 +263,8 @@ Some keywords accept functions:
The `edge-` keywords accept functions with arguments `(edgenumber, sourcevertex, destinationvertex, frompoint, topoint)`.
The `vertex-` keywords accept functions with arguments `(vertex)`.

These functions aren't used if you supply functions to `vertexfunction` or `edgefunction`.

## Vertex labels and shapes

### `vertexlabels`
Expand All @@ -273,7 +275,7 @@ This example draws all vertices, and numbers them from 1 to 6.

!!! note

In Graphs.jl, vertices are numbered from 1 to `n`. If you remove a vertex, vertices are effectively re-numbered.
In Graphs.jl, vertices are always numbered from 1 to `n`. If you remove a vertex, vertices are effectively re-numbered.

```@example graphsection
@drawsvg begin
Expand Down Expand Up @@ -319,7 +321,7 @@ drawgraph(g, layout=shell, vertexshapes = [:square, :circle])
end 600 300
```

`vertexshapesizes` can set the sizes for the vertex shapes.
`vertexshapesizes` can set the sizes for the built-in vertex shapes.

```@example graphsection
@drawsvg begin
Expand All @@ -328,8 +330,17 @@ g = smallgraph(:moebiuskantor)
sethue("gold")
drawgraph(g, layout=shell,
vertexshapes = [:square, :circle],
vertexshapesizes = [15, 5],
)
vertexshapesizes = [15, 5])
end 600 300
```

```@example graphsection
@drawsvg begin
background("grey10")
g = smallgraph(:moebiuskantor)
sethue("gold")
drawgraph(g, layout=shell,
vertexshapesizes = (v) -> rescale(v, 1, nv(g), 5, 25))
end 600 300
```

Expand All @@ -348,7 +359,7 @@ drawgraph(g, layout=shell,
end 600 300
```

To show every other vertex, you could use something like this:
To show every other vertex and label, you could use something like this:

```@example graphsection
@drawsvg begin
Expand Down
120 changes: 120 additions & 0 deletions test/ftests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using Karnak, Graphs, NetworkLayout, Colors, Test

#=
TODO
vertexshapes
vertexshapesizes
vertexstrokecolors
vertexstrokeweights
=#

@info "starting func tests"
@drawsvg begin
background("grey10")
g = smallgraph(:octahedral)
sethue("gold")
drawgraph(g, layout=stress,
vertexlabels = 1:nv(g),
vertexshapes = :none,
edgelabelrotations = (n, s, d, from, to) -> begin
sethue("green")
circle(from, 10, :fill)
sethue("red")
circle(to, 15, :fill)
end
)
end 600 300

@drawsvg begin
background("grey10")
g = smallgraph(:octahedral)
sethue("gold")
drawgraph(g, layout=stress,
vertexlabels = 1:nv(g),
vertexshapes = :none,
edgelabels = (n, s, d, from, to) -> begin
text(string("Edge $n: $s -> $d"), midpoint(from, to))
end
)
end 600 300

@drawsvg begin
background("grey10")
g = smallgraph(:octahedral)
sethue("gold")
drawgraph(g, layout=stress,
vertexshapes = :none,
edgelines = (n, s, d, from, to) -> begin
randomhue()
arrow(from, to)
end
)
end 600 300

@drawsvg begin
background("grey10")
g = smallgraph(:octahedral)
sethue("gold")
drawgraph(g, layout=stress,
vertexshapes = :none,
edgestrokecolors = (n, s, d, from, to) -> begin
c = Luxor.get_current_color()
if isodd(n)
RGB(c.g, c.b, c.r)
else
c
end
end
)
end 600 300

@drawsvg begin
background("grey10")
g = smallgraph(:octahedral)
sethue("gold")
drawgraph(g, layout=stress,
vertexshapes = :none,
edgestrokeweights = (n, s, d, from, to) -> begin
rescale((s + d), 2, 12, 10, 0.2)
end
)
end 600 300

@drawsvg begin
background("grey10")
g = smallgraph(:octahedral)
sethue("gold")
drawgraph(g, layout=stress,
vertexshapesizes=30,
vertexfillcolors = (v) -> begin
RGB(rescale(v, 1, nv(g), 0, 1), rescale(v, 1, nv(g), 1, 0), .7)
end
)
end 600 300

@drawsvg begin
background("grey10")
g = smallgraph(:octahedral)
sethue("gold")
drawgraph(g, layout=stress,
vertexshapesizes=20,
vertexlabels = (v) -> begin
string("vertex $v")
end
)
end 600 300

@drawsvg begin
background("grey10")
g = smallgraph(:octahedral)
sethue("gold")
drawgraph(g, layout=stress,
vertexshapesizes=20,
vertexshapes = :square,
vertexlabels = 1:nv(g),
vertexshaperotations = (v) -> begin
v * π/6
end
)
end 600 300
@info "finishing func tests"
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using NetworkLayout
using Colors

@testset "Karnak.jl" begin

@info "starting basic test"
Drawing(600, 600, :svg)
origin()
background("grey10")
Expand Down Expand Up @@ -79,5 +79,10 @@ using Colors
end
end
@test finish() == true
@info " finishing basic test"
end


@testset "functions" begin
include("ftests.jl")
end

0 comments on commit 47f4a79

Please sign in to comment.