Skip to content

Commit 7029243

Browse files
committed
add docs on marker and position metadata
1 parent 23fd287 commit 7029243

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

docs/src/API.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ set_metadata!(::NetworkDynamics.ComponentModel, ::Symbol, ::Any)
108108
has_graphelement
109109
get_graphelement
110110
set_graphelement!
111+
has_position
112+
get_position
113+
set_position!
114+
has_marker
115+
get_marker
116+
set_marker!
111117
```
112118
### Per-Symbol Metadata API
113119
```@docs

docs/src/metadata.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Special metadata:
1414
component (`vidx`) for vertices, `(;src,dst)` named tuple of either vertex
1515
names or vertex indices for edges. Has special accessors `has_/get_/set_graphelement`.
1616
- `:callback`: optional field to define callback functions on the component level. See [Callbacks](@ref) and [Callbacks API](@ref) for more information.
17+
- `:position`: Store a tuple `(x, y)` with position of the node for plotting. Has special accessors `has_/get_/set_position`.
18+
- `:marker`: Store a `Symbol` for the graph plot. Possible values could be `:circle`, `:rect`, `:utriangle`, `:cross`, `:diamond`, `:dtriangle`, `:pentagon`, `:xcross` or anything which works as a `marker` keyword argument in Makie.
1719

1820

1921
## Symbol Metadata

src/metadata.jl

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ for md in [:default, :guess, :init, :bounds]
5959

6060

6161
"""
62-
set_$($(QuoteNode(md)))(c::ComponentModel, sym::Symbol, value)
63-
set_$($(QuoteNode(md)))(nw::Network, sni::SymbolicIndex, value)
62+
set_$($(QuoteNode(md)))!(c::ComponentModel, sym::Symbol, value)
63+
set_$($(QuoteNode(md)))!(nw::Network, sni::SymbolicIndex, value)
6464
6565
Sets the `$($(QuoteNode(md)))` value for symbol `sym` to `value`.
6666
@@ -246,13 +246,40 @@ function get_defaults_or_inits(c::ComponentModel, syms; missing_val=nothing)
246246
[has_default_or_init(c, sym) ? get_default_or_init(c, sym) : missing_val for sym in syms]
247247
end
248248

249-
has_position(c::ComponentModel) = has_metadata(c, :position)
250-
get_position(c::ComponentModel) = get_metadata(c, :position)
251-
set_position!(c::ComponentModel, pos) = set_metadata!(c, :position, pos)
249+
# generate methods and docstrings for position and marker
250+
for md in [:position, :marker]
251+
fname_has = Symbol(:has_, md)
252+
fname_get = Symbol(:get_, md)
253+
fname_set = Symbol(:set_, md, :!)
254+
@eval begin
255+
"""
256+
has_$($(QuoteNode(md)))(v::VertexModel)
257+
258+
Checks if vertex `v` has `$($(QuoteNode(md)))` metadata.
259+
260+
See also: [`get_$($(QuoteNode(md)))`](@ref), [`set_$($(QuoteNode(md)))!`](@ref).
261+
"""
262+
$fname_has(c::VertexModel) = has_metadata(c, $(QuoteNode(md)))
263+
264+
"""
265+
get_$($(QuoteNode(md)))(v::VertexModel)
252266
253-
has_marker(c::ComponentModel) = has_metadata(c, :marker)
254-
get_marker(c::ComponentModel)::Symbol = get_metadata(c, :marker)
255-
set_marker!(c::ComponentModel, marker::Symbol) = set_metadata!(c, :marker, marker)
267+
Returns the `$($(QuoteNode(md)))` metadata of vertex `v`. Might error if not present.
268+
269+
See also: [`has_$($(QuoteNode(md)))`](@ref), [`set_$($(QuoteNode(md)))!`](@ref).
270+
"""
271+
$fname_get(c::VertexModel) = get_metadata(c, $(QuoteNode(md)))
272+
273+
"""
274+
set_$($(QuoteNode(md)))!(v::VertexModel, val)
275+
276+
Sets the `$($(QuoteNode(md)))` metadata of vertex `v` to `val`.
277+
278+
See also: [`has_$($(QuoteNode(md)))`](@ref), [`get_$($(QuoteNode(md)))`](@ref).
279+
"""
280+
$fname_set(c::VertexModel, val) = set_metadata!(c, $(QuoteNode(md)), val)
281+
end
282+
end
256283

257284
####
258285
#### Extract initial state from component

0 commit comments

Comments
 (0)