sigmajs
lets you add buttons to trigger events, in static documents.
A button to export the graph as SVG, not that you can export to an image (png, jpeg, gif or tiff).
nodes <- sg_make_nodes()
edges <- sg_make_edges(nodes)
sigmajs() %>%
sg_nodes(nodes, id, size, color) %>%
sg_edges(edges, id, source, target) %>%
sg_layout() %>%
sg_export_svg() %>%
sg_button(
"<i class='fa fa-download'></i>",
"export_svg", # event to trigger
class = "btn btn-default"
)
You can also trigger mutliple events with the button by passing a vector of events to event
. Below we add a button that will start the forceAtlas2 layout and stop it after 3 seconds.
sigmajs() %>%
sg_nodes(nodes, id, size, color) %>%
sg_edges(edges, id, source, target) %>%
sg_force_start() %>%
sg_force_stop(3000) %>%
sg_button(
"<i class='fa fa-play'></i> Layout", # only use icon if document imports fontawesome
c("force_start", "force_stop"),
class = "btn btn-success"
)
Events that can be triggered via a button (corresponding function name minus sg_
):
force_start
force_stop
noverlap
drag_nodes
relative_size
add_nodes
add_edges
add_nodes_edges
drop_nodes
drop_edges
animate
export_svg
export_img
You will examples of the above scattered throughout the documentation.