Layout API Reference

This page documents the layout computation, timeline visualization, and filmstrip functions in NDTV.jl.

Animation

NDTV.render_animation — Function
render_animation(dnet::DynamicNetwork; algorithm=FRLayout(), n_frames=nothing,
                 onset=nothing, terminus=nothing, slice=:interval, rule=:any,
                 interpolation=:linear, rng=...)

Compute layout positions for animating a dynamic network (R ndtv's compute.animation). The frames cover n_frames equal, contiguous slices of a time range; with slice=:interval (default, as R's aggregate.dur equal to the interval) frame k shows everything active during its slice under rule, so spells shorter than the frame spacing are not lost; slice=:instant shows the network at each slice onset.

  • With an observation window (DynamicNetworks' get_observation_period), or with explicit onset and terminus, the range is [onset, terminus), cut into half-open slices; no frame sits on its end, where every half-open spell has ended.
  • Without a window, the range is the closed range [first, last] of the change times (get_change_times), as ndtv's default slice.par takes it: the slices are spaced (last - first)/(n_frames - 1) apart and the last one starts at the last change time, so a tie that forms then is drawn. Either end can be overridden with onset/terminus. A network with neither a window nor a finite spell bound raises an ArgumentError asking for one (ndtv would animate the placeholder range (0, 1)).

Number of frames. n_frames defaults to 100 on a floating-point time axis. A discrete axis (integer, Date, DateTime) has a smallest step (1, a day, a millisecond); there the default is 100 frames or one per step, whichever is fewer, so a panel built with an integer start gets one frame per wave, as ndtv's interval = 1 gives. On a discrete axis every slice bound is a whole number of steps from the start: when the range does not divide into n_frames equal slices, the bounds are rounded and the slices differ in length by one step at most, staying contiguous so that no activity falls between two frames. Asking for more frames than the range has steps raises an ArgumentError.

Works for any DynamicNetworks time type (including Int, Date and DateTime). Returns a DynamicLayout (interpolation = :linear or :none) or an InterpolatedLayout (interpolation = :ease).

Example

using NDTV, DynamicNetworks, NetworkCore, Random
dnet = DynamicNetwork(3)                         # no explicit window
activate!(dnet, 0.0, 4.0; edge=(1, 2))
activate!(dnet, 4.0, Inf; edge=(2, 3))           # forms at the last change time
dl = render_animation(dnet; n_frames=3, rng=Xoshiro(1))
dl.times                                         # [0.0, 2.0, 4.0]: closed range
dl.frame_edges[end]                              # [(2, 3)]

panel = [network(3) for _ in 1:3]                # three waves on an integer axis
add_edge!(panel[1], 1, 2); add_edge!(panel[3], 2, 3)
waves = DynamicNetwork(panel; start=1)           # waves at [1,2), [2,3), [3,4)
render_animation(waves; rng=Xoshiro(1)).times    # [1, 2, 3]: one frame per wave
source
NDTV.compute_animation_layout — Function
compute_animation_layout(dnet; kwargs...)

Alias of render_animation, after R ndtv's compute.animation.

Example

using NDTV, DynamicNetworks, Random
dnet = DynamicNetwork(2; observation_start=0.0, observation_end=2.0)
activate!(dnet, 0.0, 2.0; edge=(1, 2))
length(compute_animation_layout(dnet; n_frames=2, rng=Xoshiro(1)))   # 2
source

Layout Computation

NDTV.compute_slice_layout — Function
compute_slice_layout(dnet::DynamicNetwork, time; algorithm=FRLayout(),
                     rng=...) -> Dict

Layout of the network active at time, keyed by the dynamic network's stable vertex IDs. Structural layouts (FRLayout, MDSLayout) place only the vertices active at time (inactive vertices are not laid out and have no entry); CircleLayout and RandomLayout place every vertex. Vertices with no spells are active (DynamicNetworks' active_default).

Example

using NDTV, DynamicNetworks, Random
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 5.0; vertex=3)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
sort(collect(keys(compute_slice_layout(dnet, 7.0; rng=Xoshiro(1)))))   # [1, 2]
source
NDTV.layout_sequence — Function
layout_sequence(dnet::DynamicNetwork, times; termini=nothing, rule=:any,
                algorithm=FRLayout(), anchor=true, rng=...) -> DynamicLayout

Layouts for a sequence of slices. Slice k is the instant times[k], or, when termini is given, the interval [times[k], termini[k]) under rule (:any — R ndtv's aggregated slices — or :all).

Structural layouts (FRLayout, MDSLayout) are computed on the vertices active in the slice only, so an inactive vertex never pulls the active ones around. Every frame still holds a position for every vertex: an inactive vertex keeps its last position (or, before it first appears, its first one) and is not drawn. With anchor=true (default) each frame is seeded from the previous frame's positions — matched by stable vertex ID — so vertices move smoothly. Per-frame active vertices and edges are recorded for rendering.

Example

using NDTV, DynamicNetworks, Random
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 5.0; edge=(1, 2))
activate!(dnet, 5.0, 10.0; edge=(2, 3))
dl = layout_sequence(dnet, [1.0, 6.0]; rng=Xoshiro(1))
dl.frame_edges                 # [[(1, 2)], [(2, 3)]]
source
NDTV.compute_layout — Function
compute_layout(net::Network, algorithm; rng=Random.default_rng())
    -> Dict{T, Tuple{Float64, Float64}}

