Usage guidesInteraction
Click to select
Click a node or edge to toggle selection. Click empty canvas to clear it.
Click a node or edge to toggle selection. Click empty canvas to clear it.
Configuration
With multiple enabled, hold the key named by trigger while clicking to add to the selection.
Example
const behaviors: BehaviorOption[] = [{ type: 'click-select', multiple: true, trigger: 'shift' }];import { Graph, type BehaviorOption } from '@antv/g6-lite';
export async function run(container: HTMLElement) {
// #region behavior-config
const behaviors: BehaviorOption[] = [{ type: 'click-select', multiple: true, trigger: 'shift' }];
// #endregion behavior-config
const graph = new Graph({
container,
data: {
nodes: [
{ id: 'A', x: 0, y: 0 },
{ id: 'B', x: 120, y: -65 },
{ id: 'C', x: 120, y: 65 },
{ id: 'D', x: 240, y: 0 },
{ id: 'E', x: 360, y: 0 },
],
edges: [
{ id: 'A-B', source: 'A', target: 'B' },
{ id: 'A-C', source: 'A', target: 'C' },
{ id: 'B-D', source: 'B', target: 'D' },
{ id: 'C-D', source: 'C', target: 'D' },
{ id: 'D-E', source: 'D', target: 'E' },
],
},
node: {
style: { size: 30, label: (node) => node.id, labelOffsetY: 8 },
stateStyles: { selected: { fill: '#8050d2', haloWidth: 10 } },
},
edge: {
style: { lineWidth: 2, hitAreaWidth: 14, endArrow: false },
stateStyles: { selected: { stroke: '#8050d2', lineWidth: 4 } },
},
behaviors,
autoFit: { padding: 48, maxZoom: 1 },
});
try {
await graph.render();
return graph;
} catch (error) {
graph.destroy();
throw error;
}
}