Plots
Visualization is not the main focus of Vahana, but two rudimentary auxiliary functions exist for creating plots with Makie.
Vahana.plot_globals
— Functionplot_globals(sim, names::Vector{Symbol})
Creates a Makie lineplot with one line for each global in names
, wherby those global values must be Vectors (or Iterable).
Returns figure, axis, plots. plots
is a vector of Plots, which one plot for element of names
.
plot_globals
is only available when a Makie backend is imported by the client.
See also push_global!
, get_global
Vahana.create_graphplot
— Functioncreate_graphplot(sim; [agenttypes, edgetypes, update_fn, pos_jitter])
Creates an interactive Makie plot for the the simulation sim
.
The graph can be restricted to a subgraph with the given agentypes
and edgestatetypes
, see vahanagraph
for details.
To modify the properties of the edges and agents a update_fn
can be defined. This function is called for each agent and edge (of types in agenttypes and edgetypes) and must have for agents the signature
f(state, id, vp::VahanaPlot)
and for edges
f(state, source, target, vp::VahanaPlot)
The arguments of this functions are state
for the agent or edgestate, ID for the id
of the agent called, from
and to
for the ID of the agents at the source or target of the edge. vp
is the struct returned by create_graphplot
and can be used to determine the id of last clicked agent by calling clicked_agent(vp)
. The function must return a Dict with property names (as Symbol) as keys and their values as values. The following properties are available: node_pos
, node_color
, node_size
, node_marker
, nlabels
, nlabels_align
, nlabels_color
, nlabels_distance
, nlabels_offset
, nlabels_textsize
, edge_color
, edge_width
, elables
, elables_align
, elables_color
, elables_distance
, elables_offset
, elables_rotation
, elables_shift
, elables_side
, elabes_textsize
, arrow_shift
, and arrow_size
.
In the case that creategraphplot is not called from a parallel simulation, it is possible to call inside `updatefnfunctions that are normally only available inside of a transition function (like [
agentstate](@ref), [
neighborstates`](@ref) etc.).
The pos_jitter
argument must be a dictonary of agentstypes to float values. The node positions will be then (x + rand() * jitter - jitter/2, y + rand() * jitter - jitter/2).
The edge_plottype
keyword is forwarded to GraphMakie.graphplot.
Returns a VahanaPlot structure that can be used to access the Makie figure, axis and plot via call to the methods figure
, axis
and plot
with this struct as (single) argument.
create_graphplot
is only available when the GraphMakie package and a Makie backend is imported by the client.
For the mouse click and hover interaction, the current state of the simulation used to construct the VahanaGraph is accessed. In the case that a transition function is called after the construction of the VahanaGraph, and this transition function modifies the structure of the Graph (add/removes nodes or edges), then this changes are not reflected by the current implementation and can cause errors.
See also vahanagraph