Configures interaction behaviors for a G6 graph visualization. This function collects and combines multiple behavior configurations into a list that can be passed to graph initialization functions.
Arguments
- graph
A g6 graph instance.
- ...
Behavior configuration objects created by behavior-specific functions. These can include any of the following behaviors:
Navigation behaviors:
drag_canvas()- Drag the entire canvas viewzoom_canvas()- Zoom the canvas viewscroll_canvas()- Scroll the canvas using the wheeloptimize_viewport_transform()- Optimize view transform performance
Selection behaviors:
click_select()- Click to select graph elementsbrush_select()- Select elements by dragging a rectangular arealasso_select()- Freely draw an area to select elements
Editing behaviors:
create_edge()- Interactively create new edgesdrag_element()- Drag nodes or combosdrag_element_force()- Drag nodes in force-directed layout
Data Exploration behaviors:
collapse_expand()- Expand or collapse subtree nodesfocus_element()- Focus on specific elements and automatically adjust the viewhover_activate()- Highlight elements when hovering
Visual Optimization behaviors:
fix_element_size()- Fix the element size to a specified valueauto_adapt_label()- Automatically adjust label position
Note
You can create custom behaviors from JavaScript and use them on the R side. See more at https://g6.antv.antgroup.com/en/manual/behavior/custom-behavior.
Examples
# Create a basic set of behaviors
behaviors <- g6_behaviors(
g6(),
drag_canvas(),
zoom_canvas(),
click_select()
)
# Create a more customized set of behaviors
behaviors <- g6_behaviors(
g6(),
drag_canvas(),
zoom_canvas(sensitivity = 1.5),
hover_activate(state = "highlight"),
fix_element_size(
node = list(
list(shape = "circle", fields = c("r", "lineWidth"))
)
)
)