layout({ nodes: nodes, edges: edges }).then(({ nodes, edges }) => {
const { x, y, zoom } = trellis.boundsToViewport(
trellis.getSelectionBounds(nodes, 40),
{ width: width, height: 600 }
)
const options = {
x,
y,
zoom,
width: width,
height: 600,
onNodeDrag: ({ nodeX: x, nodeY: y, target: { id } }) => {
nodes = nodes.map((node) => node.id === id ? { ...node, x, y } : node)
render({ nodes, edges, options })
},
onNodePointerEnter: ({ target }) => {
nodes = nodes.map((node) => target.id === node.id ? {
...node,
style: {
...node.style,
stroke: [...node.style.stroke, { color: '#ccc', width: 2 }]
}
} : node)
render({ nodes, edges, options })
},
onNodePointerLeave: ({ target }) => {
nodes = nodes.map((n) => target.id === n.id ? ({ ...n, style: styleNode(n.count) }) : n)
render({ nodes, edges, options })
}
}
render({ nodes, edges, options })
})