Changelog
Source:NEWS.md
g6R 0.6.0.9000
Breaking changes
- Not a g6R change but bslib recently introduced the
toolbar()function which unfortunately overlaps with the g6R one. From now, you’ll have to useg6R::toolbar()to avoid conflicts. In later releases, we’ll provide more prefixed functions likeg6_toolbar.
New feature
- Added new
collapseparameter to nodes. This will only work if you use any of thecustom-*-nodenode types (see below). Now if a node haschildren(vector of character node IDs), it can be collapsed or uncollapsed.collapseaccepts a list of options viag6_collapse_options(). When a node haschildrenset (character vector/list of node IDs expected), an optiong6R.directed_graphis set to TRUE so that, when a connection is created between 2 nodes, we automatically establish parent/child relation and inversely when an edge or node is removed. You can also manually opt-in for this setup by settingoptions(g6R.directed_graph = TRUE). Importantly, the parent/child relations are only maintained if you use the g6R proxy functions. Using the direct JS G6 API yourself (like withgraph.removeEdgeData(...)won’t do anything to keep the tree state in sync! Theset_g6_max_collapse_depth()option controls which nodes display a collapse button based on their depth in the graph. Only nodes at depth<= maxCollapseDepthshow collapse buttons. Defaults toInf(all nodes with children are collapsible). Set to0to restrict collapsing to root nodes only. Set to-1to disable collapsing entirely (collapse buttons are removed even wheng6_collapse_options()is provided and nodes have children).
g6_node(
id = 1,
type = "custom-rect-node", # to enable use custom class
children = c(2, 3),
collapse = g6_collapse_options(collapsed = TRUE)
)- Added new
collapseparameter tog6_combo(). Acceptsg6_collapse_options()just like nodes. Whencollapseis provided andtypeis NULL, the combo type is automatically set to"rect-combo-with-extra-button". The combo collapse button now supports all the same configuration as nodes: configurableplacement,r,fill,stroke,iconStroke,visibility(including"hover"mode), etc.
g6_combo(
"combo1",
collapse = g6_collapse_options(
placement = "bottom",
fill = "#f0f0f0",
visibility = "hover"
)
)bubble_sets()andhull()now automatically setpointerEvents = "none"andzIndex = -1by default. This fixes two issues when using the SVG renderer: overlay shapes no longer block pointer events (drag, click) on nodes, and they render behind nodes so they don’t visually cover collapse buttons or other node UI. These defaults can be overridden by passing explicit values.Overlay plugins (
bubble_sets(),hull()) now resize dynamically when nodes are collapsed or uncollapsed. Hidden members are temporarily removed from the overlay shape and restored when expanded again.New
rect-combo-with-extra-buttoncombo type, the rectangular counterpart ofcircle-combo-with-extra-button.
Bug fixes
Fixed
hull()label not displaying: the defaultlabelMaxWidthwas0, which caused G6 to ellipsize the label to zero width. Changed default toNULL(consistent withbubble_sets()).Fixed port
+indicators incorrectly showing on at-capacity ports during node selection or drag. G6’s internalsetVisibility()call during update was making all child shapes visible, and the cleanup was skipped when the cursor was hovering the node. Now the capacity-aware port logic is re-applied during updates while hovering.Improvements to how
drag_element()anddrag_element_force()work withcreate_edge(). Now, thecreate_edge()can bedragand work withdrag_element()as we handle the behavior conflicts/priorities JS side.input[["<graph_ID>-state"]]now does not return unnamed lists for nodes, edges and combos. Instead, each sublist is named with the corresponding element IDs. This makes it easier to retrieve the state of a specific element when we know the ID.-
Added better port support for nodes ports:
- To enable it, you must pass a custom type to
g6_node()such ascustom-circle-node,custom-rect-node(We support 9 shapes, except HTML which does not handle port in the g6 library) -
g6_node()get a newportsargument to define ports for each node. In the g6 JS library, ports are normally defined insidestylebut we consider they are too important to be hidden there. Now you can define ports directly in the node data, g6R automatically moves them tostyle.portswhen rendering the graph. - New
g6_port()function to create ports easily and wrap them insideg6_ports(). A port has a unique key, an arity that is the number of connections it can make or take and other style parameters inherited from g6. When giving a key to a port, don’t worry if key names collide between nodes, g6R automatically makes them unique by prefixing them with the node ID on the JS side. - 2 kind of ports have been designed:
-
input ports (
g6_input_port()): they can only be the target of an edge. -
output ports (
g6_output_port()): they can only be the source of an edge.
-
input ports (
- When creating edges, if you provide
sourcePortand/ortargetPortwithin thestylelist, the edge will be connected to the corresponding ports. Validation is made so we don’t connect incompatible ports (e.g. connecting an output port to another output port) or connecting a port to itself. -
create_edge()behavior was improved to work better with ports. For instance, you can’t drag from a port that is already at its arity limit. You can’t drag from a node if it has ports (drag from the ports instead). - Ports gain a
labelparameter to display text on the port. - In a Shiny context,
showGuidesallows to display connection guides when hovering over a port. Combined withinput[["<GRAPH_ID>-selected_port"]]andinput[["<graph_ID>-mouse_position"]], this allows to add and connect nodes on the fly at the guide location. - Use
g6_update_ports()to update port (3 possible actions: remove/add/update) ports of existing nodes. - Use
g6_get_ports()to get the ports of existing nodes. Specifically, you can callg6_get_input_ports()andg6_get_output_ports()to get only input or output ports respectively. This are only convenience functions.
- To enable it, you must pass a custom type to
g6R 0.5.0
CRAN release: 2025-12-09
Potential breaking changes
Due to the new data validation for nodes, edges and combos, some existing code might break if the data provided to g6R functions is not valid. See the corresponding documentation section. If you had to pass custom data you can do it in the data slot.
New features and fixes
- Support for svg rendering:
g6_options(renderer = JS("() => new SVGRenderer()"))- Fix issue which was preventing from removing a node from a combo.
- Layout is not recomputed when calling data proxy functions, except if
options("g6R.layout_on_data_change" = TRUE). In the later case, the layout is recomputed after drawing. - New option
g6R.preserve_elements_position. If TRUE, and only ifg6_options(animation = FALSE), the elements (nodes and combos) coordinates are preserved when updating the layout to avoid elements from jumping to new positions. Default is FALSE. A warning is raised if this option is TRUE and animation is TRUE to tell the user that the option will be ignored. - New
g6_update_layout()proxy function to order the layout re-execution and optionally update its parameters. - New
input[["<graph_ID>-mouse_position"]]: any click/right click or drag release event captures the mouse position.input[["<graph_ID>-mouse_position"]]contains the x and y coordinates of the mouse relative to the canvas. This is useful to add a node where the mouse was clicked, a context menu was triggered or the create edge was released on the canvas without a specific target. - Elements selected via
brush_select()orlasso_select()have a custom input handler. This may give:
Notice the extra attribute, which allows to make a difference between click_select() and brush_select() events.
- Get correct element type on click: it was possible that when clicking a combo, it appeared under
input$<graph_ID>-selected_nodeinstead ofinput$<graph_ID>-selected_combo. -
create_edge()behavior improved: when creating an edge and it is release on the canvas, the edge isn’t cancelled and data are available. We added atargetTypeproperty which allows to know where the edge was dropped. - Added new elements API:
g6_node(),g6_edge(),g6_combo()to create nodes, edges and combos respectively. We suggest to use them instead of passing lists or dataframes to g6 as they provide safety checks. We also addedg6_nodes(),g6_edges()andg6_combos()which are internally used by some proxy functions likeg6_add_nodes()to provide more flexibility. - New
options("g6R.mode)that can bedevorprod(default). Indevmode, Shiny notifications are displayed in the UI whenever a JavaScript error happens (they are still available in the JS console). -
g6_focus_elements(),g6_hide_elements()andg6_show_elements()gain more specific siblings:g6_focus_nodes(),g6_focus_edges(),g6_focus_combos(),g6_hide_nodes(),g6_hide_edges(),g6_hide_combos(),g6_show_nodes(),g6_show_edges(),g6_show_combos(). -
brush_select(),lasso_select()andcreate_edge()gain anoutputIdparameter which allows to manually pass the Shiny output ID of the graph instance. This is useful when the graph is initialised outside the shiny render function and the ID cannot be automatically inferred withshiny::getCurrentOutputInfo(). This allows to set input values from the callback function with the right namespace and graph ID. You must typically passsession$ns("graphid")to ensure this also works in modules. - Improvements to
brush_select(): now it correctly returns the list of selected nodes, edges and combos, available viainput$<graph_ID>-selected_node,input$<graph_ID>-selected_edgeandinput$<graph_ID>-selected_combo, thanks to the internal IDs refactoring. After a brush select operation, you can now shift click (depending on theclick_select()multiple selection trigger settings you set, it might be another key) to add/remove elements to/from the current selection. -
lasso_select()also gets the same quality of life improvements. - Fix: when selecting (simple select not multiselect) an edge/node/combo, if another type of element was selected, the corresponding input is reset. This avoids to accidentally delete a previously selected element when another type of element is selected.
- Fix: state never get set on first render.
- Fix #23: graph has to be re-rendered after dynamic plugin addition so that new elements like
hullare drawn. - Fix #22: internal typo in JS function when an error was caught in the graph.
- Add
input$<graph_ID>-contextmenuto extract the type and id of element which was clicked in the context menu. This can be listened to from the Shiny server function. - Fix layout and behavior issues in some examples:
drag_element_forceonly works whenanimationis TRUE. Also addedautoFit = TRUEwherever required (manual layout vignette).