# Create a configuration with multiple plugins
plugins <- g6_plugins(
g6(),
minimap(),
grid_line(),
tooltips(
getContent = JS("(e, items) => {
return `${items[0].id}`;
}")
)
)
# Add a context menu and toolbar
plugins <- g6_plugins(
g6(),
context_menu(
key = "my-context-menu",
className = "my-context-menu",
trigger = "click",
offset = c(10, 10),
getItems = JS("(event) => {
const type = event.itemType;
const isNode = type === 'node';
return [
{ key: 'delete', text: 'Delete' },
{ key: 'edit', text: 'Edit' },
{ key: 'details', text: 'View Details', disabled: !isNode }
];
}"),
onClick = JS("(value, target, current) => {
if (value === 'delete') {
// do stuff
}")
),
toolbar(
position = "top-right",
getItems = JS("() => [
{ id: 'zoom-in', value: 'zoom-in' },
{ id: 'zoom-out', value: 'zoom-out' },
{ id: 'fit', value: 'fit' }
]"),
onClick = JS("(value) => {
if (value === 'zoom-in') graph.zoomTo(1.1);
else if (value === 'zoom-out') graph.zoomTo(0.9);
else if (value === 'fit') graph.fitView();
}")
)
)
Run the code above in your browser using DataLab