Compute a static layout of every vertex of net, keyed by its vertex IDs. algorithm is an FRLayout, MDSLayout, CircleLayout or RandomLayout; randomness comes only from rng.

Example

using NDTV, NetworkCore, Random
net = network(5); add_edge!(net, 1, 2); add_edge!(net, 2, 3)
pos = compute_layout(net, FRLayout(); rng=Xoshiro(3))
sort(collect(keys(pos)))       # [1, 2, 3, 4, 5]
source
NDTV.get_position — Function
get_position(layout::InterpolatedLayout, vertex, time) -> Tuple{Float64, Float64}

Interpolated position of a (stable-ID) vertex at any time point. Works for any time type supporting subtraction with / (numbers, DateTime). Times before the first frame (after the last) return the first (last) frame's position.

Example

using NDTV
base = DynamicLayout([Dict(1 => (0.0, 0.0)), Dict(1 => (1.0, 2.0))], [0.0, 1.0])
get_position(InterpolatedLayout(base), 1, 0.5)   # (0.5, 1.0)
source

Timeline Visualization

NDTV.timeline_plot — Function
timeline_plot(dnet::DynamicNetwork; width=60, onset=nothing, terminus=nothing, io=stdout)

ASCII timeline of vertex and edge activity spells over the window [onset, terminus]: by default the observation window or, when none is set, the range of the change times (get_change_times); a network with neither raises an ArgumentError unless both bounds are given. Open-ended spells run to the window edge; elements with no spells are active throughout. Edges are labelled i→j on directed networks and i—j on undirected ones.

Example

using NDTV, DynamicNetworks
dnet = DynamicNetwork(2; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 5.0; edge=(1, 2))
timeline_plot(dnet; width=20)
source
NDTV.ego_timeline — Function
ego_timeline(dnet::DynamicNetwork, vertex; width=60, io=stdout)

Ego-centric ASCII timeline: activity spells of all edges incident to vertex, marked →/← (out/in) on directed networks and — on undirected ones, over the range timeline_plot uses.

Not R ndtv's proximity.timeline, a different display (vertex positions from an MDS of geodesic distances drawn as lines over time), which is not ported.

Example

using NDTV, DynamicNetworks
dnet = DynamicNetwork(3; directed=false, observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 5.0; edge=(1, 2))
ego_timeline(dnet, 1; width=20)
source
NDTV.transmission_timeline — Function
transmission_timeline(dnet::DynamicNetwork, transmissions; width=60, io=stdout)

ASCII timeline marking transmission events (from, to, time) over the observation window or, when none is set, over the range of the change times and the transmission times.

Not R ndtv's transmissionTimeline, which draws a transmission tree (generation against time) from a tEdgeList; this text display only marks when each transmission happened.

Example

using NDTV, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
transmission_timeline(dnet, [(1, 2, 2.0), (2, 3, 6.0)]; width=20)
source
NDTV.timeline_data — Function
timeline_data(dnet::DynamicNetwork) -> NamedTuple

Vertex and edge activity spells as two vectors of named tuples ((vertex, onset, terminus) and (source, target, onset, terminus)), sorted by element. Elements with no spells are reported as active over (-Inf, Inf) (DynamicNetworks' get_vertex_activity/get_edge_activity).

Example

using NDTV, DynamicNetworks
dnet = DynamicNetwork(2; observation_start=0.0, observation_end=10.0)
activate!(dnet, 1.0, 3.0; edge=(1, 2))
td = timeline_data(dnet)
td.edges[1]                    # (source = 1, target = 2, onset = 1.0, terminus = 3.0)
source

Filmstrip

NDTV.filmstrip — Function
filmstrip(dnet::DynamicNetwork, times; termini=nothing, rule=:any,
          algorithm=FRLayout(), rng=...) -> Vector{NamedTuple}

Layout frames at the given times (or slices [times[k], termini[k])) for filmstrip (small-multiples) display, after R ndtv's filmstrip. Each frame is a named tuple (time, positions, active, edges, n_vertices, n_edges): positions keyed by stable ID, the active vertex set, the active edges, and their counts. The vector is concretely typed.

Example

using NDTV, DynamicNetworks, Random
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 5.0; edge=(1, 2))
fs = filmstrip(dnet, [1.0, 6.0]; rng=Xoshiro(1))
[f.n_edges for f in fs]        # [1, 0]
source
NDTV.slice_layout — Function
slice_layout(dnet::DynamicNetwork, onset, terminus; n_slices=nothing, slice=:interval,
             rule=:any, algorithm=FRLayout(), rng=...)

Filmstrip frames for n_slices equal, contiguous slices of [onset, terminus); with slice=:interval (default) each frame shows what was active during its slice under rule, with slice=:instant the network at each slice onset.

n_slices defaults to 5, or, on a discrete time axis (integer, Date, DateTime), to one slice per step when the range has fewer than 5 steps. On a discrete axis the slice bounds are rounded to whole steps, as described under render_animation.

Example

using NDTV, DynamicNetworks, Random
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 5.0; edge=(1, 2))
fs = slice_layout(dnet, 0.0, 10.0; n_slices=2, rng=Xoshiro(1))
[f.time for f in fs], [f.n_edges for f in fs]   # ([0.0, 5.0], [1, 0])
source